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

1 line
8.3 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(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;l(),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");v.ie&&v.ie<11||(f.innerHTML='<br data-mce-bogus="1">'),c?b.parentNode.insertBefore(f,b):e.insertAfter(f,b),l(),c&&d===w.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;if(b){if(b===o)return void k(b);a.getBody().focus(),l(),o=b,e.setAttrib(b,"data-mce-selected",1),k(b),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(o,"beforedeactivate focusin focusout",f),B?a.selection.select(c):a.selection.select(c,!0),a.nodeChanged(),a.fire("wpview-selected",b)}}function k(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 l(){var b,c=a.dom;o&&(b=a.dom.select(".wpview-clipboard",o)[0],c.unbind(b),c.remove(b),c.unbind(o,"beforedeactivate focusin focusout click mouseup",f),c.setAttrib(o,"data-mce-selected",null)),o=null}function m(a){return a.replace(/<div[^>]+data-wpview-text=\"([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>(?:&nbsp;|\u00a0)*<\/p><\/div>/g,"$1")}function n(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 o,p,q,r,s,t,u,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.lastLevel&&m(a.level.content)===m(a.lastLevel.content)&&a.preventDefault()}),a.on("BeforeSetContent",function(b){var c;b.content&&(o&&i(o),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.toViews(b.content)))}),a.on("SetContent",function(){wp.mce.views.render()}),a.on("click",function(c){var d,e=c.clientX,f=c.clientY,h=a.getBody(),i=h.getBoundingClientRect(),j=h.firstChild,k=j.getBoundingClientRect(),l=h.lastChild,m=l.getBoundingClientRect();f<k.top&&(d=b(j))?(g(!0,d),c.preventDefault()):f>m.bottom&&(d=b(l))?(g(!1,d),c.preventDefault()):(e<i.left||e>i.right)&&tinymce.each(a.dom.select(".wpview-wrap"),function(a){var b=a.getBoundingClientRect();return f<b.top?!1:f>=b.top&&f<=b.bottom?(e<i.left?(g(!0,a),c.preventDefault()):e>i.right&&(g(!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(d){var e=b(d.target);if(z=!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 v.ie&&a.focus(),wp.mce.views.edit(e),!1;if(a.dom.hasClass(d.target,"remov