mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-25 02:27:50 +01:00
bd164e628f
git-svn-id: http://core.svn.wordpress.org/trunk@23770 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
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_model_loading();b._right_handle_revisions=new wp.revisions.Collection();b._right_handle_revisions.url=ajaxurl+"?action=revisions-data&compare_to="+(b._revisions.at(b._left_diff).get("ID")-1)+"&post_id="+wpRevisionsSettings.post_id+"&show_autosaves="+REVAPP._autosaves+"&show_split_view="+REVAPP._show_split_view+"&nonce="+wpRevisionsSettings.nonce;b._right_handle_revisions.fetch({success:function(){b.stop_right_model_loading();b.reload_toload_revisions(b._right_handle_revisions);b._tickmarkView.model=b._right_handle_revisions;a("#slider").slider("option","max",b._revisions.length);a("#slider").slider("values",[REVAPP._left_diff,REVAPP._right_diff]).trigger("slide")},error:function(c){b.stop_right_model_loading()}})},reloadleftright:function(){this.start_right_model_loading();this.start_left_model_loading();this.reloadleft();this.reloadright()},initialize:function(c){var b=this;if(this._revisions===null){b._revisions=new wp.revisions.Collection();b.start_right_model_loading();b._revisions.fetch({success:function(){b.stop_right_model_loading();b.completeApplicationSetup()}})}return this},addTooltip:function(c,b){c.attr("title","").tooltip({track:false,position:{my:"left-30 top-66",at:"top left",using:function(d,e){a(this).css(d);a("<div>").addClass("arrow").addClass(e.vertical).addClass(e.horizontal).appendTo(a(this))}},show:false,hide:false,content:function(){return b}})},completeApplicationSetup:function(){this._revisionView=new wp.revisions.views.View({model:this._revisions});this._revisionView.render();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();this._tickmarkView=new wp.revisions.views.Tickmarks({model:this._revisions});this._tickmarkView.render();this._tickmarkView.resetticks()}})};wp.revisions.Collection=Backbone.Collection.extend({model:wp.revisions.Model,url:ajaxurl+"?action=revisions-data&compare_to="+wpRevisionsSettings.post_id+"&show_autosaves=true&show_split_view=true&nonce="+wpRevisionsSettings.nonce,initialize:function(){}});_.extend(wp.revisions.views,{Tickmarks:Backbone.View.extend({el:a("#diff-slider-ticks")[0],tagName:"diff-slider-ticks-view",className:"diff-slider-ticks-container",template:wp.template("revision-ticks"),model:wp.revisions.Model,resetticks:function(){var d=a("#slider").slider("option","max");var c=a("#slider").width();var f=(2===REVAPP._compareoneortwo)?1:0;var b=Math.floor(c/(d-f));b=(b>50)?50:b;b=(b<10)?10:b;c=b*(d-f)+1;a("#slider").width(c);a(".diff-slider-ticks-wrapper").width(c);a("#diffslider").width(c);a("#diff-slider-ticks").width(c);var e=a(".revision-tick").width();if(b!==e){a(".revision-tick").each(function(){a(this).css("margin-right",b-1+"px")});if(2===REVAPP._compareoneortwo){a(".revision-tick").first().remove()}a(".revision-tick").last().css("margin-right","0")}},render:function(){var b=this;if(null!==b.model){var c="";_.each(b.model.models,function(d){c=c+b.template(d.toJSON())});b.$el.html(c)}b.resetticks();return b}}),View:Backbone.View.extend({el:a("#backbonerevisionsdiff")[0],tagName:"revisionvview",className:"revisionview-container",template:wp.template("revision"),comparetwochecked:"",draggingleft:false,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()}if(this.model.length<2){a("div#diffslider").hide();a("div.diff-slider-ticks-wrapper").hide()}if(2===REVAPP._compareoneortwo){REVAPP.addTooltip(a("a.ui-slider-handle.left-handle"),(REVAPP._right_diff>=REVAPP._revisions.length)?"":REVAPP._revisions.at(REVAPP._left_diff).get("revision_date_author_short"));REVAPP.addTooltip(a("a.ui-slider-handle.right-handle"),(REVAPP._right_diff>=REVAPP._revisions.length)?"":REVAPP._revisions.at(REVAPP._right_diff).get("revision_date_author_short"))}else{REVAPP.addTooltip(a("a.ui-slider-handle"),(REVAPP._right_diff>=REVAPP._revisions.length)?"":REVAPP._revisions.at(REVAPP._right_diff).get("revision_date_author_short"))}if(REVAPP._right_diff===REVAPP._revisions.length){a(".restore-button").hide()}else{a(".restore-button").show()}return this},events:{"click #comparetwo":"clickcomparetwo"},clickcomparetwo:function(){self=this;if(a("input#comparetwo").is(":checked")){REVAPP._compareoneortwo=2;if(1===REVAPP._right_diff){REVAPP._right_diff=2}REVAPP._revisionView.draggingleft=false;wpRevisionsSettings.revision_id="";REVAPP.reloadleftright();REVAPP._revisionView.model=REVAPP._right_handle_revisions}else{REVAPP._compareoneortwo=1;REVAPP._revisionView.draggingleft=false;REVAPP.reloadmodelsingle()}REVAPP._revisionsInteractions.render();REVAPP._tickmarkView.render()}}),Interact:Backbone.View.extend({el:a("#backbonerevisionsinteract")[0],tagName:"revisionvinteract",className:"revisionvinteract-container",template:wp.template("revisionvinteract"),initialize:function(){},render:function(){var b=this;var d=this.template;this.$el.html(d);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){REVAPP._right_diff=(f.value+1);REVAPP._revisionView.render()}});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}REVAPP._revisionView.draggingleft=true;if(REVAPP._revisionView.model!==REVAPP._left_handle_revisions&&null!==REVAPP._left_handle_revisions){REVAPP._revisionView.model=REVAPP._left_handle_revisions;REVAPP._tickmarkView.model=REVAPP._left_handle_revisions;REVAPP._tickmarkView.render()}REVAPP._left_diff_start=g.values[0];break;case 2:if(REVAPP._right_model_loading||0===REVAPP._right_handle_revisions.length){return false}if(REVAPP._revisionView.model!==REVAPP._right_handle_revisions&&null!==REVAPP._right_handle_revisions){REVAPP._revisionView.model=REVAPP._right_handle_revisions;REVAPP._tickmarkView.model=REVAPP._right_handle_revisions;REVAPP._tickmarkView.render()}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];break;case 2:if(REVAPP._right_model_loading){return false}REVAPP._right_diff=g.values[1];break}if(0===REVAPP._left_diff){a(".revisiondiffcontainer").addClass("currentversion")}else{a(".revisiondiffcontainer").removeClass("currentversion")}REVAPP._revisionView.render()},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.reloadright()}break;case 2:if(REVAPP._right_diff_start!==g.values[1]){REVAPP.reloadleft()}break}}}});a(".revisiondiffcontainer").addClass("comparetwo");a("#diffslider a.ui-slider-handle").first().addClass("left-handle").next().addClass("right-handle")}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("#slider").slider("value",REVAPP._right_diff-1).trigger("slide")},previousrevision:function(){if(REVAPP._right_diff>1){REVAPP._right_diff=REVAPP._right_diff-1}REVAPP._revisionView.render();a("#slider").slider("value",REVAPP._right_diff-1).trigger("slide")}})});REVAPP=new wp.revisions.App()}(jQuery)); |