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

1 line
8.2 KiB
JavaScript
Raw Normal View History

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;i(),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");v.ie&&v.ie<11||(g.innerHTML='<br data-mce-bogus="1">'),c?b.parentNode.insertBefore(g,b):f.insertAfter(g,b),i(),c&&d===w.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;b&&(b!==m&&(a.getBody().focus(),i(),m=b,e.setAttrib(b,"data-mce-selected",1),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),B?a.selection.select(c):a.selection.select(c,!0)),a.nodeChanged(),a.fire("wpview-selected",b))}function i(){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 j(a){return a=a.replace(/<div[^>]+data-wpview-text="([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>[^<>]*<\/p>\s*<\/div>/g,function(a,b){return"<p>"+window.decodeURIComponent(b)+"</p>"}),a.replace(/ data-wpview-marker="[^"]+"/g,"")}function k(b){u("div[data-wpview-text]",b).each(function(b,c){var d=u(c),e=window.decodeURIComponent(d.attr("data-wpview-text")||"");e&&c.parentNode&&d.replaceWith(u(a.dom.create("p")).text(e))}),u("p[data-wpview-marker]",b).attr("data-wpview-marker",null)}function l(a){return 47>=a&&a!==w.SPACEBAR&&a!==w.ENTER&&a!==w.DELETE&&a!==w.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,u=a.$,v=tinymce.Env,w=tinymce.util.VK,x=tinymce.dom.TreeWalker,y=!1,z=!0,A=function(){return!1},B=/iPad|iPod|iPhone/.test(navigator.userAgent);return"undefined"!=typeof wp&&wp.mce?(a.on("BeforeAddUndo",function(a){a.level.content&&(a.level.content=j(a.level.content))}),a.on("BeforeSetContent",function(b){var c;if(b.selection||wp.mce.views.unbind(),b.content){if(!b.load&&(m&&g(m),c=a.selection.getNode(),c&&c!==a.getBody()&&/^\s*https?:\/\/\S+\s*$/i.test(b.content))){if(c=a.dom.getParent(c,"p"),!c||!/^[\s\uFEFF\u00A0]*$/.test(u(c).text()||""))return;c.innerHTML=""}b.content=wp.mce.views.setMarkers(b.content)}}),a.on("pastePreProcess",function(a){var b=a.content;b&&(b=tinymce.trim(b.replace(/<[^>]+>/g,"")),/^https?:\/\/\S+$/i.test(b)&&(a.content=b))}),a.on("SetContent",function(){wp.mce.views.render()}),a.on("click",function(c){var d,f,g,h=c.clientX,i=c.clientY,j=a.getBody(),k=j.getBoundingClientRect(),l=j.firstChild,m=j.lastChild;l&&m&&(d=l.getBoundingClientRect(),f=m.getBoundingClientRect(),i<d.top&&(g=b(l))?(e(!0,g),c.preventDefault()):i>f.bottom&&(g=b(m))?(e(!1,g),c.preventDefault()):(h<k.left||h>k.right)&&tinymce.each(a.dom.select(".wpview-wrap"),function(a){var b=a.getBoundingClientRect();return i<b.top?!1:i>=b.top&&i<=b.bottom?(h<k.left?(e(!0,a),c.preventDefault()):h>k.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 x(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(a){var d=b(a.target);return z=!1,d?(a.stopImmediatePropagation(),a.preventDefault(),"touchend"===a.type&&c?c=!1:h(d),!1):(("touchend"===a.type||"mousedown"===a.type)&&i(),void("touchend"===a.type&&c&&(c=!1)))},!0),e&&new e(function(){a.fire("wp-body-class-change")}).observe(a.ge