2012-09-17 02:59:40 +02:00
|
|
|
if(typeof wp==="undefined"){var wp={}}(function(d){var c,b,a;media=wp.media=function(e){if(media.controller.Workflow){return new media.controller.Workflow(e).attach().render()}};_.extend(media,{model:{},view:{},controller:{}});_.extend(media,{template:_.memoize(function(f){var e;return function(g){e=e||_.template(d("#tmpl-"+f).html());return e(g)}}),post:function(f,e){return media.ajax({data:_.isObject(f)?f:_.extend(e||{},{action:f})})},ajax:function(f,e){if(_.isObject(f)){e=f}else{e=e||{};e.data=_.extend(e.data||{},{action:f})}e=_.defaults(e||{},{type:"POST",url:ajaxurl,context:this});return d.Deferred(function(g){if(e.success){g.done(e.success)}if(e.error){g.fail(e.error)}delete e.success;delete e.error;d.ajax(e).done(function(h){if(_.isObject(h)&&!_.isUndefined(h.success)){g[h.success?"resolveWith":"rejectWith"](this,[h.data])}else{g.rejectWith(this,[h])}}).fail(function(){g.rejectWith(this,arguments)})}).promise()}});c=media.model.Attachment=Backbone.Model.extend({sync:function(g,f,e){if("read"===g){e=e||{};e.context=this;e.data=_.extend(e.data||{},{action:"get-attachment",id:this.id});return media.ajax(e)}else{return Backbone.sync.apply(this,arguments)}},parse:function(f,e){f.date=new Date(f.date);f.modified=new Date(f.modified);return f}},{create:function(e){return b.all.push(e)},get:_.memoize(function(f,e){return b.all.push(e||{id:f})})});b=media.model.Attachments=Backbone.Collection.extend({model:c,initialize:function(f,e){e=e||{};this.filters=e.filters||{};if(e.observe){this.observe(e.observe)}if(e.mirror){this.mirror(e.mirror)}},validator:function(e){return _.all(this.filters,function(f){return !!f.call(this,e)},this)},validate:function(f,e){return this[this.validator(f)?"add":"remove"](f,e)},observe:function(e){e.on("add change",this.validate,this)},unobserve:function(e){e.off("add change",this.validate,this)},mirror:function(e){if(this.mirroring&&this.mirroring===e){return}this.unmirror();this.mirroring=e;this.reset(e.models);e.on("add",this._mirrorAdd,this);e.on("remove",this._mirrorRemove,this);e.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(g,e,f){this.add(g,{at:f.index})},_mirrorRemove:function(e){this.remove(e)},_mirrorReset:function(e){this.reset(e.models)},more:function(e){if(this.mirroring&&this.mirroring.more){return this.mirroring.more(e)}},parse:function(f,e){return _.map(f,function(g){var h=c.get(g.id);return h.set(h.parse(g,e))})}});b.all=new b();media.query=(function(){var e=[];return function(g,f){g=_.defaults(g||{},a.defaultArgs);var h=_.find(e,function(i){return _.isEqual(i.args,g)});if(!h){h=new a([],_.extend(f||{},{args:g}));e.push(h)}return h}}());a=media.model.Query=b.extend({initialize:function(h,e){var f,g=a.defaultArgs;e=e||{};b.prototype.initialize.apply(this,arguments);this.args=_.defaults(e.args||{},g);this.args.order=this.args.order.toUpperCase();if("DESC"!==this.args.order&&"ASC"!==this.args.order){this.args.order=g.order.toUpperCase()}f={allowed:["name","author","date","title","modified","parent","ID"],keymap:{ID:"id",parent:"uploadedTo"}};if(!_.contains(f.allowed,this.args.orderby)){this.args.orderby=g.orderby}this.orderkey=f.keymap[this.args.orderby]||this.args.orderby;this.hasMore=true;this.created=new Date();this.filters.order=function(i){if(this.length){return 1!==this.comparator(i,this.last())}else{if("DESC"===this.args.order&&("date"===this.orderkey||"modified"===this.orderkey)){return i.get(this.orderkey)>=this.created}}return false};if(this.args.s){this.filters.search=function(i){return _.any(["title","filename","description","caption","name"],function(j){var k=i.get(j);return k&&-1!==k.search(this.args.s)},this)}}this.observe(b.all)},more:function(e){var f=this;if(!this.hasMore){return}e=e||{};e.add=true;return this.fetch(e).done(function(g){if(_.isEmpty(g)||g.length<this.args.posts_per_page){f.hasMore=false}})},sync:function(h,f,e){var g;if(
|