mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-13 10:11:22 +01:00
1 line
14 KiB
JavaScript
1 line
14 KiB
JavaScript
!function(){"use strict";var o,e=tinymce.util.Tools.resolve("tinymce.PluginManager"),c=Object.prototype.hasOwnProperty,g=(o=function(e,t){return t},function(){for(var e=new Array(arguments.length),t=0;t<e.length;t++)e[t]=arguments[t];if(0===e.length)throw new Error("Can't merge zero objects");for(var r={},i=0;i<e.length;i++){var n=e[i];for(var a in n)c.call(n,a)&&(r[a]=o(r[a],n[a]))}return r}),w=tinymce.util.Tools.resolve("tinymce.util.Tools"),b=function(e){return e.getParam("media_scripts")},v=function(e){return e.getParam("audio_template_callback")},y=function(e){return e.getParam("video_template_callback")},a=function(e){return e.getParam("media_live_embeds",!0)},t=function(e){return e.getParam("media_filter_html",!0)},s=function(e){return e.getParam("media_url_resolver")},x=function(e){return e.getParam("media_alt_source",!0)},j=function(e){return e.getParam("media_poster",!0)},C=function(e){return e.getParam("media_dimensions",!0)},m=tinymce.util.Tools.resolve("tinymce.html.SaxParser"),r=tinymce.util.Tools.resolve("tinymce.dom.DOMUtils"),_=function(e,t){if(e)for(var r=0;r<e.length;r++)if(-1!==t.indexOf(e[r].filter))return e[r]},i=function(t){return function(e){return e?e.style[t].replace(/px$/,""):""}},n=function(i){return function(e,t){var r;e&&(e.style[i]=/^[0-9.]+$/.test(r=t)?r+"px":r)}},M={getMaxWidth:i("maxWidth"),getMaxHeight:i("maxHeight"),setMaxWidth:n("maxWidth"),setMaxHeight:n("maxHeight")},u=r.DOM,l=function(e){return u.getAttrib(e,"data-ephox-embed-iri")},A=function(e,t){return c=t,s=u.createFragment(c),""!==l(s.firstChild)?(a=t,o=u.createFragment(a).firstChild,{type:"ephox-embed-iri",source1:l(o),source2:"",poster:"",width:M.getMaxWidth(o),height:M.getMaxHeight(o)}):(i=e,r=t,m({validate:(n={},!1),allow_conditional_comments:!0,special:"script,noscript",start:function(e,t){if(n.source1||"param"!==e||(n.source1=t.map.movie),"iframe"!==e&&"object"!==e&&"embed"!==e&&"video"!==e&&"audio"!==e||(n.type||(n.type=e),n=w.extend(t.map,n)),"script"===e){var r=_(i,t.map.src);if(!r)return;n={type:"script",source1:t.map.src,width:r.width,height:r.height}}"source"===e&&(n.source1?n.source2||(n.source2=t.map.src):n.source1=t.map.src),"img"!==e||n.poster||(n.poster=t.map.src)}}).parse(r),n.source1=n.source1||n.src||n.data,n.source2=n.source2||"",n.poster=n.poster||"",n);var i,r,n,a,o,c,s},d=tinymce.util.Tools.resolve("tinymce.util.Promise"),F=function(e){var t={mp3:"audio/mpeg",wav:"audio/wav",mp4:"video/mp4",webm:"video/webm",ogg:"video/ogg",swf:"application/x-shockwave-flash"}[e.toLowerCase().split(".").pop()];return t||""},h=tinymce.util.Tools.resolve("tinymce.html.Writer"),p=tinymce.util.Tools.resolve("tinymce.html.Schema"),f=r.DOM,P=function(e,t){var r,i,n,a;for(r in t)if(n=""+t[r],e.map[r])for(i=e.length;i--;)(a=e[i]).name===r&&(n?(e.map[r]=n,a.value=n):(delete e.map[r],e.splice(i,1)));else n&&(e.push({name:r,value:n}),e.map[r]=n)},k=function(e,t){var r,i,n=f.createFragment(e).firstChild;return M.setMaxWidth(n,t.width),M.setMaxHeight(n,t.height),r=n.outerHTML,i=h(),m(i).parse(r),i.getContent()},$=function(e,t,r){return u=e,l=f.createFragment(u),""!==f.getAttrib(l.firstChild,"data-ephox-embed-iri")?k(e,t):(i=e,n=t,a=r,c=h(),m({validate:!1,allow_conditional_comments:!(s=0),special:"script,noscript",comment:function(e){c.comment(e)},cdata:function(e){c.cdata(e)},text:function(e,t){c.text(e,t)},start:function(e,t,r){switch(e){case"video":case"object":case"embed":case"img":case"iframe":n.height!==undefined&&n.width!==undefined&&P(t,{width:n.width,height:n.height})}if(a)switch(e){case"video":P(t,{poster:n.poster,src:""}),n.source2&&P(t,{src:""});break;case"iframe":P(t,{src:n.source1});break;case"source":if(++s<=2&&(P(t,{src:n["source"+s],type:n["source"+s+"mime"]}),!n["source"+s]))return;break;case"img":if(!n.poster)return;o=!0}c.start(e,t,r)},end:function(e){if("video"===e&&a)for(var t=1;t<=2;t++)if(n["source"+t]){var r=[];r.map={},s<t&&(P(r,{src:n["source"+t],type:n["source"+t+"mime"]}),c.start("source",r,!0))}if(n.poster&&"object"===e&&a&&!o){var i=[];i.map={},P(i,{src:n.poster,width:n.width,height:n.height}),c.start("img",i,!0)}c.end(e)}},p({})).parse(i),c.getContent());var i,n,a,o,c,s,u,l},T=[{regex:/youtu\.be\/([\w\-_\?&=.]+)/i,type:"iframe",w:560,h:314,url:"//www.youtube.com/embed/$1",allowFullscreen:!0},{regex:/youtube\.com(.+)v=([^&]+)(&([a-z0-9&=\-_]+))?/i,type:"iframe",w:560,h:314,url:"//www.youtube.com/embed/$2?$4",allowFullscreen:!0},{regex:/youtube.com\/embed\/([a-z0-9\?&=\-_]+)/i,type:"iframe",w:560,h:314,url:"//www.youtube.com/embed/$1",allowFullscreen:!0},{regex:/vimeo\.com\/([0-9]+)/,type:"iframe",w:425,h:350,url:"//player.vimeo.com/video/$1?title=0&byline=0&portrait=0&color=8dc7dc",allowFullscreen:!0},{regex:/vimeo\.com\/(.*)\/([0-9]+)/,type:"iframe",w:425,h:350,url:"//player.vimeo.com/video/$2?title=0&byline=0",allowFullscreen:!0},{regex:/maps\.google\.([a-z]{2,3})\/maps\/(.+)msid=(.+)/,type:"iframe",w:425,h:350,url:'//maps.google.com/maps/ms?msid=$2&output=embed"',allowFullscreen:!1},{regex:/dailymotion\.com\/video\/([^_]+)/,type:"iframe",w:480,h:270,url:"//www.dailymotion.com/embed/video/$1",allowFullscreen:!0},{regex:/dai\.ly\/([^_]+)/,type:"iframe",w:480,h:270,url:"//www.dailymotion.com/embed/video/$1",allowFullscreen:!0}],z=function(r,e){var i=w.extend({},e);if(!i.source1&&(w.extend(i,A(b(r),i.embed)),!i.source1))return"";i.source2||(i.source2=""),i.poster||(i.poster=""),i.source1=r.convertURL(i.source1,"source"),i.source2=r.convertURL(i.source2,"source"),i.source1mime=F(i.source1),i.source2mime=F(i.source2),i.poster=r.convertURL(i.poster,"poster");var t,n,a=(t=i.source1,0<(n=T.filter(function(e){return e.regex.test(t)})).length?w.extend({},n[0],{url:function(e,t){for(var r=e.regex.exec(t),i=e.url,n=function(e){i=i.replace("$"+e,function(){return r[e]?r[e]:""})},a=0;a<r.length;a++)n(a);return i.replace(/\?$/,"")}(n[0],t)}):null);if(a&&(i.source1=a.url,i.type=a.type,i.allowFullscreen=a.allowFullscreen,i.width=i.width||a.w,i.height=i.height||a.h),i.embed)return $(i.embed,i,!0);var o=_(b(r),i.source1);o&&(i.type="script",i.width=o.width,i.height=o.height);var c,s,u,l,m,d,h,p,f=v(r),g=y(r);return i.width=i.width||300,i.height=i.height||150,w.each(i,function(e,t){i[t]=r.dom.encode(e)}),"iframe"===i.type?(p=(h=i).allowFullscreen?' allowFullscreen="1"':"",'<iframe src="'+h.source1+'" width="'+h.width+'" height="'+h.height+'"'+p+"></iframe>"):"application/x-shockwave-flash"===i.source1mime?(d='<object data="'+(m=i).source1+'" width="'+m.width+'" height="'+m.height+'" type="application/x-shockwave-flash">',m.poster&&(d+='<img src="'+m.poster+'" width="'+m.width+'" height="'+m.height+'" />'),d+="</object>"):-1!==i.source1mime.indexOf("audio")?(u=i,(l=f)?l(u):'<audio controls="controls" src="'+u.source1+'">'+(u.source2?'\n<source src="'+u.source2+'"'+(u.source2mime?' type="'+u.source2mime+'"':"")+" />\n":"")+"</audio>"):"script"===i.type?'<script src="'+i.source1+'"><\/script>':(c=i,(s=g)?s(c):'<video width="'+c.width+'" height="'+c.height+'"'+(c.poster?' poster="'+c.poster+'"':"")+' controls="controls">\n<source src="'+c.source1+'"'+(c.source1mime?' type="'+c.source1mime+'"':"")+" />\n"+(c.source2?'<source src="'+c.source2+'"'+(c.source2mime?' type="'+c.source2mime+'"':"")+" />\n":"")+"</video>")},O={},S=function(t){return function(e){return z(t,e)}},D=function(e,t){var r,i,n,a,o,c=s(e);return c?(n=t,a=S(e),o=c,new d(function(t,e){var r=function(e){return e.html&&(O[n.source1]=e),t({url:n.source1,html:e.html?e.html:a(n)})};O[n.source1]?r(O[n.source1]):o({url:n.source1},r,e)})):(r=t,i=S(e),new d(function(e){e({html:i(r),url:r.source1})}))},W=function(e){return O.hasOwnProperty(e)},E=function(r){return function(e){var t=e&&e.msg?"Media embed handler error: "+e.msg:"Media embed handler threw unknown error.";r.notificationManager.open({type:"error",text:t})}},H=function(e,t){return w.extend({},A(b(e),t))},R=function(e,t){var r=e.dom.select("img[data-mce-object]");e.insertContent(t),function(e,t){var r,i,n=e.dom.select("img[data-mce-object]");for(r=0;r<t.length;r++)for(i=n.length-1;0<=i;i--)t[r]===n[i]&&n.splice(i,1);e.selection.select(n[0])}(e,r),e.nodeChanged()},L=function(o){var r,e,t,i,n,a,c=(t=(e=o).selection.getNode(),(i=t.getAttribute("data-ephox-embed-iri"))?{source1:i,"data-ephox-embed-iri":i,dimensions:{width:M.getMaxWidth(t),height:M.getMaxHeight(t)}}:t.getAttribute("data-mce-object")?A(b(e),e.serializer.serialize(t,{selection:!0})):{}),s={source1:"",source2:"",embed:(n=o,a=n.selection.getNode(),a.getAttribute("data-mce-object")||a.getAttribute("data-ephox-embed-iri")?n.selection.getContent():""),poster:"",dimensions:{height:c.height?c.height:"",width:c.width?c.width:""}},u=g(s,c),l=function(e){var t=e.getData();return C(o)?g(t,{width:t.dimensions.width,height:t.dimensions.height}):t},m=function(e){var n,a,t=l(e);D(o,t).then((n=r,a=o,function(e){var t=e.html,r=H(a,t),i={source1:e.url,embed:t,dimensions:{width:r.width?r.width:"",height:r.height?r.height:""}};n.setData(i)}))["catch"](E(o))},d=C(o)?{title:"General",items:[{name:"source1",type:"input",filetype:"media",label:"Source"},{type:"sizeinput",name:"dimensions",label:"size",constrain:!0}]}:{title:"General",items:[{name:"source1",type:"input",filetype:"media",label:"Source"}]},h=[];x(o)&&h.push({name:"source2",type:"input",filetype:"media",label:"Alternative source"}),j(o)&&h.push({name:"poster",type:"input",filetype:"image",label:"Poster"});var p={title:"Advanced",items:h},f=[d,{title:"Embed",items:[{type:"textarea",name:"embed",label:"Paste your embed code below:"}]}];0<h.length&&f.push(p),r=o.windowManager.open({title:"Insert/Edit Media",size:"normal",body:{type:"tabpanel",tabs:f},buttons:[{type:"submit",name:"ok",text:"Ok",primary:!0},{type:"cancel",name:"cancel",text:"Cancel"}],onSubmit:function(e){var t,r,i=l(e);r=o,(t=i).embed=$(t.embed,t),t.embed&&W(t.source1)?R(r,t.embed):D(r,t).then(function(e){R(r,e.html)})["catch"](E(r)),e.close()},onChange:function(e,t){switch(t.name){case"source1":m(e);break;case"dimensions":m(e);case"embed":i=(r=e).getData(),(n=H(o,i.embed)).dimensions={width:n.width?n.width:i.dimensions.width,height:n.height?n.height:i.dimensions.height},r.setData(n)}var r,i,n},initialData:u})},N=function(e){return{showDialog:function(){L(e)}}},U=function(e){e.addCommand("mceMedia",function(){L(e)})},I=tinymce.util.Tools.resolve("tinymce.html.Node"),B=tinymce.util.Tools.resolve("tinymce.Env"),G=function(n,e){if(!1===t(n))return e;var a,o=h();return m({validate:!1,allow_conditional_comments:!1,special:"script,noscript",comment:function(e){o.comment(e)},cdata:function(e){o.cdata(e)},text:function(e,t){o.text(e,t)},start:function(e,t,r){if(a=!0,"script"!==e&&"noscript"!==e){for(var i=0;i<t.length;i++){if(0===t[i].name.indexOf("on"))return;"style"===t[i].name&&(t[i].value=n.dom.serializeStyle(n.dom.parseStyle(t[i].value),e))}o.start(e,t,r),a=!1}},end:function(e){a||o.end(e)}},p({})).parse(e),o.getContent()},q=function(e,t){var r,i=t.name;return(r=new I("img",1)).shortEnded=!0,K(e,t,r),r.attr({width:t.attr("width")||"300",height:t.attr("height")||("audio"===i?"30":"150"),style:t.attr("style"),src:B.transparentSrc,"data-mce-object":i,"class":"mce-object mce-object-"+i}),r},J=function(e,t){var r,i,n,a=t.name;return(r=new I("span",1)).attr({contentEditable:"false",style:t.attr("style"),"data-mce-object":a,"class":"mce-preview-object mce-object-"+a}),K(e,t,r),(i=new I(a,1)).attr({src:t.attr("src"),allowfullscreen:t.attr("allowfullscreen"),style:t.attr("style"),"class":t.attr("class"),width:t.attr("width"),height:t.attr("height"),frameborder:"0"}),(n=new I("span",1)).attr("class","mce-shim"),r.append(i),r.append(n),r},K=function(e,t,r){var i,n,a,o,c;for(o=(a=t.attributes).length;o--;)i=a[o].name,n=a[o].value,"width"!==i&&"height"!==i&&"style"!==i&&("data"!==i&&"src"!==i||(n=e.convertURL(n,i)),r.attr("data-mce-p-"+i,n));(c=t.firstChild&&t.firstChild.value)&&(r.attr("data-mce-html",escape(G(e,c))),r.firstChild=null)},Q=function(e){for(;e=e.parent;)if(e.attr("data-ephox-embed-iri"))return!0;return!1},V=function(n){return function(e){for(var t,r,i=e.length;i--;)(t=e[i]).parent&&(t.parent.attr("data-mce-object")||("script"!==t.name||(r=_(b(n),t.attr("src"))))&&(r&&(r.width&&t.attr("width",r.width.toString()),r.height&&t.attr("height",r.height.toString())),"iframe"===t.name&&a(n)&&B.ceFalse?Q(t)||t.replace(J(n,t)):Q(t)||t.replace(q(n,t))))}},X=function(d){d.on("preInit",function(){var t=d.schema.getSpecialElements();w.each("video audio iframe object".split(" "),function(e){t[e]=new RegExp("</"+e+"[^>]*>","gi")});var r=d.schema.getBoolAttrs();w.each("webkitallowfullscreen mozallowfullscreen allowfullscreen".split(" "),function(e){r[e]={}}),d.parser.addNodeFilter("iframe,video,audio,object,embed,script",V(d)),d.serializer.addAttributeFilter("data-mce-object",function(e,t){for(var r,i,n,a,o,c,s,u,l=e.length;l--;)if((r=e[l]).parent){for(s=r.attr(t),i=new I(s,1),"audio"!==s&&"script"!==s&&((u=r.attr("class"))&&-1!==u.indexOf("mce-preview-object")?i.attr({width:r.firstChild.attr("width"),height:r.firstChild.attr("height")}):i.attr({width:r.attr("width"),height:r.attr("height")})),i.attr({style:r.attr("style")}),n=(a=r.attributes).length;n--;){var m=a[n].name;0===m.indexOf("data-mce-p-")&&i.attr(m.substr(11),a[n].value)}"script"===s&&i.attr("type","text/javascript"),(o=r.attr("data-mce-html"))&&((c=new I("#text",3)).raw=!0,c.value=G(d,unescape(o)),i.append(c)),r.replace(i)}})}),d.on("setContent",function(){d.$("span.mce-preview-object").each(function(e,t){var r=d.$(t);0===r.find("span.mce-shim",t).length&&r.append('<span class="mce-shim"></span>')})})},Y=function(e){e.on("ResolveName",function(e){var t;1===e.target.nodeType&&(t=e.target.getAttribute("data-mce-object"))&&(e.name=t)})},Z=function(t){t.on("click keyup",function(){var e=t.selection.getNode();e&&t.dom.hasClass(e,"mce-preview-object")&&t.dom.getAttrib(e,"data-mce-selected")&&e.setAttribute("data-mce-selected","2")}),t.on("ObjectSelected",function(e){var t=e.target.getAttribute("data-mce-object");"audio"!==t&&"script"!==t||e.preventDefault()}),t.on("objectResized",function(e){var t,r=e.target;r.getAttribute("data-mce-object")&&(t=r.getAttribute("data-mce-html"))&&(t=unescape(t),r.setAttribute("data-mce-html",escape($(t,{width:e.width,height:e.height}))))})},ee=function(e){var t,r;e.ui.registry.addToggleButton("media",{tooltip:"Insert/edit media",icon:"embed",onAction:function(){e.execCommand("mceMedia")},onSetup:(t=e,r=["img[data-mce-object]","span[data-mce-object]","div[data-ephox-embed-iri]"],function(e){return t.selection.selectorChangedWithUnbind(r.join(","),e.setActive).unbind})}),e.ui.registry.addMenuItem("media",{icon:"embed",text:"Media",prependToContext:!0,onAction:function(){e.execCommand("mceMedia")}})};e.add("media",function(e){return U(e),ee(e),Y(e),X(e),Z(e),N(e)}),function te(){}}(); |