WordPress/wp-includes/js/media-models.min.js

1 line
13 KiB
JavaScript
Raw Normal View History

!function s(r,n,a){function o(e,t){if(!n[e]){if(!r[e]){var i="function"==typeof require&&require;if(!t&&i)return i(e,!0);if(h)return h(e,!0);throw(i=new Error("Cannot find module '"+e+"'")).code="MODULE_NOT_FOUND",i}i=n[e]={exports:{}},r[e][0].call(i.exports,function(t){return o(r[e][1][t]||t)},i,i.exports,s,r,n,a)}return n[e].exports}for(var h="function"==typeof require&&require,t=0;t<a.length;t++)o(a[t]);return o}({1:[function(t,e,i){var s,r,n,a,o=jQuery;window.wp=window.wp||{},a=wp.media=function(t){var e,i=a.view.MediaFrame;if(i)return"select"===(t=_.defaults(t||{},{frame:"select"})).frame&&i.Select?e=new i.Select(t):"post"===t.frame&&i.Post?e=new i.Post(t):"manage"===t.frame&&i.Manage?e=new i.Manage(t):"image"===t.frame&&i.ImageDetails?e=new i.ImageDetails(t):"audio"===t.frame&&i.AudioDetails?e=new i.AudioDetails(t):"video"===t.frame&&i.VideoDetails?e=new i.VideoDetails(t):"edit-attachments"===t.frame&&i.EditAttachments&&(e=new i.EditAttachments(t)),delete t.frame,a.frame=e},_.extend(a,{model:{},view:{},controller:{},frames:{}}),n=a.model.l10n=window._wpMediaModelsL10n||{},a.model.settings=n.settings||{},delete n.settings,s=a.model.Attachment=t("./models/attachment.js"),r=a.model.Attachments=t("./models/attachments.js"),a.model.Query=t("./models/query.js"),a.model.PostImage=t("./models/post-image.js"),a.model.Selection=t("./models/selection.js"),a.compare=function(t,e,i,s){return _.isEqual(t,e)?i===s?0:s<i?-1:1:e<t?-1:1},_.extend(a,{template:wp.template,post:wp.ajax.post,ajax:wp.ajax.send,fit:function(t){var e,i=t.width,s=t.height,r=t.maxWidth,t=t.maxHeight;return _.isUndefined(r)||_.isUndefined(t)?_.isUndefined(t)?e="width":_.isUndefined(r)&&t<s&&(e="height"):e=r/t<i/s?"width":"height","width"===e&&r<i?{width:r,height:Math.round(r*s/i)}:"height"===e&&t<s?{width:Math.round(t*i/s),height:t}:{width:i,height:s}},truncate:function(t,e,i){return e=e||30,i=i||"&hellip;",t.length<=e?t:t.substr(0,e/2)+i+t.substr(-1*e/2)}}),a.attachment=function(t){return s.get(t)},r.all=new r,a.query=function(t){return new r(null,{props:_.extend(_.defaults(t||{},{orderby:"date"}),{query:!0})})},o(window).on("unload",function(){window.wp=null})},{"./models/attachment.js":2,"./models/attachments.js":3,"./models/post-image.js":4,"./models/query.js":5,"./models/selection.js":6}],2:[function(t,e,i){var n=Backbone.$,s=Backbone.Model.extend({sync:function(t,e,i){return _.isUndefined(this.id)?n.Deferred().rejectWith(this).promise():"read"===t?((i=i||{}).context=this,i.data=_.extend(i.data||{},{action:"get-attachment",id:this.id}),wp.media.ajax(i)):"update"===t?this.get("nonces")&&this.get("nonces").update?((i=i||{}).context=this,i.data=_.extend(i.data||{},{action:"save-attachment",id:this.id,nonce:this.get("nonces").update,post_id:wp.media.model.settings.post.id}),e.hasChanged()&&(i.data.changes={},_.each(e.changed,function(t,e){i.data.changes[e]=this.get(e)},this)),wp.media.ajax(i)):n.Deferred().rejectWith(this).promise():"delete"===t?((i=i||{}).wait||(this.destroyed=!0),i.context=this,i.data=_.extend(i.data||{},{action:"delete-post",id:this.id,_wpnonce:this.get("nonces")["delete"]}),wp.media.ajax(i).done(function(){this.destroyed=!0}).fail(function(){this.destroyed=!1})):Backbone.Model.prototype.sync.apply(this,arguments)},parse:function(t){return t&&(t.date=new Date(t.date),t.modified=new Date(t.modified),t)},saveCompat:function(t,s){var r=this;return this.get("nonces")&&this.get("nonces").update?wp.media.post("save-attachment-compat",_.defaults({id:this.id,nonce:this.get("nonces").update,post_id:wp.media.model.settings.post.id},t)).done(function(t,e,i){r.set(r.parse(t,i),s)}):n.Deferred().rejectWith(this).promise()}},{create:function(t){return wp.media.model.Attachments.all.push(t)},get:_.memoize(function(t,e){return wp.media.model.Attachments.all.push(e||{id:t})})});e.exports=s},{}],3:[function(t,e,i){var n=Backbone.Collection.extend({model:wp.media.model.Attachment,initialize:function(t,e){e=e||{},this.props=new Backbone.Model,this.filters=e.filters||{},this.props.on("change",this._changeFilteredProps,this),this.props.on("change:order",this.