Wordpress/wp-includes/js/tinymce/plugins/wpview/editor_plugin.js

1 line
1.9 KiB
JavaScript

(function(){var c=tinymce.VK,a=tinymce.dom.TreeWalker,b;tinymce.create("tinymce.plugins.wpView",{init:function(f,e){var d=this;if(typeof wp==="undefined"||!wp.mce){return}f.onPreInit.add(function(g){g.schema.addValidElements("div[*],span[*]")});f.onBeforeSetContent.add(function(g,h){if(!h.content){return}h.content=wp.mce.view.toViews(h.content)});f.onSetContent.add(function(g,h){wp.mce.view.render(g.getDoc())});f.onInit.add(function(g){g.selection.onBeforeSetContent.add(function(i,l){var h=d.getParentView(i.getNode()),k,j;if(!h){return}if(!h.nextSibling||d.isView(h.nextSibling)){j=g.getDoc().createTextNode("");g.dom.insertAfter(j,h)}else{k=new a(h.nextSibling,h.nextSibling);j=k.next()}i.select(j);i.collapse(true)});g.selection.onSetContent.add(function(h,j){if(!j.context){return}var i=h.getNode();if(!i.innerHTML){return}i.innerHTML=wp.mce.view.toViews(i.innerHTML);wp.mce.view.render(i)})});f.onPostProcess.add(function(g,h){if((!h.get&&!h.save)||!h.content){return}h.content=wp.mce.view.toText(h.content)});f.onNodeChange.addToTop(function(i,g,j,l,k){var h=d.getParentView(j);if(h){d.select(h);return false}else{d.deselect()}});f.onKeyDown.addToTop(function(i,j){var k=j.keyCode,h,g;if(!b){return}h=d.getParentView(i.selection.getNode());if(h!==b){d.deselect();return}if(k===c.DELETE||k===c.BACKSPACE){if((g=wp.mce.view.instance(b))){g.remove();d.deselect()}}if(j.metaKey||j.ctrlKey||(k>=112&&k<=123)){return}j.preventDefault()})},getParentView:function(d){while(d){if(this.isView(d)){return d}d=d.parentNode}},isView:function(d){return(/(?:^|\s)wp-view-wrap(?:\s|$)/).test(d.className)},select:function(d){if(d===b){return}this.deselect();b=d;wp.mce.view.select(b)},deselect:function(){if(b){wp.mce.view.deselect(b)}b=null},getInfo:function(){return{longname:"WordPress Views",author:"WordPress",authorurl:"http://wordpress.org",infourl:"http://wordpress.org",version:"1.0"}}});tinymce.PluginManager.add("wpview",tinymce.plugins.wpView)})();