diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index be2681a06b..73e33c9cfb 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -31,10 +31,14 @@ window.wp = window.wp || {}; var html = this.getHtml(); // Search all tinymce editor instances and update the placeholders _.each( tinymce.editors, function( editor ) { - var doc; + var doc, self = this; if ( editor.plugins.wpview ) { doc = editor.getDoc(); - $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).html( html ); + $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each(function (i, elem) { + var node = $( elem ); + node.html( html ); + $( self ).trigger( 'ready', elem ); + }); } }, this ); } @@ -178,7 +182,7 @@ window.wp = window.wp || {}; /** * Refresh views after an update is made - * + * * @param view {object} being refreshed * @param text {string} textual representation of the view */ @@ -204,9 +208,9 @@ window.wp = window.wp || {}; return instances[ encodedText ]; }, - /** + /** * render( scope ) - * + * * Renders any view instances inside a DOM node `scope`. * * View instances are detected by the presence of wrapper elements. diff --git a/wp-includes/js/mce-view.min.js b/wp-includes/js/mce-view.min.js index c0229cce0e..92d42a172b 100644 --- a/wp-includes/js/mce-view.min.js +++ b/wp-includes/js/mce-view.min.js @@ -1 +1 @@ -window.wp=window.wp||{},function(a){var b={},c={},d=wp.media,e=["encodedText"];wp.mce=wp.mce||{},wp.mce.View=function(a){a||(a={}),_.extend(this,_.pick(a,e)),this.initialize.apply(this,arguments)},_.extend(wp.mce.View.prototype,{initialize:function(){},html:function(){},render:function(){var b=this.getHtml();_.each(tinymce.editors,function(c){var d;c.plugins.wpview&&(d=c.getDoc(),a(d).find('[data-wpview-text="'+this.encodedText+'"]').html(b))},this)}}),wp.mce.View.extend=Backbone.View.extend,wp.mce.views={register:function(a,c){b[a]=c},get:function(a){return b[a]},unregister:function(a){delete b[a]},toViews:function(a){var c,d=[{content:a}];return _.each(b,function(a,b){c=d.slice(),d=[],_.each(c,function(c){var e,f=c.content;if(c.processed)return void d.push(c);for(;f&&(e=a.toView(f));)e.index&&d.push({content:f.substring(0,e.index)}),d.push({content:wp.mce.views.toView(b,e.content,e.options),processed:!0}),f=f.slice(e.index+e.content.length);f&&d.push({content:f})})}),_.pluck(d,"content").join("")},toView:function(a,b,d){var e,f,g=wp.mce.views.get(a),h=window.encodeURIComponent(b);return g?(wp.mce.views.getInstance(h)||(f=d,f.encodedText=h,e=new g.View(f),c[h]=e),wp.html.string({tag:"div",attrs:{"class":"wpview-wrap wpview-type-"+a,"data-wpview-text":h,"data-wpview-type":a,contenteditable:"false"},content:" "})):b},refreshView:function(a,b){var d,e,f,g=window.encodeURIComponent(b);f=wp.mce.views.getInstance(g),f||(e=a.toView(b),d=e.options,d.encodedText=g,f=new a.View(d),c[g]=f),wp.mce.views.render()},getInstance:function(a){return c[a]},render:function(){_.each(c,function(a){a.render()})},edit:function(b){var c=a(b).data("wpview-type"),d=wp.mce.views.get(c);d&&d.edit(b)}},wp.mce.gallery={shortcode:"gallery",toView:function(a){var b=wp.shortcode.next(this.shortcode,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}},View:wp.mce.View.extend({className:"editor-gallery",template:d.template("editor-gallery"),postID:a("#post_ID").val(),initialize:function(a){this.shortcode=a.shortcode,this.fetch()},fetch:function(){this.attachments=wp.media.gallery.attachments(this.shortcode,this.postID),this.attachments.more().done(_.bind(this.render,this))},getHtml:function(){var a,b,c=this.shortcode.attrs.named;if(this.attachments.length)return b=this.attachments.toJSON(),_.each(b,function(a){a.thumbnail=a.sizes.thumbnail?a.sizes.thumbnail:a.sizes.full}),a={attachments:b,columns:c.columns?parseInt(c.columns,10):3},this.template(a)}}),edit:function(b){var c,d,e=wp.media.gallery,f=this;d=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=e.edit(d),c.state("gallery-edit").on("update",function(d){var g=e.shortcode(d).string();a(b).attr("data-wpview-text",window.encodeURIComponent(g)),wp.mce.views.refreshView(f,g),c.detach()})}},wp.mce.views.register("gallery",wp.mce.gallery)}(jQuery); \ No newline at end of file +window.wp=window.wp||{},function(a){var b={},c={},d=wp.media,e=["encodedText"];wp.mce=wp.mce||{},wp.mce.View=function(a){a||(a={}),_.extend(this,_.pick(a,e)),this.initialize.apply(this,arguments)},_.extend(wp.mce.View.prototype,{initialize:function(){},html:function(){},render:function(){var b=this.getHtml();_.each(tinymce.editors,function(c){var d,e=this;c.plugins.wpview&&(d=c.getDoc(),a(d).find('[data-wpview-text="'+this.encodedText+'"]').each(function(c,d){var f=a(d);f.html(b),a(e).trigger("ready",d)}))},this)}}),wp.mce.View.extend=Backbone.View.extend,wp.mce.views={register:function(a,c){b[a]=c},get:function(a){return b[a]},unregister:function(a){delete b[a]},toViews:function(a){var c,d=[{content:a}];return _.each(b,function(a,b){c=d.slice(),d=[],_.each(c,function(c){var e,f=c.content;if(c.processed)return void d.push(c);for(;f&&(e=a.toView(f));)e.index&&d.push({content:f.substring(0,e.index)}),d.push({content:wp.mce.views.toView(b,e.content,e.options),processed:!0}),f=f.slice(e.index+e.content.length);f&&d.push({content:f})})}),_.pluck(d,"content").join("")},toView:function(a,b,d){var e,f,g=wp.mce.views.get(a),h=window.encodeURIComponent(b);return g?(wp.mce.views.getInstance(h)||(f=d,f.encodedText=h,e=new g.View(f),c[h]=e),wp.html.string({tag:"div",attrs:{"class":"wpview-wrap wpview-type-"+a,"data-wpview-text":h,"data-wpview-type":a,contenteditable:"false"},content:" "})):b},refreshView:function(a,b){var d,e,f,g=window.encodeURIComponent(b);f=wp.mce.views.getInstance(g),f||(e=a.toView(b),d=e.options,d.encodedText=g,f=new a.View(d),c[g]=f),wp.mce.views.render()},getInstance:function(a){return c[a]},render:function(){_.each(c,function(a){a.render()})},edit:function(b){var c=a(b).data("wpview-type"),d=wp.mce.views.get(c);d&&d.edit(b)}},wp.mce.gallery={shortcode:"gallery",toView:function(a){var b=wp.shortcode.next(this.shortcode,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}},View:wp.mce.View.extend({className:"editor-gallery",template:d.template("editor-gallery"),postID:a("#post_ID").val(),initialize:function(a){this.shortcode=a.shortcode,this.fetch()},fetch:function(){this.attachments=wp.media.gallery.attachments(this.shortcode,this.postID),this.attachments.more().done(_.bind(this.render,this))},getHtml:function(){var a,b,c=this.shortcode.attrs.named;if(this.attachments.length)return b=this.attachments.toJSON(),_.each(b,function(a){a.thumbnail=a.sizes.thumbnail?a.sizes.thumbnail:a.sizes.full}),a={attachments:b,columns:c.columns?parseInt(c.columns,10):3},this.template(a)}}),edit:function(b){var c,d,e=wp.media.gallery,f=this;d=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=e.edit(d),c.state("gallery-edit").on("update",function(d){var g=e.shortcode(d).string();a(b).attr("data-wpview-text",window.encodeURIComponent(g)),wp.mce.views.refreshView(f,g),c.detach()})}},wp.mce.views.register("gallery",wp.mce.gallery)}(jQuery); \ No newline at end of file diff --git a/wp-includes/js/media-audiovideo.js b/wp-includes/js/media-audiovideo.js index 173a203ec3..c3e2910655 100644 --- a/wp-includes/js/media-audiovideo.js +++ b/wp-includes/js/media-audiovideo.js @@ -1,4 +1,4 @@ -/* global _wpMediaViewsL10n */ +/* global _wpMediaViewsL10n, _wpmejsSettings, MediaElementPlayer */ (function ($, _, Backbone) { var media = wp.media, l10n = typeof _wpMediaViewsL10n === 'undefined' ? {} : _wpMediaViewsL10n; @@ -61,7 +61,7 @@ video: ['ogg', 'webm'] }, 'chrome' : { - audio: ['ogg', 'mpeg', 'x-ms-wma'], + audio: ['ogg', 'mpeg'], video: ['ogg', 'webm', 'mp4', 'm4v', 'mpeg'] }, 'ff' : { @@ -227,20 +227,24 @@ return frame; }, - shortcode : function (shortcode) { - var self = this; + update : function (model) { + var self = this, content; - _.each( wp.media.audio.defaults, function( value, key ) { - shortcode[ key ] = self.coerce( shortcode, key ); + _.each( this.defaults, function( value, key ) { + model[ key ] = self.coerce( model, key ); - if ( value === shortcode[ key ] ) { - delete shortcode[ key ]; + if ( value === model[ key ] ) { + delete model[ key ]; } }); - return wp.shortcode.string({ - tag: 'audio', - attrs: shortcode + content = model.content; + delete model.content; + + return new wp.shortcode({ + tag: 'audio', + attrs: model, + content: content }); } }; @@ -283,21 +287,23 @@ return frame; }, - shortcode : function (shortcode) { - var self = this, content = shortcode.content; - delete shortcode.content; + update : function (model) { + var self = this, content; _.each( this.defaults, function( value, key ) { - shortcode[ key ] = self.coerce( shortcode, key ); + model[ key ] = self.coerce( model, key ); - if ( value === shortcode[ key ] ) { - delete shortcode[ key ]; + if ( value === model[ key ] ) { + delete model[ key ]; } }); - return wp.shortcode.string({ - tag: 'video', - attrs: shortcode, + content = model.content; + delete model.content; + + return new wp.shortcode({ + tag: 'video', + attrs: model, content: content }); } @@ -972,6 +978,125 @@ } } ); + wp.mce.media = { + toView: function( content ) { + var match = wp.shortcode.next( this.shortcode, content ); + + if ( ! match ) { + return; + } + + return { + index: match.index, + content: match.content, + options: { + shortcode: match.shortcode + } + }; + }, + + edit: function( node ) { + var p, + media = wp.media[ this.shortcode ], + self = this, + frame, data; + + wp.media.mixin.pauseAllPlayers(); + + data = window.decodeURIComponent( $( node ).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(); + $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) ); + wp.mce.views.refreshView( self, shortcode ); + frame.detach(); + } ); + frame.open(); + } + }; + + wp.mce.media.View = wp.mce.View.extend({ + initialize: function( options ) { + this.shortcode = options.shortcode; + _.bindAll( this, 'setPlayer' ); + $(this).on( 'ready', this.setPlayer ); + }, + + setPlayer: function (e, node) { + // if the ready event fires on an empty node + if ( ! node ) { + return; + } + + var self = this, + media, + settings = {}, + className = '.wp-' + this.shortcode.tag + '-shortcode'; + + if ( this.player ) { + this.unsetPlayer(); + } + + media = $( node ).find( className ); + + if ( ! _.isUndefined( window._wpmejsSettings ) ) { + settings.pluginPath = _wpmejsSettings.pluginPath; + } + + if ( ! this.isCompatible( media ) ) { + media.closest( '.wpview-wrap' ).addClass( 'wont-play' ); + if ( ! media.parent().hasClass( 'wpview-wrap' ) ) { + media.parent().replaceWith( media ); + } + media.replaceWith( '

' + media.find( 'source' ).eq(0).prop( 'src' ) + '

' ); + return; + } else { + media.closest( '.wpview-wrap' ).removeClass( 'wont-play' ); + if ( this.ua.is( 'ff' ) ) { + media.prop( 'preload', 'metadata' ); + } else { + media.prop( 'preload', 'none' ); + } + } + + media = wp.media.view.MediaDetails.prepareSrc( media.get(0) ); + + // Thanks, Firefox! + setTimeout(function () { + self.player = new MediaElementPlayer( media, settings ); + }, 50); + }, + + getHtml: function() { + var attrs = this.shortcode.attrs.named; + return this.template({ model: attrs }); + } + }); + _.extend( wp.mce.media.View.prototype, wp.media.mixin ); + + wp.mce.video = _.extend( {}, wp.mce.media, { + shortcode: 'video', + View: wp.mce.media.View.extend({ + className: 'editor-video', + template: media.template('editor-video') + }) + } ); + + wp.mce.views.register( 'video', wp.mce.video ); + + wp.mce.audio = _.extend( {}, wp.mce.media, { + shortcode: 'audio', + View: wp.mce.media.View.extend({ + className: 'editor-audio', + template: media.template('editor-audio') + }) + } ); + + wp.mce.views.register( 'audio', wp.mce.audio ); + 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 4e3f40bf77..151b42e2c4 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","x-ms-wma"],video:["ogg","webm","mp4","m4v","mpeg"]},ff:{audio:["ogg","mpeg"],video:["ogg","webm"]},safari:{audio:["mpeg","wav"],video:["mp4","m4v","mpeg","x-ms-wmv","quicktime"]},ie:{audio:["mpeg"],video:["mp4","m4v","mpeg"]}},isCompatible:function(a){if(!a.find("source").length)return!1;var c,d=this.ua,e=!1,f=!1;return d.is("oldIE")?!1:(c=a.find("source"),b.find(this.compat,function(a,g){return d.is(g)&&(f=!0,b.each(c,function(b){var c=new RegExp("audio/("+a.audio.join("|")+")","gi"),d=new RegExp("video/("+a.video.join("|")+")","gi");(null!==b.type.match(d)||null!==b.type.match(c))&&(e=!0)})),e||f}),e)},removePlayer:function(){var a,b,c=this.player;for(a in c.options.features)if(b=c.options.features[a],c["clean"+b])try{c["clean"+b](c)}catch(d){}c.isDynamic||c.$node.remove(),"native"!==c.media.pluginType&&c.media.remove(),delete window.mejs.players[c.id],c.container.remove(),c.globalUnbind(),delete c.node.player},unsetPlayer:function(){this.player&&(wp.media.mixin.pauseAllPlayers(),wp.media.mixin.removePlayer.apply(this),this.player=!1)}},wp.media.playlist=new wp.media.collection({tag:"playlist",type:"audio",editTitle:f.editPlaylistTitle,defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!0,tracknumbers:!0,images:!0,artists:!0}}),wp.media["video-playlist"]=new wp.media.collection({tag:"video-playlist",type:"video",editTitle:f.editVideoPlaylistTitle,defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!1,tracknumbers:!1,images:!0}}),wp.media.audio={coerce:wp.media.coerce,defaults:{id:wp.media.view.settings.post.id,src:"",loop:!1,autoplay:!1,preload:"none"},edit:function(a){var c,d=wp.shortcode.next("audio",a).shortcode;return c=wp.media({frame:"audio",state:"audio-details",metadata:b.defaults(d.attrs.named,wp.media.audio.defaults)})},shortcode:function(a){var c=this;return b.each(wp.media.audio.defaults,function(b,d){a[d]=c.coerce(a,d),b===a[d]&&delete a[d]}),wp.shortcode.string({tag:"audio",attrs:a})}},wp.media.video={coerce:wp.media.coerce,defaults:{id:wp.media.view.settings.post.id,src:"",poster:"",loop:!1,autoplay:!1,preload:"metadata",content:""},edit:function(a){var c,d,e=this.defaults,f=wp.shortcode.next("video",a).shortcode;return d=f.attrs.named,d.content=f.content,c=wp.media({frame:"video",state:"video-details",metadata:b.defaults(d,e)})},shortcode:function(a){var c=this,d=a.content;return delete a.content,b.each(this.defaults,function(b,d){a[d]=c.coerce(a,d),b===a[d]&&delete a[d]}),wp.shortcode.string({tag:"video",attrs:a,content:d})}},e.model.PostMedia=c.Model.extend({initialize:function(){this.attachment=!1},setSource:function(a){this.attachment=a,this.extension=a.get("filename").split(".").pop(),this.get("src")&&this.extension===this.get("src").split(".").pop()&&this.unset("src"),b.contains(wp.media.view.settings.embedExts,this.extension)?this.set(this.extension,this.attachment.get("url")):this.unset(this.extension)},changeAttachment:function(a){var c=this;this.setSource(a),this.unset("src"),b.each(b.without(wp.media.view.settings.embedExts,this.extension),function(a){c.unset(a)})}}),e.controller.AudioDetails=e.controller.State.extend({defaults:b.defaults({id:"audio-details",toolbar:"audio-details",title:f.audioDetailsTitle,content:"audio-details",menu:"audio-details",router:!1,attachment:!1,priority:60,editing:!1},e.controller.Library.prototype.defaults),initialize:function(a){this.media=a.media,e.controller.State.prototype.initialize.apply(this,arguments)}}),e.controller.VideoDetails=e.controller.State.extend({defaults:b.defaults({id:"video-details",toolbar:"video-details",title:f.videoDetailsTitle,content:"video-details",menu:"video-details",router:!1,attachment:!1,priority:60,editing:!1},e.controller.Library.prototype.defaults),initialize:function(a){this.media=a.media,e.controller.State.prototype.initialize.apply(this,arguments)}}),e.view.MediaFrame.MediaDetails=e.view.MediaFrame.Select.extend({defaults:{id:"media",url:"",menu:"media-details",content:"media-details",toolbar:"media-details",type:"link",priority:120},initialize:function(a){this.DetailsView=a.DetailsView,this.cancelText=a.cancelText,this.addText=a.addText,this.media=new e.model.PostMedia(a.metadata),this.options.selection=new e.model.Selection(this.media.attachment,{multiple:!1}),e.view.MediaFrame.Select.prototype.initialize.apply(this,arguments)},bindHandlers:function(){var a=this.defaults.menu;e.view.MediaFrame.Select.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:"+a,this.createMenu,this),this.on("content:render:"+a,this.renderDetailsContent,this),this.on("menu:render:"+a,this.renderMenu,this),this.on("toolbar:render:"+a,this.renderDetailsToolbar,this)},renderDetailsContent:function(){var a=new this.DetailsView({controller:this,model:this.state().media,attachment:this.state().media.attachment}).render();this.content.set(a)},renderMenu:function(a){var b=this.lastState(),c=b&&b.id,d=this;a.set({cancel:{text:this.cancelText,priority:20,click:function(){c?d.setState(c):d.close()}},separateCancel:new e.View({className:"separator",priority:40})})},renderDetailsToolbar:function(){this.toolbar.set(new e.view.Toolbar({controller:this,items:{select:{style:"primary",text:f.update,priority:80,click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))},renderReplaceToolbar:function(){this.toolbar.set(new e.view.Toolbar({controller:this,items:{replace:{style:"primary",text:f.replace,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.media.changeAttachment(d),b.trigger("replace",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))},renderAddSourceToolbar:function(){this.toolbar.set(new e.view.Toolbar({controller:this,items:{replace:{style:"primary",text:this.addText,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.media.setSource(d),b.trigger("add-source",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))}}),e.view.MediaFrame.AudioDetails=e.view.MediaFrame.MediaDetails.extend({defaults:{id:"audio",url:"",menu:"audio-details",content:"audio-details",toolbar:"audio-details",type:"link",title:f.audioDetailsTitle,priority:120},initialize:function(a){a.DetailsView=e.view.AudioDetails,a.cancelText=f.audioDetailsCancel,a.addText=f.audioAddSourceTitle,e.view.MediaFrame.MediaDetails.prototype.initialize.call(this,a)},bindHandlers:function(){e.view.MediaFrame.MediaDetails.prototype.bindHandlers.apply(this,arguments),this.on("toolbar:render:replace-audio",this.renderReplaceToolbar,this),this.on("toolbar:render:add-audio-source",this.renderAddSourceToolbar,this)},createStates:function(){this.states.add([new e.controller.AudioDetails({media:this.media,editable:!1,menu:"audio-details"}),new e.controller.MediaLibrary({type:"audio",id:"replace-audio",title:f.audioReplaceTitle,toolbar:"replace-audio",media:this.media,menu:"audio-details"}),new e.controller.MediaLibrary({type:"audio",id:"add-audio-source",title:f.audioAddSourceTitle,toolbar:"add-audio-source",media:this.media,menu:!1})])}}),e.view.MediaFrame.VideoDetails=e.view.MediaFrame.MediaDetails.extend({defaults:{id:"video",url:"",menu:"video-details",content:"video-details",toolbar:"video-details",type:"link",title:f.videoDetailsTitle,priority:120},initialize:function(a){a.DetailsView=e.view.VideoDetails,a.cancelText=f.videoDetailsCancel,a.addText=f.videoAddSourceTitle,e.view.MediaFrame.MediaDetails.prototype.initialize.call(this,a)},bindHandlers:function(){e.view.MediaFrame.MediaDetails.prototype.bindHandlers.apply(this,arguments),this.on("toolbar:render:replace-video",this.renderReplaceToolbar,this),this.on("toolbar:render:add-video-source",this.renderAddSourceToolbar,this),this.on("toolbar:render:select-poster-image",this.renderSelectPosterImageToolbar,this),this.on("toolbar:render:add-track",this.renderAddTrackToolbar,this)},createStates:function(){this.states.add([new e.controller.VideoDetails({media:this.media,editable:!1,menu:"video-details"}),new e.controller.MediaLibrary({type:"video",id:"replace-video",title:f.videoReplaceTitle,toolbar:"replace-video",media:this.media,menu:"video-details"}),new e.controller.MediaLibrary({type:"video",id:"add-video-source",title:f.videoAddSourceTitle,toolbar:"add-video-source",media:this.media,menu:!1}),new e.controller.MediaLibrary({type:"image",id:"select-poster-image",title:f.videoSelectPosterImageTitle,toolbar:"select-poster-image",media:this.media,menu:"video-details"}),new e.controller.MediaLibrary({type:"text",id:"add-track",title:f.videoAddTrackTitle,toolbar:"add-track",media:this.media,menu:"video-details"})])},renderSelectPosterImageToolbar:function(){this.toolbar.set(new e.view.Toolbar({controller:this,items:{replace:{style:"primary",text:f.videoSelectPosterImageTitle,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.media.set("poster",d.get("url")),b.trigger("set-poster-image",a.media.toJSON()),a.setState(a.options.state),a.reset()}}}}))},renderAddTrackToolbar:function(){this.toolbar.set(new e.view.Toolbar({controller:this,items:{replace:{style:"primary",text:f.videoAddTrackTitle,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single(),e=a.media.get("content");-1===e.indexOf(d.get("url"))&&(e+=[''].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'].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"+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 diff --git a/wp-includes/js/tinymce/plugins/wpgallery/plugin.js b/wp-includes/js/tinymce/plugins/wpgallery/plugin.js index d33dbca088..2f0912873b 100644 --- a/wp-includes/js/tinymce/plugins/wpgallery/plugin.js +++ b/wp-includes/js/tinymce/plugins/wpgallery/plugin.js @@ -25,8 +25,8 @@ tinymce.PluginManager.add('wpgallery', function( editor ) { } function replaceAVShortcodes( content ) { - var testRegex = /\[(video-playlist|audio|video|playlist)[^\]]*\]/, - replaceRegex = /\[(video-playlist|audio|video|playlist)[^\]]*\]([\s\S]*?\[\/\1\])?/; + var testRegex = /\[(video-playlist|playlist)[^\]]*\]/, + replaceRegex = /\[(video-playlist|playlist)[^\]]*\]([\s\S]*?\[\/\1\])?/; while ( testRegex.test( content ) ) { content = content.replace( replaceRegex, replaceCallback ); @@ -92,31 +92,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-video' ) ) { - frame = wp.media.video.edit( data ); - frame.on( 'close', function () { - frame.detach(); - } ); - frame.state( 'video-details' ).on( - 'update replace add-source select-poster-image add-track', - function ( selection ) { - var shortcode = wp.media.video.shortcode( selection ); - editor.dom.setAttrib( node, 'data-wp-media', window.encodeURIComponent( shortcode ) ); - frame.detach(); - } - ); - frame.open(); - } else if ( editor.dom.hasClass( node, 'wp-audio' ) ) { - frame = wp.media.audio.edit( data ); - frame.on( 'close', function () { - frame.detach(); - } ); - frame.state( 'audio-details' ).on( 'update replace add-source', function ( selection ) { - var shortcode = wp.media.audio.shortcode( selection ); - editor.dom.setAttrib( node, 'data-wp-media', window.encodeURIComponent( shortcode ) ); - frame.detach(); - } ); - frame.open(); } else { // temp window.console && window.console.log( 'Edit AV shortcode ' + data ); @@ -177,10 +152,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-video' ) ) { - event.name = 'video'; - } else if ( dom.hasClass( node, 'wp-audio' ) ) { - event.name = 'audio'; } else if ( dom.hasClass( node, 'wp-playlist' ) ) { event.name = 'playlist'; } else if ( dom.hasClass( node, 'wp-video-playlist' ) ) { diff --git a/wp-includes/js/tinymce/plugins/wpgallery/plugin.min.js b/wp-includes/js/tinymce/plugins/wpgallery/plugin.min.js index 5e3e970106..65596d7bd7 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|audio|video|playlist)[^\]]*\]/,c=/\[(video-playlist|audio|video|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()})):a.dom.hasClass(b,"wp-video")?(d=wp.media.video.edit(e),d.on("close",function(){d.detach()}),d.state("video-details").on("update replace add-source select-poster-image add-track",function(c){var e=wp.media.video.shortcode(c);a.dom.setAttrib(b,"data-wp-media",window.encodeURIComponent(e)),d.detach()}),d.open()):a.dom.hasClass(b,"wp-audio")?(d=wp.media.audio.edit(e),d.on("close",function(){d.detach()}),d.state("audio-details").on("update replace add-source",function(c){var e=wp.media.audio.shortcode(c);a.dom.setAttrib(b,"data-wp-media",window.encodeURIComponent(e)),d.detach()}),d.open()):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-video")?b.name="video":c.hasClass(d,"wp-audio")?b.name="audio":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,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 diff --git a/wp-includes/js/tinymce/skins/wordpress/wp-content.css b/wp-includes/js/tinymce/skins/wordpress/wp-content.css index 8e208de1d3..d90dc9386d 100644 --- a/wp-includes/js/tinymce/skins/wordpress/wp-content.css +++ b/wp-includes/js/tinymce/skins/wordpress/wp-content.css @@ -141,15 +141,6 @@ img::selection { background-image: url(images/gallery.png); } -.mce-content-body img.wp-media.wp-video { - background-image: url(images/video.png); -} - -.mce-content-body img.wp-media.wp-audio { - height: 70px; - background-image: url(images/audio.png); -} - .mce-content-body img.wp-media.wp-playlist { background-image: url("images/playlist-audio.png"); } @@ -223,44 +214,81 @@ embed { } /** - * Gallery preview + * Media previews */ -.wpview-type-gallery { +.wpview-type-gallery, +.wpview-type-audio, +.wpview-type-video { position: relative; margin-bottom: 16px; cursor: pointer; border: 1px solid transparent; } - .wpview-type-gallery:after { +.wpview-type-audio { + padding: 24px 0 0; +} + +.wpview-type-video { + padding: 0; +} + +.wont-play { + padding: 4px 0; +} + +.wont-play p { + font-size: 13px; + line-height: 1.3; + display: block; + width: 70%; + margin: 0 15%; + text-align: center; +} + +.wpview-type-gallery:after { content: ''; display: table; clear: both; } - .wpview-type-gallery.selected { +.wpview-type-gallery.selected, +.wpview-type-audio, +.wpview-type-video { background-color: #f2f8ff; border-color: #777; } -.wpview-type-gallery .toolbar { - position: absolute; - top: 0; - right: 0; - background-color: #333; - color: white; +.wpview-type-gallery .toolbar, +.wpview-type-audio .toolbar, +.wpview-type-video .toolbar { + position: absolute; + top: 0; + right: 0; + background-color: #333; + color: white; display: none; + z-index: 100; } +.wpview-type-video .toolbar div, .wpview-type-gallery .toolbar div, #wp-image-toolbar div { margin: 5px; } +.wpview-type-audio .toolbar div { + margin: 2px 5px; +} + +.wpview-type-audio .toolbar, +.wpview-type-video .toolbar, .wpview-type-gallery.selected .toolbar { display: block; } +.wpview-type-audio .toolbar span, +.wpview-type-video .toolbar span, .wpview-type-gallery .toolbar span { cursor: pointer; } diff --git a/wp-includes/js/tinymce/wp-tinymce.js.gz b/wp-includes/js/tinymce/wp-tinymce.js.gz index 9af78c5e79..0c65177662 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 0cad787ba3..5cde40b056 100644 --- a/wp-includes/media-template.php +++ b/wp-includes/media-template.php @@ -961,6 +961,23 @@ function wp_print_media_templates() { <# } ); #> + + + + + add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable', 'wp-mediaelement', 'image-edit' ), 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' ), false, 1 ); + $scripts->add( 'media-audiovideo', "/wp-includes/js/media-audiovideo$suffix.js", array( 'media-editor', 'mce-view' ), false, 1 ); $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'media-models' ), false, 1 ); if ( is_admin() ) {