Wordpress/wp-admin/js/revisions.min.js

1 line
16 KiB
JavaScript
Raw Normal View History

window.wp=window.wp||{};(function(b){var a;a=wp.revisions={model:{},view:{},controller:{}};a.settings=_.isUndefined(_wpRevisionsSettings)?{}:_wpRevisionsSettings;a.debug=true;a.log=function(){if(a.debug){console.log.apply(console,arguments)}};if(a.settings.to){a.settings.to=parseInt(a.settings.to,10)}if(a.settings.from){a.settings.from=parseInt(a.settings.from,10)}if(a.settings.compareTwoMode){a.settings.compareTwoMode=a.settings.compareTwoMode==="1"}a.model.Slider=Backbone.Model.extend({defaults:{value:0,min:0,max:1,step:1,compareTwoMode:false},initialize:function(c){this.frame=c.frame;this.revisions=c.revisions;this.set({max:this.revisions.length-1,value:this.revisions.indexOf(this.revisions.get(a.settings.to)),compareTwoMode:this.frame.get("compareTwoMode")});this.listenTo(this.frame,"update:revisions",this.receiveRevisions);this.listenTo(this.frame,"change:compareTwoMode",this.updateMode);this.listenTo(this,"change:from",this.handleLocalChanges);this.listenTo(this,"change:to",this.handleLocalChanges);this.listenTo(this,"change:hoveredRevision",this.hoverRevision)},hoverRevision:function(c,d){this.trigger("hovered:revision",d)},updateMode:function(c,d){this.set({compareTwoMode:d})},handleLocalChanges:function(){this.frame.set({from:this.get("from"),to:this.get("to")})},receiveRevisions:function(d,c){if(this.get("from")===d&&this.get("to")===c){return}this.set({from:d,to:c},{silent:true});this.trigger("update:revisions",d,c)}});a.model.Tooltip=Backbone.Model.extend({defaults:{revision:null,hovering:false,scrubbing:false},initialize:function(c){this.revisions=c.revisions;this.slider=c.slider;this.listenTo(this.slider,"hovered:revision",this.updateRevision);this.listenTo(this.slider,"change:hovering",this.setHovering);this.listenTo(this.slider,"change:scrubbing",this.setScrubbing)},updateRevision:function(c){this.set({revision:c})},setHovering:function(c,d){this.set({hovering:d})},setScrubbing:function(c,d){this.set({scrubbing:d})}});a.model.Revision=Backbone.Model.extend({});a.model.Revisions=Backbone.Collection.extend({model:a.model.Revision,initialize:function(){_.bindAll(this,"next","prev")},comparator:function(e,c){var g=e.get("dateUnix");var d=c.get("dateUnix");var f=(g>d)-(g<d);if(f===0&&e.id!=c.id){f=e.id<c.id?-1:1}return f},next:function(d){var c=this.indexOf(d);if(c!==-1&&c!==this.length-1){return this.at(c+1)}},prev:function(d){var c=this.indexOf(d);if(c!==-1&&c!==0){return this.at(c-1)}}});a.model.Field=Backbone.Model.extend({});a.model.Fields=Backbone.Collection.extend({model:a.model.Field});a.model.Diff=Backbone.Model.extend({initialize:function(d,e){var c=this.get("fields");this.unset("fields");this.fields=new a.model.Fields(c)}});a.model.Diffs=Backbone.Collection.extend({initialize:function(d,c){this.revisions=c.revisions;this.requests={}},model:a.model.Diff,ensure:function(h,d){var g=this.get(h);var f=this.requests[h];var c=b.Deferred();var e={};if(g){c.resolveWith(d,[g])}else{this.trigger("ensure:load",e);_.each(e,_.bind(function(i){if(this.requests[i]){delete e[i]}},this));if(!f){e[h]=true;f=this.load(_.keys(e))}f.done(_.bind(function(){c.resolveWith(d,[this.get(h)])},this))}return c.promise()},loadNew:function(d){var c=this;_.each(d,function(f,e){if(c.get(f)){delete d[e]}});wp.revisions.log("loadNew",d);if(d.length){return this.load(d)}else{return b.Deferred().resolve().promise()}},load:function(c){wp.revisions.log("load",c);return this.fetch({data:{compare:c},remove:false})},loadLast:function(c){var d;c=c||1;d=_.last(this.getProximalDiffIds(),c);if(d.length){return this.loadNew(d)}else{return b.Deferred().resolve().promise()}},loadLastUnloaded:function(c){var d;c=c||1;d=_.last(this.getUnloadedProximalDiffIds(),c);if(d.length){return this.loadNew(d)}else{return b.Deferred().resolve().promise()}},getProximalDiffIds:function(){var d=0,c=[];this.revisions.each(_.bind(function(e){c.push(d+":"+e.id);d=e.id},this));return c},getUnloadedProximalDiffIds:function(){var c=this.getProximalDiffIds();c=_.object(c,c);_.each(c,_.bind(function(d){if(this.get(d)){delete c[d]}},this));return _.toArray(c)},loadAllBy:fu