WordPress/wp-includes/js/tinymce/plugins/wordpress/plugin.min.js

1 line
7.7 KiB
JavaScript

tinymce.PluginManager.add("wordpress",function(a){function b(b){var c,d,e,f=0;d="hide"===b,a.theme.panel&&(e=a.theme.panel.find(".toolbar:not(.menubar)")),!e||e.length<2||"hide"===b&&!e[1].visible()||(!b&&e[1].visible()&&(b="hide"),tinymce.each(e,function(a,c){c>0&&("hide"===b?(a.hide(),f+=30):(a.show(),f-=30))}),f&&!d&&(c=a.getContentAreaContainer().firstChild,j.setStyle(c,"height",c.clientHeight+f),"hide"===b?(setUserSetting("hidetb","1"),g&&g.active(!1)):(setUserSetting("hidetb","0"),g&&g.active(!0))))}function c(a){return a.replace(/\[embed\]([\s\S]+?)\[\/embed\][\s\u00a0]*/g,function(a,b){return'<img width="300" height="200" src="'+tinymce.Env.transparentSrc+'" class="wp-oembed" alt="'+b+'" title="'+b+'" data-mce-resize="false" data-mce-placeholder="1" />'})}function d(a){return a.replace(/<img[^>]+>/g,function(a){if(-1!==a.indexOf('class="wp-oembed')){var b=a.match(/alt="([^\"]+)"/);b[1]&&(a="[embed]"+b[1]+"[/embed]")}return a})}function e(b,c){var d,e,f,g,h;f=a.dom.getViewPort(a.getWin()),d=j.getPos(a.getContentAreaContainer()),e=a.dom.getPos(b),g=Math.max(e.x-f.x,0)+d.x,h=Math.max(e.y-f.y,0)+d.y,j.setStyles(c,{top:h+5+"px",left:g+5+"px",display:"block"})}function f(){j.hide(j.select("#wp_editbtns, #wp_gallerybtns"))}var g,h,i,j=tinymce.DOM,k=0;return a.addButton("wp_adv",{tooltip:"Toolbar Toggle",cmd:"WP_Adv",onPostRender:function(){g=this}}),a.on("PostRender",function(){"1"===getUserSetting("hidetb","1")&&b("hide")}),a.addCommand("WP_Adv",function(){b()}),a.on("focus",function(){window.wpActiveEditor=a.id}),a.on("BeforeSetContent",function(a){a.content&&(-1!==a.content.indexOf("<!--more")&&(a.content=a.content.replace(/<!--more(.*?)-->/g,function(a,b){return'<img src="'+tinymce.Env.transparentSrc+'" data-wp-more="'+b+'" class="wp-more-tag mce-wp-more" title="Read More..." data-mce-resize="false" data-mce-placeholder="1" />'})),-1!==a.content.indexOf("<!--nextpage-->")&&(a.content=a.content.replace(/<!--nextpage-->/g,'<img src="'+tinymce.Env.transparentSrc+'" class="wp-more-tag mce-wp-nextpage" title="Page break" data-mce-resize="false" data-mce-placeholder="1" />')))}),a.on("PostProcess",function(a){a.get&&(a.content=a.content.replace(/<img[^>]+>/g,function(a){var b,c="";return-1!==a.indexOf("wp-more-tag")&&(-1!==a.indexOf("mce-wp-more")?((b=a.match(/data-wp-more="([^"]+)"/))&&(c=b[1]),a="<!--more"+c+"-->"):-1!==a.indexOf("mce-wp-nextpage")&&(a="<!--nextpage-->")),a}))}),a.on("ResolveName",function(b){var c=a.dom,d=b.target;"IMG"===d.nodeName&&c.hasClass(d,"wp-more-tag")&&(c.hasClass(d,"mce-wp-more")?b.name="more":c.hasClass(d,"mce-wp-nextpage")&&(b.name="nextpage"))}),a.on("PreProcess",function(b){var c;b.save&&(c=a.dom.select("img.wp-more-tag",b.node),c.length&&tinymce.each(c,function(b){var c,d=b.parentNode;"P"===d.nodeName&&d.childNodes.length>1&&(c=a.dom.create("p"),d.parentNode.insertBefore(c,d),c.appendChild(b))}))}),a.addCommand("WP_More",function(b){var c,d,e,f,g,h="wp-more-tag",i=tinymce.Env.ie?"":'<br data-mce-bogus="1" />',j=a.dom,k=a.selection.getNode();return b=b||"more",h+=" mce-wp-"+b,e="more"===b?"More...":"Next Page",d='<img src="'+tinymce.Env.transparentSrc+'" title="'+e+'" class="'+h+'" data-mce-resize="false" data-mce-placeholder="1" />',"BODY"===k.nodeName?void a.insertContent("<p>"+d+"</p><p></p>"):(c=j.getParent(k,function(a){return a.parentNode&&"BODY"===a.parentNode.nodeName?!0:!1},a.getBody()),void(c&&(f=j.create("p",null,d),j.insertAfter(f,c),(g=f.nextSibling)||(g=j.create("p",null,i),j.insertAfter(g,f)),a.nodeChanged(),a.selection.setCursorLocation(g,0))))}),a.addCommand("WP_Page",function(){a.execCommand("WP_More","nextpage")}),a.addCommand("WP_Help",function(){a.windowManager.open({url:tinymce.baseURL+"/wp-mce-help.php",width:450,height:420,inline:1})}),a.addCommand("WP_Medialib",function(){"undefined"!=typeof wp&&wp.media&&wp.media.editor&&wp.media.editor.open(a.id)}),a.addButton("wp_more",{tooltip:"Insert Read More tag",onclick:function(){a.execCommand("WP_More","more")}}),a.addButton("wp_page",{tooltip:"Page break",onclick:function(){a.execCommand("WP_More","nextpage")}}),a.addButton("wp_help",{tooltip:"Help",cmd:"WP_Help"}),"undefined"!=typeof wp&&wp.media&&wp.media.editor&&a.addMenuItem("add_media",{text:"Add Media",context:"insert",cmd:"WP_Medialib"}),a.addMenuItem("wp_more",{text:"Insert Read More tag",context:"insert",onclick:function(){a.execCommand("WP_More","more")}}),a.addMenuItem("wp_page",{text:"Page break",context:"insert",onclick:function(){a.execCommand("WP_More","nextpage")}}),a.on("BeforeExecCommand",function(b){!tinymce.Env.webkit||"InsertUnorderedList"!==b.command&&"InsertOrderedList"!==b.command||(i||(i=a.dom.create("style",{type:"text/css"},"#tinymce,#tinymce span,#tinymce li,#tinymce li>span,#tinymce p,#tinymce p>span{font:medium sans-serif;color:#000;line-height:normal;}")),a.getDoc().head.appendChild(i))}),a.on("ExecCommand",function(b){tinymce.Env.webkit&&i&&("InsertUnorderedList"===b.command||"InsertOrderedList"===b.command)&&a.dom.remove(i)}),a.on("init",function(){var b=tinymce.Env,c=["mceContentBody"],d=a.getDoc();"rtl"===a.getParam("directionality")&&c.push("rtl"),b.ie&&(9===parseInt(b.ie,10)?c.push("ie9"):8===parseInt(b.ie,10)?c.push("ie8"):b.ie<8&&c.push("ie7")),c.push("wp-editor"),tinymce.each(c,function(b){b&&a.dom.addClass(d.body,b)}),a.on("BeforeSetContent",function(a){a.content&&(a.content=a.content.replace(/<p>\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre|address)( [^>]*)?>/gi,"<$1$2>"),a.content=a.content.replace(/<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre|address)>\s*<\/p>/gi,"</$1>"))}),"undefined"!=typeof window.jQuery&&window.jQuery(document).triggerHandler("tinymce-editor-init",[a]),"ontouchstart"in window||a.dom.bind(d,"onwheel"in d?"wheel":"mousewheel",function(c){var e,f=d.documentElement;a.settings.wp_fullscreen||("undefined"!=typeof c.deltaY?(e=c.deltaY,"undefined"!=typeof c.deltaMode&&c.deltaMode===c.DOM_DELTA_LINE&&(e*=20)):e=-c.wheelDelta,c.preventDefault(),b.webkit?d.body.scrollTop+=e:f.scrollTop+=e)})}),"undefined"!=typeof window.jQuery&&a.on("keyup",function(b){var c=b.keyCode||b.charCode;c!==k&&((13===c||8===k||46===k)&&window.jQuery(document).triggerHandler("wpcountwords",[a.getContent({format:"raw"})]),k=c)}),a.on("SaveContent",function(b){return a.isHidden()?void(b.content=b.element.value):(b.content=b.content.replace(/<p>(<br ?\/?>|\u00a0|\uFEFF)?<\/p>/g,"<p>&nbsp;</p>"),void(a.getParam("wpautop",!0)&&"undefined"!=typeof switchEditors&&(b.content=switchEditors.pre_wpautop(b.content))))}),a.on("preInit",function(){a.schema.addValidElements("@[id|accesskey|class|dir|lang|style|tabindex|title|contenteditable|draggable|dropzone|hidden|spellcheck|translate],i,b")}),h="alt+shift",a.addShortcut(h+"+c","","JustifyCenter"),a.addShortcut(h+"+r","","JustifyRight"),a.addShortcut(h+"+l","","JustifyLeft"),a.addShortcut(h+"+j","","JustifyFull"),a.addShortcut(h+"+q","","mceBlockQuote"),a.addShortcut(h+"+u","","InsertUnorderedList"),a.addShortcut(h+"+o","","InsertOrderedList"),a.addShortcut(h+"+n","","mceSpellCheck"),a.addShortcut(h+"+a","","WP_Link"),a.addShortcut(h+"+s","","unlink"),a.addShortcut(h+"+m","","WP_Medialib"),a.addShortcut(h+"+z","","WP_Adv"),a.addShortcut(h+"+t","","WP_More"),a.addShortcut(h+"+d","","Strikethrough"),a.addShortcut(h+"+h","","WP_Help"),a.addShortcut(h+"+p","","WP_Page"),a.addShortcut("ctrl+s","",function(){"undefined"!=typeof wp&&wp.autosave&&wp.autosave.server.triggerSave()}),a.on("init",function(){a.dom.bind(a.getWin(),"scroll",function(){f()}),a.dom.bind(a.getBody(),"dragstart",function(){f()})}),a.on("BeforeExecCommand",function(){f()}),a.on("SaveContent",function(){f()}),a.on("MouseDown",function(a){"IMG"!==a.target.nodeName&&f()}),a.on("keydown",function(a){(a.which===tinymce.util.VK.DELETE||a.which===tinymce.util.VK.BACKSPACE)&&f()}),{_showButtons:e,_hideButtons:f,_setEmbed:c,_getEmbed:d}});