diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index 25637d45e3..fb934b73c2 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -22,11 +22,13 @@ window.wp = window.wp || {}; * * A Backbone-like View constructor intended for use when rendering a TinyMCE View. The main difference is * that the TinyMCE View is not tied to a particular DOM node. + * + * @param {Object} [options={}] */ wp.mce.View = function( options ) { - options || (options = {}); - _.extend(this, _.pick(options, viewOptions)); - this.initialize.apply(this, arguments); + options = options || {}; + _.extend( this, _.pick( options, viewOptions ) ); + this.initialize.apply( this, arguments ); }; _.extend( wp.mce.View.prototype, { @@ -36,15 +38,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, self = this; + var self = this; if ( editor.plugins.wpview ) { - doc = editor.getDoc(); - $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each(function (i, elem) { - var node = $( elem ); + $( editor.getDoc() ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each( function ( i, element ) { + var node = $( element ); // The is used to mark the end of the wrapper div. Needed when comparing // the content as string for preventing extra undo levels. node.html( html ).append( '' ); - $( self ).trigger( 'ready', elem ); + $( self ).trigger( 'ready', element ); }); } }, this ); @@ -74,6 +75,29 @@ window.wp = window.wp || {}; * */ register: function( type, constructor ) { + var defaultConstructor = { + type: type, + View: {}, + toView: function( content ) { + var match = wp.shortcode.next( this.type, content ); + + if ( ! match ) { + return; + } + + return { + index: match.index, + content: match.content, + options: { + shortcode: match.shortcode + } + }; + } + }; + + constructor = _.defaults( constructor, defaultConstructor ); + constructor.View = wp.mce.View.extend( constructor.View ); + views[ type ] = constructor; }, @@ -81,6 +105,8 @@ window.wp = window.wp || {}; * wp.mce.views.get( id ) * * Returns a TinyMCE view constructor. + * + * @param type */ get: function( type ) { return views[ type ]; @@ -90,6 +116,8 @@ window.wp = window.wp || {}; * wp.mce.views.unregister( type ) * * Unregisters a TinyMCE view. + * + * @param type */ unregister: function( type ) { delete views[ type ]; @@ -112,6 +140,7 @@ window.wp = window.wp || {}; * matches with wrapper elements, and creates a new instance for * every match, which triggers the related data to be fetched. * + * @param content */ toViews: function( content ) { var pieces = [ { content: content } ], @@ -252,26 +281,9 @@ window.wp = window.wp || {}; } }; - wp.mce.gallery = { - shortcode: 'gallery', - 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 - } - }; - }, - View: wp.mce.View.extend({ - className: 'editor-gallery', - template: media.template('editor-gallery'), + wp.mce.views.register( 'gallery', { + View: { + template: media.template( 'editor-gallery' ), // The fallback post ID to use as a parent for galleries that don't // specify the `ids` or `include` parameters. @@ -321,7 +333,7 @@ window.wp = window.wp || {}; return this.template( options ); } - }), + }, edit: function( node ) { var gallery = wp.media.gallery, @@ -338,23 +350,90 @@ window.wp = window.wp || {}; frame.detach(); }); } - - }; - wp.mce.views.register( 'gallery', wp.mce.gallery ); + } ); /** - * Tiny MCE Views for Audio / Video - * - */ - - /** - * These are base methods that are shared by each shortcode's MCE controller + * These are base methods that are shared by the audio and video shortcode's MCE controller. * * @mixin */ - wp.mce.media = { + wp.mce.av = { loaded: false, - toView: wp.mce.gallery.toView, + + View: _.extend( {}, wp.media.mixin, { + initialize: function( options ) { + this.players = []; + this.shortcode = options.shortcode; + _.bindAll( this, 'setPlayer', 'pausePlayers' ); + $( this ).on( 'ready', this.setPlayer ); + $( 'body' ).on( 'click', '.wp-switch-editor', this.pausePlayers ); + $( document ).on( 'media:edit', this.pausePlayers ); + }, + + /** + * Creates the player instance for the current node + * + * @global MediaElementPlayer + * + * @param {Event} e + * @param {HTMLElement} node + */ + setPlayer: function(e, node) { + // if the ready event fires on an empty node + if ( ! node ) { + return; + } + + var self = this, + media, + firefox = this.ua.is( 'ff' ), + className = '.wp-' + this.shortcode.tag + '-shortcode'; + + media = $( node ).find( className ); + + 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 ( firefox ) { + media.prop( 'preload', 'metadata' ); + } else { + media.prop( 'preload', 'none' ); + } + } + + media = wp.media.view.MediaDetails.prepareSrc( media.get(0) ); + + setTimeout( function() { + wp.mce.av.loaded = true; + self.players.push( new MediaElementPlayer( media, self.mejsSettings ) ); + }, wp.mce.av.loaded ? 10 : 500 ); + }, + + /** + * Pass data to the View's Underscore template and return the compiled output + * + * @returns {string} + */ + getHtml: function() { + var attrs = this.shortcode.attrs.named; + attrs.content = this.shortcode.content; + + return this.template({ model: _.defaults( + attrs, + wp.media[ this.shortcode.tag ].defaults ) + }); + }, + + unbind: function() { + this.unsetPlayers(); + } + } ), /** * Called when a TinyMCE view is clicked for editing. @@ -396,295 +475,171 @@ window.wp = window.wp || {}; } }; - /** - * Base View class for audio and video shortcodes - * - * @constructor - * @augments wp.mce.View - * @mixes wp.media.mixin - */ - wp.mce.media.View = wp.mce.View.extend({ - initialize: function( options ) { - this.players = []; - this.shortcode = options.shortcode; - _.bindAll( this, 'setPlayer', 'pausePlayers' ); - $( this ).on( 'ready', this.setPlayer ); - $( 'body' ).on( 'click', '.wp-switch-editor', this.pausePlayers ); - $( document ).on( 'media:edit', this.pausePlayers ); - }, - - /** - * Creates the player instance for the current node - * - * @global MediaElementPlayer - * @global _wpmejsSettings - * - * @param {Event} e - * @param {HTMLElement} node - */ - setPlayer: function(e, node) { - // if the ready event fires on an empty node - if ( ! node ) { - return; - } - - var self = this, - media, - firefox = this.ua.is( 'ff' ), - className = '.wp-' + this.shortcode.tag + '-shortcode'; - - media = $( node ).find( className ); - - 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 ( firefox ) { - media.prop( 'preload', 'metadata' ); - } else { - media.prop( 'preload', 'none' ); - } - } - - media = wp.media.view.MediaDetails.prepareSrc( media.get(0) ); - - setTimeout( function() { - wp.mce.media.loaded = true; - self.players.push( new MediaElementPlayer( media, self.mejsSettings ) ); - }, wp.mce.media.loaded ? 10 : 500 ); - }, - - /** - * Pass data to the View's Underscore template and return the compiled output - * - * @returns {string} - */ - getHtml: function() { - var attrs = this.shortcode.attrs.named; - attrs.content = this.shortcode.content; - - return this.template({ model: _.defaults( - attrs, - wp.media[ this.shortcode.tag ].defaults ) - }); - }, - - unbind: function() { - this.unsetPlayers(); - } - }); - _.extend( wp.mce.media.View.prototype, wp.media.mixin ); - /** * TinyMCE handler for the video shortcode * - * @mixes wp.mce.media + * @mixes wp.mce.av */ - wp.mce.video = _.extend( {}, wp.mce.media, { + wp.mce.views.register( 'video', _.extend( {}, wp.mce.av, { shortcode: 'video', state: 'video-details', - View: wp.mce.media.View.extend({ - className: 'editor-video', - template: media.template('editor-video') - }) - } ); - wp.mce.views.register( 'video', wp.mce.video ); + View: _.extend( {}, wp.mce.av.View, { + template: media.template( 'editor-video' ) + } ) + } ) ); /** * TinyMCE handler for the audio shortcode * - * @mixes wp.mce.media + * @mixes wp.mce.av */ - wp.mce.audio = _.extend( {}, wp.mce.media, { + wp.mce.views.register( 'audio', _.extend( {}, wp.mce.av, { shortcode: 'audio', state: 'audio-details', - View: wp.mce.media.View.extend({ - className: 'editor-audio', - template: media.template('editor-audio') - }) - } ); - wp.mce.views.register( 'audio', wp.mce.audio ); - - /** - * Base View class for playlist shortcodes - * - * @constructor - * @augments wp.mce.View - * @mixes wp.media.mixin - */ - wp.mce.media.PlaylistView = wp.mce.View.extend({ - className: 'editor-playlist', - template: media.template('editor-playlist'), - - initialize: function( options ) { - this.players = []; - this.data = {}; - this.attachments = []; - this.shortcode = options.shortcode; - - $( 'body' ).on( 'click', '.wp-switch-editor', this.pausePlayers ); - $( document ).on( 'media:edit', this.pausePlayers ); - - this.fetch(); - }, - - /** - * Asynchronously fetch the shortcode's attachments - */ - fetch: function() { - this.attachments = wp.media.playlist.attachments( this.shortcode ); - this.dfd = this.attachments.more().done( _.bind( this.render, this ) ); - }, - - /** - * Get the HTML for the view (which also set's the data), replace the - * current HTML, and then invoke the WPPlaylistView instance to render - * the playlist in the editor - * - * @global WPPlaylistView - * @global tinymce.editors - */ - render: function() { - var html = this.getHtml(), self = this; - - _.each( tinymce.editors, function( editor ) { - var doc; - if ( editor.plugins.wpview ) { - doc = editor.getDoc(); - $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each(function (i, elem) { - var node = $( elem ); - - // The is used to mark the end of the wrapper div. Needed when comparing - // the content as string for preventing extra undo levels. - node.html( html ).append( '' ); - - if ( ! self.data.tracks ) { - return; - } - - self.players.push( new WPPlaylistView({ - el: $( elem ).find( '.wp-playlist' ).get(0), - metadata: self.data - }).player ); - }); - } - }, this ); - }, - - /** - * Set the data that will be used to compile the Underscore template, - * compile the template, and then return it. - * - * @returns {string} - */ - getHtml: function() { - var data = this.shortcode.attrs.named, - model = wp.media.playlist, - options, - attachments, - tracks = []; - - // Don't render errors while still fetching attachments - if ( this.dfd && 'pending' === this.dfd.state() && ! this.attachments.length ) { - return; - } - - _.each( model.defaults, function( value, key ) { - data[ key ] = model.coerce( data, key ); - }); - - options = { - type: data.type, - style: data.style, - tracklist: data.tracklist, - tracknumbers: data.tracknumbers, - images: data.images, - artists: data.artists - }; - - if ( ! this.attachments.length ) { - return this.template( options ); - } - - attachments = this.attachments.toJSON(); - - _.each( attachments, function( attachment ) { - var size = {}, resize = {}, track = { - src : attachment.url, - type : attachment.mime, - title : attachment.title, - caption : attachment.caption, - description : attachment.description, - meta : attachment.meta - }; - - if ( 'video' === data.type ) { - size.width = attachment.width; - size.height = attachment.height; - if ( media.view.settings.contentWidth ) { - resize.width = media.view.settings.contentWidth - 22; - resize.height = Math.ceil( ( size.height * resize.width ) / size.width ); - if ( ! options.width ) { - options.width = resize.width; - options.height = resize.height; - } - } else { - if ( ! options.width ) { - options.width = attachment.width; - options.height = attachment.height; - } - } - track.dimensions = { - original : size, - resized : _.isEmpty( resize ) ? size : resize - }; - } 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 ); - }, - - unbind: function() { - this.unsetPlayers(); - } - }); - _.extend( wp.mce.media.PlaylistView.prototype, wp.media.mixin ); + View: _.extend( {}, wp.mce.av.View, { + template: media.template( 'editor-audio' ) + } ) + } ) ); /** * TinyMCE handler for the playlist shortcode * - * @mixes wp.mce.media + * @mixes wp.mce.av */ - wp.mce.playlist = _.extend( {}, wp.mce.media, { + wp.mce.views.register( 'playlist', _.extend( {}, wp.mce.av, { shortcode: 'playlist', state: ['playlist-edit', 'video-playlist-edit'], - View: wp.mce.media.PlaylistView - } ); - wp.mce.views.register( 'playlist', wp.mce.playlist ); + View: _.extend( {}, wp.media.mixin, { + template: media.template( 'editor-playlist' ), + + initialize: function( options ) { + this.players = []; + this.data = {}; + this.attachments = []; + this.shortcode = options.shortcode; + + $( 'body' ).on( 'click', '.wp-switch-editor', this.pausePlayers ); + $( document ).on( 'media:edit', this.pausePlayers ); + + this.fetch(); + + $( this ).on( 'ready', this.setPlaylist ); + }, + + /** + * Asynchronously fetch the shortcode's attachments + */ + fetch: function() { + this.attachments = wp.media.playlist.attachments( this.shortcode ); + this.dfd = this.attachments.more().done( _.bind( this.render, this ) ); + }, + + setPlaylist: function( event, element ) { + if ( ! this.data.tracks ) { + return; + } + + this.players.push( new WPPlaylistView( { + el: $( element ).find( '.wp-playlist' ).get( 0 ), + metadata: this.data + } ).player ); + }, + + /** + * Set the data that will be used to compile the Underscore template, + * compile the template, and then return it. + * + * @returns {string} + */ + getHtml: function() { + var data = this.shortcode.attrs.named, + model = wp.media.playlist, + options, + attachments, + tracks = []; + + // Don't render errors while still fetching attachments + if ( this.dfd && 'pending' === this.dfd.state() && ! this.attachments.length ) { + return; + } + + _.each( model.defaults, function( value, key ) { + data[ key ] = model.coerce( data, key ); + }); + + options = { + type: data.type, + style: data.style, + tracklist: data.tracklist, + tracknumbers: data.tracknumbers, + images: data.images, + artists: data.artists + }; + + if ( ! this.attachments.length ) { + return this.template( options ); + } + + attachments = this.attachments.toJSON(); + + _.each( attachments, function( attachment ) { + var size = {}, resize = {}, track = { + src : attachment.url, + type : attachment.mime, + title : attachment.title, + caption : attachment.caption, + description : attachment.description, + meta : attachment.meta + }; + + if ( 'video' === data.type ) { + size.width = attachment.width; + size.height = attachment.height; + if ( media.view.settings.contentWidth ) { + resize.width = media.view.settings.contentWidth - 22; + resize.height = Math.ceil( ( size.height * resize.width ) / size.width ); + if ( ! options.width ) { + options.width = resize.width; + options.height = resize.height; + } + } else { + if ( ! options.width ) { + options.width = attachment.width; + options.height = attachment.height; + } + } + track.dimensions = { + original : size, + resized : _.isEmpty( resize ) ? size : resize + }; + } 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 ); + }, + + unbind: function() { + this.unsetPlayers(); + } + } ) + } ) ); /** * TinyMCE handler for the embed shortcode */ - wp.mce.embed = { + wp.mce.views.register( 'embed', { shortcode: 'embed', - toView: wp.mce.gallery.toView, - View: wp.mce.View.extend( { - className: 'editor-embed', + View: _.extend( {}, wp.media.mixin, { template: media.template( 'editor-embed' ), initialize: function( options ) { this.players = []; @@ -737,10 +692,6 @@ window.wp = window.wp || {}; } } ), edit: function() {} - }; - - _.extend( wp.mce.embed.View.prototype, wp.media.mixin ); - - wp.mce.views.register( 'embed', wp.mce.embed ); + } ); }(jQuery)); diff --git a/wp-includes/js/mce-view.min.js b/wp-includes/js/mce-view.min.js index 7772c71989..2f71da1418 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(){},getHtml: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).append(''),a(e).trigger("ready",d)}))},this)},unbind:function(){}}),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]},unbind:function(){_.each(c,function(a){a.unbind()})},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.dfd=this.attachments.more().done(_.bind(this.render,this))},getHtml:function(){var a,b=this.shortcode.attrs.named,c=!1;if(!this.dfd||"pending"!==this.dfd.state()||this.attachments.length)return this.attachments.length&&(c=this.attachments.toJSON(),_.each(c,function(a){a.sizes&&(a.sizes.thumbnail?a.thumbnail=a.sizes.thumbnail:a.sizes.full&&(a.thumbnail=a.sizes.full))})),a={attachments:c,columns:b.columns?parseInt(b.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),wp.mce.media={loaded:!1,toView:wp.mce.gallery.toView,edit:function(b){var c,d,e,f=wp.media[this.shortcode],g=this;a(document).trigger("media:edit"),d=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=f.edit(d),c.on("close",function(){c.detach()}),e=function(d){var e=wp.media[g.shortcode].shortcode(d).string();a(b).attr("data-wpview-text",window.encodeURIComponent(e)),wp.mce.views.refreshView(g,e),c.detach()},_.isArray(g.state)?_.each(g.state,function(a){c.state(a).on("update",e)}):c.state(g.state).on("update",e),c.open()}},wp.mce.media.View=wp.mce.View.extend({initialize:function(b){this.players=[],this.shortcode=b.shortcode,_.bindAll(this,"setPlayer","pausePlayers"),a(this).on("ready",this.setPlayer),a("body").on("click",".wp-switch-editor",this.pausePlayers),a(document).on("media:edit",this.pausePlayers)},setPlayer:function(b,c){if(c){var d,e=this,f=this.ua.is("ff"),g=".wp-"+this.shortcode.tag+"-shortcode";if(d=a(c).find(g),!this.isCompatible(d))return d.closest(".wpview-wrap").addClass("wont-play"),d.parent().hasClass("wpview-wrap")||d.parent().replaceWith(d),void d.replaceWith("

"+d.find("source").eq(0).prop("src")+"

");d.closest(".wpview-wrap").removeClass("wont-play"),f?d.prop("preload","metadata"):d.prop("preload","none"),d=wp.media.view.MediaDetails.prepareSrc(d.get(0)),setTimeout(function(){wp.mce.media.loaded=!0,e.players.push(new MediaElementPlayer(d,e.mejsSettings))},wp.mce.media.loaded?10:500)}},getHtml:function(){var a=this.shortcode.attrs.named;return a.content=this.shortcode.content,this.template({model:_.defaults(a,wp.media[this.shortcode.tag].defaults)})},unbind:function(){this.unsetPlayers()}}),_.extend(wp.mce.media.View.prototype,wp.media.mixin),wp.mce.video=_.extend({},wp.mce.media,{shortcode:"video",state:"video-details",View:wp.mce.media.View.extend({className:"editor-video",template:d.template("editor-video")})}),wp.mce.views.register("video",wp.mce.video),wp.mce.audio=_.extend({},wp.mce.media,{shortcode:"audio",state:"audio-details",View:wp.mce.media.View.extend({className:"editor-audio",template:d.template("editor-audio")})}),wp.mce.views.register("audio",wp.mce.audio),wp.mce.media.PlaylistView=wp.mce.View.extend({className:"editor-playlist",template:d.template("editor-playlist"),initialize:function(b){this.players=[],this.data={},this.attachments=[],this.shortcode=b.shortcode,a("body").on("click",".wp-switch-editor",this.pausePlayers),a(document).on("media:edit",this.pausePlayers),this.fetch()},fetch:function(){this.attachments=wp.media.playlist.attachments(this.shortcode),this.dfd=this.attachments.more().done(_.bind(this.render,this))},render:function(){var b=this.getHtml(),c=this;_.each(tinymce.editors,function(d){var e;d.plugins.wpview&&(e=d.getDoc(),a(e).find('[data-wpview-text="'+this.encodedText+'"]').each(function(d,e){var f=a(e);f.html(b).append(''),c.data.tracks&&c.players.push(new WPPlaylistView({el:a(e).find(".wp-playlist").get(0),metadata:c.data}).player)}))},this)},getHtml:function(){var a,b,c=this.shortcode.attrs.named,e=wp.media.playlist,f=[];if(!this.dfd||"pending"!==this.dfd.state()||this.attachments.length)return _.each(e.defaults,function(a,b){c[b]=e.coerce(c,b)}),a={type:c.type,style:c.style,tracklist:c.tracklist,tracknumbers:c.tracknumbers,images:c.images,artists:c.artists},this.attachments.length?(b=this.attachments.toJSON(),_.each(b,function(b){var e={},g={},h={src:b.url,type:b.mime,title:b.title,caption:b.caption,description:b.description,meta:b.meta};"video"===c.type?(e.width=b.width,e.height=b.height,d.view.settings.contentWidth?(g.width=d.view.settings.contentWidth-22,g.height=Math.ceil(e.height*g.width/e.width),a.width||(a.width=g.width,a.height=g.height)):a.width||(a.width=b.width,a.height=b.height),h.dimensions={original:e,resized:_.isEmpty(g)?e:g}):a.width=400,h.image=b.image,h.thumb=b.thumb,f.push(h)}),a.tracks=f,this.data=a,this.template(a)):this.template(a)},unbind:function(){this.unsetPlayers()}}),_.extend(wp.mce.media.PlaylistView.prototype,wp.media.mixin),wp.mce.playlist=_.extend({},wp.mce.media,{shortcode:"playlist",state:["playlist-edit","video-playlist-edit"],View:wp.mce.media.PlaylistView}),wp.mce.views.register("playlist",wp.mce.playlist),wp.mce.embed={shortcode:"embed",toView:wp.mce.gallery.toView,View:wp.mce.View.extend({className:"editor-embed",template:d.template("editor-embed"),initialize:function(b){this.players=[],this.content=b.content,this.parsed=!1,this.shortcode=b.shortcode,_.bindAll(this,"setHtml","setNode","fetch"),a(this).on("ready",this.setNode)},unbind:function(){var a=this;_.each(this.players,function(b){b.pause(),a.removePlayer(b)}),this.players=[]},setNode:function(a,b){this.node=b,this.parsed?this.parseMediaShortcodes():this.fetch()},fetch:function(){wp.ajax.send("parse-embed",{data:{post_ID:a("#post_ID").val(),content:this.shortcode.string()}}).done(this.setHtml)},setHtml:function(b){this.parsed=b,a(this.node).html(this.getHtml()),this.parseMediaShortcodes()},parseMediaShortcodes:function(){var b=this;a(".wp-audio-shortcode, .wp-video-shortcode",this.node).each(function(a,c){b.players.push(new MediaElementPlayer(c,b.mejsSettings))})},getHtml:function(){return this.parsed?this.template({content:this.parsed}):""}}),edit:function(){}},_.extend(wp.mce.embed.View.prototype,wp.media.mixin),wp.mce.views.register("embed",wp.mce.embed)}(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(){},getHtml:function(){},render:function(){var b=this.getHtml();_.each(tinymce.editors,function(c){var d=this;c.plugins.wpview&&a(c.getDoc()).find('[data-wpview-text="'+this.encodedText+'"]').each(function(c,e){var f=a(e);f.html(b).append(''),a(d).trigger("ready",e)})},this)},unbind:function(){}}),wp.mce.View.extend=Backbone.View.extend,wp.mce.views={register:function(a,c){var d={type:a,View:{},toView:function(a){var b=wp.shortcode.next(this.type,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}}};c=_.defaults(c,d),c.View=wp.mce.View.extend(c.View),b[a]=c},get:function(a){return b[a]},unregister:function(a){delete b[a]},unbind:function(){_.each(c,function(a){a.unbind()})},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.views.register("gallery",{View:{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.dfd=this.attachments.more().done(_.bind(this.render,this))},getHtml:function(){var a,b=this.shortcode.attrs.named,c=!1;if(!this.dfd||"pending"!==this.dfd.state()||this.attachments.length)return this.attachments.length&&(c=this.attachments.toJSON(),_.each(c,function(a){a.sizes&&(a.sizes.thumbnail?a.thumbnail=a.sizes.thumbnail:a.sizes.full&&(a.thumbnail=a.sizes.full))})),a={attachments:c,columns:b.columns?parseInt(b.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.av={loaded:!1,View:_.extend({},wp.media.mixin,{initialize:function(b){this.players=[],this.shortcode=b.shortcode,_.bindAll(this,"setPlayer","pausePlayers"),a(this).on("ready",this.setPlayer),a("body").on("click",".wp-switch-editor",this.pausePlayers),a(document).on("media:edit",this.pausePlayers)},setPlayer:function(b,c){if(c){var d,e=this,f=this.ua.is("ff"),g=".wp-"+this.shortcode.tag+"-shortcode";if(d=a(c).find(g),!this.isCompatible(d))return d.closest(".wpview-wrap").addClass("wont-play"),d.parent().hasClass("wpview-wrap")||d.parent().replaceWith(d),void d.replaceWith("

"+d.find("source").eq(0).prop("src")+"

");d.closest(".wpview-wrap").removeClass("wont-play"),f?d.prop("preload","metadata"):d.prop("preload","none"),d=wp.media.view.MediaDetails.prepareSrc(d.get(0)),setTimeout(function(){wp.mce.av.loaded=!0,e.players.push(new MediaElementPlayer(d,e.mejsSettings))},wp.mce.av.loaded?10:500)}},getHtml:function(){var a=this.shortcode.attrs.named;return a.content=this.shortcode.content,this.template({model:_.defaults(a,wp.media[this.shortcode.tag].defaults)})},unbind:function(){this.unsetPlayers()}}),edit:function(b){var c,d,e,f=wp.media[this.shortcode],g=this;a(document).trigger("media:edit"),d=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=f.edit(d),c.on("close",function(){c.detach()}),e=function(d){var e=wp.media[g.shortcode].shortcode(d).string();a(b).attr("data-wpview-text",window.encodeURIComponent(e)),wp.mce.views.refreshView(g,e),c.detach()},_.isArray(g.state)?_.each(g.state,function(a){c.state(a).on("update",e)}):c.state(g.state).on("update",e),c.open()}},wp.mce.views.register("video",_.extend({},wp.mce.av,{shortcode:"video",state:"video-details",View:_.extend({},wp.mce.av.View,{template:d.template("editor-video")})})),wp.mce.views.register("audio",_.extend({},wp.mce.av,{shortcode:"audio",state:"audio-details",View:_.extend({},wp.mce.av.View,{template:d.template("editor-audio")})})),wp.mce.views.register("playlist",_.extend({},wp.mce.av,{shortcode:"playlist",state:["playlist-edit","video-playlist-edit"],View:_.extend({},wp.media.mixin,{template:d.template("editor-playlist"),initialize:function(b){this.players=[],this.data={},this.attachments=[],this.shortcode=b.shortcode,a("body").on("click",".wp-switch-editor",this.pausePlayers),a(document).on("media:edit",this.pausePlayers),this.fetch(),a(this).on("ready",this.setPlaylist)},fetch:function(){this.attachments=wp.media.playlist.attachments(this.shortcode),this.dfd=this.attachments.more().done(_.bind(this.render,this))},setPlaylist:function(b,c){this.data.tracks&&this.players.push(new WPPlaylistView({el:a(c).find(".wp-playlist").get(0),metadata:this.data}).player)},getHtml:function(){var a,b,c=this.shortcode.attrs.named,e=wp.media.playlist,f=[];if(!this.dfd||"pending"!==this.dfd.state()||this.attachments.length)return _.each(e.defaults,function(a,b){c[b]=e.coerce(c,b)}),a={type:c.type,style:c.style,tracklist:c.tracklist,tracknumbers:c.tracknumbers,images:c.images,artists:c.artists},this.attachments.length?(b=this.attachments.toJSON(),_.each(b,function(b){var e={},g={},h={src:b.url,type:b.mime,title:b.title,caption:b.caption,description:b.description,meta:b.meta};"video"===c.type?(e.width=b.width,e.height=b.height,d.view.settings.contentWidth?(g.width=d.view.settings.contentWidth-22,g.height=Math.ceil(e.height*g.width/e.width),a.width||(a.width=g.width,a.height=g.height)):a.width||(a.width=b.width,a.height=b.height),h.dimensions={original:e,resized:_.isEmpty(g)?e:g}):a.width=400,h.image=b.image,h.thumb=b.thumb,f.push(h)}),a.tracks=f,this.data=a,this.template(a)):this.template(a)},unbind:function(){this.unsetPlayers()}})})),wp.mce.views.register("embed",{shortcode:"embed",View:_.extend({},wp.media.mixin,{template:d.template("editor-embed"),initialize:function(b){this.players=[],this.content=b.content,this.parsed=!1,this.shortcode=b.shortcode,_.bindAll(this,"setHtml","setNode","fetch"),a(this).on("ready",this.setNode)},unbind:function(){var a=this;_.each(this.players,function(b){b.pause(),a.removePlayer(b)}),this.players=[]},setNode:function(a,b){this.node=b,this.parsed?this.parseMediaShortcodes():this.fetch()},fetch:function(){wp.ajax.send("parse-embed",{data:{post_ID:a("#post_ID").val(),content:this.shortcode.string()}}).done(this.setHtml)},setHtml:function(b){this.parsed=b,a(this.node).html(this.getHtml()),this.parseMediaShortcodes()},parseMediaShortcodes:function(){var b=this;a(".wp-audio-shortcode, .wp-video-shortcode",this.node).each(function(a,c){b.players.push(new MediaElementPlayer(c,b.mejsSettings))})},getHtml:function(){return this.parsed?this.template({content:this.parsed}):""}}),edit:function(){}})}(jQuery); \ No newline at end of file