2013-05-08 18:58:55 -04:00
|
|
|
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(){var f=this;this.slider=new c.view.Slider();if(null===this.revisions){this.revisions=new d();this.startRightModelLoading();this.revisions.fetch({success:function(){f.stopRightModelLoading();f.completeApplicationSetup()}})}},loadDiffs:function(j){var g=this,i=j.where({completed:false}),h=0,f;_.each(i,function(k){if(k.get("ID")==c.model.settings.revision_id){g.rightDiff=g.revisions.indexOf(k)+1}});_.each(i,function(k){_.delay(function(){k.fetch({update:true,add:false,remove:false,success:function(l){l.set("completed",true);if(0===j.where({completed:false}).length){g.stopModelLoadingSpinner()}f=l.get("linesAdded")+l.get("linesDeleted"),scopeOfChanges="vsmall";if(f>1&&f<=3){scopeOfChanges="small"}else{if(f>3&&f<=5){scopeOfChanges="med"}else{if(f>5&&f<=10){scopeOfChanges="large"}else{if(f>10){scopeOfChanges="vlarge"}}}}l.set("scopeOfChanges",scopeOfChanges);if(0!==g.rightDiff&&l.get("ID")===g.revisions.at(g.rightDiff-1).get("ID")){g.revisionView.render()}g.tickmarkView.render()}})},h);h=h+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},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=!isRtl?e("#next"):e("#previous"),g=!isRtl?e("#previous"):e("#next");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.revis
|