tinymce.PluginManager.add("wpview",function(a){function b(a){return c(a,"wpview-wrap")}function c(a,b){for(;a&&a.parentNode;){if(a.className&&-1!==(" "+a.className+" ").indexOf(" "+b+" "))return a;a=a.parentNode}return!1}function d(c){return(c=b(c))?window.decodeURIComponent(a.dom.getAttrib(c,"data-wpview-text")||""):""}function e(c,d){return c=b(c),c?(a.dom.setAttrib(c,"data-wpview-text",window.encodeURIComponent(d||"")),!0):!1}function f(a){a.stopPropagation()}function g(b,c){var d=b?"before":"after",e=b?0:1;k(),a.selection.setCursorLocation(a.dom.select(".wpview-selection-"+d,c)[0],e),a.nodeChanged()}function h(b,c,d){var e=a.dom,f=e.create("p");u.ie&&u.ie<11||(f.innerHTML='
'),c?b.parentNode.insertBefore(f,b):e.insertAfter(f,b),k(),c&&d===v.ENTER?g(c,b):a.selection.setCursorLocation(f,0),a.nodeChanged()}function i(b){a.undoManager.transact(function(){h(b),a.dom.remove(b)})}function j(b){var c,e=a.dom;b&&b!==n&&(a.getBody().focus(),k(),n=b,e.setAttrib(b,"data-mce-selected",1),c=e.create("div",{"class":"wpview-clipboard",contenteditable:"true"},d(b)),a.dom.select(".wpview-body",b)[0].appendChild(c),e.bind(c,"beforedeactivate focusin focusout",f),e.bind(n,"beforedeactivate focusin focusout",f),A?a.selection.select(c):a.selection.select(c,!0),a.nodeChanged(),a.fire("wpview-selected",b))}function k(){var b,c=a.dom;n&&(b=a.dom.select(".wpview-clipboard",n)[0],c.unbind(b),c.remove(b),c.unbind(n,"beforedeactivate focusin focusout click mouseup",f),c.setAttrib(n,"data-mce-selected",null)),n=null}function l(a){return a.replace(/
"+window.decodeURIComponent(b)+"
":""}))}),a.on("keydown",function(c){var d,e,f,l,o,q,r,s=c.keyCode,t=a.dom,u=a.selection;if(n){if((c.metaKey||c.ctrlKey)&&s!==v.BACKSPACE&&86!==s||s>=112&&123>=s)return void((c.metaKey||c.ctrlKey)&&88===s&&(x=n));if(e=b(u.getNode()),e!==n)return void k();s===v.LEFT?(g(!0,e),c.preventDefault()):s===v.UP?(e.previousSibling?b(e.previousSibling)?g(!0,e.previousSibling):(k(),u.select(e.previousSibling,!0),u.collapse()):g(!0,e),c.preventDefault()):s===v.RIGHT?(g(!1,e),c.preventDefault()):s===v.DOWN?(e.nextSibling?b(e.nextSibling)?g(!1,e.nextSibling):(k(),u.setCursorLocation(e.nextSibling,0)):g(!1,e),c.preventDefault()):m(s)||(i(n),(s===v.ENTER||s===v.DELETE||s===v.BACKSPACE)&&c.preventDefault())}else{if(c.metaKey||c.ctrlKey||s>=112&&123>=s)return;if(d=u.getNode(),p=d,e=b(d),u.isCollapsed()||(o=u.getRng(),(e=b(o.endContainer))?(q=o.cloneRange(),u.select(e.previousSibling,!0),u.collapse(),r=u.getRng(),q.setEnd(r.endContainer,r.endOffset),u.setRng(q)):(e=b(o.startContainer))&&(q=o.cloneRange(),q.setStart(e.nextSibling,0),u.setRng(q))),!e)return void(c.keyCode===v.BACKSPACE&&(a.dom.isEmpty(d)?(e=b(d.previousSibling))&&(g(!1,e),a.dom.remove(d),c.preventDefault()):(o=u.getRng())&&0===o.startOffset&&0===o.endOffset&&(e=b(d.previousSibling))&&(g(!1,e),c.preventDefault())));if(!(f=t.hasClass(e,"wpview-selection-before"))&&!(l=t.hasClass(e,"wpview-selection-after")))return;if(m(s))return;l&&s===v.UP||f&&s===v.BACKSPACE?(e.previousSibling?b(e.previousSibling)?g(!1,e.previousSibling):t.isEmpty(e.previousSibling)&&s===v.BACKSPACE?t.remove(e.previousSibling):(u.select(e.previousSibling,!0),u.collapse()):g(!0,e),c.preventDefault()):!l||s!==v.DOWN&&s!==v.RIGHT?!f||s!==v.UP&&s!==v.LEFT?f&&s===v.DOWN?(e.nextSibling?b(e.nextSibling)?g(!0,e.nextSibling):u.setCursorLocation(e.nextSibling,0):g(!1,e),c.preventDefault()):l&&s===v.LEFT||f&&s===v.RIGHT?(j(e),c.preventDefault()):l&&s===v.BACKSPACE?(i(e),c.preventDefault()):l?h(e):f&&h(e,!0,s):(e.previousSibling&&(b(e.previousSibling)?g(s===v.UP,e.previousSibling):(u.select(e.previousSibling,!0),u.collapse())),c.preventDefault()):(e.nextSibling&&(b(e.nextSibling)?g(s===v.RIGHT,e.nextSibling):u.setCursorLocation(e.nextSibling,0)),c.preventDefault()),s===v.ENTER&&c.preventDefault()}}),a.on("keyup",function(){x&&(i(x),x=!1)}),a.on("focus",function(){var c;r=!0,a.dom.addClass(a.getBody(),"has-focus"),y&&(c=b(a.getBody().firstChild))&&g(!0,c),y=!1}),a.on("blur",function(){r=!1,a.dom.removeClass(a.getBody(),"has-focus")}),a.on("NodeChange",function(d){var e=a.dom,f=a.dom.select(".wpview-wrap"),h=d.element.className,i=b(d.element),j=p;if(p=!1,clearInterval(o),tinymce.each(f,function(a){a.className&&(a.className=a.className.replace(/ ?\bwpview-(?:selection-before|selection-after|cursor-hide)\b/g,""))}),r&&i)if("wpview-selection-before"!==h&&"wpview-selection-after"!==h||!a.selection.isCollapsed())c(d.element,"wpview-clipboard")||q||(k(),q++,g(!0,i));else{if(q=0,k(),j===i.previousSibling)return void g(!0,i);if(j===i.nextSibling)return void g(!1,i);e.addClass(i,h),o=setInterval(function(){e.hasClass(i,"wpview-cursor-hide")?e.removeClass(i,"wpview-cursor-hide"):e.addClass(i,"wpview-cursor-hide")},500)}}),a.on("BeforeExecCommand",function(){var c,d=a.selection.getNode();d&&((t="wpview-selection-before"===d.className)||"wpview-selection-after"===d.className)&&(c=b(d))&&(h(c,t),s=c)}),a.on("ExecCommand",function(){var b,c;n&&(b=n,k(),j(b)),s&&(c=s[t?"previousSibling":"nextSibling"],c&&"P"===c.nodeName&&a.dom.isEmpty(c)&&(a.dom.remove(c),g(t,s)),s=!1)}),a.on("ResolveName",function(c){a.dom.hasClass(c.target,"wpview-wrap")?(c.name=a.dom.getAttrib(c.target,"data-wpview-type")||"wpview",c.stopPropagation()):b(c.target)&&(c.preventDefault(),c.stopPropagation())}),{getViewText:d,setViewText:e,getView:b}):{getViewText:z,setViewText:z,getView:z}});