]+>([\s\S]*?)<\/dd>\s*<\/dl>/gi, function(a,b,c,cap){
var id, cls, w;
w = c.match(/width="([0-9]*)"/);
w = ( w && w[1] ) ? w[1] : '';
if ( !w || !cap )
return c;
id = b.match(/id="([^"]*)"/);
id = ( id && id[1] ) ? id[1] : '';
cls = b.match(/class="([^"]*)"/);
cls = ( cls && cls[1] ) ? cls[1] : '';
cls = cls.match(/align[a-z]+/) || 'alignnone';
cap = cap.replace(/\r\n|\r/g, '\n').replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){
// no line breaks inside HTML tags
return a.replace(/[\r\n\t]+/, ' ');
});
// convert remaining line breaks to
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 with the caption text.
ret = b.replace(/[\s\S]*?((?:]+>)?
]+>(?:<\/a>)?)([\s\S]*<\/p>)?[\s\S]*/gi, '
$1
$2');
}
return ret;
});
},
_createButtons : function() {
var t = this, ed = tinymce.activeEditor, DOM = tinymce.DOM, editButton, dellButton, isRetina;
if ( DOM.get('wp_editbtns') )
return;
isRetina = ( window.devicePixelRatio && window.devicePixelRatio > 1 ) || // WebKit, Opera
( window.matchMedia && window.matchMedia('(min-resolution:130dpi)').matches ); // Firefox, IE10, Opera
DOM.add(document.body, 'div', {
id : 'wp_editbtns',
style : 'display:none;'
});
editButton = DOM.add('wp_editbtns', 'img', {
src : isRetina ? t.url+'/img/image-2x.png' : t.url+'/img/image.png',
id : 'wp_editimgbtn',
width : '24',
height : '24',
title : ed.getLang('wpeditimage.edit_img')
});
tinymce.dom.Event.add(editButton, 'mousedown', function(e) {
t._editImage();
ed.plugins.wordpress._hideButtons();
});
dellButton = DOM.add('wp_editbtns', 'img', {
src : isRetina ? t.url+'/img/delete-2x.png' : t.url+'/img/delete.png',
id : 'wp_delimgbtn',
width : '24',
height : '24',
title : ed.getLang('wpeditimage.del_img')
});
tinymce.dom.Event.add(dellButton, 'mousedown', function(e) {
var ed = tinymce.activeEditor, el = ed.selection.getNode(), parent;
if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('mceItem') == -1 ) {
if ( (parent = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(parent, 'mceTemp') ) {
ed.dom.remove(parent);
} else {
if ( el.parentNode.nodeName == 'A' && el.parentNode.childNodes.length == 1 )
el = el.parentNode;
if ( el.parentNode.nodeName == 'P' && el.parentNode.childNodes.length == 1 )
el = el.parentNode;
ed.dom.remove(el);
}
ed.execCommand('mceRepaint');
return false;
}
ed.plugins.wordpress._hideButtons();
});
},
_editImage : function() {
var ed = tinymce.activeEditor, url = this.url, el = ed.selection.getNode(), vp, H, W, cls = el.className;
if ( cls.indexOf('mceItem') != -1 || cls.indexOf('wpGallery') != -1 || el.nodeName != 'IMG' )
return;
vp = tinymce.DOM.getViewPort();
H = 680 < (vp.h - 70) ? 680 : vp.h - 70;
W = 650 < vp.w ? 650 : vp.w;
ed.windowManager.open({
file: url + '/editimage.html',
width: W+'px',
height: H+'px',
inline: true
});
},
_showButtons : function(e) {
var ed = this.editor, target = e.target;
if ( target.nodeName != 'IMG' ) {
if ( target.firstChild && target.firstChild.nodeName == 'IMG' && target.childNodes.length == 1 ) {
target = target.firstChild;
} else {
ed.plugins.wordpress._hideButtons();
return;
}
}
if ( ed.dom.getAttrib(target, 'class').indexOf('mceItem') == -1 ) {
mouse = {
x: e.clientX,
y: e.clientY,
img_w: target.clientWidth,
img_h: target.clientHeight
};
if ( e.type == 'touchstart' ) {
ed.selection.select(target);
ed.dom.events.cancel(e);
}
ed.plugins.wordpress._hideButtons();
ed.plugins.wordpress._showButtons(target, 'wp_editbtns');
}
},
getInfo : function() {
return {
longname : 'Edit Image',
author : 'WordPress',
authorurl : 'http://wordpress.org',
infourl : '',
version : "1.0"
};
}
});
tinymce.PluginManager.add('wpeditimage', tinymce.plugins.wpEditImage);
})();