WordPress/wp-includes/js/tinymce/plugins/wpview/plugin.min.js
2014-07-05 00:25:14 +00:00

1 line
6.2 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(b){return a.dom.getParent(b,function(b){return a.dom.hasClass(b,"wpview-wrap")})}function c(c){return(c=b(c))?window.decodeURIComponent(a.dom.getAttrib(c,"data-wpview-text")||""):""}function d(c,d){return c=b(c),c?(a.dom.setAttrib(c,"data-wpview-text",window.encodeURIComponent(d||"")),!0):!1}function e(a){a.stopPropagation()}function f(b,c){var d=b?"before":"after",e=b?0:1;a.selection.setCursorLocation(a.dom.select(".wpview-selection-"+d,c)[0],e),a.nodeChanged()}function g(b,c){var d,e=a.dom;!c&&b.nextSibling&&e.isEmpty(b.nextSibling)&&"P"===b.nextSibling.nodeName?d=b.nextSibling:c&&b.previousSibling&&e.isEmpty(b.previousSibling)&&"P"===b.previousSibling.nodeName?d=b.previousSibling:(d=e.create("p"),o.ie&&o.ie<11||(d.innerHTML='<br data-mce-bogus="1">'),c?b.parentNode.insertBefore(d,b):e.insertAfter(d,b)),i(),a.getBody().focus(),a.selection.setCursorLocation(d,0),a.nodeChanged()}function h(b){var d,f=a.dom;b!==k&&(i(),k=b,f.setAttrib(b,"data-mce-selected",1),d=f.create("div",{"class":"wpview-clipboard",contenteditable:"true"},c(b)),a.dom.select(".wpview-body",b)[0].appendChild(d),f.bind(d,"beforedeactivate focusin focusout",e),f.bind(k,"beforedeactivate focusin focusout",e),a.getBody().focus(),a.selection.select(d,!0),a.nodeChanged())}function i(){var b,c=a.dom;k&&(b=a.dom.select(".wpview-clipboard",k)[0],c.unbind(b),c.remove(b),c.unbind(k,"beforedeactivate focusin focusout click mouseup",e),c.setAttrib(k,"data-mce-selected",null)),k=null}function j(a){return a.replace(/<div[^>]+data-wpview-text=\"([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>(?:&nbsp;|\u00a0)*<\/p><\/div>/g,"$1")}var k,l,m,n,o=tinymce.Env,p=tinymce.util.VK,q=tinymce.dom.TreeWalker,r=!1;if("undefined"!=typeof wp&&wp.mce)return a.on("BeforeAddUndo",function(a){a.lastLevel&&j(a.level.content)===j(a.lastLevel.content)&&a.preventDefault()}),a.on("BeforeSetContent",function(b){var c;b.content&&(b.initial||wp.mce.views.unbind(a),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,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))?(f(!0,d),c.preventDefault()):g>m.bottom&&(d=b(l))?(f(!1,d),c.preventDefault()):tinymce.each(a.dom.select(".wpview-wrap"),function(a){var b=a.getBoundingClientRect();return g>=b.top&&g<=b.bottom?void(e<i.left?(f(!0,a),c.preventDefault()):e>i.right&&(f(!1,a),c.preventDefault())):void 0})}),a.on("init",function(){var c=a.selection;a.on("BeforeSetContent",function(){var d,e,f=b(c.getNode());f&&(!f.nextSibling||b(f.nextSibling)?(e=a.getDoc().createTextNode(""),a.dom.insertAfter(e,f)):(d=new q(f.nextSibling,f.nextSibling),e=d.next()),c.select(e),c.collapse(!0))}),a.on("SetContent",function(a){if(a.context){var b=c.getNode();b.innerHTML&&(b.innerHTML=wp.mce.views.toViews(b.innerHTML))}}),a.dom.bind(a.getBody().parentNode,"mousedown mouseup click",function(c){var d,e=b(c.target);return e?(c.stopPropagation(),o.ie<=10&&i(),h(e),"click"!==c.type||c.metaKey||c.ctrlKey||(a.dom.hasClass(c.target,"edit")?wp.mce.views.edit(e):a.dom.hasClass(c.target,"remove")&&a.dom.remove(e)),!1):(d=o.ie&&o.ie<=8?"mouseup":"mousedown",void(c.type===d&&i()))})}),a.on("PreProcess",function(b){tinymce.each(a.dom.select("div[data-wpview-text]",b.node),function(a){"textContent"in 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){if(!(c.metaKey||c.ctrlKey||i>=112&&123>=i||k)){var d,e,i=c.keyCode,j=a.dom,l=a.selection,n=l.getNode(),o=b(n);m=n,o&&((d=j.hasClass(o,"wpview-selection-before"))||(e=j.hasClass(o,"wpview-selection-after")))&&(e&&i===p.UP||d&&i===p.BACKSPACE?(o.previousSibling?b(o.previousSibling)?f(!1,o.previousSibling):j.isEmpty(o.previousSibling)&&i===p.BACKSPACE?j.remove(o.previousSibling):(l.select(o.previousSibling,!0),l.collapse()):g(o,!0),c.preventDefault()):!e||i!==p.DOWN&&i!==p.RIGHT?!d||i!==p.UP&&i!==p.LEFT?d&&i===p.DOWN?(o.nextSibling?b(o.nextSibling)?f(!0,o.nextSibling):l.setCursorLocation(o.nextSibling,0):g(o),c.preventDefault()):e&&i===p.LEFT||d&&i===p.RIGHT?(h(o),c.preventDefault(),c.stopImmediatePropagation()):e&&i===p.BACKSPACE?(j.remove(o),c.preventDefault()):e?g(o):d&&g(o,!0):(o.previousSibling?b(o.previousSibling)?f(!0,o.previousSibling):(l.select(o.previousSibling,!0),l.collapse()):g(o,!0),c.preventDefault()):(o.nextSibling?b(o.nextSibling)?f(!1,o.nextSibling):l.setCursorLocation(o.nextSibling,0):g(o),c.preventDefault()),i===p.ENTER&&c.preventDefault())}}),a.on("keydown",function(c){var d,e=a.dom,h=c.keyCode,j=a.selection;if(k){if(c.metaKey||c.ctrlKey||h>=112&&123>=h)return void(!c.metaKey&&!c.ctrlKey||88!==h&&h!==p.BACKSPACE||(88===h?r=k:a.dom.remove(k)));if(d=b(j.getNode()),d!==k)return void i();h===p.LEFT||h===p.UP?(f(!0,d),i()):h===p.RIGHT||h===p.DOWN?(f(!1,d),i()):h===p.ENTER?g(d):(h===p.DELETE||h===p.BACKSPACE)&&e.remove(k),c.preventDefault()}}),a.on("keydown",function(c){var d,e,g,h=a.selection;c.keyCode===p.BACKSPACE&&(d=h.getNode(),a.dom.isEmpty(d)?(g=b(d.previousSibling))&&(f(!1,g),a.dom.remove(d),c.preventDefault()):(e=h.getRng())&&0===e.startOffset&&0===e.endOffset&&(g=b(d.previousSibling))&&(f(!1,g),c.preventDefault()))}),a.on("keyup",function(){r&&(a.dom.remove(r),r=!1)}),a.on("nodechange",function(c){var d=a.dom,e=a.dom.select(".wpview-wrap"),g=c.element.className,h=b(c.element),i=m;if(m=!1,clearInterval(l),d.removeClass(e,"wpview-selection-before"),d.removeClass(e,"wpview-selection-after"),d.removeClass(e,"wpview-cursor-hide"),h)if("wpview-selection-before"===g||"wpview-selection-after"===g){if(n=0,i===h.previousSibling)return void f(!0,h);if(i===h.nextSibling)return void f(!1,h);d.addClass(h,g),l=setInterval(function(){d.hasClass(h,"wpview-cursor-hide")?d.removeClass(h,"wpview-cursor-hide"):d.addClass(h,"wpview-cursor-hide")},500)}else k||n||(n++,f(!0,h))}),{getViewText:c,setViewText:d}});