/* global tinymce */ (function() { var mouse = {}; tinymce.create('tinymce.plugins.wpEditImage', { url: '', editor: {}, init: function(ed, url) { var t = this; t.url = url; t.editor = ed; t._createButtons(); ed.addCommand('WP_EditImage', t._editImage); ed.onInit.add(function(ed) { ed.dom.events.add(ed.getBody(), 'mousedown', function(e) { var parent; if ( e.target.nodeName == 'IMG' && ( parent = ed.dom.getParent(e.target, 'div.mceTemp') ) ) { if ( tinymce.isGecko ) ed.selection.select(parent); else if ( tinymce.isWebKit ) ed.dom.events.prevent(e); } }); // when pressing Return inside a caption move the caret to a new parapraph under it ed.dom.events.add(ed.getBody(), 'keydown', function(e) { var n, DL, DIV, P; if ( e.keyCode == 13 ) { n = ed.selection.getNode(); DL = ed.dom.getParent(n, 'dl.wp-caption'); if ( DL ) DIV = ed.dom.getParent(DL, 'div.mceTemp'); if ( DIV ) { ed.dom.events.cancel(e); P = ed.dom.create('p', {}, '\uFEFF'); ed.dom.insertAfter( P, DIV ); ed.selection.setCursorLocation(P, 0); return false; } } }); // iOS6 doesn't show the buttons properly on click, show them on 'touchstart' if ( 'ontouchstart' in window ) { ed.dom.events.add(ed.getBody(), 'touchstart', function(e){ t._showButtons(e); }); } }); // resize the caption
)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:<\/p>)?/g, function(a,b,c){
var id, cls, w, cap, div_cls, img, trim = tinymce.trim;
id = b.match(/id=['"]([^'"]*)['"] ?/);
if ( id )
b = b.replace(id[0], '');
cls = b.match(/align=['"]([^'"]*)['"] ?/);
if ( cls )
b = b.replace(cls[0], '');
w = b.match(/width=['"]([0-9]*)['"] ?/);
if ( w )
b = b.replace(w[0], '');
c = trim(c);
img = c.match(/((?:]+>)?]+>(?:<\/a>)?)([\s\S]*)/i);
if ( img && img[2] ) {
cap = trim( img[2] );
img = trim( img[1] );
} else {
// old captions shortcode style
cap = trim(b).replace(/caption=['"]/, '').replace(/['"]$/, '');
img = c;
}
id = ( id && id[1] ) ? id[1] : '';
cls = ( cls && cls[1] ) ? cls[1] : 'alignnone';
w = ( w && w[1] ) ? w[1] : '';
if ( !w || !cap )
return c;
div_cls = 'mceTemp';
if ( cls == 'aligncenter' )
div_cls += ' mceIEcenter';
w = parseInt( w, 10 ) + 10;
return '
]+)>\s*
cap = cap.replace(/\s*\n\s*/g, '
');
return '[caption id="'+id+'" align="'+cls+'" width="'+w+'"]'+c+' '+cap+'[/caption]';
});
if ( ret.indexOf('[caption') !== 0 ) {
// the caption html seems brocken, try to find the image that may be wrapped in a link
// and may be followed by