X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/a5227bf01edbe6660486c9f5c0f0ed7b7fea3130..f9001779751f83dc8a10e478bfecb4d8dd5f964c:/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.dev.js?ds=inline diff --git a/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.dev.js b/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.dev.js index 0cc2bab9..f8998688 100644 --- a/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.dev.js +++ b/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.dev.js @@ -35,13 +35,13 @@ }); ed.addCommand('WP_Help', function() { - ed.windowManager.open({ - url : tinymce.baseURL + '/wp-mce-help.php', - width : 450, - height : 420, - inline : 1 - }); + ed.windowManager.open({ + url : tinymce.baseURL + '/wp-mce-help.php', + width : 450, + height : 420, + inline : 1 }); + }); ed.addCommand('WP_Adv', function() { var cm = ed.controlManager, id = cm.get(tbId).id; @@ -126,37 +126,76 @@ } }); - // Add Media buttons to fullscreen - ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) { - var DOM = tinymce.DOM; - if ( 'mceFullScreen' != cmd ) return; - if ( 'mce_fullscreen' != ed.id && DOM.get('add_audio') && DOM.get('add_video') && DOM.get('add_image') && DOM.get('add_media') ) - ed.settings.theme_advanced_buttons1 += ',|,add_image,add_video,add_audio,add_media'; - }); - - // Add class "alignleft", "alignright" and "aligncenter" when selecting align for images. - ed.addCommand('JustifyLeft', function() { - var n = ed.selection.getNode(); - - if ( n.nodeName != 'IMG' ) - ed.editorCommands.mceJustify('JustifyLeft', 'left'); - else ed.plugins.wordpress.do_align(n, 'alignleft'); - }); - - ed.addCommand('JustifyRight', function() { - var n = ed.selection.getNode(); + // Add Media buttons to fullscreen and handle align buttons for image captions + ed.onBeforeExecCommand.add(function(ed, cmd, ui, val, o) { + var DOM = tinymce.DOM, n, DL, DIV, cls, a, align; + if ( 'mceFullScreen' == cmd ) { + if ( 'mce_fullscreen' != ed.id && DOM.get('add_audio') && DOM.get('add_video') && DOM.get('add_image') && DOM.get('add_media') ) + ed.settings.theme_advanced_buttons1 += ',|,add_image,add_video,add_audio,add_media'; + } - if ( n.nodeName != 'IMG' ) - ed.editorCommands.mceJustify('JustifyRight', 'right'); - else ed.plugins.wordpress.do_align(n, 'alignright'); + if ( 'JustifyLeft' == cmd || 'JustifyRight' == cmd || 'JustifyCenter' == cmd ) { + n = ed.selection.getNode(); + + if ( n.nodeName == 'IMG' ) { + align = cmd.substr(7).toLowerCase(); + a = 'align' + align; + DL = ed.dom.getParent(n, 'dl.wp-caption'); + DIV = ed.dom.getParent(n, 'div.mceTemp'); + + if ( DL && DIV ) { + cls = ed.dom.hasClass(DL, a) ? 'alignnone' : a; + DL.className = DL.className.replace(/align[^ '"]+\s?/g, ''); + ed.dom.addClass(DL, cls); + + if (cls == 'aligncenter') + ed.dom.addClass(DIV, 'mceIEcenter'); + else + ed.dom.removeClass(DIV, 'mceIEcenter'); + + o.terminate = true; + ed.execCommand('mceRepaint'); + } else { + if ( ed.dom.hasClass(n, a) ) + ed.dom.addClass(n, 'alignnone'); + else + ed.dom.removeClass(n, 'alignnone'); + } + } + } }); + + ed.onInit.add(function(ed) { + // make sure these run last + ed.onNodeChange.add( function(ed, cm, e) { + var DL; + + if ( e.nodeName == 'IMG' ) { + DL = ed.dom.getParent(e, 'dl.wp-caption'); + } else if ( e.nodeName == 'DIV' && ed.dom.hasClass(e, 'mceTemp') ) { + DL = e.firstChild; + + if ( ! ed.dom.hasClass(DL, 'wp-caption') ) + DL = false; + } + + if ( DL ) { + if ( ed.dom.hasClass(DL, 'alignleft') ) + cm.setActive('justifyleft', 1); + else if ( ed.dom.hasClass(DL, 'alignright') ) + cm.setActive('justifyright', 1); + else if ( ed.dom.hasClass(DL, 'aligncenter') ) + cm.setActive('justifycenter', 1); + } + }); - ed.addCommand('JustifyCenter', function() { - var n = ed.selection.getNode(), P = ed.dom.getParent(n, 'p'), DL = ed.dom.getParent(n, 'dl'); - - if ( n.nodeName == 'IMG' && ( P || DL ) ) - ed.plugins.wordpress.do_align(n, 'aligncenter'); - else ed.editorCommands.mceJustify('JustifyCenter', 'center'); + // remove invalid parent paragraphs when pasting HTML and/or switching to the HTML editor and back + ed.onBeforeSetContent.add(function(ed, o) { + if ( o.content ) { + o.content = o.content.replace(/

\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre|address)( [^>]*)?>/gi, '<$1$2>'); + o.content = o.content.replace(/<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre|address)>\s*<\/p>/gi, ''); + } + }); }); // Word count if script is loaded @@ -303,34 +342,6 @@ this.mceTout = 0; }, - do_align : function(n, a) { - var P, DL, DIV, cls, c, ed = tinyMCE.activeEditor; - - if ( /^(mceItemFlash|mceItemShockWave|mceItemWindowsMedia|mceItemQuickTime|mceItemRealMedia)$/.test(n.className) ) - return; - - P = ed.dom.getParent(n, 'p'); - DL = ed.dom.getParent(n, 'dl'); - DIV = ed.dom.getParent(n, 'div'); - - if ( DL && DIV ) { - cls = ed.dom.hasClass(DL, a) ? 'alignnone' : a; - DL.className = DL.className.replace(/align[^ '"]+\s?/g, ''); - ed.dom.addClass(DL, cls); - c = (cls == 'aligncenter') ? ed.dom.addClass(DIV, 'mceIEcenter') : ed.dom.removeClass(DIV, 'mceIEcenter'); - } else if ( P ) { - cls = ed.dom.hasClass(n, a) ? 'alignnone' : a; - n.className = n.className.replace(/align[^ '"]+\s?/g, ''); - ed.dom.addClass(n, cls); - if ( cls == 'aligncenter' ) - ed.dom.setStyle(P, 'textAlign', 'center'); - else if (P.style && P.style.textAlign == 'center') - ed.dom.setStyle(P, 'textAlign', ''); - } - - ed.execCommand('mceRepaint'); - }, - // Resizes the iframe by a relative height value _resizeIframe : function(ed, tb_id, dy) { var ifr = ed.getContentAreaContainer().firstChild; @@ -367,8 +378,10 @@ // Replace morebreak with images ed.onBeforeSetContent.add(function(ed, o) { - o.content = o.content.replace(//g, moreHTML); - o.content = o.content.replace(//g, nextpageHTML); + if ( o.content ) { + o.content = o.content.replace(//g, moreHTML); + o.content = o.content.replace(//g, nextpageHTML); + } }); // Replace images with morebreak