2013-02-28 14:07:34 -05:00
|
|
|
window.wp=window.wp||{};(function(a){wp.revisions={views:{},Model:Backbone.Model.extend({defaults:{ID:0,revision_date_author:"",revisiondiff:"",restoreaction:"",diff_max:0,diff_count:0,diff_revision_to:0,revision_from_date_author:"",}}),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:0,_right_diff:1,_autosaves:false,_showsplitview:true,_compareoneortwo:1,left_model_loading:false,right_model_loading:false,routes:{"viewrevision/:revision":"viewrevision",},viewrevision:function(b){},start_left_model_loading:function(){this.left_model_loading=true;a(".revisiondiffcontainer").addClass("leftmodelloading")},stop_left_model_loading:function(){this.left_model_loading=false;a(".revisiondiffcontainer").removeClass("leftmodelloading")},start_right_model_loading:function(){this.right_model_loading=true;a(".revisiondiffcontainer").addClass("rightmodelloading")},stop_right_model_loading:function(){this.right_model_loading=false;a(".revisiondiffcontainer").removeClass("rightmodelloading")},reloadmodel:function(){if(2==this._compareoneortwo){this.reloadleftright()}else{this.reloadmodelsingle()}},reloadmodelsingle:function(){var b=this;b._revisions.url=ajaxurl+"?action=revisions-data&compareto="+wpRevisionsSettings.post_id+"&showautosaves="+b.self_autosaves+"&showsplitview="+REVAPP._showsplitview+"&nonce="+wpRevisionsSettings.nonce;b.start_right_model_loading();this._revisions.fetch({success:function(){b.stop_right_model_loading();var c=b._revisions.length;if(b._right_diff>c){b._right_diff=c}b._revisionView.render();a("#slider").slider("option","max",c-1)},error:function(){b.stop_right_model_loading();window.console&&console.log("Error loading revision data")}})},reloadleftright:function(){var b=this;b.start_left_model_loading();b.start_right_model_loading();b._left_handle_revisions=new wp.revisions.Collection();b._right_handle_revisions=new wp.revisions.Collection();if(0==b._left_diff){b._right_handle_revisions.url=ajaxurl+"?action=revisions-data&compareto="+wpRevisionsSettings.post_id+"&post_id="+wpRevisionsSettings.post_id+"&showautosaves="+b._autosaves+"&showsplitview="+b._showsplitview+"&nonce="+wpRevisionsSettings.nonce}else{b._right_handle_revisions.url=ajaxurl+"?action=revisions-data&compareto="+b._revisions.at(b._left_diff-1).get("ID")+"&post_id="+wpRevisionsSettings.post_id+"&showautosaves="+b._autosaves+"&showsplitview="+b._showsplitview+"&nonce="+wpRevisionsSettings.nonce}b._left_handle_revisions.url=ajaxurl+"?action=revisions-data&compareto="+b._revisions.at(b._right_diff-1).get("ID")+"&post_id="+wpRevisionsSettings.post_id+"&showautosaves="+b._autosaves+"&showsplitview="+b._showsplitview+"&nonce="+wpRevisionsSettings.nonce;b._left_handle_revisions.fetch({xhr:function(){var c=a.ajaxSettings.xhr();c.onprogress=b.handleProgress;return c},handleProgress:function(c){var d=0;if(c.lengthComputable){d=c.loaded/c.total;window.console&&console.log(Math.round(d*100)+"%")}},success:function(){b.stop_left_model_loading()},error:function(){window.console&&console.log("Error loading revision data");b.stop_left_model_loading()}});b._right_handle_revisions.fetch({success:function(){b.stop_right_model_loading()},error:function(){window.console&&console.log("Error loading revision data");b.stop_right_model_loading()}})},initialize:function(c){var b=this;if(this._revisions===null){b._autosaves="";b._revisions=new wp.revisions.Collection();b.start_right_model_loading();b._revisions.fetch({success:function(){b.stop_right_model_loading();b.revisionDiffSetup()}})}return this},revisionDiffSetup:function(){var b=this,c;this._revisionView=new wp.revisions.views.View({model:this._revisions});this._revisionView.render();this._revisionsInteractions=new wp.revisions.views.Interact({model:this._revisions});this._revisionsInteractions.render();this._revisionsOptions=new wp.revisions.views.Options({model:this._revisions});this._revisionsOptions.render()}})};wp.revisions.Collection=Backbon
|