Wordpress/wp-admin/js/revisions.min.js

1 line
11 KiB
JavaScript
Raw Normal View History

window.wp=window.wp||{};(function(e){var a,d,b,c;c=wp.revisions=function(){b=c.Diff=new b()};_.extend(c,{model:{},view:{},controller:{}});c.model.settings=typeof wpRevisionsSettings==="undefined"?{}:wpRevisionsSettings;b=c.controller.Diff=Backbone.Model.extend({rightDiff:1,leftDiff:1,revisions:null,leftHandleRevisions:null,rightHandleRevisions:null,revisionsInteractions:null,autosaves:true,showSplitView:true,singleRevision:true,leftModelLoading:false,rightModelLoading:false,tickmarkView:null,slider:null,constructor:function(){this.slider=new c.view.Slider();if(null===this.revisions){this.revisions=new d();this.startRightModelLoading();var f=this;this.revisions.fetch({success:function(){f.stopRightModelLoading();f.completeApplicationSetup()}})}},loadDiffs:function(i){var f=this,h=i.where({completed:false}),g=0;_.each(h,function(j){if(j.get("ID")==c.model.settings.revision_id){f.rightDiff=f.revisions.indexOf(j)+1}});_.each(h,function(j){_.delay(function(){j.fetch({update:true,add:false,remove:false,success:function(l){l.set("completed",true);if(0===i.where({completed:false}).length){f.stopModelLoadingSpinner()}f.tickmarkView.render();var k=l.get("linesAdded")+l.get("linesDeleted"),m="vsmall";if(k>1&&k<=3){m="small"}else{if(k>3&&k<=5){m="med"}else{if(k>5&&k<=10){m="large"}else{if(k>10){m="vlarge"}}}}l.set("scopeOfChanges",m);if(0!==f.rightDiff&&l.get("ID")===f.revisions.at(f.rightDiff-1).get("ID")){f.revisionView.render()}}})},g);g=g+150})},startLeftModelLoading:function(){this.leftModelLoading=true;e("#revision-diff-container").addClass("left-model-loading")},stopLeftModelLoading:function(){this.leftModelLoading=false},startRightModelLoading:function(){this.rightModelLoading=true;e("#revision-diff-container").addClass("right-model-loading")},stopRightModelLoading:function(){this.rightModelLoading=false},stopModelLoadingSpinner:function(){e("#revision-diff-container").removeClass("right-model-loading");e("#revision-diff-container").removeClass("left-model-loading")},reloadModel:function(){if(this.singleRevision){this.reloadModelSingle()}else{this.reloadLeftRight()}},reloadModelSingle:function(){var f=this;f.startRightModelLoading();f.revisions.reload({options:{showAutosaves:f.autosaves,showSplitView:f.showSplitView},success:function(){var g=f.revisions.length;f.revisionView.model=f.revisions;f.revisionView.render();f.loadDiffs(f.revisions);f.tickmarkView.model=f.revisions;f.tickmarkView.render();f.slider.refresh({max:g-1,value:f.rightDiff-1},true)},error:function(){f.stopRightModelLoading()}})},reloadLeft:function(){var f=this;f.startLeftModelLoading();f.leftHandleRevisions=new d({},{compareTo:f.revisions.at(f.rightDiff-1).get("ID"),showAutosaves:f.autosaves,showSplitView:f.showSplitView,rightHandleAt:f.rightDiff});f.leftHandleRevisions.fetch({success:function(){f.stopLeftModelLoading();f.loadDiffs(f.leftHandleRevisions);f.tickmarkView.model=f.leftHandleRevisions;f.slider.refresh({max:f.revisions.length});if(f.rightDiff>f.revisions.length){f.rightDiff=f.revisions.length}},error:function(){f.stopLeftModelLoading()}})},reloadRight:function(){var f=this;f.startRightModelLoading();f.rightHandleRevisions=new d({},{compareTo:f.revisions.at(f.leftDiff-1).get("ID"),showAutosaves:f.autosaves,showSplitView:f.showSplitView,leftHandleAt:f.leftDiff});f.rightHandleRevisions.fetch({success:function(){f.stopRightModelLoading();f.loadDiffs(f.rightHandleRevisions);f.tickmarkView.model=f.rightHandleRevisions;f.slider.refresh({max:f.revisions.length,values:[f.leftDiff,f.rightDiff]},true)},error:function(g){f.stopRightModelLoading()}})},reloadLeftRight:function(){this.startRightModelLoading();this.startLeftModelLoading();this.reloadLeft();this.reloadRight()},disabledButtonCheck:function(h){var i=this.revisions.length-1,f=e("#next"),g=e("#previous");if(i===h){f.prop("disabled",true)}else{f.prop("disabled",false)}if(0===h){g.prop("disabled",true)}else{g.prop("disabled",false)}},completeApplicationSetup:function(){this.revisionView=new c.view.Diff({model:this.revisions});this.revisionView.render();this.loadDiffs(this.revisions);this.revisionsInte