!function(){var i,o=tinymce.VK,r=tinymce.dom.TreeWalker;tinymce.create("tinymce.plugins.wpView",{init:function(e,n){var c=this;"undefined"!=typeof wp&&wp.mce&&(e.onPreInit.add(function(e){e.schema.addValidElements("div[*],span[*]")}),e.onBeforeSetContent.add(function(e,n){n.content&&(n.content=wp.mce.view.toViews(n.content))}),e.onSetContent.add(function(e,n){wp.mce.view.render(e.getDoc())}),e.onInit.add(function(o){o.selection.onBeforeSetContent.add(function(e,n){var t,i=c.getParentView(e.getNode());i&&(!i.nextSibling||c.isView(i.nextSibling)?(t=o.getDoc().createTextNode(""),o.dom.insertAfter(t,i)):t=new r(i.nextSibling,i.nextSibling).next(),e.select(t),e.collapse(!0))}),o.selection.onSetContent.add(function(e,n){!n.context||(e=e.getNode()).innerHTML&&(e.innerHTML=wp.mce.view.toViews(e.innerHTML),wp.mce.view.render(e))})}),e.onPostProcess.add(function(e,n){(n.get||n.save)&&n.content&&(n.content=wp.mce.view.toText(n.content))}),e.onNodeChange.addToTop(function(e,n,t,i,o){t=c.getParentView(t);if(t)return c.select(t),!1;c.deselect()}),e.onKeyDown.addToTop(function(e,n){var t=n.keyCode;i&&(c.getParentView(e.selection.getNode())===i?(t!==o.DELETE&&t!==o.BACKSPACE||(e=wp.mce.view.instance(i))&&(e.remove(),c.deselect()),n.metaKey||n.ctrlKey||112<=t&&t<=123||n.preventDefault()):c.deselect())}))},getParentView:function(e){for(;e;){if(this.isView(e))return e;e=e.parentNode}},isView:function(e){return/(?:^|\s)wp-view-wrap(?:\s|$)/.test(e.className)},select:function(e){e!==i&&(this.deselect(),i=e,wp.mce.view.select(i))},deselect:function(){i&&wp.mce.view.deselect(i),i=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)}();