5d98f47677
git-svn-id: https://develop.svn.wordpress.org/trunk@23646 602fd350-edb4-49c9-b593-d223f7449a82
1 line
10 KiB
JavaScript
1 line
10 KiB
JavaScript
window.wp=window.wp||{};(function(a){wp.revisions={views:{},Model:Backbone.Model.extend({idAttribute:"ID",urlRoot:ajaxurl+"?action=revisions-data&compare_to="+wpRevisionsSettings.post_id+"&show_autosaves=false&show_split_view=true&nonce="+wpRevisionsSettings.nonce,defaults:{ID:0,revision_date_author:"",revisiondiff:'<div class="diff-loading"><div class="spinner"></div></div>',restoreaction:"",revision_from_date_author:"",revision_toload:false},url:function(){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:0,_right_diff:1,_autosaves:false,_show_split_view:true,_compareoneortwo:1,_left_model_loading:false,_right_model_loading:false,routes:{},viewrevision:function(b){},reload_toload_revisions:function(d,e){var b=this;var f=d.where({revision_toload:true});var c=0;_.each(f,function(g){g.urlRoot=d.url;_.delay(function(){g.fetch({update:true,add:false,remove:false,success:function(h){if(h.get("ID")===b._revisions.at(b._right_diff-1).get("ID")){b._revisionView.render()}}})},c);c=c+200})},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&compare_to="+wpRevisionsSettings.post_id+"&show_autosaves="+b._autosaves+"&show_split_view="+REVAPP._show_split_view+"&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();b.reload_toload_revisions(b._revisions);a("#slider").slider("option","max",c-1)},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="+b._autosaves+"&show_split_view="+b._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)},error:function(){b.stop_left_model_loading()}})},reloadright:function(){var b=this;b.start_right_model_loading();b._right_handle_revisions=new wp.revisions.Collection();if(0===b._left_diff){b._right_handle_revisions.url=ajaxurl+"?action=revisions-data&compare_to="+wpRevisionsSettings.post_id+"&post_id="+wpRevisionsSettings.post_id+"&show_autosaves="+b._autosaves+"&show_split_view="+b._show_split_view+"&nonce="+wpRevisionsSettings.nonce}else{b._right_handle_revisions.url=ajaxurl+"?action=revisions-data&compare_to="+b._revisions.at(b._left_diff-1).get("ID")+"&post_id="+wpRevisionsSettings.post_id+"&show_autosaves="+b._autosaves+"&show_split_view="+b._show_split_view+"&nonce="+wpRevisionsSettings.nonce+"&left_handle_at="+(b._left_diff)}b._right_handle_revisions.fetch({success:function(){b.stop_right_model_loading();b.reload_toload_revisions(b._right_handle_revisions)},error:function(c){b.stop_right_model_loading()}})},reloadleftright:function(){this.reloadleft();this.reloadright()},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(){this._revisionView=new wp.revisions.views.View({model:this._revisions});this._revisionView.render();a("#diff_max, #diff_maxof").html(this._revisions.length);a("#diff_count").html(REVAPP._right_diff);a("#slider").slider("option","max",this._revisions.length-1);this.reload_toload_revisions(this._revisions);this._revisionsInteractions=new wp.revisions.views.Interact({model:this._revisions});this._revisionsInteractions.render()}})};wp.revisions.Collection=Backbone.Collection.extend({model:wp.revisions.Model,url:ajaxurl+"?action=revisions-data&compare_to="+wpRevisionsSettings.post_id+"&show_autosaves=false&show_split_view=true&nonce="+wpRevisionsSettings.nonce,initialize:function(){}});_.extend(wp.revisions.views,{View:Backbone.View.extend({el:a("#backbonerevisionsdiff")[0],tagName:"revisionvview",className:"revisionview-container",template:wp.template("revision"),revvapp:null,comparetwochecked:"",draggingleft:false,initialize:function(){},render:function(){var c="";if(2===REVAPP._compareoneortwo){this.comparetwochecked="checked";if(this.draggingleft){if(this.model.at(REVAPP._left_diff)){c=this.template(_.extend(this.model.at(REVAPP._left_diff).toJSON(),{comparetwochecked:this.comparetwochecked}))}}else{var b=REVAPP._right_diff;if(this.model.at(b)){c=this.template(_.extend(this.model.at(b).toJSON(),{comparetwochecked:this.comparetwochecked}))}}}else{this.comparetwochecked="";if(this.model.at(REVAPP._right_diff-1)){c=this.template(_.extend(this.model.at(REVAPP._right_diff-1).toJSON(),{comparetwochecked:this.comparetwochecked}))}}this.$el.html(c);if(this.model.length<3){a("div#comparetworevisions").hide()}return this},events:{"click #comparetwo":"clickcomparetwo"},clickcomparetwo:function(){self=this;if(a("input#comparetwo").is(":checked")){REVAPP._compareoneortwo=2;REVAPP.reloadleftright()}else{REVAPP._compareoneortwo=1;REVAPP._revisionView.draggingleft=false;REVAPP._left_diff=0;REVAPP.reloadmodelsingle()}REVAPP._revisionsInteractions.render()}}),Options:Backbone.View.extend({el:a("#backbonerevisionsoptions")[0],tagName:"revisionoptionsview",className:"revisionoptions-container",template:wp.template("revisionoptions"),initialize:function(){},render:function(){var b=this.template;this.$el.html(b);return this},events:{"click #toggleshowautosaves":"toggleshowautosaves","click #showsplitview":"showsplitview"},toggleshowautosaves:function(){var b=this;if(a("#toggleshowautosaves").is(":checked")){REVAPP._autosaves=true}else{REVAPP._autosaves=false}REVAPP.reloadmodel()},showsplitview:function(){var b=this;if(a("input#showsplitview").is(":checked")){REVAPP._show_split_view="true";a(".revisiondiffcontainer").addClass("diffsplit")}else{REVAPP._show_split_view="";a(".revisiondiffcontainer").removeClass("diffsplit")}REVAPP.reloadmodel()}}),Interact:Backbone.View.extend({el:a("#backbonerevisionsinteract")[0],tagName:"revisionvinteract",className:"revisionvinteract-container",template:wp.template("revisionvinteract"),_restoreword:"",initialize:function(){this._restoreword=a("input#restore").attr("value")},reset_restore_button:function(){a("input#restore").attr("value",this._restoreword+" "+REVAPP._revisions.at(REVAPP._right_diff-1).get("ID"))},render:function(){var b=this;var d=this.template;this.$el.html(d);a("#diff_max, #diff_maxof").html(this.model.length);a("#diff_count").html(REVAPP._right_diff);a("#diff_left_count_inner").html(0===REVAPP._left_diff?"":"revision"+REVAPP._left_diff);b.reset_restore_button();var c=REVAPP._revisions.length;slider=a("#slider");if(1===REVAPP._compareoneortwo){slider.slider({value:REVAPP._right_diff-1,min:0,max:c-1,step:1,slide:function(e,f){if(REVAPP._right_model_loading){return false}REVAPP._right_diff=(f.value+1);a("#diff_count").html(REVAPP._right_diff);REVAPP._revisionView.render();b.reset_restore_button()}});a(".revisiondiffcontainer").removeClass("comparetwo")}else{slider.slider({values:[REVAPP._left_diff,REVAPP._right_diff+1],min:1,max:c+1,step:1,range:true,start:function(f,g){var e=a(g.handle).index();switch(e){case 1:if(REVAPP._left_model_loading){return false}if(REVAPP._revisionView.model!==REVAPP._left_handle_revisions&&null!==REVAPP._left_handle_revisions){REVAPP._revisionView.model=REVAPP._left_handle_revisions}REVAPP._revisionView.draggingleft=true;REVAPP._left_diff_start=g.values[0];break;case 2:if(REVAPP._right_model_loading){return false}if(REVAPP._revisionView.model!==REVAPP._right_handle_revisions&&null!==REVAPP._right_handle_revisions){REVAPP._revisionView.model=REVAPP._right_handle_revisions}REVAPP._revisionView.draggingleft=false;REVAPP._right_diff_start=g.values[1];break}},slide:function(f,g){if(g.values[0]===g.values[1]){return false}var e=a(g.handle).index();switch(e){case 1:if(REVAPP._left_model_loading){return false}REVAPP._left_diff=g.values[0]-1;break;case 2:if(REVAPP._right_model_loading){return false}REVAPP._right_diff=g.values[1]-1;break}a("#diff_count").html(REVAPP._right_diff);if(0===REVAPP._left_diff){a(".revisiondiffcontainer").addClass("currentversion")}else{a(".revisiondiffcontainer").removeClass("currentversion");a("#diff_left_count_inner").html(REVAPP._left_diff)}REVAPP._revisionView.render();b.reset_restore_button()},stop:function(f,g){if(2===REVAPP._compareoneortwo){var e=a(g.handle).index();switch(e){case 1:if(!(REVAPP._left_diff_start===g.values[0]||REVAPP._left_model_loading)){REVAPP.reloadright()}break;case 2:if(!(REVAPP._right_diff_start===g.values[1]||REVAPP._right_model_loading)){REVAPP.reloadleft()}break}}}});a(".revisiondiffcontainer").addClass("comparetwo")}return this},events:{"click #next":"nextrevision","click #previous":"previousrevision"},nextrevision:function(){if(REVAPP._right_diff<this.model.length){REVAPP._right_diff=REVAPP._right_diff+1}REVAPP._revisionView.render();a("#diff_count").html(REVAPP._right_diff);a("#slider").slider("value",REVAPP._right_diff-1).trigger("slide");this.reset_restore_button()},previousrevision:function(){if(REVAPP._right_diff>1){REVAPP._right_diff=REVAPP._right_diff-1}REVAPP._revisionView.render();a("#diff_count").html(REVAPP._right_diff);a("#slider").slider("value",REVAPP._right_diff-1).trigger("slide");this.reset_restore_button()}})});REVAPP=new wp.revisions.App()}(jQuery)); |