mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-17 16:15:24 +01:00
86f4061b26
See #27389. Built from https://develop.svn.wordpress.org/trunk@27658 git-svn-id: http://core.svn.wordpress.org/trunk@27501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
18 KiB
JavaScript
1 line
18 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(b){e.frame.lastMime=a(b.currentTarget).data("mime"),e.frame.setState("add-"+e.frame.defaults.id+"-source")})}var e=wp.media,f={},g="undefined"==typeof _wpMediaViewsL10n?{}:_wpMediaViewsL10n;b.isUndefined(window._wpmejsSettings)||(f.pluginPath=_wpmejsSettings.pluginPath),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=null!==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:g.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:g.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",caption:""},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:"",caption:"",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})}},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:{id:"audio-details",toolbar:"audio-details",title:g.audioDetailsTitle,content:"audio-details",menu:"audio-details",router:!1,priority:60},initialize:function(a){this.media=a.media,e.controller.State.prototype.initialize.apply(this,arguments)}}),e.controller.VideoDetails=e.controller.State.extend({defaults:{id:"video-details",toolbar:"video-details",title:g.videoDetailsTitle,content:"video-details",menu:"video-details",router:!1,priority:60},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})})},setPrimaryButton:function(a,b){this.toolbar.set(new e.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(g.update,function(a,b){a.close(),b.trigger("update",a.media.toJSON())})},renderReplaceToolbar:function(){this.setPrimaryButton(g.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())})}}),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:g.audioDetailsTitle,priority:120},initialize:function(a){a.DetailsView=e.view.AudioDetails,a.cancelText=g.audioDetailsCancel,a.addText=g.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}),new e.controller.MediaLibrary({type:"audio",id:"replace-audio",title:g.audioReplaceTitle,toolbar:"replace-audio",media:this.media,menu:"audio-details"}),new e.controller.MediaLibrary({type:"audio",id:"add-audio-source",title:g.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:g.videoDetailsTitle,priority:120},initialize:function(a){a.DetailsView=e.view.VideoDetails,a.cancelText=g.videoDetailsCancel,a.addText=g.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}),new e.controller.MediaLibrary({type:"video",id:"replace-video",title:g.videoReplaceTitle,toolbar:"replace-video",media:this.media,menu:"video-details"}),new e.controller.MediaLibrary({type:"video",id:"add-video-source",title:g.videoAddSourceTitle,toolbar:"add-video-source",media:this.media,menu:!1}),new e.controller.MediaLibrary({type:"image",id:"select-poster-image",title:g.videoSelectPosterImageTitle,toolbar:"select-poster-image",media:this.media,menu:"video-details"}),new e.controller.MediaLibrary({type:"text",id:"add-track",title:g.videoAddTrackTitle,toolbar:"add-track",media:this.media,menu:"video-details"})])},renderSelectPosterImageToolbar:function(){this.setPrimaryButton(g.videoSelectPosterImageTitle,function(a,b){var c=b.get("selection").single();a.media.set("poster",c.get("url")),b.trigger("set-poster-image",a.media.toJSON())})},renderAddTrackToolbar:function(){this.setPrimaryButton(g.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())})}}),e.view.MediaDetails=e.view.Settings.AttachmentDisplay.extend({initialize:function(){b.bindAll(this,"success"),this.listenTo(this.controller,"close",e.mixin.unsetPlayer),this.on("ready",this.setPlayer),this.on("media:setting:remove",e.mixin.unsetPlayer,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"}),e.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)},setPlayer:function(){!this.player&&this.media&&(this.player=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 e.view.Settings.AttachmentDisplay.prototype.render.apply(this,arguments),setTimeout(function(){a.resetFocus()},10),this.settings=b.defaults({success:this.success},f),this.setMedia()},resetFocus:function(){this.$(".embed-media-settings").scrollTop(0)}},{instances:0,prepareSrc:function(c){var d=e.view.MediaDetails.instances++;return b.each(a(c).find("source"),function(a){a.src=[a.src,a.src.indexOf("?")>-1?"&":"?","_=",d].join("")}),c}}),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:g.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:g.editPlaylistTitle,SettingsView:e.view.Settings.Playlist,library:a.selection,editing:a.editing,menu:"playlist",dragInfoText:g.playlistDragInfo,dragInfo:!1}),new e.controller.CollectionAdd({type:"audio",collectionType:"playlist",title:g.addToPlaylistTitle})]},videoStates:function(a){return[new e.controller.Library({id:"video-playlist",title:g.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:g.editVideoPlaylistTitle,SettingsView:e.view.Settings.Playlist,library:a.selection,editing:a.editing,menu:"video-playlist",dragInfoText:g.videoPlaylistDragInfo,dragInfo:!1}),new e.controller.CollectionAdd({type:"video",collectionType:"video-playlist",title:g.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).attr("data-wpview-text")),c=e.edit(d),c.on("close",function(){c.detach()}),c.state(f.state).on("update",function(d){var e=wp.media[f.shortcode].shortcode(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(b,c){if(c){var d,e=this,g=this.ua.is("ff"),h=".wp-"+this.shortcode.tag+"-shortcode";if(this.player&&this.unsetPlayer(),d=a(c).find(h),!this.isCompatible(d))return d.closest(".wpview-wrap").addClass("wont-play"),d.parent().hasClass("wpview-wrap")||d.parent().replaceWith(d),void d.replaceWith("<p>"+d.find("source").eq(0).prop("src")+"</p>");d.closest(".wpview-wrap").removeClass("wont-play"),g?d.prop("preload","metadata"):d.prop("preload","none"),d=wp.media.view.MediaDetails.prepareSrc(d.get(0)),g?setTimeout(function(){e.player=new MediaElementPlayer(d,f)},50):this.player=new MediaElementPlayer(d,f)}},getHtml:function(){var a=b.defaults(this.shortcode.attrs.named,wp.media[this.shortcode.tag].defaults);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",state:"video-details",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",state:"audio-details",View:wp.mce.media.View.extend({className:"editor-audio",template:e.template("editor-audio")})}),wp.mce.views.register("audio",wp.mce.audio),wp.mce.media.PlaylistView=wp.mce.View.extend({className:"editor-playlist",template:e.template("editor-playlist"),initialize:function(c){this.data={},this.attachments=[],this.shortcode=c.shortcode,b.bindAll(this,"setPlayer"),a(this).on("ready",this.setNode)},setNode:function(a,b){this.node=b,this.fetch()},fetch:function(){this.attachments=wp.media[this.shortcode.tag].attachments(this.shortcode),this.attachments.more().done(this.setPlayer)},setPlayer:function(){var c,d=this.getHtml(),e=this.encodedText,f=this;this.unsetPlayer(),b.each(tinymce.editors,function(b){var c;b.plugins.wpview&&(c=b.getDoc(),a(c).find('[data-wpview-text="'+e+'"]').each(function(b,c){var e=a(c);e.html(d),f.node=c}))},this),c=new WPPlaylistView({el:a(f.node).find(".wp-playlist").get(0),metadata:this.data}),this.player=c._player},getHtml:function(){var a,c,d=this.shortcode.attrs.named,f=wp.media[this.shortcode.tag],g="playlist"===this.shortcode.tag?"audio":"video",h=[];if(this.attachments.length)return b.each(f.defaults,function(a,b){d[b]=f.coerce(d,b)}),c=this.attachments.toJSON(),a={type:g,style:d.style,tracklist:d.tracklist,tracknumbers:d.tracknumbers,images:d.images,artists:d.artists},b.each(c,function(c){var d={},f={},i={src:c.url,type:c.mime,title:c.title,caption:c.caption,description:c.description,meta:c.meta};"video"===g?(d.width=c.width,d.height=c.height,e.view.settings.contentWidth?(f.width=e.view.settings.contentWidth-22,f.height=Math.ceil(d.height*f.width/d.width),a.width||(a.width=f.width,a.height=f.height)):a.width||(a.width=c.width,a.height=c.height),i.dimensions={original:d,resized:b.isEmpty(f)?d:f}):a.width=400,i.image=c.image,i.thumb=c.thumb,h.push(i)}),a.tracks=h,this.data=a,this.template(a)}}),b.extend(wp.mce.media.PlaylistView.prototype,wp.media.mixin),wp.mce.playlist=b.extend({},wp.mce.media,{shortcode:"playlist",state:"playlist-edit",View:wp.mce.media.PlaylistView}),wp.mce.views.register("playlist",wp.mce.playlist),wp.mce["video-playlist"]=b.extend({},wp.mce.media,{shortcode:"video-playlist",state:"video-playlist-edit",View:wp.mce.media.PlaylistView}),wp.mce.views.register("video-playlist",wp.mce["video-playlist"]),a(d)}(jQuery,_,Backbone); |