X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/177fd6fefd2e3d5a0ea6591c71d660cabdb3c1a4..76aea3697c6043c1613370f172395b4f65ee71f0:/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.js?ds=sidebyside diff --git a/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.js b/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.js new file mode 100644 index 00000000..d0ca4ed5 --- /dev/null +++ b/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.js @@ -0,0 +1,217 @@ + +(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() { + var el = ed.selection.getNode(); + + if ( ed.dom.getAttrib(el, 'class').indexOf('mceItem') != -1 || el.nodeName != 'IMG' ) + return; + + tb_show('', url + '/editimage.html?ver=311g&TB_iframe=true'); + 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) { + ed.plugins.wpeditimage.hideButtons(); + }); + }); + + ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) { + ed.plugins.wpeditimage.hideButtons(); + }); + + ed.onSaveContent.add(function(ed, o) { + ed.plugins.wpeditimage.hideButtons(); + }); + + ed.onMouseUp.add(function(ed, e) { + 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); + } + } + }); + + ed.onMouseDown.add(function(ed, e) { + if ( tinymce.isOpera || e.target.nodeName != 'IMG' ) { + t.hideButtons(); + return; + } + ed.plugins.wpeditimage.showButtons(e.target); + }); + + 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; + } + }); + + ed.onBeforeSetContent.add(function(ed, o) { + o.content = t._do_shcode(o.content); + }); + + ed.onPostProcess.add(function(ed, o) { + if (o.get) + o.content = t._get_shcode(o.content); + }); + }, + + _do_shcode : function(co) { + return co.replace(/\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\][\s\u00a0]*/g, function(a,b,c){ + b = b.replace(/\\'|\\'|\\'/g, ''').replace(/\\"|\\"/g, '"'); + c = c.replace(/\\'|\\'/g, ''').replace(/\\"/g, '"'); + var id = b.match(/id=['"]([^'"]+)/i), cls = b.match(/align=['"]([^'"]+)/i); + var w = b.match(/width=['"]([0-9]+)/), cap = b.match(/caption=['"]([^'"]+)/i); + + 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'; + + return '