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

1 line
11 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:_.memoize(function(k){var j,i={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g,variable:"data"};return function(l){j=j||_.template(g("#tmpl-"+k).html(),null,i);return j(l)}}),post:function(j,i){return h.ajax({data:_.isObject(j)?j:_.extend(i||{},{action:j})})},ajax:function(j,i){if(_.isObject(j)){i=j}else{i=i||{};i.data=_.extend(i.data||{},{action:j})}i=_.defaults(i||{},{type:"POST",url:h.model.settings.ajaxurl,context:this});return g.Deferred(function(k){if(i.success){k.done(i.success)}if(i.error){k.fail(i.error)}delete i.success;delete i.error;g.ajax(i).done(function(l){if(l==="1"||l===1){l={success:true}}if(_.isObject(l)&&!_.isUndefined(l.success)){k[l.success?"resolveWith":"rejectWith"](this,[l.data])}else{k.rejectWith(this,[l])}}).fail(function(){k.rejectWith(this,arguments)})}).promise()},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