2013-03-27 22:58:39 -04:00
|
|
|
window.wp=window.wp||{};(function(a){wp.revisions={views:{},Model:Backbone.Model.extend({idAttribute:"ID",urlRoot:ajaxurl+"?action=revisions-data&show_autosaves=true&show_split_view=true&nonce="+wpRevisionsSettings.nonce,defaults:{ID:0,revision_date_author:"",revision_date_author_short:"",revisiondiff:'<div class="diff-loading"><div class="spinner"></div></div>',restoreaction:"",revision_from_date_author:"",revision_toload:false,lines_added:0,lines_deleted:0,scope_of_changes:"none",previous_revision_id:0},url:function(){if(1===REVAPP._compareOneOrTwo){return this.urlRoot+"&single_revision_id="+this.id+"&compare_to="+this.get("previous_revision_id")+"&post_id="+wpRevisionsSettings.post_id}else{return this.urlRoot+"&single_revision_id="+this.id}}}),app:_.extend({},Backbone.Events),App:Backbone.Router.extend({_revisions:null,_leftHandleRevisions:null,_rightHandleRevisions:null,_revisionsInteractions:null,_revisionsOptions:null,_leftDiff:1,_rightDiff:1,_autosaves:true,_showSplitView:true,_compareOneOrTwo:1,_leftModelLoading:false,_rightModelLoading:false,_tickmarkView:null,routes:{},reloadToLoadRevisions:function(d,e){var b=this,f=d.where({revision_toload:true}),c=0;_.each(f,function(g){if(g.get("ID")==wpRevisionsSettings.revision_id){b._rightDiff=b._revisions.indexOf(g)+1}});_.each(f,function(g){g.urlRoot=d.url;_.delay(function(){g.fetch({update:true,add:false,remove:false,success:function(i){i.set("revision_toload","false");if(0===d.where({revision_toload:true}).length){b.stopModelLoadingSpinner()}b._tickmarkView.render();var h=i.get("lines_added")+i.get("lines_deleted"),j="vsmall";if(h>1&&h<=3){j="small"}else{if(h>3&&h<=5){j="med"}else{if(h>5&&h<=10){j="large"}else{if(h>10){j="vlarge"}}}}i.set("scope_of_changes",j);if(0!==b._rightDiff&&i.get("ID")===b._revisions.at(b._rightDiff-1).get("ID")){b._revisionView.render()}}})},c);c=c+150})},startLeftModelLoading:function(){this._leftModelLoading=true;a(".revisiondiffcontainer").addClass("leftmodelloading")},stopLeftModelLoading:function(){this._leftModelLoading=false},startRightModelLoading:function(){this._rightModelLoading=true;a(".revisiondiffcontainer").addClass("rightmodelloading")},stopRightModelLoading:function(){this._rightModelLoading=false},stopModelLoadingSpinner:function(){a(".revisiondiffcontainer").removeClass("rightmodelloading");a(".revisiondiffcontainer").removeClass("leftmodelloading")},reloadModel:function(){if(2===this._compareOneOrTwo){this.reloadLeftRight()}else{this.reloadModelSingle()}},reloadModelSingle:function(){var b=this;b._revisions.url=ajaxurl+"?action=revisions-data&compare_to="+wpRevisionsSettings.post_id+"&show_autosaves="+b._autosaves+"&show_split_view="+b._showSplitView+"&nonce="+wpRevisionsSettings.nonce;b.startRightModelLoading();b._revisions.fetch({success:function(){console.log("loaded");var c=b._revisions.length;b._revisionView.model=b._revisions;b._revisionView.render();b.reloadToLoadRevisions(b._revisions);b._tickmarkView.model=b._revisions;b._tickmarkView.render();a("#slider").slider("option","max",c-1);a("#slider").slider("value",b._rightDiff-1).trigger("slide")},error:function(){b.stopRightModelLoading()}})},reloadLeft:function(){var b=this;b.startLeftModelLoading();b._leftHandleRevisions=new wp.revisions.Collection();b._leftHandleRevisions.url=ajaxurl+"?action=revisions-data&compare_to="+b._revisions.at(b._rightDiff-1).get("ID")+"&post_id="+wpRevisionsSettings.post_id+"&show_autosaves="+REVAPP._autosaves+"&show_split_view="+REVAPP._showSplitView+"&nonce="+wpRevisionsSettings.nonce+"&right_handle_at="+(b._rightDiff);b._leftHandleRevisions.fetch({success:function(){b.stopLeftModelLoading();b.reloadToLoadRevisions(b._leftHandleRevisions);b._tickmarkView.model=b._leftHandleRevisions;a("#slider").slider("option","max",b._revisions.length);if(b._rightDiff>b._revisions.length){b._rightDiff=b._revisions.length}},error:function(){b.stopLeftModelLoading()}})},reloadRight:function(){var b=this;b.startRightModelLoading();b._rightHandleRevisions=new wp.revisions.Collection();b._rightHandleRevisions.url=ajaxurl+"?action=revisions-data&compare_t
|