2008-06-10 06:40:21 +02:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
tinymce.create('tinymce.plugins.wpEditImage', {
|
|
|
|
|
|
|
|
init : function(ed, url) {
|
|
|
|
var t = this;
|
|
|
|
|
|
|
|
t.url = url;
|
|
|
|
t._createButtons();
|
|
|
|
|
|
|
|
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
|
|
|
|
ed.addCommand('WP_EditImage', function() {
|
2008-08-20 23:42:31 +02:00
|
|
|
var el = ed.selection.getNode(), vp = tinymce.DOM.getViewPort(), H = vp.h, W = ( 720 < vp.w ) ? 720 : vp.w;
|
2008-11-23 07:37:15 +01:00
|
|
|
var cls = ed.dom.getAttrib(el, 'class');
|
2008-06-10 06:40:21 +02:00
|
|
|
|
2008-11-23 07:37:15 +01:00
|
|
|
if ( cls.indexOf('mceItem') != -1 || cls.indexOf('wpGallery') != -1 || el.nodeName != 'IMG' )
|
2008-06-10 06:40:21 +02:00
|
|
|
return;
|
|
|
|
|
2008-11-14 03:35:02 +01:00
|
|
|
tb_show('', url + '/editimage.html?ver=321&TB_iframe=true');
|
2008-08-20 23:42:31 +02:00
|
|
|
tinymce.DOM.setStyles('TB_window', {
|
|
|
|
'width':( W - 50 )+'px',
|
|
|
|
'height':( H - 45 )+'px',
|
|
|
|
'margin-left':'-'+parseInt((( W - 50 ) / 2),10) + 'px'
|
|
|
|
});
|
2008-11-17 06:51:59 +01:00
|
|
|
|
|
|
|
if ( ! tinymce.isIE6 ) {
|
|
|
|
tinymce.DOM.setStyles('TB_window', {
|
|
|
|
'top':'20px',
|
|
|
|
'marginTop':'0'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2008-08-20 23:42:31 +02:00
|
|
|
tinymce.DOM.setStyles('TB_iframeContent', {
|
|
|
|
'width':( W - 50 )+'px',
|
|
|
|
'height':( H - 75 )+'px'
|
|
|
|
});
|
2008-06-10 06:40:21 +02:00
|
|
|
tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
|
|
|
|
});
|
|
|
|
|
|
|
|
ed.onInit.add(function(ed) {
|
|
|
|
tinymce.dom.Event.add(ed.getWin(), 'scroll', function(e) {
|
2008-07-06 18:38:37 +02:00
|
|
|
ed.plugins.wpeditimage.hideButtons();
|
2008-06-10 06:40:21 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2008-06-23 17:26:03 +02:00
|
|
|
ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
|
|
|
|
ed.plugins.wpeditimage.hideButtons();
|
2008-07-06 18:38:37 +02:00
|
|
|
});
|
2008-06-10 06:40:21 +02:00
|
|
|
|
|
|
|
ed.onSaveContent.add(function(ed, o) {
|
2008-07-06 18:38:37 +02:00
|
|
|
ed.plugins.wpeditimage.hideButtons();
|
2008-06-10 06:40:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
ed.onMouseUp.add(function(ed, e) {
|
2008-07-10 18:39:14 +02:00
|
|
|
if ( tinymce.isOpera ) {
|
|
|
|
if ( e.target.nodeName == 'IMG' )
|
|
|
|
ed.plugins.wpeditimage.showButtons(e.target);
|
|
|
|
} else if ( ! tinymce.isWebKit ) {
|
|
|
|
var n = ed.selection.getNode(), DL;
|
|
|
|
|
|
|
|
if ( n.nodeName == 'IMG' && (DL = ed.dom.getParent(n, 'DL')) ) {
|
|
|
|
window.setTimeout(function(){
|
|
|
|
var ed = tinyMCE.activeEditor, n = ed.selection.getNode(), DL = ed.dom.getParent(n, 'DL');
|
|
|
|
|
|
|
|
if ( n.width != (parseInt(ed.dom.getStyle(DL, 'width')) - 10) ) {
|
|
|
|
ed.dom.setStyle(DL, 'width', parseInt(n.width)+10);
|
|
|
|
ed.execCommand('mceRepaint');
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
}
|
2008-06-10 06:40:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
ed.onMouseDown.add(function(ed, e) {
|
2008-07-02 20:41:11 +02:00
|
|
|
if ( tinymce.isOpera || e.target.nodeName != 'IMG' ) {
|
|
|
|
t.hideButtons();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ed.plugins.wpeditimage.showButtons(e.target);
|
2008-06-10 06:40:21 +02:00
|
|
|
});
|
2008-07-02 20:41:11 +02:00
|
|
|
|
|
|
|
ed.onKeyPress.add(function(ed, e) {
|
|
|
|
var DL, DIV;
|
|
|
|
|
|
|
|
if ( e.keyCode == 13 && (DL = ed.dom.getParent(ed.selection.getNode(), 'DL')) ) {
|
|
|
|
var P = ed.dom.create('p', {}, ' ');
|
|
|
|
if ( (DIV = DL.parentNode) && DIV.nodeName == 'DIV' )
|
|
|
|
ed.dom.insertAfter( P, DIV );
|
|
|
|
else ed.dom.insertAfter( P, DL );
|
|
|
|
|
|
|
|
tinymce.dom.Event.cancel(e);
|
|
|
|
ed.selection.select(P);
|
|
|
|
return false;
|
|
|
|
}
|
2008-06-23 17:26:03 +02:00
|
|
|
});
|
|
|
|
|
2008-07-02 20:41:11 +02:00
|
|
|
ed.onBeforeSetContent.add(function(ed, o) {
|
2008-07-06 18:38:37 +02:00
|
|
|
o.content = t._do_shcode(o.content);
|
|
|
|
});
|
2008-06-23 17:26:03 +02:00
|
|
|
|
2008-07-02 20:41:11 +02:00
|
|
|
ed.onPostProcess.add(function(ed, o) {
|
2008-06-23 17:26:03 +02:00
|
|
|
if (o.get)
|
2008-07-02 20:41:11 +02:00
|
|
|
o.content = t._get_shcode(o.content);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_do_shcode : function(co) {
|
2008-07-11 17:59:14 +02:00
|
|
|
return co.replace(/\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\][\s\u00a0]*/g, function(a,b,c){
|
2008-07-09 01:38:53 +02:00
|
|
|
b = b.replace(/\\'|\\'|\\'/g, ''').replace(/\\"|\\"/g, '"');
|
|
|
|
c = c.replace(/\\'|\\'/g, ''').replace(/\\"/g, '"');
|
2008-07-06 18:38:37 +02:00
|
|
|
var id = b.match(/id=['"]([^'"]+)/i), cls = b.match(/align=['"]([^'"]+)/i);
|
|
|
|
var w = b.match(/width=['"]([0-9]+)/), cap = b.match(/caption=['"]([^'"]+)/i);
|
2008-07-02 20:41:11 +02:00
|
|
|
|
|
|
|
id = ( id && id[1] ) ? id[1] : '';
|
|
|
|
cls = ( cls && cls[1] ) ? cls[1] : 'alignnone';
|
|
|
|
w = ( w && w[1] ) ? w[1] : '';
|
|
|
|
cap = ( cap && cap[1] ) ? cap[1] : '';
|
|
|
|
if ( ! w || ! cap ) return c;
|
|
|
|
|
|
|
|
var div_cls = (cls == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
|
|
|
|
|
2008-07-11 17:59:14 +02:00
|
|
|
return '<div class="'+div_cls+'"><dl id="'+id+'" class="wp-caption '+cls+'" style="width: '+(10+parseInt(w))+
|
|
|
|
'px"><dt class="wp-caption-dt">'+c+'</dt><dd class="wp-caption-dd">'+cap+'</dd></dl></div>';
|
2008-07-02 20:41:11 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_get_shcode : function(co) {
|
2008-07-09 01:38:53 +02:00
|
|
|
return co.replace(/<div class="mceTemp[^"]*">\s*<dl([^>]+)>\s*<dt[^>]+>([\s\S]+?)<\/dt>\s*<dd[^>]+>(.+?)<\/dd>\s*<\/dl>\s*<\/div>\s*/gi, function(a,b,c,cap){
|
2008-07-06 18:38:37 +02:00
|
|
|
var id = b.match(/id=['"]([^'"]+)/i), cls = b.match(/class=['"]([^'"]+)/i);
|
2008-07-02 20:41:11 +02:00
|
|
|
var w = c.match(/width=['"]([0-9]+)/);
|
|
|
|
|
|
|
|
id = ( id && id[1] ) ? id[1] : '';
|
|
|
|
cls = ( cls && cls[1] ) ? cls[1] : 'alignnone';
|
|
|
|
w = ( w && w[1] ) ? w[1] : '';
|
|
|
|
|
|
|
|
if ( ! w || ! cap ) return c;
|
2008-07-06 18:38:37 +02:00
|
|
|
cls = cls.match(/align[^ '"]+/) || 'alignnone';
|
2008-07-09 01:38:53 +02:00
|
|
|
cap = cap.replace(/<\S[^<>]*>/gi, '').replace(/'/g, ''').replace(/"/g, '"');
|
2008-07-02 20:41:11 +02:00
|
|
|
|
2008-07-11 17:59:14 +02:00
|
|
|
return '[caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/caption]';
|
2008-06-23 17:26:03 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2008-07-02 20:41:11 +02:00
|
|
|
showButtons : function(n) {
|
|
|
|
var t = this, ed = tinyMCE.activeEditor, p1, p2, vp, DOM = tinymce.DOM, X, Y;
|
2008-11-23 07:37:15 +01:00
|
|
|
var cls = ed.dom.getAttrib(n, 'class');
|
2008-06-10 06:40:21 +02:00
|
|
|
|
2008-11-23 07:37:15 +01:00
|
|
|
if ( cls.indexOf('mceItem') != -1 || cls.indexOf('wpGallery') != -1 )
|
2008-07-02 20:41:11 +02:00
|
|
|
return;
|
2008-06-10 06:40:21 +02:00
|
|
|
|
2008-07-02 20:41:11 +02:00
|
|
|
vp = ed.dom.getViewPort(ed.getWin());
|
|
|
|
p1 = DOM.getPos(ed.getContentAreaContainer());
|
|
|
|
p2 = ed.dom.getPos(n);
|
2008-06-10 06:40:21 +02:00
|
|
|
|
2008-07-02 20:41:11 +02:00
|
|
|
X = Math.max(p2.x - vp.x, 0) + p1.x;
|
|
|
|
Y = Math.max(p2.y - vp.y, 0) + p1.y;
|
2008-06-10 06:40:21 +02:00
|
|
|
|
2008-07-02 20:41:11 +02:00
|
|
|
DOM.setStyles('wp_editbtns', {
|
|
|
|
'top' : Y+5+'px',
|
|
|
|
'left' : X+5+'px',
|
|
|
|
'display' : 'block'
|
|
|
|
});
|
2008-06-10 06:40:21 +02:00
|
|
|
|
2008-07-02 20:41:11 +02:00
|
|
|
t.btnsTout = window.setTimeout( function(){ed.plugins.wpeditimage.hideButtons();}, 5000 );
|
2008-06-10 06:40:21 +02:00
|
|
|
},
|
2008-06-23 17:26:03 +02:00
|
|
|
|
2008-06-10 06:40:21 +02:00
|
|
|
hideButtons : function() {
|
2008-07-02 20:41:11 +02:00
|
|
|
if ( tinymce.DOM.isHidden('wp_editbtns') ) return;
|
|
|
|
|
2008-06-10 06:40:21 +02:00
|
|
|
tinymce.DOM.hide('wp_editbtns');
|
|
|
|
window.clearTimeout(this.btnsTout);
|
|
|
|
},
|
|
|
|
|
|
|
|
_createButtons : function() {
|
|
|
|
var t = this, ed = tinyMCE.activeEditor, DOM = tinymce.DOM;
|
|
|
|
|
|
|
|
DOM.remove('wp_editbtns');
|
|
|
|
|
|
|
|
var wp_editbtns = DOM.add(document.body, 'div', {
|
|
|
|
id : 'wp_editbtns',
|
|
|
|
style : 'display:none;'
|
|
|
|
});
|
|
|
|
|
|
|
|
var wp_editimgbtn = DOM.add('wp_editbtns', 'img', {
|
|
|
|
src : t.url+'/img/image.png',
|
|
|
|
id : 'wp_editimgbtn',
|
|
|
|
width : '24',
|
|
|
|
height : '24',
|
2008-07-02 20:41:11 +02:00
|
|
|
title : ed.getLang('wpeditimage.edit_img')
|
2008-06-10 06:40:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
wp_editimgbtn.onmousedown = function(e) {
|
|
|
|
var ed = tinyMCE.activeEditor;
|
|
|
|
ed.windowManager.bookmark = ed.selection.getBookmark('simple');
|
|
|
|
ed.execCommand("WP_EditImage");
|
|
|
|
this.parentNode.style.display = 'none';
|
2008-07-06 18:38:37 +02:00
|
|
|
};
|
2008-06-10 06:40:21 +02:00
|
|
|
|
|
|
|
var wp_delimgbtn = DOM.add('wp_editbtns', 'img', {
|
|
|
|
src : t.url+'/img/delete.png',
|
|
|
|
id : 'wp_delimgbtn',
|
|
|
|
width : '24',
|
|
|
|
height : '24',
|
2008-07-02 20:41:11 +02:00
|
|
|
title : ed.getLang('wpeditimage.del_img')
|
2008-06-10 06:40:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
wp_delimgbtn.onmousedown = function(e) {
|
|
|
|
var ed = tinyMCE.activeEditor, el = ed.selection.getNode(), p;
|
|
|
|
|
2008-07-02 20:41:11 +02:00
|
|
|
if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('mceItem') == -1 ) {
|
|
|
|
if ( (p = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(p, 'mceTemp') )
|
|
|
|
ed.dom.remove(p);
|
|
|
|
else if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1 )
|
|
|
|
ed.dom.remove(p);
|
|
|
|
else ed.dom.remove(el);
|
2008-06-10 06:40:21 +02:00
|
|
|
|
2008-07-02 20:41:11 +02:00
|
|
|
this.parentNode.style.display = 'none';
|
|
|
|
ed.execCommand('mceRepaint');
|
|
|
|
return false;
|
|
|
|
}
|
2008-07-06 18:38:37 +02:00
|
|
|
};
|
2008-06-10 06:40:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getInfo : function() {
|
|
|
|
return {
|
|
|
|
longname : 'Edit Image',
|
|
|
|
author : 'WordPress',
|
|
|
|
authorurl : 'http://wordpress.org',
|
|
|
|
infourl : '',
|
|
|
|
version : "1.0"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
tinymce.PluginManager.add('wpeditimage', tinymce.plugins.wpEditImage);
|
|
|
|
})();
|