window.wp=window.wp||{};(function(f){var b,e,c,a,d;d=wp.revisions=function(){c=d.Diff=new c()};_.extend(d,{model:{},view:{},controller:{}});a=d.model.l10n=typeof wpRevisionsL10n==="undefined"?{}:wpRevisionsL10n;d.model.settings=a.settings||{};delete a.settings;c=d.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 d.view.Slider();if(null===this.revisions){this.revisions=new e();this.startRightModelLoading();var g=this;this.revisions.fetch({success:function(){g.stopRightModelLoading();g.completeApplicationSetup()}})}},loadDiffs:function(j){var g=this,i=j.where({completed:false}),h=0;_.each(i,function(k){if(k.get("ID")==d.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(m){m.set("completed",true);if(0===j.where({completed:false}).length){g.stopModelLoadingSpinner()}g.tickmarkView.render();var l=m.get("linesAdded")+m.get("linesDeleted"),n="vsmall";if(l>1&&l<=3){n="small"}else{if(l>3&&l<=5){n="med"}else{if(l>5&&l<=10){n="large"}else{if(l>10){n="vlarge"}}}}m.set("scopeOfChanges",n);if(0!==g.rightDiff&&m.get("ID")===g.revisions.at(g.rightDiff-1).get("ID")){g.revisionView.render()}}})},h);h=h+150})},startLeftModelLoading:function(){this.leftModelLoading=true;f("#revision-diff-container").addClass("left-model-loading")},stopLeftModelLoading:function(){this.leftModelLoading=false},startRightModelLoading:function(){this.rightModelLoading=true;f("#revision-diff-container").addClass("right-model-loading")},stopRightModelLoading:function(){this.rightModelLoading=false},stopModelLoadingSpinner:function(){f("#revision-diff-container").removeClass("right-model-loading");f("#revision-diff-container").removeClass("left-model-loading")},reloadModel:function(){if(this.singleRevision){this.reloadModelSingle()}else{this.reloadLeftRight()}},reloadModelSingle:function(){var g=this;g.startRightModelLoading();g.revisions.reload({options:{showAutosaves:g.autosaves,showSplitView:g.showSplitView},success:function(){var h=g.revisions.length;g.revisionView.model=g.revisions;g.revisionView.render();g.loadDiffs(g.revisions);g.tickmarkView.model=g.revisions;g.tickmarkView.render();g.slider.refresh({max:h-1,value:g.rightDiff-1},true)},error:function(){g.stopRightModelLoading()}})},reloadLeft:function(){var g=this;g.startLeftModelLoading();g.leftHandleRevisions=new e({},{compareTo:g.revisions.at(g.rightDiff-1).get("ID"),showAutosaves:g.autosaves,showSplitView:g.showSplitView,rightHandleAt:g.rightDiff});g.leftHandleRevisions.fetch({success:function(){g.stopLeftModelLoading();g.loadDiffs(g.leftHandleRevisions);g.tickmarkView.model=g.leftHandleRevisions;g.slider.refresh({max:g.revisions.length});if(g.rightDiff>g.revisions.length){g.rightDiff=g.revisions.length}},error:function(){g.stopLeftModelLoading()}})},reloadRight:function(){var g=this;g.startRightModelLoading();g.rightHandleRevisions=new e({},{compareTo:g.revisions.at(g.leftDiff-1).get("ID"),showAutosaves:g.autosaves,showSplitView:g.showSplitView,leftHandleAt:g.leftDiff});g.rightHandleRevisions.fetch({success:function(){g.stopRightModelLoading();g.loadDiffs(g.rightHandleRevisions);g.tickmarkView.model=g.rightHandleRevisions;g.slider.refresh({max:g.revisions.length,values:[g.leftDiff,g.rightDiff]},true)},error:function(h){g.stopRightModelLoading()}})},reloadLeftRight:function(){this.startRightModelLoading();this.startLeftModelLoading();this.reloadLeft();this.reloadRight()},disabledButtonCheck:function(i){var j=this.revisions.length-1,g=f("#next"),h=f("#previous");if(j===i){g.prop("disabled",true)}else{g.prop("disabled",false)}if(0===i){h.prop("disabled",true)}else{h.prop("disabled",false)}},completeApplicationSetup:function(){this.revisionView=new d.view.Diff({model:this.revisions});this.revisionView.render();this.loadDiffs(this.revisions);this.revisionsInteractions=new d.view.Interact({model:this.revisions});this.revisionsInteractions.render();this.tickmarkView=new d.view.Tickmarks({model:this.revisions});this.tickmarkView.render();this.tickmarkView.resetTicks()}});d.view.Slider=Backbone.View.extend({el:f("#diff-slider"),singleRevision:true,initialize:function(g){this.options=_.defaults(g||{},{value:0,min:0,max:1,step:1})},slide:function(g,h){if(this.singleRevision){c.rightDiff=(h.value+1);c.revisionView.render();c.disabledButtonCheck(h.value)}else{if(h.values[0]===h.values[1]){return false}if(f(h.handle).hasClass("left-handle")){if(c.leftModelLoading){return false}c.leftDiff=h.values[0]}else{if(c.rightModelLoading){return false}c.rightDiff=h.values[1]}if(0===c.leftDiff){f("#revision-diff-container").addClass("current-version")}else{f("#revision-diff-container").removeClass("current-version")}c.revisionView.render()}},start:function(g,h){if(this.singleRevision){return}if(f(h.handle).hasClass("left-handle")){if(c.leftModelLoading){return false}c.revisionView.draggingLeft=true;if(c.revisionView.model!==c.leftHandleRevisions&&null!==c.leftHandleRevisions){c.revisionView.model=c.leftHandleRevisions;c.tickmarkView.model=c.leftHandleRevisions;c.tickmarkView.render()}c.leftDiffStart=h.values[0]}else{if(c.rightModelLoading||0===c.rightHandleRevisions.length){return false}if(c.revisionView.model!==c.rightHandleRevisions&&null!==c.rightHandleRevisions){c.revisionView.model=c.rightHandleRevisions;c.tickmarkView.model=c.rightHandleRevisions;c.tickmarkView.render()}c.revisionView.draggingLeft=false;c.rightDiffStart=h.values[1]}},stop:function(g,h){if(this.singleRevision){return}if(f(h.handle).hasClass("left-handle")){if(c.leftDiffStart!==h.values[0]){c.reloadRight()}}else{if(c.rightDiffStart!==h.values[1]){c.reloadLeft()}}},addTooltip:function(h,g){h.attr("title","").tooltip({track:false,position:{my:"left-30 top-66",at:"top left",using:function(i,j){f(this).css(i);f("