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