1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
!function(a,b,c){var d=wp.media,e={},f="undefined"==typeof _wpMediaViewsL10n?{}:_wpMediaViewsL10n;b.isUndefined(window._wpmejsSettings)||(e=_wpmejsSettings),wp.media.mixin={mejsSettings:e,removeAllPlayers:function(){var a;if(window.mejs&&window.mejs.players)for(a in window.mejs.players)window.mejs.players[a].pause(),this.removePlayer(window.mejs.players[a])},removePlayer:function(a){var b,c;if(a.options){for(b in a.options.features)if(c=a.options.features[b],a["clean"+c])try{a["clean"+c](a)}catch(d){}a.isDynamic||a.$node.remove(),"native"!==a.media.pluginType&&a.media.remove(),delete window.mejs.players[a.id],a.container.remove(),a.globalUnbind(),delete a.node.player}},unsetPlayers:function(){this.players&&this.players.length&&(b.each(this.players,function(a){a.pause(),wp.media.mixin.removePlayer(a)}),this.players=[])}},wp.media.playlist=new wp.media.collection({tag:"playlist",editTitle:f.editPlaylistTitle,defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!0,tracknumbers:!0,images:!0,artists:!0,type:"audio"}}),wp.media.audio={coerce:wp.media.coerce,defaults:{id:wp.media.view.settings.post.id,src:"",loop:!1,autoplay:!1,preload:"none",width:400},edit:function(a){var c,d=wp.shortcode.next("audio",a).shortcode;return c=wp.media({frame:"audio",state:"audio-details",metadata:b.defaults(d.attrs.named,this.defaults)})},shortcode:function(a){var c,d=this;return b.each(this.defaults,function(b,c){a[c]=d.coerce(a,c),b===a[c]&&delete a[c]}),c=a.content,delete a.content,new wp.shortcode({tag:"audio",attrs:a,content:c})}},wp.media.video={coerce:wp.media.coerce,defaults:{id:wp.media.view.settings.post.id,src:"",poster:"",loop:!1,autoplay:!1,preload:"metadata",content:"",width:640,height:360},edit:function(a){var c,d,e=wp.shortcode.next("video",a).shortcode;return d=e.attrs.named,d.content=e.content,c=wp.media({frame:"video",state:"video-details",metadata:b.defaults(d,this.defaults)})},shortcode:function(a){var c,d=this;return b.each(this.defaults,function(b,c){a[c]=d.coerce(a,c),b===a[c]&&delete a[c]}),c=a.content,delete a.content,new wp.shortcode({tag:"video",attrs:a,content:c})}},d.model.PostMedia=c.Model.extend({initialize:function(){this.attachment=!1},setSource:function(a){this.attachment=a,this.extension=a.get("filename").split(".").pop(),this.get("src")&&this.extension===this.get("src").split(".").pop()&&this.unset("src"),b.contains(wp.media.view.settings.embedExts,this.extension)?this.set(this.extension,this.attachment.get("url")):this.unset(this.extension)},changeAttachment:function(a){var c=this;this.setSource(a),this.unset("src"),b.each(b.without(wp.media.view.settings.embedExts,this.extension),function(a){c.unset(a)})}}),d.controller.AudioDetails=d.controller.State.extend({defaults:{id:"audio-details",toolbar:"audio-details",title:f.audioDetailsTitle,content:"audio-details",menu:"audio-details",router:!1,priority:60},initialize:function(a){this.media=a.media,d.controller.State.prototype.initialize.apply(this,arguments)}}),d.controller.VideoDetails=d.controller.State.extend({defaults:{id:"video-details",toolbar:"video-details",title:f.videoDetailsTitle,content:"video-details",menu:"video-details",router:!1,priority:60},initialize:function(a){this.media=a.media,d.controller.State.prototype.initialize.apply(this,arguments)}}),d.view.MediaFrame.MediaDetails=d.view.MediaFrame.Select.extend({defaults:{id:"media",url:"",menu:"media-details",content:"media-details",toolbar:"media-details",type:"link",priority:120},initialize:function(a){this.DetailsView=a.DetailsView,this.cancelText=a.cancelText,this.addText=a.addText,this.media=new d.model.PostMedia(a.metadata),this.options.selection=new d.model.Selection(this.media.attachment,{multiple:!1}),d.view.MediaFrame.Select.prototype.initialize.apply(this,arguments)},bindHandlers:function(){var a=this.defaults.menu;d.view.MediaFrame.Select.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:"+a,this.createMenu,this),this.on("content:render:"+a,this.renderDetailsContent,this),this.on("menu:render:"+a,this.renderMenu,this),this.on("toolbar:render:"+a,this.renderDetailsToolbar,this)},renderDetailsContent:function(){var a=new this.DetailsView({controller:this,model:this.state().media,attachment:this.state().media.attachment}).render();this.content.set(a)},renderMenu:function(a){var b=this.lastState(),c=b&&b.id,e=this;a.set({cancel:{text:this.cancelText,priority:20,click:function(){c?e.setState(c):e.close()}},separateCancel:new d.View({className:"separator",priority:40})})},setPrimaryButton:function(a,b){this.toolbar.set(new d.view.Toolbar({controller:this,items:{button:{style:"primary",text:a,priority:80,click:function(){var a=this.controller;b.call(this,a,a.state()),a.setState(a.options.state),a.reset()}}}}))},renderDetailsToolbar:function(){this.setPrimaryButton(f.update,function(a,b){a.close(),b.trigger("update",a.media.toJSON())})},renderReplaceToolbar:function(){this.setPrimaryButton(f.replace,function(a,b){var c=b.get("selection").single();a.media.changeAttachment(c),b.trigger("replace",a.media.toJSON())})},renderAddSourceToolbar:function(){this.setPrimaryButton(this.addText,function(a,b){var c=b.get("selection").single();a.media.setSource(c),b.trigger("add-source",a.media.toJSON())})}}),d.view.MediaFrame.AudioDetails=d.view.MediaFrame.MediaDetails.extend({defaults:{id:"audio",url:"",menu:"audio-details",content:"audio-details",toolbar:"audio-details",type:"link",title:f.audioDetailsTitle,priority:120},initialize:function(a){a.DetailsView=d.view.AudioDetails,a.cancelText=f.audioDetailsCancel,a.addText=f.audioAddSourceTitle,d.view.MediaFrame.MediaDetails.prototype.initialize.call(this,a)},bindHandlers:function(){d.view.MediaFrame.MediaDetails.prototype.bindHandlers.apply(this,arguments),this.on("toolbar:render:replace-audio",this.renderReplaceToolbar,this),this.on("toolbar:render:add-audio-source",this.renderAddSourceToolbar,this)},createStates:function(){this.states.add([new d.controller.AudioDetails({media:this.media}),new d.controller.MediaLibrary({type:"audio",id:"replace-audio",title:f.audioReplaceTitle,toolbar:"replace-audio",media:this.media,menu:"audio-details"}),new d.controller.MediaLibrary({type:"audio",id:"add-audio-source",title:f.audioAddSourceTitle,toolbar:"add-audio-source",media:this.media,menu:!1})])}}),d.view.MediaFrame.VideoDetails=d.view.MediaFrame.MediaDetails.extend({defaults:{id:"video",url:"",menu:"video-details",content:"video-details",toolbar:"video-details",type:"link",title:f.videoDetailsTitle,priority:120},initialize:function(a){a.DetailsView=d.view.VideoDetails,a.cancelText=f.videoDetailsCancel,a.addText=f.videoAddSourceTitle,d.view.MediaFrame.MediaDetails.prototype.initialize.call(this,a)},bindHandlers:function(){d.view.MediaFrame.MediaDetails.prototype.bindHandlers.apply(this,arguments),this.on("toolbar:render:replace-video",this.renderReplaceToolbar,this),this.on("toolbar:render:add-video-source",this.renderAddSourceToolbar,this),this.on("toolbar:render:select-poster-image",this.renderSelectPosterImageToolbar,this),this.on("toolbar:render:add-track",this.renderAddTrackToolbar,this)},createStates:function(){this.states.add([new d.controller.VideoDetails({media:this.media}),new d.controller.MediaLibrary({type:"video",id:"replace-video",title:f.videoReplaceTitle,toolbar:"replace-video",media:this.media,menu:"video-details"}),new d.controller.MediaLibrary({type:"video",id:"add-video-source",title:f.videoAddSourceTitle,toolbar:"add-video-source",media:this.media,menu:!1}),new d.controller.MediaLibrary({type:"image",id:"select-poster-image",title:f.videoSelectPosterImageTitle,toolbar:"select-poster-image",media:this.media,menu:"video-details"}),new d.controller.MediaLibrary({type:"text",id:"add-track",title:f.videoAddTrackTitle,toolbar:"add-track",media:this.media,menu:"video-details"})])},renderSelectPosterImageToolbar:function(){this.setPrimaryButton(f.videoSelectPosterImageTitle,function(a,c){var d=[],e=c.get("selection").single();a.media.set("poster",e.get("url")),c.trigger("set-poster-image",a.media.toJSON()),b.each(wp.media.view.settings.embedExts,function(b){a.media.get(b)&&d.push(a.media.get(b))}),wp.ajax.send("set-attachment-thumbnail",{data:{urls:d,thumbnail_id:e.get("id")}})})},renderAddTrackToolbar:function(){this.setPrimaryButton(f.videoAddTrackTitle,function(a,b){var c=b.get("selection").single(),d=a.media.get("content");-1===d.indexOf(c.get("url"))&&(d+=['<track srclang="en" label="English"kind="subtitles" src="',c.get("url"),'" />'].join(""),a.media.set("content",d)),b.trigger("add-track",a.media.toJSON())})}}),d.view.MediaDetails=d.view.Settings.AttachmentDisplay.extend({initialize:function(){b.bindAll(this,"success"),this.players=[],this.listenTo(this.controller,"close",d.mixin.unsetPlayers),this.on("ready",this.setPlayer),this.on("media:setting:remove",d.mixin.unsetPlayers,this),this.on("media:setting:remove",this.render),this.on("media:setting:remove",this.setPlayer),this.events=b.extend(this.events,{"click .remove-setting":"removeSetting","change .content-track":"setTracks","click .remove-track":"setTracks","click .add-media-source":"addSource"}),d.view.Settings.AttachmentDisplay.prototype.initialize.apply(this,arguments)},prepare:function(){return b.defaults({model:this.model.toJSON()},this.options)},removeSetting:function(b){var c,d=a(b.currentTarget).parent();c=d.find("input").data("setting"),c&&(this.model.unset(c),this.trigger("media:setting:remove",this)),d.remove()},setTracks:function(){var c="";b.each(this.$(".content-track"),function(b){c+=a(b).val()}),this.model.set("content",c),this.trigger("media:setting:remove",this)},addSource:function(b){this.controller.lastMime=a(b.currentTarget).data("mime"),this.controller.setState("add-"+this.controller.defaults.id+"-source")},setPlayer:function(){!this.players.length&&this.media&&this.players.push(new MediaElementPlayer(this.media,this.settings))},setMedia:function(){return this},success:function(a){var b=a.attributes.autoplay&&"false"!==a.attributes.autoplay;"flash"===a.pluginType&&b&&a.addEventListener("canplay",function(){a.play()},!1),this.mejs=a},render:function(){var a=this;return d.view.Settings.AttachmentDisplay.prototype.render.apply(this,arguments),setTimeout(function(){a.resetFocus()},10),this.settings=b.defaults({success:this.success},e),this.setMedia()},resetFocus:function(){this.$(".embed-media-settings").scrollTop(0)}},{instances:0,prepareSrc:function(c){var e=d.view.MediaDetails.instances++;return b.each(a(c).find("source"),function(a){a.src=[a.src,a.src.indexOf("?")>-1?"&":"?","_=",e].join("")}),c}}),d.view.AudioDetails=d.view.MediaDetails.extend({className:"audio-details",template:d.template("audio-details"),setMedia:function(){var a=this.$(".wp-audio-shortcode");return a.find("source").length?(a.is(":hidden")&&a.show(),this.media=d.view.MediaDetails.prepareSrc(a.get(0))):(a.hide(),this.media=!1),this}}),d.view.VideoDetails=d.view.MediaDetails.extend({className:"video-details",template:d.template("video-details"),setMedia:function(){var a=this.$(".wp-video-shortcode");return a.find("source").length?(a.is(":hidden")&&a.show(),this.media=a.hasClass("youtube-video")?a.get(0):d.view.MediaDetails.prepareSrc(a.get(0))):(a.hide(),this.media=!1),this}})}(jQuery,_,Backbone); |