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

1 line
9.8 KiB
JavaScript
Raw Normal View History

window.wp=window.wp||{};(function(g){var e,d,b,f,c,h,a;h=wp.media=function(i){var j=h.view.MediaFrame,k;if(!j){return}i=_.defaults(i||{},{frame:"select"});if("select"===i.frame&&j.Select){k=new j.Select(i)}else{if("post"===i.frame&&j.Post){k=new j.Post(i)}}delete i.frame;return k};_.extend(h,{model:{},view:{},controller:{},frames:{}});c=h.model.l10n=typeof _wpMediaModelsL10n==="undefined"?{}:_wpMediaModelsL10n;h.model.settings=c.settings||{};delete c.settings;f=function(j,i,k,l){if(_.isEqual(j,i)){return k===l?0:(k>l?-1:1)}else{return j>i?-1:1}};a=function(k,j){var l=j.success,i=j.error;j.success=function(m){if(l){l(m)}k.trigger("sync",k,m,j)};j.error=function(m){if(i){i(m)}k.trigger("error",k,m,j)};return j};_.extend(h,{template:wp.template,post:wp.ajax.post,ajax:wp.ajax.send,fit:function(m){var j=m.width,i=m.height,l=m.maxWidth,k=m.maxHeight,n;if(!_.isUndefined(l)&&!_.isUndefined(k)){n=(j/i>l/k)?"width":"height"}else{if(_.isUndefined(k)){n="width"}else{if(_.isUndefined(l)&&i>k){n="height"}}}if("width"===n&&j>l){return{width:l,height:Math.round(l*i/j)}}else{if("height"===n&&i>k){return{width:Math.round(k*j/i),height:k}}else{return{width:j,height:i}}}},truncate:function(i,k,j){k=k||30;j=j||"&hellip;";if(i.length<=k){return i}return i.substr(0,k/2)+j+i.substr(-1*k/2)}});h.attachment=function(i){return e.get(i)};e=h.model.Attachment=Backbone.Model.extend({sync:function(k,j,i){if(_.isUndefined(this.id)){return g.Deferred().rejectWith(this).promise()}if("read"===k){i=i||{};i.context=this;i.data=_.extend(i.data||{},{action:"get-attachment",id:this.id});a(j,i);return h.ajax(i)}else{if("update"===k){if(!this.get("nonces")||!this.get("nonces").update){return g.Deferred().rejectWith(this).promise()}i=i||{};i.context=this;i.data=_.extend(i.data||{},{action:"save-attachment",id:this.id,nonce:this.get("nonces").update,post_id:h.model.settings.post.id});if(j.hasChanged()){i.data.changes={};_.each(j.changed,function(m,l){i.data.changes[l]=this.get(l)},this)}a(j,i);return h.ajax(i)}else{if("delete"===k){i=i||{};if(!i.wait){this.destroyed=true}i.context=this;i.data=_.extend(i.data||{},{action:"delete-post",id:this.id,_wpnonce:this.get("nonces")["delete"]});a(j,i);return h.ajax(i).done(function(){this.destroyed=true}).fail(function(){this.destroyed=false})}else{return Backbone.Model.prototype.sync.apply(this,arguments)}}}},parse:function(j,i){if(!j){return j}j.date=new Date(j.date);j.modified=new Date(j.modified);return j},saveCompat:function(k,j){var i=this;if(!this.get("nonces")||!this.get("nonces").update){return g.Deferred().rejectWith(this).promise()}return h.post("save-attachment-compat",_.defaults({id:this.id,nonce:this.get("nonces").update,post_id:h.model.settings.post.id},k)).done(function(n,l,m){i.set(i.parse(n,m),j)})}},{create:function(i){return d.all.push(i)},get:_.memoize(function(j,i){return d.all.push(i||{id:j})})});d=h.model.Attachments=Backbone.Collection.extend({model:e,initialize:function(j,i){i=i||{};this.props=new Backbone.Model();this.filters=i.filters||{};this.props.on("change",this._changeFilteredProps,this);this.props.on("change:order",this._changeOrder,this);this.props.on("change:orderby",this._changeOrderby,this);this.props.on("change:query",this._changeQuery,this);this.props.set(_.defaults(i.props||{}));if(i.observe){this.observe(i.observe)}},_changeOrder:function(j,i){if(this.comparator){this.sort()}},_changeOrderby:function(i,j){if(this.comparator&&this.comparator!==d.comparator){return}if(j&&"post__in"!==j){this.comparator=d.comparator}else{delete this.comparator}},_changeQuery:function(i,j){if(j){this.props.on("change",this._requery,this);this._requery()}else{this.props.off("change",this._requery,this)}},_changeFilteredProps:function(j,i){if(this.props.get("query")){return}var k=_.chain(j.changed).map(function(m,o){var n=d.filters[o],l=j.get(o);if(!n){return}if(l&&!this.filters[o]){this.filters[o]=n}else{if(!l&&this.filters[o]===n){delete this.filters[o]}else{return}}return true},this).any().value();if(!k){return}if(!this._source){this._source=new d(this.models)}this.reset(this._source.filter(this.valida