mirror of
https://github.com/documize/community.git
synced 2025-07-22 06:39:43 +02:00
1 line
No EOL
15 KiB
JavaScript
1 line
No EOL
15 KiB
JavaScript
!function(){"use strict";var e=tinymce.util.Tools.resolve("tinymce.PluginManager"),t=tinymce.util.Tools.resolve("tinymce.Env"),r=tinymce.util.Tools.resolve("tinymce.util.Tools"),i=function(e){return e.getParam("media_scripts")},n=function(e){return e.getParam("audio_template_callback")},o=function(e){return e.getParam("video_template_callback")},a=function(e){return e.getParam("media_live_embeds",!0)},c=function(e){return e.getParam("media_filter_html",!0)},u=function(e){return e.getParam("media_url_resolver")},s=function(e){return e.getParam("media_alt_source",!0)},l=function(e){return e.getParam("media_poster",!0)},m=function(e){return e.getParam("media_dimensions",!0)},d=tinymce.util.Tools.resolve("tinymce.html.SaxParser"),h=tinymce.util.Tools.resolve("tinymce.dom.DOMUtils"),f=function(e,t){if(e)for(var r=0;r<e.length;r++)if(-1!==t.indexOf(e[r].filter))return e[r]},p=function(e){return function(t){return t?function(e){return e.replace(/px$/,"")}(t.style[e]):""}},g=function(e){return function(t,r){t&&(t.style[e]=function(e){return/^[0-9.]+$/.test(e)?e+"px":e}(r))}},v={getMaxWidth:p("maxWidth"),getMaxHeight:p("maxHeight"),setMaxWidth:g("maxWidth"),setMaxHeight:g("maxHeight")},w=h.DOM,b=function(e){return w.getAttrib(e,"data-ephox-embed-iri")},y=function(e,t){return function(e){var t=w.createFragment(e);return""!==b(t.firstChild)}(t)?function(e){var t=w.createFragment(e).firstChild;return{type:"ephox-embed-iri",source1:b(t),source2:"",poster:"",width:v.getMaxWidth(t),height:v.getMaxHeight(t)}}(t):function(e,t){var i={};return new d({validate:!1,allow_conditional_comments:!0,special:"script,noscript",start:function(t,n){if(i.source1||"param"!==t||(i.source1=n.map.movie),"iframe"!==t&&"object"!==t&&"embed"!==t&&"video"!==t&&"audio"!==t||(i.type||(i.type=t),i=r.extend(n.map,i)),"script"===t){var o=f(e,n.map.src);if(!o)return;i={type:"script",source1:n.map.src,width:o.width,height:o.height}}"source"===t&&(i.source1?i.source2||(i.source2=n.map.src):i.source1=n.map.src),"img"!==t||i.poster||(i.poster=n.map.src)}}).parse(t),i.source1=i.source1||i.src||i.data,i.source2=i.source2||"",i.poster=i.poster||"",i}(e,t)},x=tinymce.util.Tools.resolve("tinymce.util.Promise"),j=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||""},M=tinymce.util.Tools.resolve("tinymce.html.Writer"),_=tinymce.util.Tools.resolve("tinymce.html.Schema"),C=h.DOM,S=function(e,t){var r,i,n,o;for(r in t)if(n=""+t[r],e.map[r])for(i=e.length;i--;)(o=e[i]).name===r&&(n?(e.map[r]=n,o.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=C.createFragment(e).firstChild;return v.setMaxWidth(r,t.width),v.setMaxHeight(r,t.height),function(e){var t=M();return new d(t).parse(e),t.getContent()}(r.outerHTML)},A=function(e,t,r){return function(e){var t=C.createFragment(e);return""!==C.getAttrib(t.firstChild,"data-ephox-embed-iri")}(e)?k(e,t):function(e,t,r){var i,n=M(),o=0;return new d({validate:!1,allow_conditional_comments:!0,special:"script,noscript",comment:function(e){n.comment(e)},cdata:function(e){n.cdata(e)},text:function(e,t){n.text(e,t)},start:function(e,a,c){switch(e){case"video":case"object":case"embed":case"img":case"iframe":t.height!==undefined&&t.width!==undefined&&S(a,{width:t.width,height:t.height})}if(r)switch(e){case"video":S(a,{poster:t.poster,src:""}),t.source2&&S(a,{src:""});break;case"iframe":S(a,{src:t.source1});break;case"source":if(++o<=2&&(S(a,{src:t["source"+o],type:t["source"+o+"mime"]}),!t["source"+o]))return;break;case"img":if(!t.poster)return;i=!0}n.start(e,a,c)},end:function(e){if("video"===e&&r)for(var a=1;a<=2;a++)if(t["source"+a]){var c=[];c.map={},o<a&&(S(c,{src:t["source"+a],type:t["source"+a+"mime"]}),n.start("source",c,!0))}if(t.poster&&"object"===e&&r&&!i){var u=[];u.map={},S(u,{src:t.poster,width:t.width,height:t.height}),n.start("img",u,!0)}n.end(e)}},_({})).parse(e),n.getContent()}(e,t,r)},F=[{regex:/youtu\.be\/([\w\-.]+)/,type:"iframe",w:560,h:314,url:"//www.youtube.com/embed/$1",allowFullscreen:!0},{regex:/youtube\.com(.+)v=([^&]+)/,type:"iframe",w:560,h:314,url:"//www.youtube.com/embed/$2",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}],N=function(e,t){var a=r.extend({},t);if(!a.source1&&(r.extend(a,y(i(e),a.embed)),!a.source1))return"";if(a.source2||(a.source2=""),a.poster||(a.poster=""),a.source1=e.convertURL(a.source1,"source"),a.source2=e.convertURL(a.source2,"source"),a.source1mime=j(a.source1),a.source2mime=j(a.source2),a.poster=e.convertURL(a.poster,"poster"),r.each(F,function(e){var t,r,i=e.regex.exec(a.source1);if(i){for(r=e.url,t=0;i[t];t++)r=r.replace("$"+t,function(){return i[t]});a.source1=r,a.type=e.type,a.allowFullscreen=e.allowFullscreen,a.width=a.width||e.w,a.height=a.height||e.h}}),a.embed)return A(a.embed,a,!0);var c=f(i(e),a.source1);c&&(a.type="script",a.width=c.width,a.height=c.height);var u=n(e),s=o(e);return a.width=a.width||300,a.height=a.height||150,r.each(a,function(t,r){a[r]=e.dom.encode(t)}),"iframe"===a.type?function(e){var t=e.allowFullscreen?' allowFullscreen="1"':"";return'<iframe src="'+e.source1+'" width="'+e.width+'" height="'+e.height+'"'+t+"></iframe>"}(a):"application/x-shockwave-flash"===a.source1mime?function(e){var t='<object data="'+e.source1+'" width="'+e.width+'" height="'+e.height+'" type="application/x-shockwave-flash">';return e.poster&&(t+='<img src="'+e.poster+'" width="'+e.width+'" height="'+e.height+'" />'),t+="</object>"}(a):-1!==a.source1mime.indexOf("audio")?function(e,t){return t?t(e):'<audio controls="controls" src="'+e.source1+'">'+(e.source2?'\n<source src="'+e.source2+'"'+(e.source2mime?' type="'+e.source2mime+'"':"")+" />\n":"")+"</audio>"}(a,u):"script"===a.type?function(e){return'<script src="'+e.source1+'"><\/script>'}(a):function(e,t){return t?t(e):'<video width="'+e.width+'" height="'+e.height+'"'+(e.poster?' poster="'+e.poster+'"':"")+' controls="controls">\n<source src="'+e.source1+'"'+(e.source1mime?' type="'+e.source1mime+'"':"")+" />\n"+(e.source2?'<source src="'+e.source2+'"'+(e.source2mime?' type="'+e.source2mime+'"':"")+" />\n":"")+"</video>"}(a,s)},O={},P=function(e){return function(t){return N(e,t)}},T=function(e,t){var r=u(e);return r?function(e,t,r){return new x(function(i,n){var o=function(r){return r.html&&(O[e.source1]=r),i({url:e.source1,html:r.html?r.html:t(e)})};O[e.source1]?o(O[e.source1]):r({url:e.source1},o,n)})}(t,P(e),r):function(e,t){return new x(function(r){r({html:t(e),url:e.source1})})}(t,P(e))},z=function(e){return O.hasOwnProperty(e)},$=function(e,t){e.state.set("oldVal",e.value()),t.state.set("oldVal",t.value())},L=function(e,t){var r=e.find("#width")[0],i=e.find("#height")[0],n=e.find("#constrain")[0];r&&i&&n&&t(r,i,n.checked())},H=function(e,t,r){var i=e.state.get("oldVal"),n=t.state.get("oldVal"),o=e.value(),a=t.value();r&&i&&n&&o&&a&&(o!==i?(a=Math.round(o/i*a),isNaN(a)||t.value(a)):(o=Math.round(a/n*o),isNaN(o)||e.value(o))),$(e,t)},W=function(e){L(e,H)},J=function(e){var t=function(){e(function(e){W(e)})};return{type:"container",label:"Dimensions",layout:"flex",align:"center",spacing:5,items:[{name:"width",type:"textbox",maxLength:5,size:5,onchange:t,ariaLabel:"Width"},{type:"label",text:"x"},{name:"height",type:"textbox",maxLength:5,size:5,onchange:t,ariaLabel:"Height"},{name:"constrain",type:"checkbox",checked:!0,text:"Constrain proportions"}]}},R=function(e){L(e,$)},D=W,E=t.ie&&t.ie<=8?"onChange":"onInput",I=function(e){return function(t){var r=t&&t.msg?"Media embed handler error: "+t.msg:"Media embed handler threw unknown error.";e.notificationManager.open({type:"error",text:r})}},U=function(e,t){return function(n){var o=n.html,a=e.find("#embed")[0],c=r.extend(y(i(t),o),{source1:n.url});e.fromJSON(c),a&&(a.value(o),D(e))}},V=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;i>=0;i--)t[r]===n[i]&&n.splice(i,1);e.selection.select(n[0])}(e,r),e.nodeChanged()},B=function(e){var t,n,o=[{name:"source1",type:"filepicker",filetype:"media",size:40,autofocus:!0,label:"Source",onpaste:function(){setTimeout(function(){T(e,t.toJSON()).then(U(t,e))["catch"](I(e))},1)},onchange:function(i){T(e,t.toJSON()).then(U(t,e))["catch"](I(e)),function(e,t){r.each(t,function(t,r){e.find("#"+r).value(t)})}(t,i.meta)},onbeforecall:function(e){e.meta=t.toJSON()}}],a=[];if(s(e)&&a.push({name:"source2",type:"filepicker",filetype:"media",size:40,label:"Alternative source"}),l(e)&&a.push({name:"poster",type:"filepicker",filetype:"image",size:40,label:"Poster"}),m(e)){var c=J(function(e){e(t),n=t.toJSON(),t.find("#embed").value(A(n.embed,n))});o.push(c)}n=function(e){var t=e.selection.getNode(),r=t.getAttribute("data-ephox-embed-iri");return r?{source1:r,"data-ephox-embed-iri":r,width:v.getMaxWidth(t),height:v.getMaxHeight(t)}:t.getAttribute("data-mce-object")?y(i(e),e.serializer.serialize(t,{selection:!0})):{}}(e);var u={id:"mcemediasource",type:"textbox",flex:1,name:"embed",value:function(e){var t=e.selection.getNode();if(t.getAttribute("data-mce-object")||t.getAttribute("data-ephox-embed-iri"))return e.selection.getContent()}(e),multiline:!0,rows:5,label:"Source"};u[E]=function(){n=r.extend({},y(i(e),this.value())),this.parent().parent().fromJSON(n)},t=e.windowManager.open({title:"Insert/edit media",data:n,bodyType:"tabpanel",body:[{title:"General",type:"form",items:o},{title:"Embed",type:"container",layout:"flex",direction:"column",align:"stretch",padding:10,spacing:10,items:[{type:"label",text:"Paste your embed code below:",forId:"mcemediasource"},u]},{title:"Advanced",type:"form",items:a}],onSubmit:function(){D(t),function(e,t){var r=e.toJSON();r.embed=A(r.embed,r),r.embed&&z(r.source1)?V(t,r.embed):T(t,r).then(function(e){V(t,e.html)})["catch"](I(t))}(t,e)}}),R(t)},G=function(e){return{showDialog:function(){B(e)}}},q=function(e){e.addCommand("mceMedia",function(){B(e)})},K=tinymce.util.Tools.resolve("tinymce.html.Node"),Q=function(e,t){if(!1===c(e))return t;var r,i=M();return new d({validate:!1,allow_conditional_comments:!1,special:"script,noscript",comment:function(e){i.comment(e)},cdata:function(e){i.cdata(e)},text:function(e,t){i.text(e,t)},start:function(t,n,o){if(r=!0,"script"!==t&&"noscript"!==t){for(var a=0;a<n.length;a++){if(0===n[a].name.indexOf("on"))return;"style"===n[a].name&&(n[a].value=e.dom.serializeStyle(e.dom.parseStyle(n[a].value),t))}i.start(t,n,o),r=!1}},end:function(e){r||i.end(e)}},_({})).parse(t),i.getContent()},X=function(e,r){var i,n=r.name;return i=new K("img",1),i.shortEnded=!0,Z(e,r,i),i.attr({width:r.attr("width")||"300",height:r.attr("height")||("audio"===n?"30":"150"),style:r.attr("style"),src:t.transparentSrc,"data-mce-object":n,"class":"mce-object mce-object-"+n}),i},Y=function(e,t){var r,i,n,o=t.name;return(r=new K("span",1)).attr({contentEditable:"false",style:t.attr("style"),"data-mce-object":o,"class":"mce-preview-object mce-object-"+o}),Z(e,t,r),(i=new K(o,1)).attr({src:t.attr("src"),allowfullscreen:t.attr("allowfullscreen"),width:t.attr("width")||"300",height:t.attr("height")||("audio"===o?"30":"150"),frameborder:"0"}),(n=new K("span",1)).attr("class","mce-shim"),r.append(i),r.append(n),r},Z=function(e,t,r){var i,n,o,a,c;for(a=(o=t.attributes).length;a--;)i=o[a].name,n=o[a].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(Q(e,c))),r.firstChild=null)},ee=function(e){for(;e=e.parent;)if(e.attr("data-ephox-embed-iri"))return!0;return!1},te=function(e){return function(r){for(var n,o,c=r.length;c--;)(n=r[c]).parent&&(n.parent.attr("data-mce-object")||("script"!==n.name||(o=f(i(e),n.attr("src"))))&&(o&&(o.width&&n.attr("width",o.width.toString()),o.height&&n.attr("height",o.height.toString())),"iframe"===n.name&&a(e)&&t.ceFalse?ee(n)||n.replace(Y(e,n)):ee(n)||n.replace(X(e,n))))}},re=function(e){e.on("preInit",function(){var t=e.schema.getSpecialElements();r.each("video audio iframe object".split(" "),function(e){t[e]=new RegExp("</"+e+"[^>]*>","gi")});var i=e.schema.getBoolAttrs();r.each("webkitallowfullscreen mozallowfullscreen allowfullscreen".split(" "),function(e){i[e]={}}),e.parser.addNodeFilter("iframe,video,audio,object,embed,script",te(e)),e.serializer.addAttributeFilter("data-mce-object",function(t,r){for(var i,n,o,a,c,u,s,l,m=t.length;m--;)if((i=t[m]).parent){for(s=i.attr(r),n=new K(s,1),"audio"!==s&&"script"!==s&&((l=i.attr("class"))&&-1!==l.indexOf("mce-preview-object")?n.attr({width:i.firstChild.attr("width"),height:i.firstChild.attr("height")}):n.attr({width:i.attr("width"),height:i.attr("height")})),n.attr({style:i.attr("style")}),o=(a=i.attributes).length;o--;){var d=a[o].name;0===d.indexOf("data-mce-p-")&&n.attr(d.substr(11),a[o].value)}"script"===s&&n.attr("type","text/javascript"),(c=i.attr("data-mce-html"))&&((u=new K("#text",3)).raw=!0,u.value=Q(e,unescape(c)),n.append(u)),i.replace(n)}})}),e.on("setContent",function(){e.$("span.mce-preview-object").each(function(t,r){var i=e.$(r);0===i.find("span.mce-shim",r).length&&i.append('<span class="mce-shim"></span>')})})},ie=function(e){e.on("ResolveName",function(e){var t;1===e.target.nodeType&&(t=e.target.getAttribute("data-mce-object"))&&(e.name=t)})},ne=function(e){e.on("click keyup",function(){var t=e.selection.getNode();t&&e.dom.hasClass(t,"mce-preview-object")&&e.dom.getAttrib(t,"data-mce-selected")&&t.setAttribute("data-mce-selected","2")}),e.on("ObjectSelected",function(e){var t=e.target.getAttribute("data-mce-object");"audio"!==t&&"script"!==t||e.preventDefault()}),e.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(A(t,{width:e.width,height:e.height}))))})},oe=function(e){e.addButton("media",{tooltip:"Insert/edit media",cmd:"mceMedia",stateSelector:["img[data-mce-object]","span[data-mce-object]","div[data-ephox-embed-iri]"]}),e.addMenuItem("media",{icon:"media",text:"Media",cmd:"mceMedia",context:"insert",prependToContext:!0})};e.add("media",function(e){return q(e),oe(e),ie(e),re(e),ne(e),G(e)})}(); |