WordPress/wp-includes/js/media-audiovideo.min.js
Scott Taylor a17dd704c4 Create a new file, media-audiovideo.js, to house all of the audio and video JS code in core.
UX Changes:
* Don't add a menu item for "Add Audio|Video Source"
* In the Audio|Video Details modal, add buttons and some suggestive text for adding alternate playback sources
* Don't show "Create Audio|Video Playlist" menu items until the user has uploaded audio or video files

See #27437.


Built from https://develop.svn.wordpress.org/trunk@27608


git-svn-id: http://core.svn.wordpress.org/trunk@27451 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-19 05:31:15 +00:00

1 line
12 KiB
JavaScript

!function(a,b,c){function d(){a(document.body).on("click",".wp-switch-editor",wp.media.mixin.pauseAllPlayers).on("click",".add-media-source",function(){e.frame.setState("add-"+e.frame.defaults.id+"-source")})}var e=wp.media,f="undefined"==typeof _wpMediaViewsL10n?{}:_wpMediaViewsL10n;wp.media.mixin={pauseAllPlayers:function(){var a;if(window.mejs&&window.mejs.players)for(a in window.mejs.players)window.mejs.players[a].pause()},ua:{is:function(a){var b=!1,c=window.navigator.userAgent;switch(a){case"oldie":b=null!==c.match(/MSIE [6-8]/gi);break;case"ie":b=null!==c.match(/MSIE/gi);break;case"ff":b=null!==c.match(/firefox/gi);break;case"opera":b=null!==c.match(/OPR/);break;case"safari":b=null!==c.match(/safari/gi)&&null===c.match(/chrome/gi);break;case"chrome":b=c.match(/safari/gi)&&null!==c.match(/chrome/gi)}return b}},compat:{opera:{audio:["ogg","wav"],video:["ogg","webm"]},chrome:{audio:["ogg","mpeg","x-ms-wma"],video:["ogg","webm","mp4","m4v","mpeg"]},ff:{audio:["ogg","mpeg"],video:["ogg","webm"]},safari:{audio:["mpeg","wav"],video:["mp4","m4v","mpeg","x-ms-wmv","quicktime"]},ie:{audio:["mpeg"],video:["mp4","m4v","mpeg"]}},isCompatible:function(a){if(!a.find("source").length)return!1;var c,d=this.ua,e=!1,f=!1;return d.is("oldIE")?!1:(c=a.find("source"),b.find(this.compat,function(a,g){return d.is(g)&&(f=!0,b.each(c,function(b){var c=new RegExp("audio/("+a.audio.join("|")+")","gi"),d=new RegExp("video/("+a.video.join("|")+")","gi");(null!==b.type.match(d)||null!==b.type.match(c))&&(e=!0)})),e||f}),e)},removePlayer:function(){var a,b,c=this.player;for(a in c.options.features)if(b=c.options.features[a],c["clean"+b])try{c["clean"+b](c)}catch(d){}c.isDynamic||c.$node.remove(),"native"!==c.media.pluginType&&c.media.remove(),delete window.mejs.players[c.id],c.container.remove(),c.globalUnbind(),delete c.node.player},unsetPlayer:function(){this.player&&(wp.media.mixin.pauseAllPlayers(),wp.media.mixin.removePlayer.apply(this),this.player=!1)}},wp.media.playlist=new wp.media.collection({tag:"playlist",type:"audio",editTitle:f.editPlaylistTitle,defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!0,tracknumbers:!0,images:!0,artists:!0}}),wp.media["video-playlist"]=new wp.media.collection({tag:"video-playlist",type:"video",editTitle:f.editVideoPlaylistTitle,defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!1,tracknumbers:!1,images:!0}}),wp.media.audio={coerce:wp.media.coerce,defaults:{id:wp.media.view.settings.post.id,src:"",loop:!1,autoplay:!1,preload:"none"},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,wp.media.audio.defaults)})},shortcode:function(a){var c=this;return b.each(wp.media.audio.defaults,function(b,d){a[d]=c.coerce(a,d),b===a[d]&&delete a[d]}),wp.shortcode.string({tag:"audio",attrs:a})}},wp.media.video={coerce:wp.media.coerce,defaults:{id:wp.media.view.settings.post.id,src:"",poster:"",loop:!1,autoplay:!1,preload:"metadata",content:""},edit:function(a){var c,d,e=this.defaults,f=wp.shortcode.next("video",a).shortcode;return d=f.attrs.named,d.content=f.content,c=wp.media({frame:"video",state:"video-details",metadata:b.defaults(d,e)})},shortcode:function(a){var c=this,d=a.content;return delete a.content,b.each(this.defaults,function(b,d){a[d]=c.coerce(a,d),b===a[d]&&delete a[d]}),wp.shortcode.string({tag:"video",attrs:a,content:d})}},e.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)})}}),e.controller.AudioDetails=e.controller.State.extend({defaults:b.defaults({id:"audio-details",toolbar:"audio-details",title:f.audioDetailsTitle,content:"audio-details",menu:"audio-details",router:!1,attachment:!1,priority:60,editing:!1},e.controller.Library.prototype.defaults),initialize:function(a){this.media=a.media,e.controller.State.prototype.initialize.apply(this,arguments)}}),e.controller.VideoDetails=e.controller.State.extend({defaults:b.defaults({id:"video-details",toolbar:"video-details",title:f.videoDetailsTitle,content:"video-details",menu:"video-details",router:!1,attachment:!1,priority:60,editing:!1},e.controller.Library.prototype.defaults),initialize:function(a){this.media=a.media,e.controller.State.prototype.initialize.apply(this,arguments)}}),e.view.MediaFrame.MediaDetails=e.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 e.model.PostMedia(a.metadata),this.options.selection=new e.model.Selection(this.media.attachment,{multiple:!1}),e.view.MediaFrame.Select.prototype.initialize.apply(this,arguments)},bindHandlers:function(){var a=this.defaults.menu;e.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,d=this;a.set({cancel:{text:this.cancelText,priority:20,click:function(){c?d.setState(c):d.close()}},separateCancel:new e.View({className:"separator",priority:40})})},renderDetailsToolbar:function(){this.toolbar.set(new e.view.Toolbar({controller:this,items:{select:{style:"primary",text:f.update,priority:80,click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))},renderReplaceToolbar:function(){this.toolbar.set(new e.view.Toolbar({controller:this,items:{replace:{style:"primary",text:f.replace,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.media.changeAttachment(d),b.trigger("replace",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))},renderAddSourceToolbar:function(){this.toolbar.set(new e.view.Toolbar({controller:this,items:{replace:{style:"primary",text:this.addText,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.media.setSource(d),b.trigger("add-source",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))}}),e.view.MediaFrame.AudioDetails=e.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=e.view.AudioDetails,a.cancelText=f.audioDetailsCancel,a.addText=f.audioAddSourceTitle,e.view.MediaFrame.MediaDetails.prototype.initialize.call(this,a)},bindHandlers:function(){e.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 e.controller.AudioDetails({media:this.media,editable:!1,menu:"audio-details"}),new e.controller.MediaLibrary({type:"audio",id:"replace-audio",title:f.audioReplaceTitle,toolbar:"replace-audio",media:this.media,menu:"audio-details"}),new e.controller.MediaLibrary({type:"audio",id:"add-audio-source",title:f.audioAddSourceTitle,toolbar:"add-audio-source",media:this.media,menu:!1})])}}),e.view.MediaFrame.VideoDetails=e.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=e.view.VideoDetails,a.cancelText=f.videoDetailsCancel,a.addText=f.videoAddSourceTitle,e.view.MediaFrame.MediaDetails.prototype.initialize.call(this,a)},bindHandlers:function(){e.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 e.controller.VideoDetails({media:this.media,editable:!1,menu:"video-details"}),new e.controller.MediaLibrary({type:"video",id:"replace-video",title:f.videoReplaceTitle,toolbar:"replace-video",media:this.media,menu:"video-details"}),new e.controller.MediaLibrary({type:"video",id:"add-video-source",title:f.videoAddSourceTitle,toolbar:"add-video-source",media:this.media,menu:!1}),new e.controller.MediaLibrary({type:"image",id:"select-poster-image",title:f.videoSelectPosterImageTitle,toolbar:"select-poster-image",media:this.media,menu:"video-details"}),new e.controller.MediaLibrary({type:"text",id:"add-track",title:f.videoAddTrackTitle,toolbar:"add-track",media:this.media,menu:"video-details"})])},renderSelectPosterImageToolbar:function(){this.toolbar.set(new e.view.Toolbar({controller:this,items:{replace:{style:"primary",text:f.videoSelectPosterImageTitle,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.media.set("poster",d.get("url")),b.trigger("set-poster-image",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))},renderAddTrackToolbar:function(){this.toolbar.set(new e.view.Toolbar({controller:this,items:{replace:{style:"primary",text:f.videoAddTrackTitle,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single(),e=a.media.get("content");-1===e.indexOf(d.get("url"))&&(e+=['<track srclang="en" label="English"kind="subtitles" src="',d.get("url"),'" />'].join(""),a.media.set("content",e)),b.trigger("add-track",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))}}),e.view.AudioDetails=e.view.MediaDetails.extend({className:"audio-details",template:e.template("audio-details"),setMedia:function(){var a=this.$(".wp-audio-shortcode");return a.find("source").length?(a.is(":hidden")&&a.show(),this.media=e.view.MediaDetails.prepareSrc(a.get(0))):(a.hide(),this.media=!1),this}}),e.view.VideoDetails=e.view.MediaDetails.extend({className:"video-details",template:e.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):e.view.MediaDetails.prepareSrc(a.get(0))):(a.hide(),this.media=!1),this}}),b.extend(wp.media.playlist,{counts:function(a){var c={};return function(){if(!b.isEmpty(c))return c;var d=0,e=0;return b.each(a.attachmentCounts,function(a,b){var c;if(-1<b.indexOf("/"))switch(c=b.split("/")[0],a=parseInt(a,10),c){case"audio":d+=a;break;case"video":e+=a}}),c.audio=d,c.video=e,c}}(e.view.settings),states:function(a){return[new e.controller.Library({id:"playlist",title:f.createPlaylistTitle,priority:60,toolbar:"main-playlist",filterable:"uploaded",multiple:"add",editable:!1,library:e.query(b.defaults({type:"audio"},a.library))}),new e.controller.CollectionEdit({type:"audio",collectionType:"playlist",title:f.editPlaylistTitle,SettingsView:e.view.Settings.Playlist,library:a.selection,editing:a.editing,menu:"playlist",dragInfoText:f.playlistDragInfo,dragInfo:!1}),new e.controller.CollectionAdd({type:"audio",collectionType:"playlist",title:f.addToPlaylistTitle})]},videoStates:function(a){return[new e.controller.Library({id:"video-playlist",title:f.createVideoPlaylistTitle,priority:60,toolbar:"main-video-playlist",filterable:"uploaded",multiple:"add",editable:!1,library:e.query(b.defaults({type:"video"},a.library))}),new e.controller.CollectionEdit({type:"video",collectionType:"video-playlist",title:f.editVideoPlaylistTitle,SettingsView:e.view.Settings.Playlist,library:a.selection,editing:a.editing,menu:"video-playlist",dragInfoText:f.videoPlaylistDragInfo,dragInfo:!1}),new e.controller.CollectionAdd({type:"video",collectionType:"video-playlist",title:f.addToVideoPlaylistTitle})]}}),a(d)}(jQuery,_,Backbone);