Seditio Source
Root |
./othercms/b2evolution_7.2.3/rsc/ext/tiny_mce/plugins/evo_view/plugin.min.js
tinymce.PluginManager.add("evo_view",function(d){var g,o,a,p,s,l,n,i,r=d.$,c=tinymce.Env,f=tinymce.util.VK,v=tinymce.dom.TreeWalker,m=!1,u=!0,b=/iPad|iPod|iPhone/.test(navigator.userAgent),S=["image","thumbnail","inline","button","cta","like","dislike","activate","unsubscribe"];function _(e,t){for(;e&&e.parentNode;){if(e.className&&-1!==(" "+e.className+" ").indexOf(" "+t+" "))return e;e=e.parentNode}return!1}function w(e){return _(e,"evo-view-wrap")}function e(){var e;if(o&&(e=o.getAttribute("data-evo-view-type")),-1==S.indexOf(e))return openModalWindow('<span class="loader_img loader_user_report absolute_center" title="'+evo_js_lang_loading+'..."></span>',"80%","",!0,evo_js_lang_select_image_insert,"",!0),jQuery.ajax({type:"POST",url:d.getParam("modal_url"),success:function(e){openModalWindow(e,"90%","80%",!0,"Select image","","","","","",function(){var e,t;t=null==d.getParam("temp_ID")?(e=d.getParam("target_type"),d.getParam("target_ID")):(e="temporary",d.getParam("temp_ID")),evo_link_refresh_list(e,t,"refresh"),evo_link_fix_wrapper_height()})}}),!1;var t=decodeURIComponent(g.getAttribute("data-evo-view-text"));evo_item_image_edit(d.settings.blog_ID,t)}function C(e){e.stopPropagation()}function D(e,t){var n=e?"before":"after";P(),d.selection.setCursorLocation(d.dom.select(".evo-view-selection-"+n,t)[0]),d.nodeChanged()}function y(e,t,n){var i=d.dom,o=i.create("p");c.ie&&c.ie<11||(o.innerHTML='<br data-mce-bogus="1">'),t?e.parentNode.insertBefore(o,e):i.insertAfter(o,e),P(),t&&n===f.ENTER?D(t,e):d.selection.setCursorLocation(o,0),d.nodeChanged()}function h(e){d.undoManager.transact(function(){evo.views.remove(d,e)})}function x(e){var t,n=d.dom;e&&(e!==g&&(P(),o=w(g=e),n.setAttrib(e,"data-mce-selected",1),n.addClass(g,"evo-view-selected"),t=n.create("div",{class:"evo-view-clipboard",contenteditable:"true"},evo.views.getText(e)),d.dom.select(".evo-view-body",e)[0].appendChild(t),n.bind(t,"beforedeactivate focusin focusout",C),n.bind(g,"beforedeactivate focusin focusout",C),b?d.selection.select(t):d.selection.select(t,!0)),d.nodeChanged(),d.fire("evo-view-selected",e))}function P(){var e,t=d.dom;g&&(e=d.dom.select(".evo-view-clipboard",g)[0],t.unbind(e),t.remove(e),t.unbind(g,"beforedeactivate focusin focusout click mouseup",C),t.setAttrib(g,"data-mce-selected",null),t.removeClass(g,"evo-view-selected")),o=g=null}function t(e,t){return window.decodeURIComponent(t)}function E(e){r("div[data-evo-view-text], span[data-evo-view-text], p[data-evo-view-marker]",e).each(function(e,t){t.innerHTML="."})}function N(e){return e<=47&&e!==f.SPACEBAR&&e!==f.ENTER&&e!==f.DELETE&&e!==f.BACKSPACE&&(e<37||40<e)||224<=e||144<=e&&e<=150||91<=e&&e<=93||112<=e&&e<=135}return d.on("BeforeAddUndo",function(e){e.level.content&&(e.level.content=function(e){return e.replace(/<(?:div|span)[^>]+data-evo-view-text="([^"]+)"[^>]*>(?:[\s\S]+?evo-view-selection-after[^>]+>[^<>]*<\/p>\s*|\.)<\/(?:div|span)>/g,t).replace(/<p [^>]*?data-evo-view-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g,t)}(e.level.content))}),d.on("BeforeSetContent",function(e){var t;if(e.selection||evo.views.unbind(),e.content){if(!e.load&&(g&&(h(g),P()),(t=d.selection.getNode())&&t!==d.getBody()&&/^\s*https?:\/\/\S+\s*$/i.test(e.content))){if(!(t=d.dom.getParent(t,"p"))||!/^[\s\uFEFF\u00A0]*$/.test(r(t).text()||""))return;t.innerHTML=""}e.content=evo.views.setMarkers(e.content)}}),d.on("pastePreProcess",function(e){var t=e.content;t&&(t=tinymce.trim(t.replace(/<[^>]+>/g,"")),/^https?:\/\/\S+$/i.test(t)&&(e.content=t))}),d.on("SetContent",function(){evo.views.render()}),d.on("click",function(n){var e,t,i,o=n.clientX,r=n.clientY,a=d.getBody(),s=a.getBoundingClientRect(),l=a.firstChild,c=a.lastChild;l&&c&&(e=l.getBoundingClientRect(),t=c.getBoundingClientRect(),r<e.top&&(i=w(l))?(D(!0,i),n.preventDefault()):r>t.bottom&&(i=w(c))?(D(!1,i),n.preventDefault()):(o<s.left||o>s.right)&&tinymce.each(d.dom.select(".evo-view-wrap"),function(e){var t=e.getBoundingClientRect();return!(r<t.top)&&(r>=t.top&&r<=t.bottom?(o<s.left?(D(!0,e),n.preventDefault()):o>s.right&&(D(!1,e),n.preventDefault()),!1):void 0)}))}),d.on("init",function(){var i=!1,n=d.selection,e=window.MutationObserver||window.WebKitMutationObserver;d.on("BeforeSetContent",function(){var e,t=w(n.getNode());t&&(!t.nextSibling||w(t.nextSibling)?(e=d.getDoc().createTextNode(""),d.dom.insertAfter(e,t)):e=new v(t.nextSibling,t.nextSibling).next(),n.select(e),n.collapse(!0))}),d.dom.bind(d.getDoc(),"touchmove",function(){i=!0}),d.on("dblclick",function(e){var t=w(e.target);if(t){e.stopImmediatePropagation(),e.preventDefault(),"touchend"===e.type&&i?i=!1:x(t),o&&(viewType=o.getAttribute("data-evo-view-type"));var n=decodeURIComponent(g.getAttribute("data-evo-view-text"));return evo_item_image_edit(d.settings.blog_ID,n),!1}}),d.on("mousedown mouseup click touchend",function(e){var t=w(e.target);if(u=!1,t)return e.stopImmediatePropagation(),e.preventDefault(),"touchend"===e.type&&i?i=!1:x(t),!1;"touchend"!==e.type&&"mousedown"!==e.type||P(),"touchend"===e.type&&i&&(i=!1)},!0),e&&new e(function(){d.fire("evo-body-class-change")}).observe(d.getBody(),{attributes:!0,attributeFilter:["class"]}),tinymce.Env.ie&&d.dom.bind(d.getBody(),"controlselect mscontrolselect",function(e){w(e.target)&&e.preventDefault()})}),d.on("PreProcess",function(e){E(e.node)},!0),d.on("hide",function(){evo.views.unbind(),P(),E()}),d.on("PostProcess",function(e){e.content&&(e.content=e.content.replace(/<(?:div|span) [^>]*?data-evo-view-text="([^"]+)"[^>]*>[\s\S]*?<\/(?:div|span)>/g,t).replace(/<p [^>]*?data-evo-view-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g,t))}),d.on("keydown",function(e){var t,n,i,o,r,a=e.keyCode,s=d.dom,l=d.selection;if(g){if((e.metaKey||e.ctrlKey)&&a!==f.BACKSPACE&&86!==a||112<=a&&a<=123)return void((e.metaKey||e.ctrlKey)&&88===a&&(m=g));if((n=w(l.getNode()))!==g)return void P();a===f.LEFT?(D(!0,n),e.preventDefault()):a===f.UP?(n.previousSibling?w(n.previousSibling)?D(!0,n.previousSibling):(P(),l.select(n.previousSibling,!0),l.collapse()):D(!0,n),e.preventDefault()):a===f.RIGHT?(D(!1,n),e.preventDefault()):a===f.DOWN?(n.nextSibling?w(n.nextSibling)?D(!1,n.nextSibling):(P(),l.setCursorLocation(n.nextSibling,0)):D(!1,n),e.preventDefault()):N(a)||(a===f.ENTER?(y(n,!1,a),e.preventDefault()):a===f.DELETE?(h(g),P(),e.preventDefault()):a===f.BACKSPACE&&(previousView=w(n.previousElementSibling),previousView?h(previousView):n.previousSibling?(l.setCursorLocation(n.previousSibling),P()):n.parentNode.previousSibling&&(l.setCursorLocation(n.parentNode.previousSibling,1),P())))}else{if(e.metaKey||e.ctrlKey||112<=a&&a<=123)return;if(t=l.getNode(),n=w(p=t),l.isCollapsed()||((n=w((i=l.getRng()).endContainer))?(o=i.cloneRange(),l.select(n.previousSibling,!0),l.collapse(),r=l.getRng(),o.setEnd(r.endContainer,r.endOffset),l.setRng(o)):(n=w(i.startContainer))&&((o=i.cloneRange()).setStart(n.nextSibling,0),l.setRng(o))),!n)return void(a===f.BACKSPACE&&(d.dom.isEmpty(t)?(n=w(t.previousSibling))&&(D(!1,n),d.dom.remove(t),e.preventDefault()):(i=l.getRng())&&0===i.startOffset&&0===i.endOffset&&(n=w(t.previousSibling))&&(D(!1,n),e.preventDefault())));var c=s.hasClass(n,"evo-view-selection-before"),v=s.hasClass(n,"evo-view-selection-after");if(!c&&!v)return;if(N(a))return;if(v&&a===f.UP||c&&a===f.BACKSPACE)n.previousSibling?w(n.previousSibling)?D(!1,n.previousSibling):s.isEmpty(n.previousSibling)&&a===f.BACKSPACE?s.remove(n.previousSibling):(l.select(n.previousSibling,!0),l.collapse()):D(!0,n),e.preventDefault();else if(!v||a!==f.DOWN&&a!==f.RIGHT)if(!c||a!==f.UP&&a!==f.LEFT)if(c&&a===f.DOWN)n.nextSibling?w(n.nextSibling)?D(!0,n.nextSibling):l.setCursorLocation(n.nextSibling,0):D(!1,n),e.preventDefault();else if(v&&a===f.LEFT||c&&a===f.RIGHT)x(n),e.preventDefault();else if(v&&a===f.BACKSPACE)h(n),e.preventDefault();else if(c&&a===f.DELETE){var u=w(n.nextSibling);h(n),u&&D(!0,u),e.preventDefault()}else if(v&&a===f.DELETE){(u=w(n.nextSibling))&&D(!0,u),e.preventDefault()}else v?y(n):c&&y(n,!0,a);else n.previousSibling?w(n.previousSibling)?D(a===f.UP,n.previousSibling):(l.select(n.previousSibling,!0),l.collapse()):n.parentNode.previousSibling&&(w(n.parentNode.previousSibling)?D(a===f.RIGHT,n.parentNode.previousSibling):(l.select(n.parentNode.previousSibling,!0),l.collapse(!1))),e.preventDefault();else n.nextSibling?w(n.nextSibling)?D(a===f.RIGHT,n.nextSibling):l.setCursorLocation(n.nextSibling):n.parentNode.nextSibling&&(w(n.parentNode.nextSibling)?D(a===f.RIGHT,n.parentNode.nextSibling):l.setCursorLocation(n.parentNode.nextSibling)),e.preventDefault();a===f.ENTER&&e.preventDefault()}}),d.on("keyup",function(){m&&(h(m),P(),m=!1)}),d.on("focus",function(){var e;l=!0,d.dom.addClass(d.getBody(),"has-focus"),u&&(e=w(d.getBody().firstChild))&&D(!0,e),u=!1}),d.on("blur",function(){l=!1,d.dom.removeClass(d.getBody(),"has-focus")}),d.on("NodeChange",function(e){var t=d.dom,n=d.dom.select(".evo-view-wrap"),i=e.element.className,o=w(e.element),r=p;if(p=!1,clearInterval(a),tinymce.each(n,function(e){e.className&&(e.className=e.className.replace(/ ?\bevo-view-(?:selection-before|selection-after|cursor-hide)\b/g,""))}),l&&o)if("evo-view-selection-before"!==i&&"evo-view-selection-after"!==i||!d.selection.isCollapsed())_(e.element,"evo-view-clipboard")||s||(P(),s++,D(!0,o));else{if(s=0,P(),r===o.previousSibling)return void D(!0,o);if(r===o.nextSibling)return void D(!1,o);t.addClass(o,i),a=setInterval(function(){t.hasClass(o,"evo-view-cursor-hide")?t.removeClass(o,"evo-view-cursor-hide"):t.addClass(o,"evo-view-cursor-hide")},500)}}),d.on("BeforeExecCommand",function(){var e,t=d.selection.getNode();t&&((i="evo-view-selection-before"===t.className)||"evo-view-selection-after"===t.className)&&(e=w(t))&&(y(e,i),n=e)}),d.on("ExecCommand",function(){var e,t;g&&(e=g,P(),x(e)),n&&((t=n[i?"previousSibling":"nextSibling"])&&"P"===t.nodeName&&d.dom.isEmpty(t)&&(d.dom.remove(t),D(i,n)),n=!1)}),d.on("ResolveName",function(e){d.dom.hasClass(e.target,"evo-view-wrap")?(e.name=d.dom.getAttrib(e.target,"data-evo-view-type")||"evo-view",e.stopPropagation()):w(e.target)&&(e.preventDefault(),e.stopPropagation())}),d.addButton("evo_image",{text:"inline image",icon:!1,tooltip:evo_js_lang_edit_image,onclick:function(){switch(d.getParam("target_type")){case"Item":if(!d.getParam("target_ID")&&!d.getParam("temp_ID"))return alert(evo_js_lang_alert_before_insert_item),!1;break;case"Comment":if(!d.getParam("target_ID"))return alert(evo_js_lang_alert_before_insert_comment),!1;break;case"EmailCampaign":if(!d.getParam("target_ID"))return alert(evo_js_lang_alert_before_insert_emailcampaign),!1;break;case"Message":if(!d.getParam("target_ID")&&!d.getParam("temp_ID"))return alert(evo_js_lang_alert_before_insert_message),!1}e()},onPostRender:function(){var i=this;d.on("NodeChange",function(e){var t;o&&(t=o.getAttribute("data-evo-view-type"));var n=-1!=S.indexOf(t);i.active(n)})}}),d.on("evotoolbar",function(e){g&&(e.element=g,e.toolbar=void 0)}),d.addCommand("evo_view_edit_inline",function(){e()}),{getMetadata:function(){return{name:"b2evo View plugin",url:"http://b2evolution.net"}}}});