2013-07-12 22:58:53 +02:00
|
|
|
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(window.console&&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:null,values:null,min:0,max:1,step:1,range:false,compareTwoMode:false},initialize:function(c){this.frame=c.frame;this.revisions=c.revisions;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:compareTwoMode",this.updateSliderSettings);this.listenTo(this,"update:revisions",this.updateSliderSettings);this.listenTo(this,"change:hoveredRevision",this.hoverRevision);this.set({max:this.revisions.length-1,compareTwoMode:this.frame.get("compareTwoMode"),from:this.frame.get("from"),to:this.frame.get("to")});this.updateSliderSettings()},getSliderValue:function(d,c){return isRtl?this.revisions.length-this.revisions.indexOf(this.get(d))-1:this.revisions.indexOf(this.get(c))},updateSliderSettings:function(){if(this.get("compareTwoMode")){this.set({values:[this.getSliderValue("to","from"),this.getSliderValue("from","to")],value:null,range:true})}else{this.set({value:this.getSliderValue("to","to"),values:null,range:false})}this.trigger("update:slider")},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")},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){_.bindAll(this,"getClosestUnloaded");this.loadAll=_.once(this._loadAll);this.revisions=c.revisions;this.requests={}},model:a.model.Diff,ensure:function(j,d){var g=this.get(j);var f=this.requests[j];var c=b.Deferred();var e={};var i=j.split(":")[0];var h=j.split(":")[1];e[j]=true;wp.revisions.log("ensure",j);this.trigger("ensure",e,i,h,c.promise());if(g){c.resolveWith(d,[g])}else{this.trigger("ensure:load",e,i,h,c.promise());_.each(e,_.bind(function(k){if(this.requests[k]){delete e[k]}if(this.get(k)){delete e[k]}},this));if(!f){e[j]=true;f=this.load(_.keys(e))}f.done(_.bind(function(){c.resolveWith(d,[this.get(j)])},this))}return c.promise()},getClosestUnloaded:function(e,c){var d=this;return _.chain([0].concat(e)).initial().zip(e).sortBy(function(f){return Math.abs(c-f[1])}).map(function(f){return f.join(":")}).filter(function(f){return _.isUndefin
|