mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-26 11:08:06 +01:00
7ad4205f70
* Remove the audio/video shortcode parsing from the `wpgallery` plugin. * Make `mce-view` a dependency of `media-audiovideo` * Introduce `wp.mce.video`, `wp.mce.audio`, `wp.mce.media`, and `wp.mce.media.View` * Rename `wp.media.audio|video.shortcode()` to `wp.media.audio|video.update()` since it is called on Update and returns a `wp.shortcode` object now. * In `wp.mce.View.render()`, fire a `ready` event when the placeholder is being parsed and pass the current node to the event handler. See #27389, #27437. Built from https://develop.svn.wordpress.org/trunk@27615 git-svn-id: http://core.svn.wordpress.org/trunk@27458 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
14 KiB
JavaScript
1 line
14 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"],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)})},update: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:""},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)})},update: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})}},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})]}}),wp.mce.media={toView:function(a){var b=wp.shortcode.next(this.shortcode,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}},edit:function(b){var c,d,e=wp.media[this.shortcode],f=this;wp.media.mixin.pauseAllPlayers(),d=window.decodeURIComponent(a(b).data("wpview-text")),c=e.edit(d),c.on("close",function(){c.detach()}),c.state(f.shortcode+"-details").on("update",function(d){var e=wp.media[f.shortcode].update(d).string();a(b).attr("data-wpview-text",window.encodeURIComponent(e)),wp.mce.views.refreshView(f,e),c.detach()}),c.open()}},wp.mce.media.View=wp.mce.View.extend({initialize:function(c){this.shortcode=c.shortcode,b.bindAll(this,"setPlayer"),a(this).on("ready",this.setPlayer)},setPlayer:function(c,d){if(d){var e,f=this,g={},h=".wp-"+this.shortcode.tag+"-shortcode";if(this.player&&this.unsetPlayer(),e=a(d).find(h),b.isUndefined(window._wpmejsSettings)||(g.pluginPath=_wpmejsSettings.pluginPath),!this.isCompatible(e))return e.closest(".wpview-wrap").addClass("wont-play"),e.parent().hasClass("wpview-wrap")||e.parent().replaceWith(e),void e.replaceWith("<p>"+e.find("source").eq(0).prop("src")+"</p>");e.closest(".wpview-wrap").removeClass("wont-play"),this.ua.is("ff")?e.prop("preload","metadata"):e.prop("preload","none"),e=wp.media.view.MediaDetails.prepareSrc(e.get(0)),setTimeout(function(){f.player=new MediaElementPlayer(e,g)},50)}},getHtml:function(){var a=this.shortcode.attrs.named;return this.template({model:a})}}),b.extend(wp.mce.media.View.prototype,wp.media.mixin),wp.mce.video=b.extend({},wp.mce.media,{shortcode:"video",View:wp.mce.media.View.extend({className:"editor-video",template:e.template("editor-video")})}),wp.mce.views.register("video",wp.mce.video),wp.mce.audio=b.extend({},wp.mce.media,{shortcode:"audio",View:wp.mce.media.View.extend({className:"editor-audio",template:e.template("editor-audio")})}),wp.mce.views.register("audio",wp.mce.audio),a(d)}(jQuery,_,Backbone); |