2013-03-21 17:58:38 +01: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({_revisionDifflView:null,_revisions:null,_left_handle_revisions:null,_right_handle_revisions:null,_revisionsInteractions:null,_revisionsOptions:null,_left_diff:1,_right_diff:1,_autosaves:true,_show_split_view:true,_compareoneortwo:1,_left_model_loading:false,_right_model_loading:false,_tickmarkView:null,_has_tooltip:false,routes:{},reload_toload_revisions:function(d,e){var b=this;var f=d.where({revision_toload:true});var c=0;_.each(f,function(g){if(g.get("ID")==wpRevisionsSettings.revision_id){b._right_diff=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.stop_model_loading_spinner()}b._tickmarkView.render();var h=i.get("lines_added")+i.get("lines_deleted");var 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._right_diff&&i.get("ID")===b._revisions.at(b._right_diff-1).get("ID")){b._revisionView.render()}}})},c);c=c+150})},start_left_model_loading:function(){this._left_model_loading=true;a(".revisiondiffcontainer").addClass("leftmodelloading")},stop_left_model_loading:function(){this._left_model_loading=false},start_right_model_loading:function(){this._right_model_loading=true;a(".revisiondiffcontainer").addClass("rightmodelloading")},stop_right_model_loading:function(){this._right_model_loading=false},stop_model_loading_spinner: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._show_split_view+"&nonce="+wpRevisionsSettings.nonce;b.start_right_model_loading();b._revisions.fetch({success:function(){console.log("loaded");var c=b._revisions.length;b._revisionView.model=b._revisions;b._revisionView.render();b.reload_toload_revisions(b._revisions);b._tickmarkView.model=b._revisions;b._tickmarkView.render();a("#slider").slider("option","max",c-1);a("#slider").slider("value",b._right_diff-1).trigger("slide")},error:function(){b.stop_right_model_loading()}})},reloadleft:function(){var b=this;b.start_left_model_loading();b._left_handle_revisions=new wp.revisions.Collection();b._left_handle_revisions.url=ajaxurl+"?action=revisions-data&compare_to="+b._revisions.at(b._right_diff-1).get("ID")+"&post_id="+wpRevisionsSettings.post_id+"&show_autosaves="+REVAPP._autosaves+"&show_split_view="+REVAPP._show_split_view+"&nonce="+wpRevisionsSettings.nonce+"&right_handle_at="+(b._right_diff);b._left_handle_revisions.fetch({success:function(){b.stop_left_model_loading();b.reload_toload_revisions(b._left_handle_revisions);b._tickmarkView.model=b._left_handle_revisions;a("#slider").slider("option","max",b._revisions.length);if(b._right_diff>b._revisions.length){b._right_diff=b._revisions.length}},error:function(){b.stop_left_model_loading()}})},reloadright:function(){var b=this;b.start_right_
|