2012-10-10 00:58:33 +02:00
|
|
|
window.wp=window.wp||{};(function(e){var c,b,a,d;media=wp.media=function(f){if(media.controller.Workflow){return new media.controller.Workflow(f).attach().render()}};_.extend(media,{model:{},view:{},controller:{}});d=function(g,f,h,i){if(_.isEqual(g,f)){return h===i?0:(h>i?-1:1)}else{return g>f?-1:1}};_.extend(media,{template:_.memoize(function(g){var f;return function(h){f=f||_.template(e("#tmpl-"+g).html());return f(h)}}),post:function(g,f){return media.ajax({data:_.isObject(g)?g:_.extend(f||{},{action:g})})},ajax:function(g,f){if(_.isObject(g)){f=g}else{f=f||{};f.data=_.extend(f.data||{},{action:g})}f=_.defaults(f||{},{type:"POST",url:ajaxurl,context:this});return e.Deferred(function(h){if(f.success){h.done(f.success)}if(f.error){h.fail(f.error)}delete f.success;delete f.error;e.ajax(f).done(function(i){if(_.isObject(i)&&!_.isUndefined(i.success)){h[i.success?"resolveWith":"rejectWith"](this,[i.data])}else{h.rejectWith(this,[i])}}).fail(function(){h.rejectWith(this,arguments)})}).promise()},fit:function(j){var g=j.width,f=j.height,i=j.maxWidth,h=j.maxHeight,k;if(!_.isUndefined(i)&&!_.isUndefined(h)){k=(g/f>i/h)?"width":"height"}else{if(_.isUndefined(h)){k="width"}else{if(_.isUndefined(i)&&f>h){k="height"}}}if("width"===k&&g>i){return{width:i,height:Math.round(i*f/g)}}else{if("height"===k&&f>h){return{width:Math.round(h*g/f),height:h}}else{return{width:g,height:f}}}}});c=media.model.Attachment=Backbone.Model.extend({sync:function(h,g,f){if("read"===h){f=f||{};f.context=this;f.data=_.extend(f.data||{},{action:"get-attachment",id:this.id});return media.ajax(f)}else{return Backbone.sync.apply(this,arguments)}},parse:function(g,f){g.date=new Date(g.date);g.modified=new Date(g.modified);return g}},{create:function(f){return b.all.push(f)},get:_.memoize(function(g,f){return b.all.push(f||{id:g})})});b=media.model.Attachments=Backbone.Collection.extend({model:c,initialize:function(g,f){f=f||{};this.props=new Backbone.Model();this.filters=f.filters||{};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.on("change:search",this._changeSearch,this);this.props.on("change:type",this._changeType,this);this.props.set(_.defaults(f.props||{}));if(f.observe){this.observe(f.observe)}},_changeOrder:function(g,f){if(this.comparator){this.sort()}},_changeOrderby:function(f,g){if(this.comparator&&this.comparator!==b.comparator){return}if(g&&"post__in"!==g){this.comparator=b.comparator}else{delete this.comparator}},_changeQuery:function(f,g){if(g){this.props.on("change",this._requery,this);this._requery()}else{this.props.off("change",this._requery,this)}},_changeFilteredProp:function(h,f,g){if(this.props.get(h)===g){return}if(g&&!this.filters[h]){this.filters[h]=b.filters[h]}else{if(!g&&this.filters[h]===b.filters[h]){delete this.filters[h]}}if(!this.props.get("source")){this.props.set("source",new b(this.models))}this.reset(this.props.get("source").filter(this.validator))},_changeSearch:function(f,g){return this._changeFilteredProp("search",f,g)},_changeType:function(f,g){return this._changeFilteredProp("type",f,g)},validator:function(f){return _.all(this.filters,function(h,g){return !!h.call(this,f)},this)},validate:function(g,f){return this[this.validator(g)?"add":"remove"](g,f)},observe:function(f){f.on("add change",this.validate,this)},unobserve:function(f){f.off("add change",this.validate,this)},mirror:function(f){if(this.mirroring&&this.mirroring===f){return}this.unmirror();this.mirroring=f;this.reset(f.models);f.on("add",this._mirrorAdd,this);f.on("remove",this._mirrorRemove,this);f.on("reset",this._mirrorReset,this)},unmirror:function(){if(!this.mirroring){return}this.mirroring.off("add",this._mirrorAdd,this);this.mirroring.off("remove",this._mirrorRemove,this);this.mirroring.off("reset",this._mirrorReset,this);delete this.mirroring},_mirrorAdd:function(h,f,g){this.add(h,{at:g.index})},_mirrorRemove:function(f){this.remove(f)},_mirrorReset:function(f){this.reset(f.models)},more:function(f){if(this.mirroring&&thi
|