tinymce.PluginManager.add("wpview",function(d){function e(){return!1}var u,a,p,s,c,n,i,r=tinymce.Env,v=tinymce.util.VK,o=tinymce.dom.TreeWalker,f=!1,l=!0,g=/iPad|iPod|iPhone/.test(navigator.userAgent);function w(e){return m(e,"wpview-wrap")}function m(e,t){for(;e&&e.parentNode;){if(e.className&&-1!==(" "+e.className+" ").indexOf(" "+t+" "))return e;e=e.parentNode}return!1}function b(e){return(e=w(e))?window.decodeURIComponent(d.dom.getAttrib(e,"data-wpview-text")||""):""}function C(e){e.stopPropagation()}function S(e,t){var n=e?"before":"after",e=e?0:1;E(),d.selection.setCursorLocation(d.dom.select(".wpview-selection-"+n,t)[0],e),d.nodeChanged()}function y(e,t,n){var i=d.dom,o=i.create("p");r.ie&&r.ie<11||(o.innerHTML='
'),t?e.parentNode.insertBefore(o,e):i.insertAfter(o,e),E(),t&&n===v.ENTER?S(t,e):d.selection.setCursorLocation(o,0),d.nodeChanged()}function x(e){d.undoManager.transact(function(){y(e),d.dom.remove(e)})}function h(e){var t,n=d.dom;e&&e!==u&&(d.getBody().focus(),E(),u=e,n.setAttrib(e,"data-mce-selected",1),t=n.create("div",{"class":"wpview-clipboard",contenteditable:"true"},b(e)),d.dom.select(".wpview-body",e)[0].appendChild(t),n.bind(t,"beforedeactivate focusin focusout",C),n.bind(u,"beforedeactivate focusin focusout",C),g?d.selection.select(t):d.selection.select(t,!0),d.nodeChanged(),d.fire("wpview-selected",e))}function E(){var e,t=d.dom;u&&(e=d.dom.select(".wpview-clipboard",u)[0],t.unbind(e),t.remove(e),t.unbind(u,"beforedeactivate focusin focusout click mouseup",C),t.setAttrib(u,"data-mce-selected",null)),u=null}return"undefined"!=typeof wp&&wp.mce?(d.on("BeforeAddUndo",function(e){e.lastLevel&&t(e.level.content)===t(e.lastLevel.content)&&e.preventDefault()}),d.on("BeforeSetContent",function(e){var t;e.content&&(u&&x(u),t=d.selection.getNode(),(!e.content.match(/^\s*(https?:\/\/[^\s"]+)\s*$/i)||"P"===t.nodeName&&t.parentNode===d.getBody()&&d.dom.isEmpty(t))&&(e.content=wp.mce.views.toViews(e.content)))}),d.on("SetContent",function(){wp.mce.views.render()}),d.on("click",function(n){var e,i=n.clientX,o=n.clientY,t=d.getBody(),r=t.getBoundingClientRect(),a=t.firstChild,s=a.getBoundingClientRect(),c=t.lastChild,t=c.getBoundingClientRect();ot.bottom&&(e=w(c))?(S(!1,e),n.preventDefault()):tinymce.each(d.dom.select(".wpview-wrap"),function(e){var t=e.getBoundingClientRect();o>=t.top&&o<=t.bottom&&(ir.right&&(S(!1,e),n.preventDefault()))})}),d.on("init",function(){var n=!1,i=d.selection,e=window.MutationObserver||window.WebKitMutationObserver;d.on("BeforeSetContent",function(){var e,t=w(i.getNode());t&&(!t.nextSibling||w(t.nextSibling)?(e=d.getDoc().createTextNode(""),d.dom.insertAfter(e,t)):e=new o(t.nextSibling,t.nextSibling).next(),i.select(e),i.collapse(!0))}),d.dom.bind(d.getDoc(),"touchmove",function(){n=!0}),d.on("mousedown mouseup click touchend",function(e){var t=w(e.target);if(l=!1,t){if(e.stopImmediatePropagation(),e.preventDefault(),!("touchend"!==e.type&&"mousedown"!==e.type||e.metaKey||e.ctrlKey)){if(d.dom.hasClass(e.target,"edit"))return wp.mce.views.edit(t),d.focus(),!1;if(d.dom.hasClass(e.target,"remove"))return x(t),!1}return"touchend"===e.type&&n?n=!1:h(t),!1}"touchend"!==e.type&&"mousedown"!==e.type||E(),"touchend"===e.type&&n&&(n=!1)},!0),e&&new e(function(){d.fire("wp-body-class-change")}).observe(d.getBody(),{attributes:!0,attributeFilter:["class"]})}),d.on("PreProcess",function(e){tinymce.each(d.dom.select("div[data-wpview-text]",e.node),function(e){e.textContent=e.innerText=" "})}),d.on("PostProcess",function(e){e.content&&(e.content=e.content.replace(/
]*?data-wpview-text="([^"]*)"[^>]*>[\s\S]*?<\/div>/g,function(e,t){return t?"

"+window.decodeURIComponent(t)+"

":""}))}),d.on("keydown",function(e){var t,n,i,o,r,a,s=e.keyCode,c=d.dom,l=d.selection;u?(e.metaKey||e.ctrlKey)&&s!==v.BACKSPACE&&86!==s||112<=s&&s<=123?(e.metaKey||e.ctrlKey)&&88===s&&(f=u):(n=w(l.getNode()))===u?s===v.LEFT?(S(!0,n),e.preventDefault()):s===v.UP?(n.previousSibling?w(n.previousSibling)?S(!0,n.previousSibling):(E(),l.select(n.previousSibling,!0),l.collapse()):S(!0,n),e.preventDefault()):s===v.RIGHT?(S(!1,n),e.preventDefault()):s===v.DOWN?(n.nextSibling?w(n.nextSibling)?S(!1,n.nextSibling):(E(),l.setCursorLocation(n.nextSibling,0)):S(!1,n),e.preventDefault()):N(s)||(x(u),s!==v.ENTER&&s!==v.DELETE&&s!==v.BACKSPACE||e.preventDefault()):E():e.metaKey||e.ctrlKey||112<=s&&s<=123||(t=l.getNode(),n=w(p=t),l.isCollapsed()||((n=w((o=l.getRng()).endContainer))?(r=o.cloneRange(),l.select(n.previousSibling,!0),l.collapse(),a=l.getRng(),r.setEnd(a.endContainer,a.endOffset),l.setRng(r)):(n=w(o.startContainer))&&((r=o.cloneRange()).setStart(n.nextSibling,0),l.setRng(r))),n?((r=c.hasClass(n,"wpview-selection-before"))||(i=c.hasClass(n,"wpview-selection-after")))&&(N(s)||(i&&s===v.UP||r&&s===v.BACKSPACE?(n.previousSibling?w(n.previousSibling)?S(!1,n.previousSibling):c.isEmpty(n.previousSibling)&&s===v.BACKSPACE?c.remove(n.previousSibling):(l.select(n.previousSibling,!0),l.collapse()):S(!0,n),e.preventDefault()):!i||s!==v.DOWN&&s!==v.RIGHT?!r||s!==v.UP&&s!==v.LEFT?r&&s===v.DOWN?(n.nextSibling?w(n.nextSibling)?S(!0,n.nextSibling):l.setCursorLocation(n.nextSibling,0):S(!1,n),e.preventDefault()):i&&s===v.LEFT||r&&s===v.RIGHT?(h(n),e.preventDefault()):i&&s===v.BACKSPACE?(x(n),e.preventDefault()):i?y(n):r&&y(n,!0,s):(n.previousSibling&&(w(n.previousSibling)?S(s===v.UP,n.previousSibling):(l.select(n.previousSibling,!0),l.collapse())),e.preventDefault()):(n.nextSibling&&(w(n.nextSibling)?S(s===v.RIGHT,n.nextSibling):l.setCursorLocation(n.nextSibling,0)),e.preventDefault()),s===v.ENTER&&e.preventDefault())):e.keyCode===v.BACKSPACE&&(d.dom.isEmpty(t)?(n=w(t.previousSibling))&&(S(!1,n),d.dom.remove(t),e.preventDefault()):(o=l.getRng())&&0===o.startOffset&&0===o.endOffset&&(n=w(t.previousSibling))&&(S(!1,n),e.preventDefault())))}),d.on("keyup",function(){f&&(x(f),f=!1)}),d.on("focus",function(){var e;c=!0,d.dom.addClass(d.getBody(),"has-focus"),l&&(e=w(d.getBody().firstChild))&&S(!0,e),l=!1}),d.on("blur",function(){c=!1,d.dom.removeClass(d.getBody(),"has-focus")}),d.on("NodeChange",function(e){var t=d.dom,n=d.dom.select(".wpview-wrap"),i=e.element.className,o=w(e.element),r=p;p=!1,clearInterval(a),tinymce.each(n,function(e){e.className&&(e.className=e.className.replace(/ ?\bwpview-(?:selection-before|selection-after|cursor-hide)\b/g,""))}),c&&o&&("wpview-selection-before"!==i&&"wpview-selection-after"!==i||!d.selection.isCollapsed()?m(e.element,"wpview-clipboard")||s||(E(),s++,S(!0,o)):(s=0,E(),r!==o.previousSibling?r!==o.nextSibling?(t.addClass(o,i),a=setInterval(function(){t.hasClass(o,"wpview-cursor-hide")?t.removeClass(o,"wpview-cursor-hide"):t.addClass(o,"wpview-cursor-hide")},500)):S(!1,o):S(!0,o)))}),d.on("BeforeExecCommand",function(){var e,t=d.selection.getNode();t&&((i="wpview-selection-before"===t.className)||"wpview-selection-after"===t.className)&&(e=w(t))&&(y(e,i),n=e)}),d.on("ExecCommand",function(){var e;u&&(e=u,E(),h(e)),n&&((e=n[i?"previousSibling":"nextSibling"])&&"P"===e.nodeName&&d.dom.isEmpty(e)&&(d.dom.remove(e),S(i,n)),n=!1)}),d.on("ResolveName",function(e){d.dom.hasClass(e.target,"wpview-wrap")?(e.name=d.dom.getAttrib(e.target,"data-wpview-type")||"wpview",e.stopPropagation()):w(e.target)&&(e.preventDefault(),e.stopPropagation())}),{getViewText:b,setViewText:function(e,t){return!!(e=w(e))&&(d.dom.setAttrib(e,"data-wpview-text",window.encodeURIComponent(t||"")),!0)},getView:w}):{getViewText:e,setViewText:e,getView:e};function t(e){return e.replace(/]+data-wpview-text=\"([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>(?: |\u00a0)*<\/p><\/div>/g,"$1")}function N(e){return e<=47&&e!==v.SPACEBAR&&e!==v.ENTER&&e!==v.DELETE&&e!==v.BACKSPACE&&(e<37||40