tinymce.PluginManager.add("wpview",function(a){var r,d=tinymce.util.VK,o=tinymce.dom.TreeWalker,s=!1;function c(e){for(;e&&"BODY"!==e.nodeName;){if(l(e))return e;e=e.parentNode}}function l(e){return e&&/\bwpview-wrap\b/.test(e.className)}function f(){return a.dom.create("p",{"data-wpview-pad":1},tinymce.Env.ie&&tinymce.Env.ie<11?"":'
')}function i(e){return(e=c("string"==typeof e?a.dom.get(e):e))?window.decodeURIComponent(a.dom.getAttrib(e,"data-wpview-text")||""):""}function u(e){e.stopPropagation()}function p(e){var t,n=a.dom;e!==r&&(v(),r=e,n.addClass(e,"selected"),t=n.create("div",{"class":"wpview-clipboard",contenteditable:"true"},i(e)),e.insertBefore(t,e.firstChild),n.bind(t,"beforedeactivate focusin focusout",u),n.bind(r,"beforedeactivate focusin focusout",u),a.getBody().focus(),a.selection.select(t,!0))}function v(){var e,t=a.dom;r&&(e=a.dom.select(".wpview-clipboard",r)[0],t.unbind(e),t.remove(e),t.unbind(r,"beforedeactivate focusin focusout click mouseup",u),t.removeClass(r,"selected")),r=null}function m(e,t){for(var n=a.getBody(),o="previous"===t?"previousSibling":"nextSibling";e&&e.parentNode!==n;){if(e[o])return;e=e.parentNode}return l(e[o])&&(p(e[o]),1)}if("undefined"!=typeof wp&&wp.mce)return a.on("BeforeAddUndo",function(e){e.lastLevel&&t(e.level.content)===t(e.lastLevel.content)&&e.preventDefault()}),a.on("BeforeSetContent",function(e){e.content&&(e.initial||wp.mce.views.unbind(a),e.content=wp.mce.views.toViews(e.content))}),a.on("SetContent",function(e){var t,n;wp.mce.views.render(),!e.load&&e.set||l((t=a.getBody()).lastChild)&&(n=f(),t.appendChild(n),e.initial||a.selection.setCursorLocation(n,0))}),a.on("click",function(e){var t,n,o,i,r=a.getBody(),s=a.getDoc().documentElement.scrollTop||r.scrollTop||0;"HTML"!==e.target.nodeName||e.metaKey||e.ctrlKey||(n=r.firstChild,o=r.lastChild,t=e.clientX,e=e.clientY,l(n)&&(to.offsetLeft+o.offsetWidth||0]*?data-wpview-text="([^"]*)"[^>]*>[\s\S]*?<\/div>/g,function(e,t){return t?"

"+window.decodeURIComponent(t)+"

":""}))}),a.on("keydown",function(e){var t,n,o=e.keyCode,i=a.getBody();r&&(e.metaKey||e.ctrlKey||112<=o&&o<=123?(e.metaKey||e.ctrlKey)&&88===o&&(s=r):(t=c(a.selection.getNode()))===r?(o===d.LEFT||o===d.UP?(v(),l(t.previousSibling)?p(t.previousSibling):t.previousSibling?(a.selection.select(t.previousSibling,!0),a.selection.collapse()):(n=f(),i.insertBefore(n,i.firstChild),a.selection.setCursorLocation(i.firstChild,0))):o===d.RIGHT||o===d.DOWN?(v(),l(t.nextSibling)?p(t.nextSibling):t.nextSibling?a.selection.setCursorLocation(t.nextSibling,0):(n=f(),i.appendChild(n),a.selection.setCursorLocation(i.lastChild,0))):o!==d.DELETE&&o!==d.BACKSPACE||a.dom.remove(r),e.preventDefault()):v())}),a.on("keydown",function(e){var t,n,o=e.keyCode,i=a.dom,r=a.selection.getRng(),s=r.startContainer,c=a.getBody();if(s&&s!==c&&!e.metaKey&&!e.ctrlKey)if(o===d.UP||o===d.LEFT)(o!==d.LEFT||r.collapsed&&0===r.startOffset)&&(t=i.getParent(s,i.isBlock))&&m(t,"previous")&&e.preventDefault();else if((o===d.DOWN||o===d.RIGHT)&&(t=i.getParent(s,i.isBlock))){if(o===d.RIGHT){if(n=r.endContainer,!r.collapsed||0===r.startOffset&&n.length||n.nextSibling||3===n.nodeType&&r.startOffset!==n.length)return;for(;n&&n!==t&&n!==c;){if(n.nextSibling)return;n=n.parentNode}}m(t,"next")&&e.preventDefault()}}),a.on("keyup",function(e){var t,n=e.keyCode,e=a.getBody();s&&(a.dom.remove(s),s=!1),n!==d.DELETE&&n!==d.BACKSPACE||(l(e.lastChild)&&(t=f(),e.appendChild(t),2===e.childNodes.length&&a.selection.setCursorLocation(t,0)),t=a.selection.getRng(),e.firstChild===t.startContainer&&!0===t.collapsed&&l(t.startContainer.nextSibling)&&0===t.startOffset&&a.dom.remove(t.startContainer))}),{getViewText:i,setViewText:function(e,t){return!!(e=c("string"==typeof e?a.dom.get(e):e))&&(a.dom.setAttrib(e,"data-wpview-text",window.encodeURIComponent(t||"")),!0)}};function t(e){return e.replace(/(]+wpview-wrap[^>]+>)[\s\S]+?data-wpview-end[^>]*><\/ins><\/div>/g,"$1")}});