WordPress/wp-includes/js/tinymce/plugins/wpview/plugin.min.js

1 line
8.1 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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(a){a.stopPropagation()}function e(b,c){var d=b?"before":"after",e=b?0:1;j(),a.selection.setCursorLocation(a.dom.select(".wpview-selection-"+d,c)[0],e),a.nodeChanged()}function f(b,c,d){var f=a.dom,g=f.create("p");t.ie&&t.ie<11||(g.innerHTML='<br data-mce-bogus="1">'),c?b.parentNode.insertBefore(g,b):f.insertAfter(g,b),j(),c&&d===u.ENTER?e(c,b):a.selection.setCursorLocation(g,0),a.nodeChanged()}function g(b){a.undoManager.transact(function(){f(b),wp.mce.views.remove(a,b)})}function h(b){var c,e=a.dom;if(b){if(b===m)return void i(b);a.getBody().focus(),j(),m=b,e.setAttrib(b,"data-mce-selected",1),i(b),c=e.create("div",{"class":"wpview-clipboard",contenteditable:"true"},wp.mce.views.getText(b)),a.dom.select(".wpview-body",b)[0].appendChild(c),e.bind(c,"beforedeactivate focusin focusout",d),e.bind(m,"beforedeactivate focusin focusout",d),z?a.selection.select(c):a.selection.select(c,!0),a.nodeChanged(),a.fire("wpview-selected",b)}}function i(b){var c=0,d=a.$(b).find(".toolbar"),e=tinymce.$(a.editorContainer).find(".mce-toolbar-grp")[0],f=e&&e.getBoundingClientRect().bottom||0;d.length&&a.iframeElement&&(c=b.getBoundingClientRect().top+a.iframeElement.getBoundingClientRect().top-f-48),0>c?d.removeClass("mce-arrow-down").css({top:-43+-1*c}):c>0&&!d.hasClass("mce-arrow-down")&&d.addClass("mce-arrow-down").css({top:""})}function j(){var b,c=a.dom;m&&(b=a.dom.select(".wpview-clipboard",m)[0],c.unbind(b),c.remove(b),c.unbind(m,"beforedeactivate focusin focusout click mouseup",d),c.setAttrib(m,"data-mce-selected",null)),m=null}function k(a){return a.replace(/<div[^>]+data-wpview-text=\"([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>(?:&nbsp;|\u00a0)*<\/p><\/div>/g,"$1")}function l(a){return 47>=a&&a!==u.SPACEBAR&&a!==u.ENTER&&a!==u.DELETE&&a!==u.BACKSPACE&&(37>a||a>40)||a>=224||a>=144&&150>=a||a>=91&&93>=a||a>=112&&135>=a}var m,n,o,p,q,r,s,t=tinymce.Env,u=tinymce.util.VK,v=tinymce.dom.TreeWalker,w=!1,x=!0,y=function(){return!1},z=/iPad|iPod|iPhone/.test(navigator.userAgent);return"undefined"!=typeof wp&&wp.mce?(a.on("BeforeAddUndo",function(a){a.lastLevel&&k(a.level.content)===k(a.lastLevel.content)&&a.preventDefault()}),a.on("BeforeSetContent",function(b){var c;b.content&&(m&&g(m),c=a.selection.getNode(),(!b.content.match(/^\s*(https?:\/\/[^\s"]+)\s*$/i)||"P"===c.nodeName&&c.parentNode===a.getBody()&&a.dom.isEmpty(c))&&(b.content=wp.mce.views.setMarkers(b.content)))}),a.on("SetContent",function(){wp.mce.views.render()}),a.on("click",function(c){var d,f=c.clientX,g=c.clientY,h=a.getBody(),i=h.getBoundingClientRect(),j=h.firstChild,k=j.getBoundingClientRect(),l=h.lastChild,m=l.getBoundingClientRect();g<k.top&&(d=b(j))?(e(!0,d),c.preventDefault()):g>m.bottom&&(d=b(l))?(e(!1,d),c.preventDefault()):(f<i.left||f>i.right)&&tinymce.each(a.dom.select(".wpview-wrap"),function(a){var b=a.getBoundingClientRect();return g<b.top?!1:g>=b.top&&g<=b.bottom?(f<i.left?(e(!0,a),c.preventDefault()):f>i.right&&(e(!1,a),c.preventDefault()),!1):void 0})}),a.on("init",function(){var c=!1,d=a.selection,e=window.MutationObserver||window.WebKitMutationObserver;a.on("BeforeSetContent",function(){var c,e,f=b(d.getNode());f&&(!f.nextSibling||b(f.nextSibling)?(e=a.getDoc().createTextNode(""),a.dom.insertAfter(e,f)):(c=new v(f.nextSibling,f.nextSibling),e=c.next()),d.select(e),d.collapse(!0))}),a.dom.bind(a.getDoc(),"touchmove",function(){c=!0}),a.on("mousedown mouseup click touchend",function(d){var e=b(d.target);if(x=!1,e){if(d.stopImmediatePropagation(),d.preventDefault(),!("touchend"!==d.type&&"mousedown"!==d.type||d.metaKey||d.ctrlKey)){if(a.dom.hasClass(d.target,"edit"))return t.ie&&a.focus(),wp.mce.views.edit(a,e),!1;if(a.dom.hasClass(d.target,"remove"))return g(e),!1}return"touchend"===d.type&&c?c=!1:h(e),!1}("touchend"===d.type||"mousedown"===d.type)&&j(),"touchend"===d.type&&c&&(c=!1)},!0),e&&new e(function(){a.fire("wp-body-class-change")}).observe(a.getBody(),{attributes:!0,attributeFilter:["class"]})}),a.on("PreProcess",function(b){tinymce.each(a.dom.select("div[data-wpview-text]",b.node),function(a){a.textContent=a.innerText=" "})}),a.on("PostProcess",function(a){a.content&&(a.content=a.content.replace(/<div [^>]*?data-wpview-text="([^"]*)"[^>]*>[\s\S]*?<\/div>/g,function(a,b){return b?"<p>"+window.decodeURIComponent(b)+"</p>":""}))}),a.on("keydown",function(c){var d,i,k,n,p,q,r,s=c.keyCode,t=a.dom,v=a.selection;if(m){if((c.metaKey||c.ctrlKey)&&s!==u.BACKSPACE&&86!==s||s>=112&&123>=s)return void((c.metaKey||c.ctrlKey)&&88===s&&(w=m));if(i=b(v.getNode()),i!==m)return void j();s===u.LEFT?(e(!0,i),c.preventDefault()):s===u.UP?(i.previousSibling?b(i.previousSibling)?e(!0,i.previousSibling):(j(),v.select(i.previousSibling,!0),v.collapse()):e(!0,i),c.preventDefault()):s===u.RIGHT?(e(!1,i),c.preventDefault()):s===u.DOWN?(i.nextSibling?b(i.nextSibling)?e(!1,i.nextSibling):(j(),v.setCursorLocation(i.nextSibling,0)):e(!1,i),c.preventDefault()):l(s)||(g(m),(s===u.ENTER||s===u.DELETE||s===u.BACKSPACE)&&c.preventDefault())}else{if(c.metaKey||c.ctrlKey||s>=112&&123>=s)return;if(d=v.getNode(),o=d,i=b(d),v.isCollapsed()||(p=v.getRng(),(i=b(p.endContainer))?(q=p.cloneRange(),v.select(i.previousSibling,!0),v.collapse(),r=v.getRng(),q.setEnd(r.endContainer,r.endOffset),v.setRng(q)):(i=b(p.startContainer))&&(q=p.cloneRange(),q.setStart(i.nextSibling,0),v.setRng(q))),!i)return void(c.keyCode===u.BACKSPACE&&(a.dom.isEmpty(d)?(i=b(d.previousSibling))&&(e(!1,i),a.dom.remove(d),c.preventDefault()):(p=v.getRng())&&0===p.startOffset&&0===p.endOffset&&(i=b(d.previousSibling))&&(e(!1,i),c.preventDefault())));if(!(k=t.hasClass(i,"wpview-selection-before"))&&!(n=t.hasClass(i,"wpview-selection-after")))return;if(l(s))return;n&&s===u.UP||k&&s===u.BACKSPACE?(i.previousSibling?b(i.previousSibling)?e(!1,i.previousSibling):t.isEmpty(i.previousSibling)&&s===u.BACKSPACE?t.remove(i.previousSibling):(v.select(i.previousSibling,!0),v.collapse()):e(!0,i),c.preventDefault()):!n||s!==u.DOWN&&s!==u.RIGHT?!k||s!==u.UP&&s!==u.LEFT?k&&s===u.DOWN?(i.nextSibling?b(i.nextSibling)?e(!0,i.nextSibling):v.setCursorLocation(i.nextSibling,0):e(!1,i),c.preventDefault()):n&&s===u.LEFT||k&&s===u.RIGHT?(h(i),c.preventDefault()):n&&s===u.BACKSPACE?(g(i),c.preventDefault()):n?f(i):k&&f(i,!0,s):(i.previousSibling&&(b(i.previousSibling)?e(s===u.UP,i.previousSibling):(v.select(i.previousSibling,!0),v.collapse())),c.preventDefault()):(i.nextSibling&&(b(i.nextSibling)?e(s===u.RIGHT,i.nextSibling):v.setCursorLocation(i.nextSibling,0)),c.preventDefault()),s===u.ENTER&&c.preventDefault()}}),a.on("keyup",function(){w&&(g(w),w=!1)}),a.on("focus",function(){var c;q=!0,a.dom.addClass(a.getBody(),"has-focus"),x&&(c=b(a.getBody().firstChild))&&e(!0,c),x=!1}),a.on("blur",function(){q=!1,a.dom.removeClass(a.getBody(),"has-focus")}),a.on("NodeChange",function(d){var f=a.dom,g=a.dom.select(".wpview-wrap"),h=d.element.className,i=b(d.element),k=o;if(o=!1,clearInterval(n),tinymce.each(g,function(a){a.className&&(a.className=a.className.replace(/ ?\bwpview-(?:selection-before|selection-after|cursor-hide)\b/g,""))}),q&&i)if("wpview-selection-before"!==h&&"wpview-selection-after"!==h||!a.selection.isCollapsed())c(d.element,"wpview-clipboard")||p||(j(),p++,e(!0,i));else{if(p=0,j(),k===i.previousSibling)return void e(!0,i);if(k===i.nextSibling)return void e(!1,i);f.addClass(i,h),n=setInterval(function(){f.hasClass(i,"wpview-cursor-hide")?f.removeClass(i,"wpview-cursor-hide"):f.addClass(i,"wpview-cursor-hide")},500)}}),a.on("BeforeExecCommand",function(){var c,d=a.selection.getNode();d&&((s="wpview-selection-before"===d.className)||"wpview-selection-after"===d.className)&&(c=b(d))&&(f(c,s),r=c)}),a.on("ExecCommand",function(){var b,c;m&&(b=m,j(),h(b)),r&&(c=r[s?"previousSibling":"nextSibling"],c&&"P"===c.nodeName&&a.dom.isEmpty(c)&&(a.dom.remove(c),e(s,r)),r=!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())}),{getView:b}):{getView:y}});