2012-11-15 05:58:34 +01:00
|
|
|
window.wp=window.wp||{};(function(f){var d,c,a,e,b;media=wp.media=function(g){var h=media.view.MediaFrame,i;if(!h){return}g=_.defaults(g||{},{frame:"select"});if("select"===g.frame&&h.Select){i=new h.Select(g)}else{if("post"===g.frame&&h.Post){i=new h.Post(g)}}delete g.frame;i.state(i.options.state);return i.render().attach().open()};_.extend(media,{model:{},view:{},controller:{}});b=media.model.l10n=_.isUndefined(_wpMediaModelsL10n)?{}:_wpMediaModelsL10n;e=function(h,g,i,j){if(_.isEqual(h,g)){return i===j?0:(i>j?-1:1)}else{return h>g?-1:1}};_.extend(media,{template:_.memoize(function(i){var h,g={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g,variable:"data"};return function(j){h=h||_.template(f("#tmpl-"+i).html(),null,g);return h(j)}}),post:function(h,g){return media.ajax({data:_.isObject(h)?h:_.extend(g||{},{action:h})})},ajax:function(h,g){if(_.isObject(h)){g=h}else{g=g||{};g.data=_.extend(g.data||{},{action:h})}g=_.defaults(g||{},{type:"POST",url:ajaxurl,context:this});return f.Deferred(function(i){if(g.success){i.done(g.success)}if(g.error){i.fail(g.error)}delete g.success;delete g.error;f.ajax(g).done(function(j){if(_.isObject(j)&&!_.isUndefined(j.success)){i[j.success?"resolveWith":"rejectWith"](this,[j.data])}else{i.rejectWith(this,[j])}}).fail(function(){i.rejectWith(this,arguments)})}).promise()},fit:function(k){var h=k.width,g=k.height,j=k.maxWidth,i=k.maxHeight,l;if(!_.isUndefined(j)&&!_.isUndefined(i)){l=(h/g>j/i)?"width":"height"}else{if(_.isUndefined(i)){l="width"}else{if(_.isUndefined(j)&&g>i){l="height"}}}if("width"===l&&h>j){return{width:j,height:Math.round(j*g/h)}}else{if("height"===l&&g>i){return{width:Math.round(i*h/g),height:i}}else{return{width:h,height:g}}}}});d=media.model.Attachment=Backbone.Model.extend({sync:function(i,h,g){if("read"===i){g=g||{};g.context=this;g.data=_.extend(g.data||{},{action:"get-attachment",id:this.id});return media.ajax(g)}else{if("update"===i){g=g||{};g.context=this;g.data=_.extend(g.data||{},{action:"save-attachment",id:this.id,nonce:b.saveAttachmentNonce});if(g.changes){_.each(g.changes,function(k,j){g.changes[j]=this.get(j)},this);g.data.changes=g.changes;delete g.changes}return media.ajax(g)}}},parse:function(h,g){if(!h){return h}h.date=new Date(h.date);h.modified=new Date(h.modified);return h},saveCompat:function(i,h){var g=this;return media.post("save-attachment-compat",_.defaults({id:this.id,nonce:b.saveAttachmentNonce},i)).done(function(l,j,k){g.set(g.parse(l,k),h)})}},{create:function(g){return c.all.push(g)},get:_.memoize(function(h,g){return c.all.push(g||{id:h})})});c=media.model.Attachments=Backbone.Collection.extend({model:d,initialize:function(h,g){g=g||{};this.props=new Backbone.Model();this.filters=g.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(g.props||{}));if(g.observe){this.observe(g.observe)}},_changeOrder:function(h,g){if(this.comparator){this.sort()}},_changeOrderby:function(g,h){if(this.comparator&&this.comparator!==c.comparator){return}if(h&&"post__in"!==h){this.comparator=c.comparator}else{delete this.comparator}},_changeQuery:function(g,h){if(h){this.props.on("change",this._requery,this);this._requery()}else{this.props.off("change",this._requery,this)}},_changeFilteredProp:function(i,g,h){if(this.props.get(i)===h){return}if(h&&!this.filters[i]){this.filters[i]=c.filters[i]}else{if(!h&&this.filters[i]===c.filters[i]){delete this.filters[i]}}if(!this.props.get("source")){this.props.set("source",new c(this.models))}this.reset(this.props.get("source").filter(this.validator))},_changeSearch:function(g,h){return this._changeFilteredProp("search",g,h)},_changeType:function(g,h){return this._changeFilteredProp("type",g,h)},validator:function(g){return _.all(this.filters,function(i,h){return !!i.call(this,g)},this)},validate:function(h,g){g={s
|