2016-01-20 05:18:33 +01:00
|
|
|
tinymce.PluginManager.add("media",function(e,t){function n(e){return e=e.toLowerCase(),-1!=e.indexOf(".mp3")?"audio/mpeg":-1!=e.indexOf(".wav")?"audio/wav":-1!=e.indexOf(".mp4")?"video/mp4":-1!=e.indexOf(".webm")?"video/webm":-1!=e.indexOf(".ogg")?"video/ogg":-1!=e.indexOf(".swf")?"application/x-shockwave-flash":""}function r(t){var n=e.settings.media_scripts;if(n)for(var r=0;r<n.length;r++)if(-1!==t.indexOf(n[r].filter))return n[r]}function i(){function t(e){var t,n,o,a;t=r.find("#width")[0],n=r.find("#height")[0],o=t.value(),a=n.value(),r.find("#constrain")[0].checked()&&i&&c&&o&&a&&(e.control==t?(a=Math.round(o/i*a),isNaN(a)||n.value(a)):(o=Math.round(a/c*o),isNaN(o)||t.value(o))),i=o,c=a}function n(){u=s(this.value()),this.parent().parent().fromJSON(u)}var r,i,c,u,d=[{name:"source1",type:"filepicker",filetype:"media",size:40,autofocus:!0,label:"Source",onchange:function(e){tinymce.each(e.meta,function(e,t){r.find("#"+t).value(e)})}}];e.settings.media_alt_source!==!1&&d.push({name:"source2",type:"filepicker",filetype:"media",size:40,label:"Alternative source"}),e.settings.media_poster!==!1&&d.push({name:"poster",type:"filepicker",filetype:"image",size:40,label:"Poster"}),e.settings.media_dimensions!==!1&&d.push({type:"container",label:"Dimensions",layout:"flex",align:"center",spacing:5,items:[{name:"width",type:"textbox",maxLength:5,size:3,onchange:t,ariaLabel:"Width"},{type:"label",text:"x"},{name:"height",type:"textbox",maxLength:5,size:3,onchange:t,ariaLabel:"Height"},{name:"constrain",type:"checkbox",checked:!0,text:"Constrain proportions"}]}),u=l(e.selection.getNode()),i=u.width,c=u.height;var f={id:"mcemediasource",type:"textbox",flex:1,name:"embed",value:o(),multiline:!0,label:"Source"};f[p]=n,r=e.windowManager.open({title:"Insert/edit video",data:u,bodyType:"tabpanel",body:[{title:"General",type:"form",onShowTab:function(){u=s(this.next().find("#embed").value()),this.fromJSON(u)},items:d},{title:"Embed",type:"container",layout:"flex",direction:"column",align:"stretch",padding:10,spacing:10,onShowTab:function(){this.find("#embed").value(a(this.parent().toJSON()))},items:[{type:"label",text:"Paste your embed code below:",forId:"mcemediasource"},f]}],onSubmit:function(){var t,n,r,i;for(t=e.dom.select("img[data-mce-object]"),e.insertContent(a(this.toJSON())),n=e.dom.select("img[data-mce-object]"),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.nodeChanged()}})}function o(){var t=e.selection.getNode();return t.getAttribute("data-mce-object")?e.selection.getContent():void 0}function a(i){var o="";if(!i.source1&&(tinymce.extend(i,s(i.embed)),!i.source1))return"";if(i.source2||(i.source2=""),i.poster||(i.poster=""),i.source1=e.convertURL(i.source1,"source"),i.source2=e.convertURL(i.source2,"source"),i.source1mime=n(i.source1),i.source2mime=n(i.source2),i.poster=e.convertURL(i.poster,"poster"),i.flashPlayerUrl=e.convertURL(t+"/moxieplayer.swf","movie"),tinymce.each(m,function(e){var t,n,r;if(t=e.regex.exec(i.source1)){for(r=e.url,n=0;t[n];n++)r=r.replace("$"+n,function(){return t[n]});i.source1=r,i.type=e.type,i.allowFullscreen=e.allowFullscreen,i.width=i.width||e.w,i.height=i.height||e.h}}),i.embed)o=u(i.embed,i,!0);else{var a=r(i.source1);if(a&&(i.type="script",i.width=a.width,i.height=a.height),i.width=i.width||300,i.height=i.height||150,tinymce.each(i,function(t,n){i[n]=e.dom.encode(t)}),"iframe"==i.type){var l=i.allowFullscreen?' allowFullscreen="1"':"";o+='<iframe src="'+i.source1+'" width="'+i.width+'" height="'+i.height+'"'+l+"></iframe>"}else"application/x-shockwave-flash"==i.source1mime?(o+='<object data="'+i.source1+'" width="'+i.width+'" height="'+i.height+'" type="application/x-shockwave-flash">',i.poster&&(o+='<img src="'+i.poster+'" width="'+i.width+'" height="'+i.height+'" />'),o+="</object>"):-1!=i.source1mime.indexOf("audio")?e.settings.audio_template_callback?o=e.settings.audio_template_callback(i):o+='<audio controls="controls" src="'+i.source1+'">'+(i.source2?'\n<source src="'+i.source2+'"'+(i.source2mime?' type="'+i.source2mime+'"':"")+" />\n":"")
|