X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/3e7fab96d7874067884348df10bbdcdefa4a89ad..1c09677af04c9e37714e09b73eb9dbc5b2e3eb13:/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js diff --git a/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js b/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js index f834e97a..ec97912d 100644 --- a/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js +++ b/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js @@ -1,592 +1 @@ -/* Import plugin specific language pack */ -tinyMCE.importPluginLanguagePack('wordpress', 'en'); - -var TinyMCE_wordpressPlugin = { - getInfo : function() { - return { - longname : 'WordPress Plugin', - author : 'WordPress', - authorurl : 'http://wordpress.org', - infourl : 'http://wordpress.org', - version : '1' - }; - }, - - getControlHTML : function(control_name) { - switch (control_name) { - case "wp_more": - return tinyMCE.getButtonHTML(control_name, 'lang_wordpress_more_button', '{$pluginurl}/images/more.gif', 'wpMore'); - case "wp_page": - return tinyMCE.getButtonHTML(control_name, 'lang_wordpress_page_button', '{$pluginurl}/images/page.gif', 'wpPage'); - case "wp_help": - var buttons = tinyMCE.getButtonHTML(control_name, 'lang_help_button_title', '{$pluginurl}/images/help.gif', 'wpHelp'); - var hiddenControls = '
' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '
'; - return buttons+hiddenControls; - case "wp_adv": - return tinyMCE.getButtonHTML(control_name, 'lang_wordpress_adv_button', '{$pluginurl}/images/toolbars.gif', 'wpAdv'); - case "wp_adv_start": - return ''; - } - return ''; - }, - - execCommand : function(editor_id, element, command, user_interface, value) { - var inst = tinyMCE.getInstanceById(editor_id); - var focusElm = inst.getFocusElement(); - var doc = inst.getDoc(); - - function getAttrib(elm, name) { - return elm.getAttribute(name) ? elm.getAttribute(name) : ""; - } - - // Handle commands - switch (command) { - case "wpMore": - var flag = ""; - var template = new Array(); - var altMore = tinyMCE.getLang('lang_wordpress_more_alt'); - - // Is selection a image - if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") { - flag = getAttrib(focusElm, 'class'); - - if (flag != 'mce_plugin_wordpress_more') // Not a wordpress - return true; - - action = "update"; - } - - html = '' - + ''; - tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, html); - tinyMCE.selectedInstance.repaint(); - return true; - - case "wpPage": - var flag = ""; - var template = new Array(); - var altPage = tinyMCE.getLang('lang_wordpress_more_alt'); - - // Is selection a image - if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") { - flag = getAttrib(focusElm, 'name'); - - if (flag != 'mce_plugin_wordpress_page') // Not a wordpress - return true; - - action = "update"; - } - - html = '' - + ''; - tinyMCE.execCommand("mceInsertContent",true,html); - tinyMCE.selectedInstance.repaint(); - return true; - - case "wpHelp": - var template = new Array(); - - template['file'] = tinyMCE.baseURL + '/wp-mce-help.php'; - template['width'] = 480; - template['height'] = 380; - - args = { - resizable : 'yes', - scrollbars : 'yes' - }; - - tinyMCE.openWindow(template, args); - return true; - case "wpAdv": - var adv = document.getElementById('wpadvbar'); - if ( adv.style.display == 'none' ) { - adv.style.display = 'block'; - tinyMCE.switchClass(editor_id + '_wp_adv', 'mceButtonSelected'); - } else { - adv.style.display = 'none'; - tinyMCE.switchClass(editor_id + '_wp_adv', 'mceButtonNormal'); - } - return true; - } - - // Pass to next handler in chain - return false; - }, - - cleanup : function(type, content) { - switch (type) { - - case "insert_to_editor": - var startPos = 0; - var altMore = tinyMCE.getLang('lang_wordpress_more_alt'); - var altPage = tinyMCE.getLang('lang_wordpress_page_alt'); - - // Parse all tags and replace them with images - while ((startPos = content.indexOf('', startPos) + 3; - // Insert image - var moreText = content.substring(startPos + 8, endPos - 3); - var contentAfter = content.substring(endPos); - content = content.substring(0, startPos); - content += ''; - content += contentAfter; - - startPos++; - } - var startPos = 0; - - // Parse all tags and replace them with images - while ((startPos = content.indexOf('', startPos)) != -1) { - // Insert image - var contentAfter = content.substring(startPos + 15); - content = content.substring(0, startPos); - content += ''; - content += contentAfter; - - startPos++; - } - - // Look for \n in
, replace with 
- var startPos = -1; - while ((startPos = content.indexOf('', startPos+1); - var innerPos = content.indexOf('>', startPos+1); - var chunkBefore = content.substring(0, innerPos); - var chunkAfter = content.substring(endPos); - - var innards = content.substring(innerPos, endPos); - innards = innards.replace(/\n/g, '
'); - content = chunkBefore + innards + chunkAfter; - } - - break; - - case "get_from_editor": - // Parse all img tags and replace them with - var startPos = -1; - while ((startPos = content.indexOf('', startPos); - var attribs = this._parseAttributes(content.substring(startPos + 4, endPos)); - - if (attribs['class'] == "mce_plugin_wordpress_more" || attribs['name'] == "mce_plugin_wordpress_more") { - endPos += 2; - - var moreText = attribs['moretext'] ? attribs['moretext'] : ''; - var embedHTML = ''; - - // Insert embed/object chunk - chunkBefore = content.substring(0, startPos); - chunkAfter = content.substring(endPos); - content = chunkBefore + embedHTML + chunkAfter; - } - if (attribs['class'] == "mce_plugin_wordpress_page" || attribs['name'] == "mce_plugin_wordpress_page") { - endPos += 2; - - var embedHTML = ''; - - // Insert embed/object chunk - chunkBefore = content.substring(0, startPos); - chunkAfter = content.substring(endPos); - content = chunkBefore + embedHTML + chunkAfter; - } - } - - // Remove normal line breaks - content = content.replace(/\n|\r/g, ' '); - - // Look for
in
, replace with \n
-				var startPos = -1;
-				while ((startPos = content.indexOf('', startPos+1);
-					var innerPos = content.indexOf('>', startPos+1);
-					var chunkBefore = content.substring(0, innerPos);
-					var chunkAfter = content.substring(endPos);
-					
-					var innards = content.substring(innerPos, endPos);
-					innards = innards.replace(new RegExp('', 'g'), '\n');
-					innards = innards.replace(new RegExp('\\s$', ''), '');
-					content = chunkBefore + innards + chunkAfter;
-				}
-
-				// Remove anonymous, empty paragraphs.
-				content = content.replace(new RegExp('

(\\s| )*

', 'mg'), ''); - - // Handle table badness. - content = content.replace(new RegExp('<(table( [^>]*)?)>.*?<((tr|thead)( [^>]*)?)>', 'mg'), '<$1><$3>'); - content = content.replace(new RegExp('<(tr|thead|tfoot)>.*?<((td|th)( [^>]*)?)>', 'mg'), '<$1><$2>'); - content = content.replace(new RegExp('.*?<(td( [^>]*)?|th( [^>]*)?|/tr|/thead|/tfoot)>', 'mg'), '<$2>'); - content = content.replace(new RegExp('.*?<(tr|/table)>', 'mg'), '<$1>'); - content = content.replace(new RegExp('<(/?(table|tbody|tr|th|td)[^>]*)>(\\s*|(
)*)*', 'g'), '<$1>'); - - // Pretty it up for the source editor. - var blocklist = 'blockquote|ul|ol|li|table|thead|tr|th|td|div|h\\d|pre|p'; - content = content.replace(new RegExp('\\s*\\s*', 'mg'), '\n'); - content = content.replace(new RegExp('\\s*<(('+blocklist+')[^>]*)>', 'mg'), '\n<$1>'); - content = content.replace(new RegExp('<((li|/?tr|/?thead|/?tfoot)( [^>]*)?)>', 'g'), '\t<$1>'); - content = content.replace(new RegExp('<((td|th)( [^>]*)?)>', 'g'), '\t\t<$1>'); - content = content.replace(new RegExp('\\s*
\\s*', 'mg'), '
\n'); - content = content.replace(new RegExp('^\\s*', ''), ''); - content = content.replace(new RegExp('\\s*$', ''), ''); - - break; - } - - // Pass through to next handler in chain - return content; - }, - - handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) { - - tinyMCE.switchClass(editor_id + '_wp_more', 'mceButtonNormal'); - tinyMCE.switchClass(editor_id + '_wp_page', 'mceButtonNormal'); - - if (node == null) - return; - - do { - if (node.nodeName.toLowerCase() == "img" && tinyMCE.getAttrib(node, 'class').indexOf('mce_plugin_wordpress_more') == 0) - tinyMCE.switchClass(editor_id + '_wp_more', 'mceButtonSelected'); - if (node.nodeName.toLowerCase() == "img" && tinyMCE.getAttrib(node, 'class').indexOf('mce_plugin_wordpress_page') == 0) - tinyMCE.switchClass(editor_id + '_wp_page', 'mceButtonSelected'); - } while ((node = node.parentNode)); - - return true; - }, - - saveCallback : function(el, content, body) { - // We have a TON of cleanup to do. - - // Mark

if it has any attributes. - content = content.replace(new RegExp('(]+>.*?)

', 'mg'), '$1'); - - // Decode the ampersands of time. - // content = content.replace(new RegExp('&', 'g'), '&'); - - // Get it ready for wpautop. - content = content.replace(new RegExp('\\s*

', 'mgi'), ''); - content = content.replace(new RegExp('\\s*

\\s*', 'mgi'), '\n\n'); - content = content.replace(new RegExp('\\n\\s*\\n', 'mgi'), '\n\n'); - content = content.replace(new RegExp('\\s*
\\s*', 'gi'), '\n'); - - // Fix some block element newline issues - var blocklist = 'blockquote|ul|ol|li|table|thead|tr|th|td|div|h\\d|pre'; - content = content.replace(new RegExp('\\s*<(('+blocklist+') ?[^>]*)\\s*>', 'mg'), '\n<$1>'); - content = content.replace(new RegExp('\\s*\\s*', 'mg'), '\n'); - content = content.replace(new RegExp('
  • ', 'g'), '\t
  • '); - - // Unmark special paragraph closing tags - content = content.replace(new RegExp('', 'g'), '

    \n'); - content = content.replace(new RegExp('\\s*(]+>.*

    )', 'mg'), '\n$1'); - - // Trim trailing whitespace - content = content.replace(new RegExp('\\s*$', ''), ''); - - // Hope. - return content; - - }, - - _parseAttributes : function(attribute_string) { - var attributeName = ""; - var attributeValue = ""; - var withInName; - var withInValue; - var attributes = new Array(); - var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g'); - var titleText = tinyMCE.getLang('lang_wordpress_more'); - var titleTextPage = tinyMCE.getLang('lang_wordpress_page'); - - if (attribute_string == null || attribute_string.length < 2) - return null; - - withInName = withInValue = false; - - for (var i=0; i
  • !ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '
    ' "); // Hmm... - return pee; -} +(function(){var a=tinymce.DOM;tinymce.create("tinymce.plugins.WordPress",{mceTout:0,init:function(c,d){var e=this,h=c.getParam("wordpress_adv_toolbar","toolbar2"),g=0,f,b;f='';b='';if(getUserSetting("hidetb","0")=="1"){c.settings.wordpress_adv_hidden=0}c.onPostRender.add(function(){var i=c.controlManager.get(h);if(c.getParam("wordpress_adv_hidden",1)&&i){a.hide(i.id);e._resizeIframe(c,h,28)}});c.addCommand("WP_More",function(){c.execCommand("mceInsertContent",0,f)});c.addCommand("WP_Page",function(){c.execCommand("mceInsertContent",0,b)});c.addCommand("WP_Help",function(){c.windowManager.open({url:tinymce.baseURL+"/wp-mce-help.php",width:450,height:420,inline:1})});c.addCommand("WP_Adv",function(){var i=c.controlManager,j=i.get(h).id;if("undefined"==j){return}if(a.isHidden(j)){i.setActive("wp_adv",1);a.show(j);e._resizeIframe(c,h,-28);c.settings.wordpress_adv_hidden=0;setUserSetting("hidetb","1")}else{i.setActive("wp_adv",0);a.hide(j);e._resizeIframe(c,h,28);c.settings.wordpress_adv_hidden=1;setUserSetting("hidetb","0")}});c.addButton("wp_more",{title:"wordpress.wp_more_desc",image:d+"/img/more.gif",cmd:"WP_More"});c.addButton("wp_page",{title:"wordpress.wp_page_desc",image:d+"/img/page.gif",cmd:"WP_Page"});c.addButton("wp_help",{title:"wordpress.wp_help_desc",image:d+"/img/help.gif",cmd:"WP_Help"});c.addButton("wp_adv",{title:"wordpress.wp_adv_desc",image:d+"/img/toolbars.gif",cmd:"WP_Adv"});c.addButton("add_media",{title:"wordpress.add_media",image:d+"/img/media.gif",onclick:function(){tb_show("",tinymce.DOM.get("add_media").href);tinymce.DOM.setStyle(["TB_overlay","TB_window","TB_load"],"z-index","999999")}});c.addButton("add_image",{title:"wordpress.add_image",image:d+"/img/image.gif",onclick:function(){tb_show("",tinymce.DOM.get("add_image").href);tinymce.DOM.setStyle(["TB_overlay","TB_window","TB_load"],"z-index","999999")}});c.addButton("add_video",{title:"wordpress.add_video",image:d+"/img/video.gif",onclick:function(){tb_show("",tinymce.DOM.get("add_video").href);tinymce.DOM.setStyle(["TB_overlay","TB_window","TB_load"],"z-index","999999")}});c.addButton("add_audio",{title:"wordpress.add_audio",image:d+"/img/audio.gif",onclick:function(){tb_show("",tinymce.DOM.get("add_audio").href);tinymce.DOM.setStyle(["TB_overlay","TB_window","TB_load"],"z-index","999999")}});c.onBeforeExecCommand.add(function(i,l,k,m){var j=tinymce.DOM;if("mceFullScreen"!=l){return}if("mce_fullscreen"!=i.id&&j.get("add_audio")&&j.get("add_video")&&j.get("add_image")&&j.get("add_media")){i.settings.theme_advanced_buttons1+=",|,add_image,add_video,add_audio,add_media"}});c.addCommand("JustifyLeft",function(){var i=c.selection.getNode();if(i.nodeName!="IMG"){c.editorCommands.mceJustify("JustifyLeft","left")}else{c.plugins.wordpress.do_align(i,"alignleft")}});c.addCommand("JustifyRight",function(){var i=c.selection.getNode();if(i.nodeName!="IMG"){c.editorCommands.mceJustify("JustifyRight","right")}else{c.plugins.wordpress.do_align(i,"alignright")}});c.addCommand("JustifyCenter",function(){var k=c.selection.getNode(),j=c.dom.getParent(k,"p"),i=c.dom.getParent(k,"dl");if(k.nodeName=="IMG"&&(j||i)){c.plugins.wordpress.do_align(k,"aligncenter")}else{c.editorCommands.mceJustify("JustifyCenter","center")}});if("undefined"!=typeof wpWordCount){c.onKeyUp.add(function(i,j){if(j.keyCode==g){return}if(13==j.keyCode||8==g||46==g){wpWordCount.wc(i.getContent({format:"raw"}))}g=j.keyCode})}c.onSaveContent.add(function(i,j){if(typeof(switchEditors)=="object"){if(i.isHidden()){j.content=j.element.value}else{j.content=switchEditors.pre_wpautop(j.content)}}});e._handleMoreBreak(c,d);c.addShortcut("alt+shift+c",c.getLang("justifycenter_desc"),"JustifyCenter");c.addShortcut("alt+shift+r",c.getLang("justifyright_desc"),"JustifyRight");c.addShortcut("alt+shift+l",c.getLang("justifyleft_desc"),"JustifyLeft");c.addShortcut("alt+shift+j",c.getLang("justifyfull_desc"),"JustifyFull");c.addShortcut("alt+shift+q",c.getLang("blockquote_desc"),"mceBlockQuote");c.addShortcut("alt+shift+u",c.getLang("bullist_desc"),"InsertUnorderedList");c.addShortcut("alt+shift+o",c.getLang("numlist_desc"),"InsertOrderedList");c.addShortcut("alt+shift+d",c.getLang("striketrough_desc"),"Strikethrough");c.addShortcut("alt+shift+n",c.getLang("spellchecker.desc"),"mceSpellCheck");c.addShortcut("alt+shift+a",c.getLang("link_desc"),"mceLink");c.addShortcut("alt+shift+s",c.getLang("unlink_desc"),"unlink");c.addShortcut("alt+shift+m",c.getLang("image_desc"),"mceImage");c.addShortcut("alt+shift+g",c.getLang("fullscreen.desc"),"mceFullScreen");c.addShortcut("alt+shift+z",c.getLang("wp_adv_desc"),"WP_Adv");c.addShortcut("alt+shift+h",c.getLang("help_desc"),"WP_Help");c.addShortcut("alt+shift+t",c.getLang("wp_more_desc"),"WP_More");c.addShortcut("alt+shift+p",c.getLang("wp_page_desc"),"WP_Page");c.addShortcut("ctrl+s",c.getLang("save_desc"),function(){if("function"==typeof autosave){autosave()}});if(tinymce.isWebKit){c.addShortcut("alt+shift+b",c.getLang("bold_desc"),"Bold");c.addShortcut("alt+shift+i",c.getLang("italic_desc"),"Italic")}c.onInit.add(function(i){tinymce.dom.Event.add(i.getWin(),"scroll",function(j){i.plugins.wordpress._hideButtons()});tinymce.dom.Event.add(i.getBody(),"dragstart",function(j){i.plugins.wordpress._hideButtons()})});c.onBeforeExecCommand.add(function(i,k,j,l){i.plugins.wordpress._hideButtons()});c.onSaveContent.add(function(i,j){i.plugins.wordpress._hideButtons()});c.onMouseDown.add(function(i,j){if(j.target.nodeName!="IMG"){i.plugins.wordpress._hideButtons()}})},getInfo:function(){return{longname:"WordPress Plugin",author:"WordPress",authorurl:"http://wordpress.org",infourl:"http://wordpress.org",version:"3.0"}},_setEmbed:function(b){return b.replace(/\[embed\]([\s\S]+?)\[\/embed\][\s\u00a0]*/g,function(d,c){return''+c+''})},_getEmbed:function(b){return b.replace(/]+>/g,function(c){if(c.indexOf('class="wp-oembed')!=-1){var d=c.match(/alt="([^\"]+)"/);if(d[1]){c="[embed]"+d[1]+"[/embed]"}}return c})},_showButtons:function(f,d){var g=tinyMCE.activeEditor,i,h,b,j=tinymce.DOM,e,c;b=g.dom.getViewPort(g.getWin());i=j.getPos(g.getContentAreaContainer());h=g.dom.getPos(f);e=Math.max(h.x-b.x,0)+i.x;c=Math.max(h.y-b.y,0)+i.y;j.setStyles(d,{top:c+5+"px",left:e+5+"px",display:"block"});if(this.mceTout){clearTimeout(this.mceTout)}this.mceTout=setTimeout(function(){g.plugins.wordpress._hideButtons()},5000)},_hideButtons:function(){if(!this.mceTout){return}if(document.getElementById("wp_editbtns")){tinymce.DOM.hide("wp_editbtns")}if(document.getElementById("wp_gallerybtns")){tinymce.DOM.hide("wp_gallerybtns")}clearTimeout(this.mceTout);this.mceTout=0},do_align:function(j,d){var h,f,g,b,i,e=tinyMCE.activeEditor;if(/^(mceItemFlash|mceItemShockWave|mceItemWindowsMedia|mceItemQuickTime|mceItemRealMedia)$/.test(j.className)){return}h=e.dom.getParent(j,"p");f=e.dom.getParent(j,"dl");g=e.dom.getParent(j,"div");if(f&&g){b=e.dom.hasClass(f,d)?"alignnone":d;f.className=f.className.replace(/align[^ '"]+\s?/g,"");e.dom.addClass(f,b);i=(b=="aligncenter")?e.dom.addClass(g,"mceIEcenter"):e.dom.removeClass(g,"mceIEcenter")}else{if(h){b=e.dom.hasClass(j,d)?"alignnone":d;j.className=j.className.replace(/align[^ '"]+\s?/g,"");e.dom.addClass(j,b);if(b=="aligncenter"){e.dom.setStyle(h,"textAlign","center")}else{if(h.style&&h.style.textAlign=="center"){e.dom.setStyle(h,"textAlign","")}}}}e.execCommand("mceRepaint")},_resizeIframe:function(c,e,b){var d=c.getContentAreaContainer().firstChild;a.setStyle(d,"height",d.clientHeight+b);c.theme.deltaHeight+=b},_handleMoreBreak:function(c,d){var e,b;e='$1';b='';c.onInit.add(function(){c.dom.loadCSS(d+"/css/content.css")});c.onPostRender.add(function(){if(c.theme.onResolveName){c.theme.onResolveName.add(function(f,g){if(g.node.nodeName=="IMG"){if(c.dom.hasClass(g.node,"mceWPmore")){g.name="wpmore"}if(c.dom.hasClass(g.node,"mceWPnextpage")){g.name="wppage"}}})}});c.onBeforeSetContent.add(function(f,g){g.content=g.content.replace(//g,e);g.content=g.content.replace(//g,b)});c.onPostProcess.add(function(f,g){if(g.get){g.content=g.content.replace(/]+>/g,function(i){if(i.indexOf('class="mceWPmore')!==-1){var h,j=(h=i.match(/alt="(.*?)"/))?h[1]:"";i=""}if(i.indexOf('class="mceWPnextpage')!==-1){i=""}return i})}});c.onNodeChange.add(function(g,f,h){f.setActive("wp_page",h.nodeName==="IMG"&&g.dom.hasClass(h,"mceWPnextpage"));f.setActive("wp_more",h.nodeName==="IMG"&&g.dom.hasClass(h,"mceWPmore"))})}});tinymce.PluginManager.add("wordpress",tinymce.plugins.WordPress)})(); \ No newline at end of file