diff --git a/wp-includes/js/media-audiovideo.js b/wp-includes/js/media-audiovideo.js index 182cc158da..261be871bc 100644 --- a/wp-includes/js/media-audiovideo.js +++ b/wp-includes/js/media-audiovideo.js @@ -207,10 +207,11 @@ defaults : { id : wp.media.view.settings.post.id, - src : '', - loop : false, + src : '', + loop : false, autoplay : false, - preload : 'none' + preload : 'none', + caption : '' }, edit : function (data) { @@ -227,7 +228,7 @@ return frame; }, - update : function (model) { + shortcode : function (model) { var self = this, content; _.each( this.defaults, function( value, key ) { @@ -266,7 +267,8 @@ loop : false, autoplay : false, preload : 'metadata', - content : '' + content : '', + caption : '' }, edit : function (data) { @@ -287,7 +289,7 @@ return frame; }, - update : function (model) { + shortcode : function (model) { var self = this, content; _.each( this.defaults, function( value, key ) { @@ -1129,13 +1131,13 @@ wp.media.mixin.pauseAllPlayers(); - data = window.decodeURIComponent( $( node ).data('wpview-text') ); + data = window.decodeURIComponent( $( node ).attr('data-wpview-text') ); frame = media.edit( data ); frame.on( 'close', function () { frame.detach(); } ); - frame.state( self.shortcode + '-details' ).on( 'update', function( selection ) { - var shortcode = wp.media[ self.shortcode ].update( selection ).string(); + frame.state( self.state ).on( 'update', function( selection ) { + var shortcode = wp.media[ self.shortcode ].shortcode( selection ).string(); $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) ); wp.mce.views.refreshView( self, shortcode ); frame.detach(); @@ -1205,6 +1207,7 @@ wp.mce.video = _.extend( {}, wp.mce.media, { shortcode: 'video', + state: 'video-details', View: wp.mce.media.View.extend({ className: 'editor-video', template: media.template('editor-video') @@ -1215,6 +1218,7 @@ wp.mce.audio = _.extend( {}, wp.mce.media, { shortcode: 'audio', + state: 'audio-details', View: wp.mce.media.View.extend({ className: 'editor-audio', template: media.template('editor-audio') @@ -1223,6 +1227,138 @@ wp.mce.views.register( 'audio', wp.mce.audio ); + wp.mce.media.PlaylistView = wp.mce.View.extend({ + className: 'editor-playlist', + template: media.template('editor-playlist'), + + initialize: function( options ) { + this.data = {}; + this.attachments = []; + this.shortcode = options.shortcode; + _.bindAll( this, 'setPlayer' ); + $(this).on('ready', this.setNode); + }, + + setNode: function (e, node) { + this.node = node; + this.fetch(); + }, + + fetch: function() { + this.attachments = wp.media[ this.shortcode.tag ].attachments( this.shortcode ); + this.attachments.more().done( this.setPlayer ); + }, + + setPlayer: function () { + var p, + html = this.getHtml(), + t = this.encodedText, + self = this; + + this.unsetPlayer(); + + _.each( tinymce.editors, function( editor ) { + var doc; + if ( editor.plugins.wpview ) { + doc = editor.getDoc(); + $( doc ).find( '[data-wpview-text="' + t + '"]' ).each(function (i, elem) { + var node = $( elem ); + node.html( html ); + self.node = elem; + }); + } + }, this ); + + p = new WPPlaylistView({ + el: $( self.node ).find( '.wp-playlist' ).get(0), + metadata: this.data + }); + + this.player = p._player; + }, + + getHtml: function() { + var data = this.shortcode.attrs.named, + model = wp.media[ this.shortcode.tag ], + type = 'playlist' === this.shortcode.tag ? 'audio' : 'video', + options, + attachments, + tracks = []; + + if ( ! this.attachments.length ) { + return; + } + + _.each( model.defaults, function( value, key ) { + data[ key ] = model.coerce( data, key ); + }); + + attachments = this.attachments.toJSON(); + + options = { + type: type, + style: data.style, + tracklist: data.tracklist, + tracknumbers: data.tracknumbers, + images: data.images, + artists: data.artists + }; + + _.each( attachments, function (attachment) { + var size = {}, track = { + src : attachment.url, + type : attachment.mime, + title : attachment.title, + caption : attachment.caption, + description : attachment.description, + meta : attachment.meta + }; + + if ( 'video' === type ) { + if ( ! options.width ) { + options.width = attachment.width; + options.height = attachment.height; + } + size.width = attachment.width; + size.height = attachment.height; + track.dimensions = { + original : size, + resized : size + }; + } else { + options.width = 400; + } + + track.image = attachment.image; + track.thumb = attachment.thumb; + + tracks.push( track ); + } ); + + options.tracks = tracks; + this.data = options; + + return this.template( options ); + } + }); + _.extend( wp.mce.media.PlaylistView.prototype, wp.media.mixin ); + + wp.mce.playlist = _.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'] = _.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'] ); + function init() { $(document.body) .on( 'click', '.wp-switch-editor', wp.media.mixin.pauseAllPlayers ) diff --git a/wp-includes/js/media-audiovideo.min.js b/wp-includes/js/media-audiovideo.min.js index f1e4f25f36..6977c98fc9 100644 --- a/wp-includes/js/media-audiovideo.min.js +++ b/wp-includes/js/media-audiovideo.min.js @@ -1 +1 @@ -!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+=[''].join(""),a.media.set("content",e)),b.trigger("add-track",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))}}),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,c={success:this.success};return b.isUndefined(window._wpmejsSettings)||(c.pluginPath=_wpmejsSettings.pluginPath),e.view.Settings.AttachmentDisplay.prototype.render.apply(this,arguments),setTimeout(function(){a.resetFocus()},10),this.settings=c,this.setMedia()},resetFocus:function(){this.$(".embed-media-settings").scrollTop(0)}},{instances:0,prepareSrc:function(c){var d=wp.media.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"+e.find("source").eq(0).prop("src")+"

");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); \ No newline at end of file +!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",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,wp.media.audio.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:""},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,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+=[''].join(""),a.media.set("content",e)),b.trigger("add-track",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))}}),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,c={success:this.success};return b.isUndefined(window._wpmejsSettings)||(c.pluginPath=_wpmejsSettings.pluginPath),e.view.Settings.AttachmentDisplay.prototype.render.apply(this,arguments),setTimeout(function(){a.resetFocus()},10),this.settings=c,this.setMedia()},resetFocus:function(){this.$(".embed-media-settings").scrollTop(0)}},{instances:0,prepareSrc:function(c){var d=wp.media.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"+e.find("source").eq(0).prop("src")+"

");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",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,e=wp.media[this.shortcode.tag],f="playlist"===this.shortcode.tag?"audio":"video",g=[];if(this.attachments.length)return b.each(e.defaults,function(a,b){d[b]=e.coerce(d,b)}),c=this.attachments.toJSON(),a={type:f,style:d.style,tracklist:d.tracklist,tracknumbers:d.tracknumbers,images:d.images,artists:d.artists},b.each(c,function(b){var c={},d={src:b.url,type:b.mime,title:b.title,caption:b.caption,description:b.description,meta:b.meta};"video"===f?(a.width||(a.width=b.width,a.height=b.height),c.width=b.width,c.height=b.height,d.dimensions={original:c,resized:c}):a.width=400,d.image=b.image,d.thumb=b.thumb,g.push(d)}),a.tracks=g,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); \ No newline at end of file diff --git a/wp-includes/js/media-editor.js b/wp-includes/js/media-editor.js index d0b4308810..f7253b7969 100644 --- a/wp-includes/js/media-editor.js +++ b/wp-includes/js/media-editor.js @@ -198,6 +198,23 @@ } } + if ( ! _.isEmpty( attachment.caption ) ) { + shortcode.caption = attachment.caption; + } else if ( attachment.meta && attachment.meta.title ) { + shortcode.caption = '“' + attachment.meta.title + '”'; + if ( attachment.meta.album ) { + shortcode.caption += ' from ' + attachment.meta.album; + } + + if ( attachment.meta.artist ) { + shortcode.caption += ' by ' + attachment.meta.artist; + } + } else if ( ! _.isEmpty( attachment.description ) ) { + shortcode.caption = attachment.description; + } else { + shortcode.caption = attachment.title; + } + extension = attachment.filename.split('.').pop(); if ( _.contains( wp.media.view.settings.embedExts, extension ) ) { @@ -387,6 +404,7 @@ if ( attachments[this.tag] ) { _.extend( attrs, attachments[this.tag].toJSON() ); } + // Convert all gallery shortcodes to use the `ids` property. // Ignore `post__in` and `post__not_in`; the attachments in // the collection will already reflect those properties. diff --git a/wp-includes/js/media-editor.min.js b/wp-includes/js/media-editor.min.js index 5c058c5a98..0ae0e9301d 100644 --- a/wp-includes/js/media-editor.min.js +++ b/wp-includes/js/media-editor.min.js @@ -1 +1 @@ -!function(a,b){var c={};wp.media.coerce=function(a,c){return b.isUndefined(a[c])&&!b.isUndefined(this.defaults[c])?a[c]=this.defaults[c]:"true"===a[c]?a[c]=!0:"false"===a[c]&&(a[c]=!1),a[c]},wp.media.string={props:function(a,c){var d,e,f,g,h,i=wp.media.view.settings.defaultProps;return h=function(a){return"image"!==a.type||a.alt||(a.alt=a.caption||a.title||"",a.alt=a.alt.replace(/<\/?[^>]+>/g,""),a.alt=a.alt.replace(/[\r\n]+/g," ")),a},a=a?b.clone(a):{},c&&c.type&&(a.type=c.type),"image"===a.type&&(a=b.defaults(a||{},{align:i.align||getUserSetting("align","none"),size:i.size||getUserSetting("imgsize","medium"),url:"",classes:[]})),c?(a.title=a.title||c.title,d=a.link||i.link||getUserSetting("urlbutton","file"),"file"===d||"embed"===d?e=c.url:"post"===d?e=c.link:"custom"===d&&(e=a.linkUrl),a.linkUrl=e||"","image"===c.type?(a.classes.push("wp-image-"+c.id),g=c.sizes,f=g&&g[a.size]?g[a.size]:c,b.extend(a,b.pick(c,"align","caption","alt"),{width:f.width,height:f.height,src:f.url,captionId:"attachment_"+c.id})):"video"===c.type||"audio"===c.type?b.extend(a,b.pick(c,"title","type","icon","mime")):(a.title=a.title||c.filename,a.rel=a.rel||"attachment wp-att-"+c.id),h(a)):h(a)},link:function(a,b){var c;return a=wp.media.string.props(a,b),c={tag:"a",content:a.title,attrs:{href:a.linkUrl}},a.rel&&(c.attrs.rel=a.rel),wp.html.string(c)},audio:function(a,b){return wp.media.string._audioVideo("audio",a,b)},video:function(a,b){return wp.media.string._audioVideo("video",a,b)},_audioVideo:function(a,c,d){var e,f,g;return c=wp.media.string.props(c,d),"embed"!==c.link?wp.media.string.link(c):(e={},"video"===a&&(d.width&&(e.width=d.width),d.height&&(e.height=d.height)),g=d.filename.split(".").pop(),b.contains(wp.media.view.settings.embedExts,g)?(e[g]=d.url,f=wp.shortcode.string({tag:a,attrs:e})):wp.media.string.link(c))},image:function(a,c){var d,e,f,g,h={};return a=wp.media.string.props(a,c),e=a.classes||[],h.src=b.isUndefined(c)?a.url:c.url,b.extend(h,b.pick(a,"width","height","alt")),a.align&&!a.caption&&e.push("align"+a.align),a.size&&e.push("size-"+a.size),h["class"]=b.compact(e).join(" "),d={tag:"img",attrs:h,single:!0},a.linkUrl&&(d={tag:"a",attrs:{href:a.linkUrl},content:d}),g=wp.html.string(d),a.caption&&(f={},h.width&&(f.width=h.width),a.captionId&&(f.id=a.captionId),a.align&&(f.align="align"+a.align),g=wp.shortcode.string({tag:"caption",attrs:f,content:g+" "+a.caption})),g}},wp.media.collection=function(a){var c={};return b.extend(a,{coerce:wp.media.coerce,attachments:function(a){var d,e,f,g,h=a.string(),i=c[h],j=this;return delete c[h],i?i:(d=b.defaults(a.attrs.named,this.defaults),e=b.pick(d,"orderby","order"),e.type=this.type,e.perPage=-1,void 0!==d.orderby&&(d._orderByField=d.orderby),"rand"===d.orderby&&(d._orderbyRandom=!0),(!d.orderby||/^menu_order(?: ID)?$/i.test(d.orderby))&&(e.orderby="menuOrder"),d.ids?(e.post__in=d.ids.split(","),e.orderby="post__in"):d.include&&(e.post__in=d.include.split(",")),d.exclude&&(e.post__not_in=d.exclude.split(",")),e.post__in||(e.uploadedTo=d.id),g=b.omit(d,"id","ids","include","exclude","orderby","order"),b.each(this.defaults,function(a,b){g[b]=j.coerce(g,b)}),f=wp.media.query(e),f[this.tag]=new Backbone.Model(g),f)},shortcode:function(a){var d,e,f=a.props.toJSON(),g=b.pick(f,"orderby","order"),h=this;return a[this.tag]&&b.extend(g,a[this.tag].toJSON()),g.ids=a.pluck("id"),f.uploadedTo&&(g.id=f.uploadedTo),delete g.orderby,g._orderbyRandom?g.orderby="rand":g._orderByField&&"rand"!=g._orderByField&&(g.orderby=g._orderByField),delete g._orderbyRandom,delete g._orderByField,g.ids&&"post__in"===g.orderby&&delete g.orderby,b.each(this.defaults,function(a,b){g[b]=h.coerce(g,b),a===g[b]&&delete g[b]}),d=new wp.shortcode({tag:this.tag,attrs:g,type:"single"}),e=new wp.media.model.Attachments(a.models,{props:f}),e[this.tag]=a[this.tag],c[d.string()]=e,d},edit:function(a){var c,d,e=wp.shortcode.next(this.tag,a),f=this.defaults.id;if(e&&e.content===a)return e=e.shortcode,b.isUndefined(e.get("id"))&&!b.isUndefined(f)&&e.set("id",f),c=this.attachments(e),d=new wp.media.model.Selection(c.models,{props:c.props.toJSON(),multiple:!0}),d[this.tag]=c[this.tag],d.more().done(function(){d.props.set({query:!1}),d.unmirror(),d.props.unset("orderby")}),this.frame&&this.frame.dispose(),this.frame=wp.media({frame:"post",state:this.tag+"-edit",title:this.editTitle,editing:!0,multiple:!0,selection:d}).open(),this.frame}})},wp.media.gallery=new wp.media.collection({tag:"gallery",type:"image",editTitle:wp.media.view.l10n.editGalleryTitle,defaults:{itemtag:"dl",icontag:"dt",captiontag:"dd",columns:"3",link:"post",size:"thumbnail",order:"ASC",id:wp.media.view.settings.post.id,orderby:"menu_order ID"}}),wp.media.featuredImage={get:function(){return wp.media.view.settings.post.featuredImageId},set:function(b){var c=wp.media.view.settings;c.post.featuredImageId=b,wp.media.post("set-post-thumbnail",{json:!0,post_id:c.post.id,thumbnail_id:c.post.featuredImageId,_wpnonce:c.post.nonce}).done(function(b){a(".inside","#postimagediv").html(b)})},frame:function(){return this._frame?this._frame:(this._frame=wp.media({state:"featured-image",states:[new wp.media.controller.FeaturedImage,new wp.media.controller.EditImage]}),this._frame.on("toolbar:create:featured-image",function(a){this.createSelectToolbar(a,{text:wp.media.view.l10n.setFeaturedImage})},this._frame),this._frame.on("content:render:edit-image",function(){var a=this.state("featured-image").get("selection"),b=new wp.media.view.EditImage({model:a.single(),controller:this}).render();this.content.set(b),b.loadEditor()},this._frame),this._frame.state("featured-image").on("select",this.select),this._frame)},select:function(){var a=this.get("selection").single();wp.media.view.settings.post.featuredImageId&&wp.media.featuredImage.set(a?a.id:-1)},init:function(){a("#postimagediv").on("click","#set-post-thumbnail",function(a){a.preventDefault(),a.stopPropagation(),wp.media.featuredImage.frame().open()}).on("click","#remove-post-thumbnail",function(){wp.media.view.settings.post.featuredImageId=-1})}},a(wp.media.featuredImage.init),wp.media.editor={insert:function(a){var c,d=!b.isUndefined(window.tinymce),e=!b.isUndefined(window.QTags),f=window.wpActiveEditor;if(window.send_to_editor)return window.send_to_editor.apply(this,arguments);if(f)d&&(c=tinymce.get(f));else if(d&&tinymce.activeEditor)c=tinymce.activeEditor,f=window.wpActiveEditor=c.id;else if(!e)return!1;if(c&&!c.isHidden()?c.execCommand("mceInsertContent",!1,a):e?QTags.insertContent(a):document.getElementById(f).value+=a,window.tb_remove)try{window.tb_remove()}catch(g){}},add:function(d,e){var f=this.get(d);return f?f:(f=c[d]=wp.media(b.defaults(e||{},{frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:!0})),f.on("insert",function(c){var d=f.state();c=c||d.get("selection"),c&&a.when.apply(a,c.map(function(a){var b=d.display(a).toJSON();return this.send.attachment(b,a.toJSON())},this)).done(function(){wp.media.editor.insert(b.toArray(arguments).join("\n\n"))})},this),f.state("gallery-edit").on("update",function(a){this.insert(wp.media.gallery.shortcode(a).string())},this),f.state("playlist-edit").on("update",function(a){this.insert(wp.media.playlist.shortcode(a).string())},this),f.state("video-playlist-edit").on("update",function(a){this.insert(wp.media["video-playlist"].shortcode(a).string())},this),f.state("embed").on("select",function(){var a=f.state(),c=a.get("type"),d=a.props.toJSON();d.url=d.url||"","link"===c?(b.defaults(d,{title:d.url,linkUrl:d.url}),this.send.link(d).done(function(a){wp.media.editor.insert(a)})):"image"===c&&(b.defaults(d,{title:d.url,linkUrl:"",align:"none",link:"none"}),"none"===d.link?d.linkUrl="":"file"===d.link&&(d.linkUrl=d.url),this.insert(wp.media.string.image(d)))},this),f.state("featured-image").on("select",wp.media.featuredImage.select),f.setState(f.options.state),f)},id:function(a){return a?a:(a=wpActiveEditor,a||b.isUndefined(window.tinymce)||!tinymce.activeEditor||(a=tinymce.activeEditor.id),a=a||"")},get:function(a){return a=this.id(a),c[a]},remove:function(a){a=this.id(a),delete c[a]},send:{attachment:function(a,c){var d,e,f=c.caption;return wp.media.view.settings.captions||delete c.caption,a=wp.media.string.props(a,c),d={id:c.id,post_content:c.description,post_excerpt:f},a.linkUrl&&(d.url=a.linkUrl),"image"===c.type?(e=wp.media.string.image(a),b.each({align:"align",size:"image-size",alt:"image_alt"},function(b,c){a[c]&&(d[b]=a[c])})):"video"===c.type?e=wp.media.string.video(a,c):"audio"===c.type?e=wp.media.string.audio(a,c):(e=wp.media.string.link(a),d.post_title=a.title),wp.media.post("send-attachment-to-editor",{nonce:wp.media.view.settings.nonce.sendToEditor,attachment:d,html:e,post_id:wp.media.view.settings.post.id})},link:function(a){return wp.media.post("send-link-to-editor",{nonce:wp.media.view.settings.nonce.sendToEditor,src:a.linkUrl,title:a.title,html:wp.media.string.link(a),post_id:wp.media.view.settings.post.id})}},open:function(a,b){var c;return b=b||{},a=this.id(a),c=this.get(a),(!c||c.options&&b.state!==c.options.state)&&(c=this.add(a,b)),c.open()},init:function(){a(document.body).on("click",".insert-media",function(b){var c=a(b.currentTarget),d=c.data("editor"),e={frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:!0};b.preventDefault(),c.blur(),c.hasClass("gallery")&&(e.state="gallery",e.title=wp.media.view.l10n.createGalleryTitle),wp.media.editor.open(d,e)}),(new wp.media.view.EditorUploader).render()}},b.bindAll(wp.media.editor,"open"),a(wp.media.editor.init)}(jQuery,_); \ No newline at end of file +!function(a,b){var c={};wp.media.coerce=function(a,c){return b.isUndefined(a[c])&&!b.isUndefined(this.defaults[c])?a[c]=this.defaults[c]:"true"===a[c]?a[c]=!0:"false"===a[c]&&(a[c]=!1),a[c]},wp.media.string={props:function(a,c){var d,e,f,g,h,i=wp.media.view.settings.defaultProps;return h=function(a){return"image"!==a.type||a.alt||(a.alt=a.caption||a.title||"",a.alt=a.alt.replace(/<\/?[^>]+>/g,""),a.alt=a.alt.replace(/[\r\n]+/g," ")),a},a=a?b.clone(a):{},c&&c.type&&(a.type=c.type),"image"===a.type&&(a=b.defaults(a||{},{align:i.align||getUserSetting("align","none"),size:i.size||getUserSetting("imgsize","medium"),url:"",classes:[]})),c?(a.title=a.title||c.title,d=a.link||i.link||getUserSetting("urlbutton","file"),"file"===d||"embed"===d?e=c.url:"post"===d?e=c.link:"custom"===d&&(e=a.linkUrl),a.linkUrl=e||"","image"===c.type?(a.classes.push("wp-image-"+c.id),g=c.sizes,f=g&&g[a.size]?g[a.size]:c,b.extend(a,b.pick(c,"align","caption","alt"),{width:f.width,height:f.height,src:f.url,captionId:"attachment_"+c.id})):"video"===c.type||"audio"===c.type?b.extend(a,b.pick(c,"title","type","icon","mime")):(a.title=a.title||c.filename,a.rel=a.rel||"attachment wp-att-"+c.id),h(a)):h(a)},link:function(a,b){var c;return a=wp.media.string.props(a,b),c={tag:"a",content:a.title,attrs:{href:a.linkUrl}},a.rel&&(c.attrs.rel=a.rel),wp.html.string(c)},audio:function(a,b){return wp.media.string._audioVideo("audio",a,b)},video:function(a,b){return wp.media.string._audioVideo("video",a,b)},_audioVideo:function(a,c,d){var e,f,g;return c=wp.media.string.props(c,d),"embed"!==c.link?wp.media.string.link(c):(e={},"video"===a&&(d.width&&(e.width=d.width),d.height&&(e.height=d.height)),b.isEmpty(d.caption)?d.meta&&d.meta.title?(e.caption="“"+d.meta.title+"”",d.meta.album&&(e.caption+=" from "+d.meta.album),d.meta.artist&&(e.caption+=" by "+d.meta.artist)):e.caption=b.isEmpty(d.description)?d.title:d.description:e.caption=d.caption,g=d.filename.split(".").pop(),b.contains(wp.media.view.settings.embedExts,g)?(e[g]=d.url,f=wp.shortcode.string({tag:a,attrs:e})):wp.media.string.link(c))},image:function(a,c){var d,e,f,g,h={};return a=wp.media.string.props(a,c),e=a.classes||[],h.src=b.isUndefined(c)?a.url:c.url,b.extend(h,b.pick(a,"width","height","alt")),a.align&&!a.caption&&e.push("align"+a.align),a.size&&e.push("size-"+a.size),h["class"]=b.compact(e).join(" "),d={tag:"img",attrs:h,single:!0},a.linkUrl&&(d={tag:"a",attrs:{href:a.linkUrl},content:d}),g=wp.html.string(d),a.caption&&(f={},h.width&&(f.width=h.width),a.captionId&&(f.id=a.captionId),a.align&&(f.align="align"+a.align),g=wp.shortcode.string({tag:"caption",attrs:f,content:g+" "+a.caption})),g}},wp.media.collection=function(a){var c={};return b.extend(a,{coerce:wp.media.coerce,attachments:function(a){var d,e,f,g,h=a.string(),i=c[h],j=this;return delete c[h],i?i:(d=b.defaults(a.attrs.named,this.defaults),e=b.pick(d,"orderby","order"),e.type=this.type,e.perPage=-1,void 0!==d.orderby&&(d._orderByField=d.orderby),"rand"===d.orderby&&(d._orderbyRandom=!0),(!d.orderby||/^menu_order(?: ID)?$/i.test(d.orderby))&&(e.orderby="menuOrder"),d.ids?(e.post__in=d.ids.split(","),e.orderby="post__in"):d.include&&(e.post__in=d.include.split(",")),d.exclude&&(e.post__not_in=d.exclude.split(",")),e.post__in||(e.uploadedTo=d.id),g=b.omit(d,"id","ids","include","exclude","orderby","order"),b.each(this.defaults,function(a,b){g[b]=j.coerce(g,b)}),f=wp.media.query(e),f[this.tag]=new Backbone.Model(g),f)},shortcode:function(a){var d,e,f=a.props.toJSON(),g=b.pick(f,"orderby","order"),h=this;return a[this.tag]&&b.extend(g,a[this.tag].toJSON()),g.ids=a.pluck("id"),f.uploadedTo&&(g.id=f.uploadedTo),delete g.orderby,g._orderbyRandom?g.orderby="rand":g._orderByField&&"rand"!=g._orderByField&&(g.orderby=g._orderByField),delete g._orderbyRandom,delete g._orderByField,g.ids&&"post__in"===g.orderby&&delete g.orderby,b.each(this.defaults,function(a,b){g[b]=h.coerce(g,b),a===g[b]&&delete g[b]}),d=new wp.shortcode({tag:this.tag,attrs:g,type:"single"}),e=new wp.media.model.Attachments(a.models,{props:f}),e[this.tag]=a[this.tag],c[d.string()]=e,d},edit:function(a){var c,d,e=wp.shortcode.next(this.tag,a),f=this.defaults.id;if(e&&e.content===a)return e=e.shortcode,b.isUndefined(e.get("id"))&&!b.isUndefined(f)&&e.set("id",f),c=this.attachments(e),d=new wp.media.model.Selection(c.models,{props:c.props.toJSON(),multiple:!0}),d[this.tag]=c[this.tag],d.more().done(function(){d.props.set({query:!1}),d.unmirror(),d.props.unset("orderby")}),this.frame&&this.frame.dispose(),this.frame=wp.media({frame:"post",state:this.tag+"-edit",title:this.editTitle,editing:!0,multiple:!0,selection:d}).open(),this.frame}})},wp.media.gallery=new wp.media.collection({tag:"gallery",type:"image",editTitle:wp.media.view.l10n.editGalleryTitle,defaults:{itemtag:"dl",icontag:"dt",captiontag:"dd",columns:"3",link:"post",size:"thumbnail",order:"ASC",id:wp.media.view.settings.post.id,orderby:"menu_order ID"}}),wp.media.featuredImage={get:function(){return wp.media.view.settings.post.featuredImageId},set:function(b){var c=wp.media.view.settings;c.post.featuredImageId=b,wp.media.post("set-post-thumbnail",{json:!0,post_id:c.post.id,thumbnail_id:c.post.featuredImageId,_wpnonce:c.post.nonce}).done(function(b){a(".inside","#postimagediv").html(b)})},frame:function(){return this._frame?this._frame:(this._frame=wp.media({state:"featured-image",states:[new wp.media.controller.FeaturedImage,new wp.media.controller.EditImage]}),this._frame.on("toolbar:create:featured-image",function(a){this.createSelectToolbar(a,{text:wp.media.view.l10n.setFeaturedImage})},this._frame),this._frame.on("content:render:edit-image",function(){var a=this.state("featured-image").get("selection"),b=new wp.media.view.EditImage({model:a.single(),controller:this}).render();this.content.set(b),b.loadEditor()},this._frame),this._frame.state("featured-image").on("select",this.select),this._frame)},select:function(){var a=this.get("selection").single();wp.media.view.settings.post.featuredImageId&&wp.media.featuredImage.set(a?a.id:-1)},init:function(){a("#postimagediv").on("click","#set-post-thumbnail",function(a){a.preventDefault(),a.stopPropagation(),wp.media.featuredImage.frame().open()}).on("click","#remove-post-thumbnail",function(){wp.media.view.settings.post.featuredImageId=-1})}},a(wp.media.featuredImage.init),wp.media.editor={insert:function(a){var c,d=!b.isUndefined(window.tinymce),e=!b.isUndefined(window.QTags),f=window.wpActiveEditor;if(window.send_to_editor)return window.send_to_editor.apply(this,arguments);if(f)d&&(c=tinymce.get(f));else if(d&&tinymce.activeEditor)c=tinymce.activeEditor,f=window.wpActiveEditor=c.id;else if(!e)return!1;if(c&&!c.isHidden()?c.execCommand("mceInsertContent",!1,a):e?QTags.insertContent(a):document.getElementById(f).value+=a,window.tb_remove)try{window.tb_remove()}catch(g){}},add:function(d,e){var f=this.get(d);return f?f:(f=c[d]=wp.media(b.defaults(e||{},{frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:!0})),f.on("insert",function(c){var d=f.state();c=c||d.get("selection"),c&&a.when.apply(a,c.map(function(a){var b=d.display(a).toJSON();return this.send.attachment(b,a.toJSON())},this)).done(function(){wp.media.editor.insert(b.toArray(arguments).join("\n\n"))})},this),f.state("gallery-edit").on("update",function(a){this.insert(wp.media.gallery.shortcode(a).string())},this),f.state("playlist-edit").on("update",function(a){this.insert(wp.media.playlist.shortcode(a).string())},this),f.state("video-playlist-edit").on("update",function(a){this.insert(wp.media["video-playlist"].shortcode(a).string())},this),f.state("embed").on("select",function(){var a=f.state(),c=a.get("type"),d=a.props.toJSON();d.url=d.url||"","link"===c?(b.defaults(d,{title:d.url,linkUrl:d.url}),this.send.link(d).done(function(a){wp.media.editor.insert(a)})):"image"===c&&(b.defaults(d,{title:d.url,linkUrl:"",align:"none",link:"none"}),"none"===d.link?d.linkUrl="":"file"===d.link&&(d.linkUrl=d.url),this.insert(wp.media.string.image(d)))},this),f.state("featured-image").on("select",wp.media.featuredImage.select),f.setState(f.options.state),f)},id:function(a){return a?a:(a=wpActiveEditor,a||b.isUndefined(window.tinymce)||!tinymce.activeEditor||(a=tinymce.activeEditor.id),a=a||"")},get:function(a){return a=this.id(a),c[a]},remove:function(a){a=this.id(a),delete c[a]},send:{attachment:function(a,c){var d,e,f=c.caption;return wp.media.view.settings.captions||delete c.caption,a=wp.media.string.props(a,c),d={id:c.id,post_content:c.description,post_excerpt:f},a.linkUrl&&(d.url=a.linkUrl),"image"===c.type?(e=wp.media.string.image(a),b.each({align:"align",size:"image-size",alt:"image_alt"},function(b,c){a[c]&&(d[b]=a[c])})):"video"===c.type?e=wp.media.string.video(a,c):"audio"===c.type?e=wp.media.string.audio(a,c):(e=wp.media.string.link(a),d.post_title=a.title),wp.media.post("send-attachment-to-editor",{nonce:wp.media.view.settings.nonce.sendToEditor,attachment:d,html:e,post_id:wp.media.view.settings.post.id})},link:function(a){return wp.media.post("send-link-to-editor",{nonce:wp.media.view.settings.nonce.sendToEditor,src:a.linkUrl,title:a.title,html:wp.media.string.link(a),post_id:wp.media.view.settings.post.id})}},open:function(a,b){var c;return b=b||{},a=this.id(a),c=this.get(a),(!c||c.options&&b.state!==c.options.state)&&(c=this.add(a,b)),c.open()},init:function(){a(document.body).on("click",".insert-media",function(b){var c=a(b.currentTarget),d=c.data("editor"),e={frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:!0};b.preventDefault(),c.blur(),c.hasClass("gallery")&&(e.state="gallery",e.title=wp.media.view.l10n.createGalleryTitle),wp.media.editor.open(d,e)}),(new wp.media.view.EditorUploader).render()}},b.bindAll(wp.media.editor,"open"),a(wp.media.editor.init)}(jQuery,_); \ No newline at end of file diff --git a/wp-includes/js/mediaelement/wp-playlist.js b/wp-includes/js/mediaelement/wp-playlist.js index 6c19e1da5f..bfe75c2bb0 100644 --- a/wp-includes/js/mediaelement/wp-playlist.js +++ b/wp-includes/js/mediaelement/wp-playlist.js @@ -8,10 +8,10 @@ itemTemplate : wp.template('wp-playlist-item'), - initialize : function () { + initialize : function (options) { var settings = {}; - this.data = $.parseJSON( this.$('script').html() ); + this.data = options.metadata || $.parseJSON( this.$('script').html() ); this.playerNode = this.$( this.data.type ); this.tracks = new Backbone.Collection( this.data.tracks ); @@ -38,7 +38,7 @@ } settings.success = this.bindPlayer; - new MediaElementPlayer( this.playerNode.get(0), settings ); + this._player = new MediaElementPlayer( this.playerNode.get(0), settings ); }, renderCurrent : function () { @@ -132,9 +132,13 @@ }); $(document).ready(function () { - $('.wp-playlist').each(function () { - return new WPPlaylistView({ el: this }); - }); + if ( ! $( 'body' ).hasClass('wp-admin') ) { + $('.wp-playlist').each(function () { + return new WPPlaylistView({ el: this }); + }); + } }); + window.WPPlaylistView = WPPlaylistView; + }(jQuery, _, Backbone)); \ No newline at end of file diff --git a/wp-includes/js/tinymce/plugins/wpgallery/plugin.js b/wp-includes/js/tinymce/plugins/wpgallery/plugin.js index 2f0912873b..7f82e3575f 100644 --- a/wp-includes/js/tinymce/plugins/wpgallery/plugin.js +++ b/wp-includes/js/tinymce/plugins/wpgallery/plugin.js @@ -13,28 +13,6 @@ tinymce.PluginManager.add('wpgallery', function( editor ) { 'data-wp-media="' + data + '" data-mce-resize="false" data-mce-placeholder="1" />'; } - function replaceCallback( match, type, close ) { - var index; - - if ( close && close.indexOf( '[' + type ) > -1 ) { - index = match.length - close.length; - return html( 'wp-' + type, match.substring( 0, index ) ) + match.substring( index ); - } - - return html( 'wp-' + type, match ); - } - - function replaceAVShortcodes( content ) { - var testRegex = /\[(video-playlist|playlist)[^\]]*\]/, - replaceRegex = /\[(video-playlist|playlist)[^\]]*\]([\s\S]*?\[\/\1\])?/; - - while ( testRegex.test( content ) ) { - content = content.replace( replaceRegex, replaceCallback ); - } - - return content; - } - function restoreMediaShortcodes( content ) { function getAttr( str, name ) { name = new RegExp( name + '=\"([^\"]+)\"' ).exec( str ); @@ -76,25 +54,6 @@ tinymce.PluginManager.add('wpgallery', function( editor ) { editor.dom.setAttrib( node, 'data-wp-media', window.encodeURIComponent( shortcode ) ); frame.detach(); }); - } else if ( editor.dom.hasClass( node, 'wp-playlist' ) && wp.media.playlist ) { - frame = wp.media.playlist.edit( data ); - - frame.state('playlist-edit').on( 'update', function( selection ) { - var shortcode = wp.media.playlist.shortcode( selection ).string(); - editor.dom.setAttrib( node, 'data-wp-media', window.encodeURIComponent( shortcode ) ); - frame.detach(); - }); - } else if ( editor.dom.hasClass( node, 'wp-video-playlist' ) && wp.media['video-playlist'] ) { - frame = wp.media['video-playlist'].edit( data ); - - frame.state('video-playlist-edit').on( 'update', function( selection ) { - var shortcode = wp.media['video-playlist'].shortcode( selection ).string(); - editor.dom.setAttrib( node, 'data-wp-media', window.encodeURIComponent( shortcode ) ); - frame.detach(); - }); - } else { - // temp - window.console && window.console.log( 'Edit AV shortcode ' + data ); } } @@ -152,10 +111,6 @@ tinymce.PluginManager.add('wpgallery', function( editor ) { if ( node.nodeName === 'IMG' && dom.getAttrib( node, 'data-wp-media' ) ) { if ( dom.hasClass( node, 'wp-gallery' ) ) { event.name = 'gallery'; - } else if ( dom.hasClass( node, 'wp-playlist' ) ) { - event.name = 'playlist'; - } else if ( dom.hasClass( node, 'wp-video-playlist' ) ) { - event.name = 'video-playlist'; } } }); @@ -165,8 +120,6 @@ tinymce.PluginManager.add('wpgallery', function( editor ) { if ( ! editor.plugins.wpview ) { event.content = replaceGalleryShortcodes( event.content ); } - - event.content = replaceAVShortcodes( event.content ); }); editor.on( 'PostProcess', function( event ) { diff --git a/wp-includes/js/tinymce/plugins/wpgallery/plugin.min.js b/wp-includes/js/tinymce/plugins/wpgallery/plugin.min.js index 65596d7bd7..dc6288ac2a 100644 --- a/wp-includes/js/tinymce/plugins/wpgallery/plugin.min.js +++ b/wp-includes/js/tinymce/plugins/wpgallery/plugin.min.js @@ -1 +1 @@ -tinymce.PluginManager.add("wpgallery",function(a){function b(a){return a.replace(/\[gallery([^\]]*)\]/g,function(a){return c("wp-gallery",a)})}function c(a,b){return b=window.encodeURIComponent(b),''}function d(a,b,d){var e;return d&&d.indexOf("["+b)>-1?(e=a.length-d.length,c("wp-"+b,a.substring(0,e))+a.substring(e)):c("wp-"+b,a)}function e(a){for(var b=/\[(video-playlist|playlist)[^\]]*\]/,c=/\[(video-playlist|playlist)[^\]]*\]([\s\S]*?\[\/\1\])?/;b.test(a);)a=a.replace(c,d);return a}function f(a){function b(a,b){return b=new RegExp(b+'="([^"]+)"').exec(a),b?window.decodeURIComponent(b[1]):""}return a.replace(/(?:]+)?>)*(]+>)(?:<\/p>)*/g,function(a,c){var d=b(c,"data-wp-media");return d?"

"+d+"

":a})}function g(b){var c,d,e;"IMG"===b.nodeName&&"undefined"!=typeof wp&&wp.media&&(e=window.decodeURIComponent(a.dom.getAttrib(b,"data-wp-media")),a.dom.hasClass(b,"wp-gallery")&&wp.media.gallery?(c=wp.media.gallery,d=c.edit(e),d.state("gallery-edit").on("update",function(e){var f=c.shortcode(e).string();a.dom.setAttrib(b,"data-wp-media",window.encodeURIComponent(f)),d.detach()})):a.dom.hasClass(b,"wp-playlist")&&wp.media.playlist?(d=wp.media.playlist.edit(e),d.state("playlist-edit").on("update",function(c){var e=wp.media.playlist.shortcode(c).string();a.dom.setAttrib(b,"data-wp-media",window.encodeURIComponent(e)),d.detach()})):a.dom.hasClass(b,"wp-video-playlist")&&wp.media["video-playlist"]?(d=wp.media["video-playlist"].edit(e),d.state("video-playlist-edit").on("update",function(c){var e=wp.media["video-playlist"].shortcode(c).string();a.dom.setAttrib(b,"data-wp-media",window.encodeURIComponent(e)),d.detach()})):window.console&&window.console.log("Edit AV shortcode "+e))}a.addCommand("WP_Gallery",function(){g(a.selection.getNode())}),a.on("mouseup",function(b){function c(){d.removeClass(d.select("img.wp-media-selected"),"wp-media-selected")}var d=a.dom,e=b.target;"IMG"===e.nodeName&&d.getAttrib(e,"data-wp-media")?2!==b.button&&(d.hasClass(e,"wp-media-selected")?g(e):(c(),d.addClass(e,"wp-media-selected"))):c()}),a.on("ResolveName",function(b){var c=a.dom,d=b.target;"IMG"===d.nodeName&&c.getAttrib(d,"data-wp-media")&&(c.hasClass(d,"wp-gallery")?b.name="gallery":c.hasClass(d,"wp-playlist")?b.name="playlist":c.hasClass(d,"wp-video-playlist")&&(b.name="video-playlist"))}),a.on("BeforeSetContent",function(c){a.plugins.wpview||(c.content=b(c.content)),c.content=e(c.content)}),a.on("PostProcess",function(a){a.get&&(a.content=f(a.content))})}); \ No newline at end of file +tinymce.PluginManager.add("wpgallery",function(a){function b(a){return a.replace(/\[gallery([^\]]*)\]/g,function(a){return c("wp-gallery",a)})}function c(a,b){return b=window.encodeURIComponent(b),''}function d(a){function b(a,b){return b=new RegExp(b+'="([^"]+)"').exec(a),b?window.decodeURIComponent(b[1]):""}return a.replace(/(?:]+)?>)*(]+>)(?:<\/p>)*/g,function(a,c){var d=b(c,"data-wp-media");return d?"

"+d+"

":a})}function e(b){var c,d,e;"IMG"===b.nodeName&&"undefined"!=typeof wp&&wp.media&&(e=window.decodeURIComponent(a.dom.getAttrib(b,"data-wp-media")),a.dom.hasClass(b,"wp-gallery")&&wp.media.gallery&&(c=wp.media.gallery,d=c.edit(e),d.state("gallery-edit").on("update",function(e){var f=c.shortcode(e).string();a.dom.setAttrib(b,"data-wp-media",window.encodeURIComponent(f)),d.detach()})))}a.addCommand("WP_Gallery",function(){e(a.selection.getNode())}),a.on("mouseup",function(b){function c(){d.removeClass(d.select("img.wp-media-selected"),"wp-media-selected")}var d=a.dom,f=b.target;"IMG"===f.nodeName&&d.getAttrib(f,"data-wp-media")?2!==b.button&&(d.hasClass(f,"wp-media-selected")?e(f):(c(),d.addClass(f,"wp-media-selected"))):c()}),a.on("ResolveName",function(b){var c=a.dom,d=b.target;"IMG"===d.nodeName&&c.getAttrib(d,"data-wp-media")&&c.hasClass(d,"wp-gallery")&&(b.name="gallery")}),a.on("BeforeSetContent",function(c){a.plugins.wpview||(c.content=b(c.content))}),a.on("PostProcess",function(a){a.get&&(a.content=d(a.content))})}); \ No newline at end of file diff --git a/wp-includes/js/tinymce/skins/wordpress/wp-content.css b/wp-includes/js/tinymce/skins/wordpress/wp-content.css index 6ee1e2f931..f758542193 100644 --- a/wp-includes/js/tinymce/skins/wordpress/wp-content.css +++ b/wp-includes/js/tinymce/skins/wordpress/wp-content.css @@ -141,14 +141,6 @@ img::selection { background-image: url(images/gallery.png); } -.mce-content-body img.wp-media.wp-playlist { - background-image: url("images/playlist-audio.png"); -} - -.mce-content-body img.wp-media.wp-video-playlist { - background-image: url("images/playlist-video.png"); -} - /* Image resize handles */ .mce-content-body div.mce-resizehandle { border-color: #777; @@ -299,6 +291,16 @@ embed { border-color: rgba(0,0,0,0.3); } +.wpview-type-audio .track-details { + position: absolute; + top: 0; + left: 5px; + width: 85%; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; +} + .gallery img[data-mce-selected]:focus { outline: none; } diff --git a/wp-includes/js/tinymce/wp-tinymce.js.gz b/wp-includes/js/tinymce/wp-tinymce.js.gz index 705004d08a..e3efca2416 100644 Binary files a/wp-includes/js/tinymce/wp-tinymce.js.gz and b/wp-includes/js/tinymce/wp-tinymce.js.gz differ diff --git a/wp-includes/media-template.php b/wp-includes/media-template.php index 9f72f176f6..add9940006 100644 --- a/wp-includes/media-template.php +++ b/wp-includes/media-template.php @@ -814,7 +814,7 @@ function wp_print_media_templates() {
- +
@@ -829,6 +829,12 @@ function wp_print_media_templates() { + + +
@@ -901,7 +907,7 @@ function wp_print_media_templates() {
- +
@@ -936,6 +942,11 @@ function wp_print_media_templates() { <# } #> + +
@@ -966,6 +977,9 @@ function wp_print_media_templates() {
+ <# if ( ! _.isEmpty( data.model.caption ) ) { #> +
{{{ data.model.caption }}}
+ <# } #> @@ -974,9 +988,31 @@ function wp_print_media_templates() {
+ <# if ( ! _.isEmpty( data.model.caption ) ) { #> +
{{{ data.model.caption }}}
+ <# } #> + + + + - + + '', 'src' => '', 'loop' => '', 'autoplay' => '', @@ -1549,6 +1561,7 @@ function wp_video_shortcode( $attr, $content = '' ) { $default_types = wp_get_video_extensions(); $defaults_atts = array( + 'caption' => '', 'src' => '', 'poster' => '', 'loop' => '', @@ -2332,6 +2345,22 @@ function wp_prepare_attachment_for_js( $attachment ) { if ( $meta && ( 'audio' === $type || 'video' === $type ) ) { if ( isset( $meta['length_formatted'] ) ) $response['fileLength'] = $meta['length_formatted']; + + $response['meta'] = array(); + $keys = array( 'title', 'artist', 'band', 'album', 'genre', 'year', 'length', 'length_formatted' ); + foreach ( $keys as $key ) { + if ( ! empty( $meta[ $key ] ) ) { + $response['meta'][ $key ] = $meta[ $key ]; + } + } + + $id = get_post_thumbnail_id( $attachment->ID ); + if ( ! empty( $id ) ) { + list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'full' ); + $response['image'] = compact( 'src', 'width', 'height' ); + list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'thumbnail' ); + $response['thumb'] = compact( 'src', 'width', 'height' ); + } } if ( function_exists('get_compat_media_markup') ) diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index ff2544ab59..77121f4f87 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -396,7 +396,7 @@ function wp_default_scripts( &$scripts ) { // Both rely on numerous settings, styles, and templates to operate correctly. $scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable', 'wp-mediaelement' ), false, 1 ); $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 ); - $scripts->add( 'media-audiovideo', "/wp-includes/js/media-audiovideo$suffix.js", array( 'media-editor', 'mce-view' ), false, 1 ); + $scripts->add( 'media-audiovideo', "/wp-includes/js/media-audiovideo$suffix.js", array( 'media-editor', 'mce-view', 'wp-playlist' ), false, 1 ); $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'media-models' ), false, 1 ); if ( is_admin() ) {