diff --git a/wp-includes/js/media-editor.js b/wp-includes/js/media-editor.js index b70a1265c2..91eb2f57b4 100644 --- a/wp-includes/js/media-editor.js +++ b/wp-includes/js/media-editor.js @@ -2,13 +2,13 @@ // WordPress, TinyMCE, and Media // ----------------------------- -(function($){ +(function($, _){ /** * Stores the editors' `wp.media.controller.Frame` instances. * * @static */ - var workflows = {}, cache = {}; + var workflows = {}; /** * wp.media.string @@ -274,39 +274,35 @@ } }; - /** - * wp.media.collection - * @namespace - */ - wp.media.collection = { - attachments : function ( prop, type ) { - /** - * Retrieve attachments based on the properties of the passed shortcode - * - * @global wp.media.query - * - * @param {wp.shortcode} shortcode An instance of wp.shortcode(). - * @returns {wp.media.model.Attachments} A Backbone.Collection containing - * the media items belonging to a collection. - * The 'prop' specified by the passed prop is a Backbone.Model - * containing the 'props' for the gallery. - */ - return function( shortcode ) { + wp.media.collection = function(attributes) { + var collections = {}; + + return _.extend( attributes, { + coerce: function ( attrs, key ) { + if ( 'undefined' === typeof attrs[ key ] && 'undefined' !== typeof this.defaults[ key ] ) { + attrs[ key ] = this.defaults[ key ]; + } else if ( 'true' === attrs[ key ] ) { + attrs[ key ] = true; + } else if ( 'false' === attrs[ key ] ) { + attrs[ key ] = false; + } + return attrs[ key ]; + }, + + attachments: function( shortcode ) { var shortcodeString = shortcode.string(), - result = cache[ shortcodeString ], - attrs, args, query, others; - - delete cache[ shortcodeString ]; + result = collections[ shortcodeString ], + attrs, args, query, others, self = this; + delete collections[ shortcodeString ]; if ( result ) { return result; } - // Fill the default shortcode attributes. attrs = _.defaults( shortcode.attrs.named, this.defaults ); args = _.pick( attrs, 'orderby', 'order' ); - args.type = type; + args.type = this.type; args.perPage = -1; // Mark the `orderby` override attribute. @@ -318,16 +314,6 @@ attrs._orderbyRandom = true; } - if ( -1 !== jQuery.inArray( prop, ['playlist', 'video-playlist'] ) ) { - _.each(['tracknumbers', 'tracklist', 'images', 'artists'], function (setting) { - if ( 'undefined' === typeof attrs[setting] ) { - attrs['_' + setting] = wp.media[ prop ].defaults[ setting ]; - } else if ( 'true' === attrs[setting] || true === attrs[setting] ) { - attrs['_' + setting] = true; - } - }); - } - // Map the `orderby` attribute to the corresponding model property. if ( ! attrs.orderby || /^menu_order(?: ID)?$/i.test( attrs.orderby ) ) { args.orderby = 'menuOrder'; @@ -352,250 +338,173 @@ // Collect the attributes that were not included in `args`. others = _.omit( attrs, 'id', 'ids', 'include', 'exclude', 'orderby', 'order' ); - query = wp.media.query( args ); - query[ prop ] = new Backbone.Model( others ); - return query; - }; - }, - - shortcodeAttrs : function ( prop, attachments ) { - var props = attachments.props.toJSON(), - attrs = _.pick( props, 'orderby', 'order', 'style' ); - - if ( attachments[ prop ] ) { - _.extend( attrs, attachments[ prop ].toJSON() ); - } - - // Convert all collection shortcodes to use the `ids` property. - // Ignore `post__in` and `post__not_in`; the attachments in - // the collection will already reflect those properties. - attrs.ids = attachments.pluck('id'); - - // Copy the `uploadedTo` post ID. - if ( props.uploadedTo ) { - attrs.id = props.uploadedTo; - } - - // Check if the collection is randomly ordered. - delete attrs.orderby; - - if ( attrs._orderbyRandom ) { - attrs.orderby = 'rand'; - } else if ( attrs._orderByField && attrs._orderByField != 'rand' ) { - attrs.orderby = attrs._orderByField; - } - - delete attrs._orderbyRandom; - delete attrs._orderByField; - - // If the `ids` attribute is set and `orderby` attribute - // is the default value, clear it for cleaner output. - if ( attrs.ids && 'post__in' === attrs.orderby ) { - delete attrs.orderby; - } - - if ( -1 !== jQuery.inArray( prop, ['playlist', 'video-playlist'] ) ) { - _.each(['tracknumbers', 'tracklist', 'images', 'artists'], function (setting) { - if ( 'undefined' === typeof attrs[ '_' + setting ] ) { - attrs[ '_' + setting ] = wp.media[ prop ].defaults[ setting ]; - } - - if ( attrs['_' + setting] ) { - attrs[setting] = true; - } else { - attrs[setting] = false; - } - delete attrs['_' + setting]; + // Remove default attributes from the shortcode. + _.each( this.defaults, function( value, key ) { + others[ key ] = self.coerce( others, key ); }); - } - // Remove default attributes from the shortcode. - _.each( wp.media[prop].defaults, function( value, key ) { - if ( value === attrs[ key ] ) { - delete attrs[ key ]; + query = wp.media.query( args ); + query[ this.tag ] = new Backbone.Model( others ); + return query; + }, + + shortcode: function( attachments ) { + var props = attachments.props.toJSON(), + attrs = _.pick( props, 'orderby', 'order' ), + shortcode, clone, self = this; + + if ( attachments[this.tag] ) { + _.extend( attrs, attachments[this.tag].toJSON() ); } - }); - return attrs; - }, + // 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. + attrs.ids = attachments.pluck('id'); - editSelection : function ( prop, shortcode ) { - var defaultPostId = wp.media[ prop ].defaults.id, - attachments, selection; + // Copy the `uploadedTo` post ID. + if ( props.uploadedTo ) { + attrs.id = props.uploadedTo; + } + // Check if the gallery is randomly ordered. + delete attrs.orderby; - // Ignore the rest of the match object. - shortcode = shortcode.shortcode; + if ( attrs._orderbyRandom ) { + attrs.orderby = 'rand'; + } else if ( attrs._orderByField && attrs._orderByField != 'rand' ) { + attrs.orderby = attrs._orderByField; + } - if ( _.isUndefined( shortcode.get('id') ) && ! _.isUndefined( defaultPostId ) ) { - shortcode.set( 'id', defaultPostId ); - } + delete attrs._orderbyRandom; + delete attrs._orderByField; - attachments = wp.media[ prop ].attachments( shortcode ); + // If the `ids` attribute is set and `orderby` attribute + // is the default value, clear it for cleaner output. + if ( attrs.ids && 'post__in' === attrs.orderby ) { + delete attrs.orderby; + } - selection = new wp.media.model.Selection( attachments.models, { - props: attachments.props.toJSON(), - multiple: true - }); - - selection[ prop ] = attachments[ prop ]; - - // Fetch the query's attachments, and then break ties from the - // query to allow for sorting. - selection.more().done( function() { - // Break ties with the query. - selection.props.set({ query: false }); - selection.unmirror(); - selection.props.unset('orderby'); - }); - - return selection; - }, - - /** - * - * @param {string} prop The shortcode slug - * @param {wp.media.model.Attachments} attachments - * @param {wp.shortcode} shortcode - * @returns {wp.shortcode} - */ - cacheShortcode : function ( prop, attachments, shortcode ) { - // Use a cloned version of the playlist. - var clone = new wp.media.model.Attachments( attachments.models, { - props: attachments.props.toJSON() - }); - clone[ prop ] = attachments[ prop ]; - cache[ shortcode.string() ] = clone; - - return shortcode; - }, - - getEditFrame : function ( args ) { - // Destroy the previous gallery frame. - if ( this.frame ) { - this.frame.dispose(); - } - - // Store the current gallery frame. - this.frame = wp.media( _.extend( { - frame: 'post', - editing: true, - multiple: true - }, args ) ).open(); - - return this.frame; - }, - - instance : function ( prop, args ) { - return { - attachments: this.attachments( prop, args.type ), - /** - * Triggered when clicking 'Insert {label}' or 'Update {label}' - * - * @global wp.shortcode - * @global wp.media.model.Attachments - * - * @param {wp.media.model.Attachments} attachments A Backbone.Collection containing - * the media items belonging to a collection. - * The 'prop' specified by the passed prop is a Backbone.Model - * containing the 'props' for the gallery. - * @returns {wp.shortcode} - */ - shortcode: function( attachments ) { - var shortcode = new wp.shortcode({ - tag: prop, - attrs: wp.media.collection.shortcodeAttrs( prop, attachments ), - type: 'single' - }); - - return wp.media.collection.cacheShortcode( prop, attachments, shortcode ); - }, - /** - * Triggered when double-clicking a collection shortcode placeholder - * in the editor - * - * @global wp.shortcode - * @global wp.media.model.Selection - * @global wp.media.view.l10n - * - * @param {string} content Content that is searched for possible - * shortcode markup matching the passed tag name, - * - * @this wp.media.{prop} - * - * @returns {wp.media.view.MediaFrame.Select} A media workflow. - */ - edit: function( content ) { - var shortcode = wp.shortcode.next( prop, content ); - - // Bail if we didn't match the shortcode or all of the content. - if ( ! shortcode || shortcode.content !== content ) { - return; + // Remove default attributes from the shortcode. + _.each( this.defaults, function( value, key ) { + attrs[ key ] = self.coerce( attrs, key ); + if ( value === attrs[ key ] ) { + delete attrs[ key ]; } + }); - return wp.media.collection.getEditFrame( { - title: args.title, - state: prop + '-edit', - selection: wp.media.collection.editSelection( prop, shortcode ) - } ); + shortcode = new wp.shortcode({ + tag: this.tag, + attrs: attrs, + type: 'single' + }); + + // Use a cloned version of the gallery. + clone = new wp.media.model.Attachments( attachments.models, { + props: props + }); + clone[ this.tag ] = attachments[ this.tag ]; + collections[ shortcode.string() ] = clone; + + return shortcode; + }, + + edit: function( content ) { + var shortcode = wp.shortcode.next( this.tag, content ), + defaultPostId = this.defaults.id, + attachments, selection; + + // Bail if we didn't match the shortcode or all of the content. + if ( ! shortcode || shortcode.content !== content ) { + return; } - }; - } + + // Ignore the rest of the match object. + shortcode = shortcode.shortcode; + + if ( _.isUndefined( shortcode.get('id') ) && ! _.isUndefined( defaultPostId ) ) { + shortcode.set( 'id', defaultPostId ); + } + + attachments = this.attachments( shortcode ); + + selection = new wp.media.model.Selection( attachments.models, { + props: attachments.props.toJSON(), + multiple: true + }); + + selection[ this.tag ] = attachments[ this.tag ]; + + // Fetch the query's attachments, and then break ties from the + // query to allow for sorting. + selection.more().done( function() { + // Break ties with the query. + selection.props.set({ query: false }); + selection.unmirror(); + selection.props.unset('orderby'); + }); + + // Destroy the previous gallery frame. + if ( this.frame ) { + this.frame.dispose(); + } + + // Store the current gallery frame. + this.frame = wp.media({ + frame: 'post', + state: this.tag + '-edit', + title: this.editTitle, + editing: true, + multiple: true, + selection: selection + }).open(); + + return this.frame; + } + }); }; - wp.media.gallery = (function() { - var gallery = { - 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.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' + } + }); - return _.extend(gallery, wp.media.collection.instance( 'gallery', { - type : 'image', - title : wp.media.view.l10n.editGalleryTitle - })); - }()); + wp.media.playlist = new wp.media.collection({ + tag: 'playlist', + type : 'audio', + editTitle : wp.media.view.l10n.editPlaylistTitle, + defaults : { + id: wp.media.view.settings.post.id, + style: 'light', + tracklist: true, + tracknumbers: true, + images: true, + artists: true + } + }); - wp.media.playlist = (function() { - var playlist = { - defaults : { - id: wp.media.view.settings.post.id, - style: 'light', - tracklist: true, - tracknumbers: true, - images: true, - artists: true - } - }; - - return _.extend(playlist, wp.media.collection.instance( 'playlist', { - type : 'audio', - title : wp.media.view.l10n.editPlaylistTitle - })); - }()); - - wp.media['video-playlist'] = (function() { - var playlist = { - defaults : { - id: wp.media.view.settings.post.id, - style: 'light', - tracklist: false, - tracknumbers: false, - images: true - } - }; - - return _.extend(playlist, wp.media.collection.instance( 'video-playlist', { - type : 'video', - title : wp.media.view.l10n.editVideoPlaylistTitle - })); - }()); + wp.media['video-playlist'] = new wp.media.collection( { + tag: 'video-playlist', + type : 'video', + editTitle : wp.media.view.l10n.editVideoPlaylistTitle, + defaults : { + id: wp.media.view.settings.post.id, + style: 'light', + tracklist: false, + tracknumbers: false, + images: true + } + } ); /** * wp.media.featuredImage @@ -1083,4 +992,4 @@ _.bindAll( wp.media.editor, 'open' ); $( wp.media.editor.init ); -}(jQuery)); +}(jQuery, _)); diff --git a/wp-includes/js/media-editor.min.js b/wp-includes/js/media-editor.min.js index a627752c7b..b0352a4433 100644 --- a/wp-includes/js/media-editor.min.js +++ b/wp-includes/js/media-editor.min.js @@ -1 +1 @@ -!function(a){var b={},c={};wp.media.string={props:function(a,b){var c,d,e,f,g,h=wp.media.view.settings.defaultProps;return g=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?_.clone(a):{},b&&b.type&&(a.type=b.type),"image"===a.type&&(a=_.defaults(a||{},{align:h.align||getUserSetting("align","none"),size:h.size||getUserSetting("imgsize","medium"),url:"",classes:[]})),b?(a.title=a.title||b.title,c=a.link||h.link||getUserSetting("urlbutton","file"),"file"===c||"embed"===c?d=b.url:"post"===c?d=b.link:"custom"===c&&(d=a.linkUrl),a.linkUrl=d||"","image"===b.type?(a.classes.push("wp-image-"+b.id),f=b.sizes,e=f&&f[a.size]?f[a.size]:b,_.extend(a,_.pick(b,"align","caption","alt"),{width:e.width,height:e.height,src:e.url,captionId:"attachment_"+b.id})):"video"===b.type||"audio"===b.type?_.extend(a,_.pick(b,"title","type","icon","mime")):(a.title=a.title||b.filename,a.rel=a.rel||"attachment wp-att-"+b.id),g(a)):g(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,b,c){var d,e,f;return b=wp.media.string.props(b,c),"embed"!==b.link?wp.media.string.link(b):(d={},"video"===a&&(c.width&&(d.width=c.width),c.height&&(d.height=c.height)),f=c.filename.split(".").pop(),_.contains(wp.media.view.settings.embedExts,f)?(d[f]=c.url,e=wp.shortcode.string({tag:a,attrs:d})):wp.media.string.link(b))},image:function(a,b){var c,d,e,f,g={};return a=wp.media.string.props(a,b),d=a.classes||[],g.src="undefined"!=typeof b?b.url:a.url,_.extend(g,_.pick(a,"width","height","alt")),a.align&&!a.caption&&d.push("align"+a.align),a.size&&d.push("size-"+a.size),g["class"]=_.compact(d).join(" "),c={tag:"img",attrs:g,single:!0},a.linkUrl&&(c={tag:"a",attrs:{href:a.linkUrl},content:c}),f=wp.html.string(c),a.caption&&(e={},g.width&&(e.width=g.width),a.captionId&&(e.id=a.captionId),a.align&&(e.align="align"+a.align),f=wp.shortcode.string({tag:"caption",attrs:e,content:f+" "+a.caption})),f}},wp.media.collection={attachments:function(a,b){return function(d){var e,f,g,h,i=d.string(),j=c[i];return delete c[i],j?j:(e=_.defaults(d.attrs.named,this.defaults),f=_.pick(e,"orderby","order"),f.type=b,f.perPage=-1,void 0!==e.orderby&&(e._orderByField=e.orderby),"rand"===e.orderby&&(e._orderbyRandom=!0),-1!==jQuery.inArray(a,["playlist","video-playlist"])&&_.each(["tracknumbers","tracklist","images","artists"],function(b){"undefined"==typeof e[b]?e["_"+b]=wp.media[a].defaults[b]:("true"===e[b]||!0===e[b])&&(e["_"+b]=!0)}),(!e.orderby||/^menu_order(?: ID)?$/i.test(e.orderby))&&(f.orderby="menuOrder"),e.ids?(f.post__in=e.ids.split(","),f.orderby="post__in"):e.include&&(f.post__in=e.include.split(",")),e.exclude&&(f.post__not_in=e.exclude.split(",")),f.post__in||(f.uploadedTo=e.id),h=_.omit(e,"id","ids","include","exclude","orderby","order"),g=wp.media.query(f),g[a]=new Backbone.Model(h),g)}},shortcodeAttrs:function(a,b){var c=b.props.toJSON(),d=_.pick(c,"orderby","order","style");return b[a]&&_.extend(d,b[a].toJSON()),d.ids=b.pluck("id"),c.uploadedTo&&(d.id=c.uploadedTo),delete d.orderby,d._orderbyRandom?d.orderby="rand":d._orderByField&&"rand"!=d._orderByField&&(d.orderby=d._orderByField),delete d._orderbyRandom,delete d._orderByField,d.ids&&"post__in"===d.orderby&&delete d.orderby,-1!==jQuery.inArray(a,["playlist","video-playlist"])&&_.each(["tracknumbers","tracklist","images","artists"],function(b){"undefined"==typeof d["_"+b]&&(d["_"+b]=wp.media[a].defaults[b]),d[b]=d["_"+b]?!0:!1,delete d["_"+b]}),_.each(wp.media[a].defaults,function(a,b){a===d[b]&&delete d[b]}),d},editSelection:function(a,b){var c,d,e=wp.media[a].defaults.id;return b=b.shortcode,_.isUndefined(b.get("id"))&&!_.isUndefined(e)&&b.set("id",e),c=wp.media[a].attachments(b),d=new wp.media.model.Selection(c.models,{props:c.props.toJSON(),multiple:!0}),d[a]=c[a],d.more().done(function(){d.props.set({query:!1}),d.unmirror(),d.props.unset("orderby")}),d},cacheShortcode:function(a,b,d){var e=new wp.media.model.Attachments(b.models,{props:b.props.toJSON()});return e[a]=b[a],c[d.string()]=e,d},getEditFrame:function(a){return this.frame&&this.frame.dispose(),this.frame=wp.media(_.extend({frame:"post",editing:!0,multiple:!0},a)).open(),this.frame},instance:function(a,b){return{attachments:this.attachments(a,b.type),shortcode:function(b){var c=new wp.shortcode({tag:a,attrs:wp.media.collection.shortcodeAttrs(a,b),type:"single"});return wp.media.collection.cacheShortcode(a,b,c)},edit:function(c){var d=wp.shortcode.next(a,c);if(d&&d.content===c)return wp.media.collection.getEditFrame({title:b.title,state:a+"-edit",selection:wp.media.collection.editSelection(a,d)})}}}},wp.media.gallery=function(){var a={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"}};return _.extend(a,wp.media.collection.instance("gallery",{type:"image",title:wp.media.view.l10n.editGalleryTitle}))}(),wp.media.playlist=function(){var a={defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!0,tracknumbers:!0,images:!0,artists:!0}};return _.extend(a,wp.media.collection.instance("playlist",{type:"audio",title:wp.media.view.l10n.editPlaylistTitle}))}(),wp.media["video-playlist"]=function(){var a={defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!1,tracknumbers:!1,images:!0}};return _.extend(a,wp.media.collection.instance("video-playlist",{type:"video",title:wp.media.view.l10n.editVideoPlaylistTitle}))}(),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]}),this._frame.on("toolbar:create:featured-image",function(a){this.createSelectToolbar(a,{text:wp.media.view.l10n.setFeaturedImage})},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 b,c="undefined"!=typeof tinymce,d="undefined"!=typeof QTags,e=window.wpActiveEditor;if(window.send_to_editor)return window.send_to_editor.apply(this,arguments);if(e)c&&(b=tinymce.get(e));else if(c&&tinymce.activeEditor)b=tinymce.activeEditor,e=window.wpActiveEditor=b.id;else if(!d)return!1;if(b&&!b.isHidden()?b.execCommand("mceInsertContent",!1,a):d?QTags.insertContent(a):document.getElementById(e).value+=a,window.tb_remove)try{window.tb_remove()}catch(f){}},add:function(c,d){var e=this.get(c);return e?e:(e=b[c]=wp.media(_.defaults(d||{},{frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:!0})),e.on("insert",function(b){var c=e.state();b=b||c.get("selection"),b&&a.when.apply(a,b.map(function(a){var b=c.display(a).toJSON();return this.send.attachment(b,a.toJSON())},this)).done(function(){wp.media.editor.insert(_.toArray(arguments).join("\n\n"))})},this),e.state("gallery-edit").on("update",function(a){this.insert(wp.media.gallery.shortcode(a).string())},this),e.state("playlist-edit").on("update",function(a){this.insert(wp.media.playlist.shortcode(a).string())},this),e.state("video-playlist-edit").on("update",function(a){this.insert(wp.media["video-playlist"].shortcode(a).string())},this),e.state("embed").on("select",function(){var a=e.state(),b=a.get("type"),c=a.props.toJSON();c.url=c.url||"","link"===b?(_.defaults(c,{title:c.url,linkUrl:c.url}),this.send.link(c).done(function(a){wp.media.editor.insert(a)})):"image"===b&&(_.defaults(c,{title:c.url,linkUrl:"",align:"none",link:"none"}),"none"===c.link?c.linkUrl="":"file"===c.link&&(c.linkUrl=c.url),this.insert(wp.media.string.image(c)))},this),e.state("featured-image").on("select",wp.media.featuredImage.select),e.setState(e.options.state),e)},id:function(a){return a?a:(a=wpActiveEditor,!a&&"undefined"!=typeof tinymce&&tinymce.activeEditor&&(a=tinymce.activeEditor.id),a=a||"")},get:function(a){return a=this.id(a),b[a]},remove:function(a){a=this.id(a),delete b[a]},send:{attachment:function(a,b){var c,d,e=b.caption;return wp.media.view.settings.captions||delete b.caption,a=wp.media.string.props(a,b),c={id:b.id,post_content:b.description,post_excerpt:e},a.linkUrl&&(c.url=a.linkUrl),"image"===b.type?(d=wp.media.string.image(a),_.each({align:"align",size:"image-size",alt:"image_alt"},function(b,d){a[d]&&(c[b]=a[d])})):"video"===b.type?d=wp.media.string.video(a,b):"audio"===b.type?d=wp.media.string.audio(a,b):(d=wp.media.string.link(a),c.post_title=a.title),wp.media.post("send-attachment-to-editor",{nonce:wp.media.view.settings.nonce.sendToEditor,attachment:c,html:d,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):c.hasClass("playlist")?(e.state="playlist",e.title=wp.media.view.l10n.createPlaylistTitle):c.hasClass("video-playlist")&&(e.state="video-playlist",e.title=wp.media.view.l10n.createVideoPlaylistTitle),wp.media.editor.open(d,e)})}},_.bindAll(wp.media.editor,"open"),a(wp.media.editor.init)}(jQuery); \ No newline at end of file +!function(a,b){var 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="undefined"!=typeof c?c.url:a.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:function(a,b){return"undefined"==typeof a[b]&&"undefined"!=typeof this.defaults[b]?a[b]=this.defaults[b]:"true"===a[b]?a[b]=!0:"false"===a[b]&&(a[b]=!1),a[b]},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.playlist=new wp.media.collection({tag:"playlist",type:"audio",editTitle:wp.media.view.l10n.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:wp.media.view.l10n.editVideoPlaylistTitle,defaults:{id:wp.media.view.settings.post.id,style:"light",tracklist:!1,tracknumbers:!1,images:!0}}),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]}),this._frame.on("toolbar:create:featured-image",function(a){this.createSelectToolbar(a,{text:wp.media.view.l10n.setFeaturedImage})},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 b,c="undefined"!=typeof tinymce,d="undefined"!=typeof QTags,e=window.wpActiveEditor;if(window.send_to_editor)return window.send_to_editor.apply(this,arguments);if(e)c&&(b=tinymce.get(e));else if(c&&tinymce.activeEditor)b=tinymce.activeEditor,e=window.wpActiveEditor=b.id;else if(!d)return!1;if(b&&!b.isHidden()?b.execCommand("mceInsertContent",!1,a):d?QTags.insertContent(a):document.getElementById(e).value+=a,window.tb_remove)try{window.tb_remove()}catch(f){}},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&&"undefined"!=typeof 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):c.hasClass("playlist")?(e.state="playlist",e.title=wp.media.view.l10n.createPlaylistTitle):c.hasClass("video-playlist")&&(e.state="video-playlist",e.title=wp.media.view.l10n.createVideoPlaylistTitle),wp.media.editor.open(d,e)})}},b.bindAll(wp.media.editor,"open"),a(wp.media.editor.init)}(jQuery,_); \ No newline at end of file diff --git a/wp-includes/media-template.php b/wp-includes/media-template.php index daf8c29911..6f9e09127f 100644 --- a/wp-includes/media-template.php +++ b/wp-includes/media-template.php @@ -432,32 +432,32 @@ function wp_print_media_templates() { <# - var playlist = 'playlist-edit' === data.controller.id, emptyModel = 'undefined' === typeof data.model.style; + var playlist = 'playlist-edit' === data.controller.id, emptyModel = _.isEmpty(data.model); #>