/** * Copyright (c) 2016 by Jamie Peabody, http://www.mergely.com * All rights reserved. * Version: 3.4.3 2016-09-07 */ "use strict";!function(a,b,c,d){var e={};e.Timer=function(){var a=this;a.start=function(){a.t0=(new Date).getTime()},a.stop=function(){var b=(new Date).getTime(),c=b-a.t0;return a.t0=b,c},a.start()},e.ChangeExpression=new RegExp(/(^(?![><\-])*\d+(?:,\d+)?)([acd])(\d+(?:,\d+)?)/),e.DiffParser=function(a){for(var b=[],c=0,d=a.split(/\n/),f=0;f0&&"c"==i.op&&(f+=1),b(f,f+j.length)}if("d"!=i.op){f=c.getLines("rhs").slice(0,i["rhs-line-from"]).join(" ").length,g=i["rhs-line-to"]+1;var k=c.getLines("rhs").slice(i["rhs-line-from"],g).join(" ");"a"==i.op?k+=" ":f>0&&"c"==i.op&&(f+=1),a(f,f+k.length)}}}}),e.CodeifyText=function(a){this._max_code=0,this._diff_codes={},this.ctxs={},this.options={ignorews:!1},c.extend(this,a),this.lhs=a.lhs.split("\n"),this.rhs=a.rhs.split("\n")},c.extend(e.CodeifyText.prototype,{getCodes:function(a){if(!this.ctxs.hasOwnProperty(a)){var b=this._diff_ctx(this[a]);this.ctxs[a]=b,b.codes.length=Object.keys(b.codes).length}return this.ctxs[a].codes},getLines:function(a){return this.ctxs[a].lines},_diff_ctx:function(a){var b={i:0,codes:{},lines:a};return this._codeify(a,b),b},_codeify:function(a,b){for(var d=(this._max_code,0);d0?f="a":c.lhs_deleted_count>0&&0==c.rhs_inserted_count&&(f="d"),d=1==c.lhs_deleted_count?c.lhs_start+1:0==c.lhs_deleted_count?c.lhs_start:c.lhs_start+1+","+(c.lhs_start+c.lhs_deleted_count),e=1==c.rhs_inserted_count?c.rhs_start+1:0==c.rhs_inserted_count?c.rhs_start:c.rhs_start+1+","+(c.rhs_start+c.rhs_inserted_count),a+=d+f+e+"\n";var g=this.getLines("lhs"),h=this.getLines("rhs");if(h&&g){var i;for(i=c.lhs_start;i "+h[i]+"\n"}}return a},_lcs:function(a,b,c,d,e,f,g,h){for(;c>b&&f>e&&a.codes[b]==d.codes[e];)++b,++e;for(;c>b&&f>e&&a.codes[c-1]==d.codes[f-1];)--c,--f;if(b==c)for(;f>e;)d.modified[e++]=!0;else if(e==f)for(;c>b;)a.modified[b++]=!0;else{var i=this._sms(a,b,c,d,e,f,g,h);this._lcs(a,b,i.x,d,e,i.y,g,h),this._lcs(a,i.x,c,d,i.y,f,g,h)}},_sms:function(a,b,c,d,e,f,g,h){var i=a.codes.length+d.codes.length+1,j=b-e,k=c-f,l=c-b-(f-e),m=0!=(1&l),n=i-j,o=i-k,p=(c-b+f-e)/2+1;h[n+j+1]=b,g[o+k-1]=c;var r,s,t,u,q={x:0,y:0};for(r=0;p>=r;++r){for(s=j-r;j+r>=s;s+=2){for(s==j-r?t=h[n+s+1]:(t=h[n+s-1]+1,j+r>s&&h[n+s+1]>=t&&(t=h[n+s+1])),u=t-s;c>t&&f>u&&a.codes[t]==d.codes[u];)t++,u++;if(h[n+s]=t,m&&s>k-r&&k+r>s&&g[o+s]<=h[n+s])return q.x=h[n+s],q.y=h[n+s]-s,q}for(s=k-r;k+r>=s;s+=2){for(s==k+r?t=g[o+s-1]:(t=g[o+s+1]-1,s>k-r&&g[o+s-1]b&&u>e&&a.codes[t-1]==d.codes[u-1];)t--,u--;if(g[o+s]=t,!m&&s>=j-r&&j+r>=s&&g[o+s]<=h[n+s])return q.x=h[n+s],q.y=h[n+s]-s,q}}throw"the algorithm should never come here."},_optimize:function(a){for(var b=0,c=0;b=b.codes.length||a.modified[f]);)f++;for(;g=a.codes.length||b.modified[g]);)g++;(f>d||g>e)&&c.push({lhs_start:d,rhs_start:e,lhs_deleted_count:f-d,rhs_inserted_count:g-e})}return c}}),e.mergely=function(a,b){a&&this.init(a,b)},c.extend(e.mergely.prototype,{name:"mergely",init:function(a,b){this.diffView=new e.CodeMirrorDiffView(a,b),this.bind(a)},bind:function(a){this.diffView.bind(a)}}),e.CodeMirrorDiffView=function(a,b){d.defineExtension("centerOnCursor",function(){var a=this.cursorCoords(null,"local");this.scrollTo(null,(a.y+a.yBot)/2-this.getScrollerElement().clientHeight/2)}),this.init(a,b)},c.extend(e.CodeMirrorDiffView.prototype,{init:function(a,b){this.settings={autoupdate:!0,autoresize:!0,rhs_margin:"right",wrap_lines:!1,line_numbers:!0,lcs:!0,sidebar:!0,viewport:!1,ignorews:!1,fadein:"fast",editor_width:"650px",editor_height:"400px",resize_timeout:500,change_timeout:150,fgcolor:{a:"#4ba3fa",c:"#a3a3a3",d:"#ff7f7f",ca:"#4b73ff",cc:"#434343",cd:"#ff4f4f"},bgcolor:"#eee",vpcolor:"rgba(0, 0, 200, 0.5)",lhs:function(a){},rhs:function(a){},loaded:function(){},_auto_width:function(a){return a},resize:function(b){var d=b?16:0,e=c(a).parent().width()+d,f=0;"auto"==this.width?e=this._auto_width(e):(e=this.width,this.editor_width=e),"auto"==this.height?f=c(a).parent().height():(f=this.height,this.editor_height=f);var g=e/2-16-8,h=f,i=c(a);i.find(".mergely-column").css({width:g+"px"}),i.find(".mergely-column, .mergely-canvas, .mergely-margin, .mergely-column textarea, .CodeMirror-scroll, .cm-s-default").css({height:h+"px"}),i.find(".mergely-canvas").css({height:h+"px"}),i.find(".mergely-column textarea").css({width:g+"px"}),i.css({width:e,height:f,clear:"both"}),"none"==i.css("display")&&(0!=this.fadein?i.fadeIn(this.fadein):i.show(),this.loaded&&this.loaded()),this.resized&&this.resized()},_debug:"",resized:function(){}};var d={mode:"text/plain",readOnly:!1,lineWrapping:this.settings.wrap_lines,lineNumbers:this.settings.line_numbers,gutters:["merge","CodeMirror-linenumbers"]};this.lhs_cmsettings={},this.rhs_cmsettings={},this.element=c(a),b&&b.cmsettings&&c.extend(this.lhs_cmsettings,d,b.cmsettings,b.lhs_cmsettings),b&&b.cmsettings&&c.extend(this.rhs_cmsettings,d,b.cmsettings,b.rhs_cmsettings),this.element.bind("destroyed",c.proxy(this.teardown,this)),c.data(a,"mergely",this),this._setOptions(b)},unbind:function(){null!=this.changed_timeout&&clearTimeout(this.changed_timeout),this.editor[this.id+"-lhs"].toTextArea(),this.editor[this.id+"-rhs"].toTextArea(),c(a).off(".mergely")},destroy:function(){this.element.unbind("destroyed",this.teardown),this.teardown()},teardown:function(){this.unbind()},lhs:function(a){this.editor[this.id+"-lhs"].setValue(a)},rhs:function(a){this.editor[this.id+"-rhs"].setValue(a)},update:function(){this._changing(this.id+"-lhs",this.id+"-rhs")},unmarkup:function(){this._clear()},scrollToDiff:function(a){this.changes.length&&("next"==a?this._current_diff=Math.min(++this._current_diff,this.changes.length-1):"prev"==a&&(this._current_diff=Math.max(--this._current_diff,0)),this._scroll_to_change(this.changes[this._current_diff]),this._changed(this.id+"-lhs",this.id+"-rhs"))},mergeCurrentChange:function(a){this.changes.length&&("lhs"!=a||this.lhs_cmsettings.readOnly?"rhs"!=a||this.rhs_cmsettings.readOnly||this._merge_change(this.changes[this._current_diff],"lhs","rhs"):this._merge_change(this.changes[this._current_diff],"rhs","lhs"))},scrollTo:function(a,b){var c=this.editor[this.id+"-lhs"],d=this.editor[this.id+"-rhs"];"lhs"==a?(c.setCursor(b),c.centerOnCursor()):(d.setCursor(b),d.centerOnCursor())},_setOptions:function(a){if(c.extend(this.settings,a),this.settings.hasOwnProperty("rhs_margin"))if("left"==this.settings.rhs_margin)this.element.find(".mergely-margin:last-child").insertAfter(this.element.find(".mergely-canvas"));else{var b=this.element.find(".mergely-margin").last();b.appendTo(b.parent())}this.settings.hasOwnProperty("sidebar")&&(this.settings.sidebar?this.element.find(".mergely-margin").css({display:"block"}):this.element.find(".mergely-margin").css({display:"none"}));var d,e;this.settings.hasOwnProperty("wrap_lines")&&this.editor&&(d=this.editor[this.id+"-lhs"],e=this.editor[this.id+"-rhs"],d.setOption("lineWrapping",this.settings.wrap_lines),e.setOption("lineWrapping",this.settings.wrap_lines)),this.settings.hasOwnProperty("line_numbers")&&this.editor&&(d=this.editor[this.id+"-lhs"],e=this.editor[this.id+"-rhs"],d.setOption("lineNumbers",this.settings.line_numbers),e.setOption("lineNumbers",this.settings.line_numbers))},options:function(a){return a?(this._setOptions(a),this.settings.autoresize&&this.resize(),this.settings.autoupdate&&this.update(),void 0):this.settings},swap:function(){if(!this.lhs_cmsettings.readOnly&&!this.rhs_cmsettings.readOnly){var a=this.editor[this.id+"-lhs"],b=this.editor[this.id+"-rhs"],c=b.getValue();b.setValue(a.getValue()),a.setValue(c)}},merge:function(a){var b=this.editor[this.id+"-lhs"],c=this.editor[this.id+"-rhs"];"lhs"!=a||this.lhs_cmsettings.readOnly?this.rhs_cmsettings.readOnly||c.setValue(b.getValue()):b.setValue(c.getValue())},get:function(a){var b=this.editor[this.id+"-"+a],c=b.getValue();return void 0==c?"":c},clear:function(a){if(!("lhs"==a&&this.lhs_cmsettings.readOnly||"rhs"==a&&this.rhs_cmsettings.readOnly)){var b=this.editor[this.id+"-"+a];b.setValue("")}},cm:function(a){return this.editor[this.id+"-"+a]},search:function(a,b,c){var f,d=this.editor[this.id+"-lhs"],e=this.editor[this.id+"-rhs"];f="lhs"==a?d:e,c="prev"==c?"findPrevious":"findNext",(0==f.getSelection().length||this.prev_query[a]!=b)&&(this.cursor[this.id]=f.getSearchCursor(b,{line:0,ch:0},!1),this.prev_query[a]=b);var g=this.cursor[this.id];g[c]()?f.setSelection(g.from(),g.to()):g=f.getSearchCursor(b,{line:0,ch:0},!1)},resize:function(){this.settings.resize(),this._changing(this.id+"-lhs",this.id+"-rhs"),this._set_top_offset(this.id+"-lhs")},diff:function(){var a=this.editor[this.id+"-lhs"].getValue(),b=this.editor[this.id+"-rhs"].getValue(),c=new e.diff(a,b,this.settings);return c.normal_form()},bind:function(b){function r(a,b,d){if(!(d.target&&c(d.target).closest(".merge-button").length>0)){var e,f;for(e=0;e=f[a+"-line-from"]&&b<=f[a+"-line-to"]){this._current_diff=e,setTimeout(function(){this.scrollToDiff()}.bind(this),10);break}}}this.element.hide(),this.id=c(b).attr("id"),this.changed_timeout=null,this.chfns={},this.chfns[this.id+"-lhs"]=[],this.chfns[this.id+"-rhs"]=[],this.prev_query=[],this.cursor=[],this._skipscroll={},this.change_exp=new RegExp(/(\d+(?:,\d+)?)([acd])(\d+(?:,\d+)?)/);var e,f;if(void 0!=c.button)e='',f='';else{var g="opacity:0.4;width:10px;height:15px;background-color:#888;cursor:pointer;text-align:center;color:#eee;border:1px solid: #222;margin-right:5px;margin-top: -2px;";e='
<
',f='
>
'}this.merge_rhs_button=c(f),this.merge_lhs_button=c(e);var h=this.settings.editor_height,i=this.settings.editor_width;this.element.append(c('
')),this.element.append(c('
')),this.element.append(c('
'));var j=c('
');this.settings.sidebar||this.element.find(".mergely-margin").css({display:"none"}),"left"==this.settings.rhs_margin&&this.element.append(j),this.element.append(c('
')),"left"!=this.settings.rhs_margin&&this.element.append(j);var k=c('