Skip to content
Browse files

2.4 changes

Added editor ability to download .diff files
Added color settings
  • Loading branch information...
1 parent b9b5508 commit ae02695b13819fd48d6d2e2e6c9091faf7e904b8 @wickedest committed Apr 9, 2012
Showing with 1,167 additions and 1,203 deletions.
  1. +1 −1 LICENSE.html
  2. +1 −1 README.md
  3. +2 −43 doc/index.html
  4. +0 −5 lib/mergely.css
  5. +1,162 −1,147 lib/mergely.js
  6. +1 −6 lib/mergely.min.js
View
2 LICENSE.html
@@ -10,7 +10,7 @@
<body>
<h1>Software License Agreement</h1>
<p>
- <b>Mergely</b> - Copyright &copy; 2011, Jamie Peabody. All rights reserved.
+ <b>Mergely</b> - Copyright &copy; 2012, Jamie Peabody. All rights reserved.
</p>
<p>
Please see the <a href="http://www.mergely.com/license.php">Mergely license agreement</a>.
View
2 README.md
@@ -1,4 +1,4 @@
# Mergely
**An online diff/merge application**
-*Mergely is an online diff/merge editor and javascript library that highlights changes in similar texts. I can be used within your own web application to compare files, text, C, C++, Java, HTML, XML, CSS, and Javascript.
+Mergely is an online diff/merge editor and javascript library that highlights changes in similar texts. I can be used within your own web application to compare files, text, C, C++, Java, HTML, XML, CSS, and Javascript.
View
45 doc/index.html
@@ -8,65 +8,24 @@
<meta name="author" content="Jamie Peabody" />
<link rel="shortcut icon" href="http://www.mergely.com/favicon.ico" />
<link rel="canonical" href="http://www.mergely.com" />
-
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans:bold"/>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
- <link type="text/css" rel="stylesheet" href="/style/mergely-theme/jquery-ui-1.8.16.custom.css" />
- <script src="/api/examples/jquery.corner.js" type="text/javascript"></script>
- <link type="text/css" rel="stylesheet" href="/api/lib/mergely.css" />
- <link type="text/css" rel="stylesheet" href="/style/editor.css" />
- <link type="text/css" rel="stylesheet" href="/style/screen.css" />
<style type="text/css">
body { font-family: Droid Sans, Arial, sans-serif; }
pre.code { border: 1px solid #37AFFF; background-color: #efefef; padding: 12px; }
dt { color: #3FA6EA; font-weight: bold; }
dd { margin-bottom: 1em; }
h1 { margin-top: 0px; }
+ .code { border-radius: 8px; }
</style>
- <script type="text/javascript">
- $(document).ready(function(){
- $('.code').corner('8px');
- $('#editor,#download').css({'visibility':'visible'}).button().click(function(){
- window.location.href = $(this).attr('formaction');
- });
- $('#editor').css({'float':'right'});
- });
- </script>
-
- <script src="http://www.mergely.com/js/gatag.js" type="text/javascript"></script>
- <script type="text/javascript">
- var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-85576-5']);
- _gaq.push(['_trackPageview']);
- (function() {
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
- })();
- </script>
- <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
</head>
<body>
<div class="main">
- <div id="header">
- <div id="info">
- <h3>Mergely - Diff online!</h3>
- <div id="logo"></div>
- <button id="editor" class="button-editor" title="Switch to Mergely Editor" type="submit" formaction="/index.php" formmethod="get">Editor</button>
- <div style="float:right;width:80px;padding-top:6px;height:30px;display:inline-block;">
- <g:plusone></g:plusone>
- </div>
- </div>
- </div>
-
<div id="body">
<div id="bodycontent" style="margin-right:0px;">
- <h1>Mergely Manual</h1>
+ <h1>Mergely Reference Manual</h1>
<h2>Overview</h2>
<p>
View
5 lib/mergely.css
@@ -1,8 +1,3 @@
-/**
- * Copyright (c) 2012 by Jamie Peabody, http://www.mergely.com/
- * All rights reserved.
- * Version: 2.3 2012-02-07
- */
/* required */
.mergely-column textarea { width: 80px; height: 200px; }
.mergely-column { float: left; }
View
2,309 lib/mergely.js
1,162 additions, 1,147 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
7 lib/mergely.min.js
@@ -1,6 +1 @@
-/**
- * Copyright (c) 2012 by Jamie Peabody, http://www.mergely.com/
- * All rights reserved.
- * Version: 2.3 2012-02-07
- */
-Mgly={},Object.size=function(a){var b=0,c;for(c in a)a.hasOwnProperty(c)&&b++;return b},Mgly.LCS=function(a,b){this.length=this._lcs(a,b);var c=[];a=a.split(""),b=b.split(""),a.unshift(""),b.unshift(""),this.C=c,this.x=a,this.y=b;var d=0,e=0;for(d=0;d<a.length+1;++d){c[d]=[];for(e=0;e<b.length+1;++e)c[d][e]=0}for(d=1;d<a.length+1;++d)for(e=1;e<b.length+1;++e)a[d-1]==b[e-1]?c[d][e]=c[d-1][e-1]+1:c[d][e]=Math.max(c[d][e-1],c[d-1][e]);this.ready=1},Mgly.LCS.prototype.clear=function(){this.ready=0},Mgly.LCS.prototype._diff=function(a,b,c,d){var e=this.x,f=this.y,g=this.C;this.ready&&a>0&&b>0&&e[a]==f[b]?this._diff(a-1,b-1,c,d):b>0&&(a==0||g[a][b-1]>=g[a-1][b])?(this._diff(a,b-1,c,d),c&&c(b-1,f[b])):a>0&&(b==0||g[a][b-1]<g[a-1][b])&&(this._diff(a-1,b,c,d),d&&d(a-1,e[a]))},Mgly.LCS.prototype.diff=function(a,b){this._diff(this.x.length-1,this.y.length-1,a,b)},Mgly.LCS.prototype._lcs=function(c,d){var e=0,f=Array(c.length);for(a=0;a<=c.length;a++){f[a]=Array(d.length);for(b=0;b<=d.length;b++)f[a][b]=0}for(var g=0;g<c.length;g++)for(var h=0;h<d.length;h++)c[g]==d[h]?(f[g][h]==0?f[g+1][h+1]=1:f[g+1][h+1]=f[g][h]+1,f[g+1][h+1]>e&&(e=f[g+1][h+1])):f[g+1][h+1]=0;return e},Mgly.diff=function(a,b){this.diff_codes={},this.max_code=0;var c=a.split("\n"),d=b.split("\n");a.length==0&&(c=[]),b.length==0&&(d=[]);var e=new Object;e.data=this._diff_codes(c),e.modified={},e.length=Object.size(e.data);var f=new Object;f.data=this._diff_codes(d),f.modified={},f.length=Object.size(f.data);var g=e.length+f.length+1,h=Array(2*g+2),i=Array(2*g+2);this._lcs(e,0,e.length,f,0,f.length,i,h),this._optimize(e),this._optimize(f),this.items=this._create_diffs(e,f)},Mgly.diff.prototype.changes=function(){return this.items},Mgly.diff.prototype.normal_form=function(){var a="";for(var b in this.items){var c=this.items[b],d="",e="",f="c";c.lhs_deleted_count==0&&c.rhs_inserted_count>0?f="a":c.lhs_deleted_count>0&&c.rhs_inserted_count==0&&(f="d"),c.lhs_deleted_count==1?d=c.lhs_start+1:c.lhs_deleted_count==0?d=c.lhs_start:d=c.lhs_start+1+","+(c.lhs_start+c.lhs_deleted_count),c.rhs_inserted_count==1?e=c.rhs_start+1:c.rhs_inserted_count==0?e=c.rhs_start:e=c.rhs_start+1+","+(c.rhs_start+c.rhs_inserted_count),a+=d+f+e+"\n"}return a},Mgly.diff.prototype._diff_codes=function(a){var b=this.max_code,c={};for(var d=0;d<a.length;++d){var e=a[d],f=this.diff_codes[e];f!=undefined?c[d]=f:(this.max_code++,this.diff_codes[e]=this.max_code,c[d]=this.max_code)}return c},Mgly.diff.prototype._lcs=function(a,b,c,d,e,f,g,h){while(b<c&&e<f&&a.data[b]==d.data[e])++b,++e;while(b<c&&e<f&&a.data[c-1]==d.data[f-1])--c,--f;if(b==c)while(e<f)d.modified[e++]=!0;else if(e==f)while(b<c)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)}},Mgly.diff.prototype._sms=function(a,b,c,d,e,f,g,h){var i=a.length+d.length+1,j=b-e,k=c-f,l=c-b-(f-e),m=(l&1)!=0,n=i-j,o=i-k,p=(c-b+f-e)/2+1;h[n+j+1]=b,g[o+k-1]=c;var q=new Object;for(var r=0;r<=p;++r){for(var s=j-r;s<=j+r;s+=2){var t,u;s==j-r?t=h[n+s+1]:(t=h[n+s-1]+1,s<j+r&&h[n+s+1]>=t&&(t=h[n+s+1])),u=t-s;while(t<c&&u<f&&a.data[t]==d.data[u])t++,u++;h[n+s]=t;if(m&&k-r<s&&s<k+r&&g[o+s]<=h[n+s])return q.x=h[n+s],q.y=h[n+s]-s,q}for(var s=k-r;s<=k+r;s+=2){var t,u;s==k+r?t=g[o+s-1]:(t=g[o+s+1]-1,s>k-r&&g[o+s-1]<t&&(t=g[o+s-1])),u=t-s;while(t>b&&u>e&&a.data[t-1]==d.data[u-1])t--,u--;g[o+s]=t;if(!m&&j-r<=s&&s<=j+r&&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."},Mgly.diff.prototype._optimize=function(a){var b=0,c=0;while(b<a.length){while(b<a.length&&(a.modified[b]==undefined||a.modified[b]==0))b++;c=b;while(c<a.length&&a.modified[c]==1)c++;c<a.length&&a.data[b]==a.data[c]?(a.modified[b]=!1,a.modified[c]=!0):b=c}},Mgly.diff.prototype._create_diffs=function(a,b){var c=[],d=0,e=0,f=0,g=0;while(f<a.length||g<b.length)if(f<a.length&&!a.modified[f]&&g<b.length&&!b.modified[g])f++,g++;else{d=f,e=g;while(f<a.length&&(g>=b.length||a.modified[f]))f++;while(g<b.length&&(f>=a.length||b.modified[g]))g++;if(d<f||e<g){var h=new Object;h.lhs_start=d,h.rhs_start=e,h.lhs_deleted_count=f-d,h.rhs_inserted_count=g-e,c.push(h)}}return c},Mgly.mergely=function(a,b){a&&this.init(a,b)},$.extend(Mgly.mergely.prototype,{name:"mergely",init:function(a,b){this.settings={autoresize:!0,fadein:"fast",editor_width:"400px",editor_height:"400px",resize_timeout:500,change_timeout:150,fgcolor:"#4ba3fa",bgcolor:"#eee",lhs:function(a){},rhs:function(a){},loaded:function(){},height:function(a){return a-20},width:function(a){return a},resize:function(){var b=$(a).parent().width(),c=$(window).height();this.width&&(b=this.width(b)),this.height&&(c=this.height(c));var d=b/2-16-8,e=c,f=$(a);f.find(".mergely-column, .CodeMirror-scroll").css({width:d+"px"}),f.find(".mergely-column, .mergely-canvas, .mergely-margin, .mergely-column textarea, .CodeMirror-scroll").css({height:e+"px"}),f.find(".mergely-canvas").css({height:e+"px"}),f.find(".mergely-column textarea").css({width:d+"px"}),f.css({width:b+"px",height:c+"px"}),f.css("display")=="none"&&(this.fadein!=0?f.fadeIn(this.fadein):f.show(),this.loaded&&this.loaded()),this.resized&&this.resized()},_debug:"",resized:function(){}},this.cmsettings={mode:"application/xml",readOnly:!1,lineWrapping:!1,lineNumbers:!0},this.element=$(a),b.cmsettings&&$.extend(this.cmsettings,b.cmsettings),b&&$.extend(this.settings,b),this.element.bind("destroyed",$.proxy(this.teardown,this)),$.data(a,this.name,this),this._setup(a)},bind:function(){var a=this;this.editor=[];var b=jQuery.extend({onChange:function(){a._changing(a.id+"-lhs",a.id+"-rhs")},onScroll:function(){a._scrolling(a.id+"-lhs")}},this.cmsettings);this.editor[this.id+"-lhs"]=CodeMirror.fromTextArea($("#"+this.id+"-lhs").get(0),b);var c=jQuery.extend({onChange:function(){a._changing(a.id+"-lhs",a.id+"-rhs")},onScroll:function(){a._scrolling(a.id+"-rhs")}},this.cmsettings);this.editor[this.id+"-rhs"]=CodeMirror.fromTextArea($("#"+this.id+"-rhs").get(0),c);var d=null;$(window).resize(function(){d&&clearTimeout(d),d=setTimeout(function(){a.em_height=null,a.settings.resize&&a.settings.resize(),a.editor[a.id+"-lhs"].refresh(),a.editor[a.id+"-rhs"].refresh(),a._changing(a.id+"-lhs",a.id+"-rhs")},a.settings.resize_timeout)})},unbind:function(){this.editor[this.id+"-lhs"].toTextArea(),this.editor[this.id+"-rhs"].toTextArea()},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)},swap:function(){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"];a=="lhs"?b.setValue(c.getValue()):c.setValue(b.getValue())},get:function(a){var b=this.editor[this.id+"-"+a],c=b.getValue();return c==undefined?"":c},clear:function(a){var b=this.editor[this.id+"-"+a];b.setValue("")},search:function(a,b){var c=this.editor[this.id+"-lhs"],d=this.editor[this.id+"-rhs"],e;a=="lhs"?e=c:e=d;if(e.getSelection().length==0||this.prev_query[a]!=b)this.cursor[this.id]=e.getSearchCursor(b,{line:0,ch:0},!1),this.prev_query[a]=b;this.cursor[this.id].findNext()?e.setSelection(this.cursor[this.id].from(),this.cursor[this.id].to()):this.cursor[this.id]=e.getSearchCursor(b,{line:0,ch:0},!1)},resize:function(){this.settings.resize(),this._changing(this.id+"-lhs",this.id+"-rhs")},_setup:function(a){$(this.element).hide(),this.id=$(a).attr("id");var b=this.settings.editor_height,c=this.settings.editor_width;this.changed_timeout=null,this.change_funcs=[],this.prev_query=[],this.cursor=[],this.change_exp=new RegExp(/(\d+(?:,\d+)?)([acd])(\d+(?:,\d+)?)/);var d,e;if($.button!=undefined)d='<button title="Merge left"></button>',e='<button title="Merge right"></button>';else{var f="width:1em;height:1em;background-color:#888;cursor:pointer;text-align:center;color:#eee;border:1px solid: #222;margin-right:5px;";d='<div style="'+f+'" title="Merge left">&lt;</div>',e='<div style="'+f+'" title="Merge right">&gt;</div>'}this.merge_right_button=$(e),this.merge_left_button=$(d),this.merge_right_button.corner&&this.merge_right_button.corner("3px"),this.merge_left_button.corner&&this.merge_left_button.corner("3px"),$(this.element).append($('<div class="mergely-margin" style="height: '+b+'"><canvas id="'+this.id+'-lhs-margin" width="8" height="'+b+'"></canvas></div>')),$(this.element).append($('<div style="width:'+c+"; height:"+b+'" id="'+this.id+'-editor-lhs" class="mergely-column"><textarea style="" id="'+this.id+'-lhs"></textarea></div>')),$(this.element).append($('<div class="mergely-canvas" style="height: '+b+'"><canvas id="'+this.id+"-lhs-"+this.id+'-rhs-canvas" width="28" height="'+b+'"></canvas></div>')),$(this.element).append($('<div style="width:'+c+"; height:"+b+'" id="'+this.id+'-editor-rhs" class="mergely-column"><textarea style="" id="'+this.id+'-rhs"></textarea></div>')),$(this.element).append($('<div class="mergely-margin" style="height: '+b+'"><canvas id="'+this.id+'-rhs-margin" width="8" height="'+b+'"></canvas></div>')),this.bind(),this.settings.lhs&&this.settings.lhs(this.editor[this.id+"-lhs"].setValue),this.settings.rhs&&this.settings.rhs(this.editor[this.id+"-rhs"].setValue),$(window).resize();var g="#"+this.id+" .CodeMirror-gutter-text { padding: 5px 0 0 0; }"+"#"+this.id+" .CodeMirror-lines pre, "+"#"+this.id+" .CodeMirror-gutter-text pre { line-height: 18px; }";this.settings.autoresize&&(g+=this.id+" .CodeMirror-scroll { height: 100%; overflow: auto; }"),$('<style type="text/css">'+g+"</style>").appendTo("head")},_scrolling:function(a){var b=$(this.editor[a].getScrollerElement());this.midway==undefined&&(this.midway=(b.height()/2+b.offset().top).toFixed(2));var c=this.editor[a].coordsChar({x:0,y:this.midway}),d=b.scrollTop(),e=b.scrollLeft();this.trace("scroll","midway",this.midway),this.trace("scroll","midline",c),this.trace("scroll","top_to",d),this.trace("scroll","left_to",e);for(var f in this.editor){if(a==f)continue;var g=a.replace(this.id+"-",""),h=f.replace(this.id+"-",""),i=0,j=null;for(var k in this.changes){var l=this.changes[k];c.line>=l[g+"-line-from"]&&(j=l,c.line>=j[g+"-line-to"]&&(i+=l[g+"-y-end"]-l[g+"-y-start"]-(l[h+"-y-end"]-l[h+"-y-start"])))}var m=!0;j&&(this.trace("scroll","last visible change",j),j[g+"-line-from"]<c.line&&j[g+"-line-to"]>c.line&&(m=!1));if(m){this.trace("scroll","scrolling other side",d-i);var b=$(this.editor[f].getScrollerElement());b.scrollTop(d-i).scrollLeft(e)}else this.trace("scroll","not scrolling other side");this._calculate_offsets(this.id+"-lhs",this.id+"-rhs",this.changes),this._draw_diff(this.id+"-lhs",this.id+"-rhs",this.changes),this.trace("scroll","scrolled")}},_changing:function(a,b){var c=this;this.changed_timeout!=null&&clearTimeout(this.changed_timeout),this.changed_timeout=setTimeout(function(){c._changed(a,b)},this.settings.change_timeout)},_changed:function(a,b){for(var c in this.editor){var d=this.editor[c];d.operation(function(){for(var a=0,b=d.lineCount();a<b;++a)d.clearMarker(a),d.setLineClass(a,null)})}for(var e in this.change_funcs){var f=this.change_funcs[e];f.clear!=undefined?f.clear():f()}this._diff(a,b)},_diff:function(a,b){var c=this.editor[a].getValue(),d=this.editor[b].getValue(),e=new Mgly.diff(c,d);this.changes=this._parse_diff(a,b,e.normal_form()),this._calculate_offsets(a,b,this.changes),this._markup_changes(a,b,this.changes),this._draw_diff(a,b,this.changes)},_parse_diff:function(a,b,c){this.trace("diff","diff results:\n",c);var d=[],e=0,f=c.split(/\n/);for(var g=0;g<f.length;++g){if(f[g].length==0)continue;var h={},i=this.change_exp.exec(f[g]);if(i==null)continue;var j=i[1].split(",");h["lhs-line-from"]=j[0]-1,j.length==1?h["lhs-line-to"]=j[0]-1:h["lhs-line-to"]=j[1]-1;var k=i[3].split(",");h["rhs-line-from"]=k[0]-1,k.length==1?h["rhs-line-to"]=k[0]-1:h["rhs-line-to"]=k[1]-1,h.op=i[2],d[e++]=h,this.trace("diff","change",h)}return d},_calculate_offsets:function(a,b,c){if(this.draw_top_offset==null){var d=this.element.find(".CodeMirror-gutter-text pre").first(),e=d.offset().top;this.em_height=d.get(0).offsetHeight,this.draw_top_offset=6.5-e,this.em_height>0&&(this.draw_lhs_min=.5,this.draw_rhs_max=$("#"+a+"-"+b+"-canvas").width()-.5,this.draw_lhs_width=5,this.draw_rhs_width=5),this.trace("calc","change offsets calculated","top_offset",e)}for(var f in c){var g=c[f];g["lhs-y-start"]=this.draw_top_offset+this.editor[a].charCoords({line:g["lhs-line-from"],ch:0}).y,g["lhs-y-end"]=this.draw_top_offset+this.editor[a].charCoords({line:g["lhs-line-to"]+1,ch:0}).y-1,g["rhs-y-start"]=this.draw_top_offset+this.editor[b].charCoords({line:g["rhs-line-from"],ch:0}).y,g["rhs-y-end"]=this.draw_top_offset+this.editor[b].charCoords({line:g["rhs-line-to"]+1,ch:0}).y-1,g["op"]=="d"?g["rhs-y-start"]=g["rhs-y-end"]:g["op"]=="a"&&(g["lhs-y-start"]=g["lhs-y-end"]),this.trace("calc","change offsets calculated",f,g)}},_markup_changes:function(a,b,c){$(".merge-button").remove();var d=this.editor[a];d.operation(function(){for(var a in c){var b=c[a],e="mergely-"+b.op+"-start",f="mergely-"+b.op+"-end",g=e+" "+f;if(b["lhs-line-from"]==b["lhs-line-to"])b["op"]=="c"?d.setLineClass(b["lhs-line-from"],g):b["op"]=="a"?d.setLineClass(b["lhs-line-from"],f+"-lhs"):b["op"]=="d"&&d.setLineClass(b["lhs-line-from"],g+" mergely-c-rem");else{d.setLineClass(b["lhs-line-from"],e+(b["op"]=="d"?" mergely-c-rem":"")),d.setLineClass(b["lhs-line-to"],f+(b["op"]=="d"?" mergely-c-rem":""));if(b["op"]=="d")for(var h=b["lhs-line-from"]+1;h<b["lhs-line-to"];++h)d.setLineClass(h,"mergely-c-rem mergely-d-mid")}}});var d=this.editor[b];d.operation(function(){for(var a in c){var b=c[a],e="mergely-"+b.op+"-start",f="mergely-"+b.op+"-end",g=e+" "+f;if(b["rhs-line-from"]==b["rhs-line-to"])b["op"]=="c"?d.setLineClass(b["rhs-line-from"],g):b["op"]=="a"?d.setLineClass(b["rhs-line-from"],g):b["op"]=="d"&&d.setLineClass(b["rhs-line-from"],f+"-rhs");else{d.setLineClass(b["rhs-line-from"],e),d.setLineClass(b["rhs-line-to"],f);if(b["op"]=="a")for(var h=b["rhs-line-from"]+1;h<b["rhs-line-to"];++h)d.setLineClass(h,"mergely-c-add mergely-a-mid")}}});for(var e in c){var f=c[e],g="mergely-"+f.op+"-start",h="mergely-"+f.op+"-end",i=g+" "+h;if(!this.cmsettings.readOnly){var j=this.merge_right_button.clone();j.button&&j.button({icons:{primary:"ui-icon-triangle-1-e"},text:!1}),j.addClass("merge-button"),j.attr("id","merge-right-"+e);var k=this;$(j).get(0).onclick=function(c){return function(){var d=k.editor[a].lineInfo(c["lhs-line-to"]),e=k.editor[b].lineInfo(c["rhs-line-to"]),f=k.editor[a].getRange({line:c["lhs-line-from"],ch:0},{line:c["lhs-line-to"],ch:d.text.length});if(c["op"]=="c")k.editor[b].replaceRange(f,{line:c["rhs-line-from"],ch:0},{line:c["rhs-line-to"],ch:e.text.length});else if(c["op"]=="a"){var g=parseInt(c["rhs-line-from"]),h=parseInt(c["rhs-line-to"]);for(var i=h;i>=g;--i)k.editor[b].removeLine(i)}else f+="\n",k.editor[b].replaceRange(f,{line:c["rhs-line-from"]+1,ch:0});return k.editor[a].setValue(k.editor[a].getValue()),k.editor[b].setValue(k.editor[b].getValue()),!1}}(f),this.trace("markup","lhs adding button",f["lhs-line-from"]),this.editor[a].addWidget({line:f["lhs-line-from"],ch:0},j.get(0),!1,"over","right"),j=this.merge_left_button.clone(),j.button&&j.button({icons:{primary:"ui-icon-triangle-1-w"},text:!1}),j.addClass("merge-button"),j.attr("id","merge-left-"+e);var k=this;$(j).get(0).onclick=function(c){return function(){var d=k.editor[a].lineInfo(c["lhs-line-to"]),e=k.editor[b].lineInfo(c["rhs-line-to"]),f=k.editor[b].getRange({line:c["rhs-line-from"],ch:0},{line:c["rhs-line-to"],ch:e.text.length});if(c["op"]=="c")k.editor[a].replaceRange(f,{line:c["lhs-line-from"],ch:0},{line:c["lhs-line-to"],ch:d.text.length});else if(c["op"]=="d"){var g=parseInt(c["lhs-line-from"]),h=parseInt(c["lhs-line-to"]);for(var i=h;i>=g;--i)k.editor[a].removeLine(i)}else f+="\n",k.editor[a].replaceRange(f,{line:c["lhs-line-from"]+1,ch:0});return k.editor[a].setValue(k.editor[a].getValue()),k.editor[b].setValue(k.editor[b].getValue()),!1}}(f),this.trace("markup","rhs adding button",f["rhs-line-from"]),this.editor[b].addWidget({line:f["rhs-line-from"],ch:0},j.get(0),!1,"over","right")}if(f["op"]=="a"){var l=f["rhs-line-from"],m=f["rhs-line-to"],n=this.editor[b].lineInfo(m);if(n){var o=this.editor[b].markText({line:l,ch:0},{line:m,ch:n.text.length},"mergely-c-add");this.change_funcs.push(o)}continue}if(f["op"]=="d"){var l=f["lhs-line-from"],m=f["lhs-line-to"],n=this.editor[a].lineInfo(m);if(n){var o=this.editor[a].markText({line:l,ch:0},{line:m,ch:n.text.length},"mergely-c-rem");this.change_funcs.push(o)}continue}var k=this;for(var p=f["lhs-line-from"],q=f["rhs-line-from"],e=0;p>=0&&p<=f["lhs-line-to"]||q>=0&&q<=f["rhs-line-to"];++p,++q){if(q+e>f["rhs-line-to"]){var r=this.editor[a].getLine(p),o=this.editor[a].markText({line:p,ch:0},{line:p,ch:r.length},"mergely-c-rem");this.change_funcs.push(o);continue}if(p+e>f["lhs-line-to"]){var s=this.editor[b].getLine(q),o=this.editor[a].markText({line:q,ch:0},{line:q,ch:r.length},"mergely-c-add");this.change_funcs.push(o);continue}var r=this.editor[a].getLine(p),s=this.editor[b].getLine(q),t={line:-1,ch:-1},u={line:-1,ch:-1},v={line:-1,ch:-1},w={line:-1,ch:-1},x=new Mgly.LCS(r,s),y=Math.max(r.length,s.length);y==0&&(y=1);var z=1*x.length/y*100;z<10&&x.clear(),x.diff(added=function(a,c){if(v.ch<0)v.line=q,v.ch=a,w.line=q,w.ch=a;else if(a==w.ch+1)w.ch=a;else{if(v.ch>=0&&w.ch>=v.ch){w.ch+=1;var d=k.editor[b].markText(v,w,"mergely-c-add");k.change_funcs.push(d)}v.ch=-1,w.ch=-1,c!="\n"&&this.added(a,c)}},removed=function(b,c){if(t.ch<0)t.line=p,t.ch=b,u.line=p,u.ch=b;else if(b==u.ch+1)u.ch=b;else{if(t.ch>=0&&u.ch>=t.ch){u.ch+=1;var d=k.editor[a].markText(t,u,"mergely-c-rem");k.change_funcs.push(d)}t.ch=-1,u.ch=-1,c!="\n"&&this.removed(b,c)}});if(v.ch>=0&&w.ch>=v.ch){w.ch+=1;var o=this.editor[b].markText(v,w,"mergely-c-add");this.change_funcs.push(o)}if(t.ch>=0&&u.ch>=t.ch){u.ch+=1;var o=this.editor[a].markText(t,u,"mergely-c-rem");this.change_funcs.push(o)}}}},_draw_diff:function(a,b,c){var d=$(this.editor[a].getScrollerElement()).height(),e=$(this.editor[a].getScrollerElement()).children(":first-child").height(),f=d/e,g=d/e,h=$(this.editor[a].getScrollerElement()),i=$(this.editor[b].getScrollerElement()),j=this.editor[a].lineCount(),k=this.editor[b].lineCount();this.trace("draw","visible_page_height",d),this.trace("draw","gutter_height",e),this.trace("draw","visible_page_ratio",f),this.trace("draw","lhs-scroller-top",h.scrollTop()),this.trace("draw","rhs-scroller-top",i.scrollTop());var l=document.getElementById(a+"-"+b+"-canvas");if(l==undefined)throw"Failed to find: "+a+"-"+b+"-canvas";$.each($("canvas"),function(){$(this).get(0).height=d});var m=$("#"+this.id+"-lhs-margin"),n=$("#"+this.id+"-rhs-margin");m.unbind("click"),n.unbind("click");var o=m.get(0),p=n.get(0),q=$(m).offset(),r=$(n).offset(),s=l.getContext("2d"),t=o.getContext("2d"),u=p.getContext("2d");t.beginPath(),t.fillStyle=this.settings.bgcolor,t.strokeStyle="#888",t.fillRect(0,0,6.5,d),t.strokeRect(0,0,6.5,d),u.beginPath(),u.fillStyle=this.settings.bgcolor,u.strokeStyle="#888",u.fillRect(0,0,6.5,d),u.strokeRect(0,0,6.5,d);for(var v in c){var w=c[v],x=w["lhs-y-start"],y=w["lhs-y-end"],z=w["rhs-y-start"],A=w["rhs-y-end"];s.beginPath(),s.strokeStyle=this.settings.fgcolor,s.lineWidth=1,s.moveTo(this.draw_lhs_min,x),s.lineTo(this.draw_lhs_min+this.draw_lhs_width,x),s.lineTo(this.draw_lhs_min+this.draw_lhs_width,y+1),s.lineTo(this.draw_lhs_min,y+1),s.stroke(),s.moveTo(this.draw_rhs_max,z),s.lineTo(this.draw_rhs_max-this.draw_rhs_width,z),s.lineTo(this.draw_rhs_max-this.draw_rhs_width,A+1),s.lineTo(this.draw_rhs_max,A+1),s.stroke(),s.moveTo(this.draw_lhs_min+this.draw_lhs_width,x+(y+1-x)/2),s.lineTo(this.draw_rhs_max-this.draw_rhs_width,z+(A+1-z)/2),s.stroke(),this.trace("draw",w),x=(w["lhs-y-start"]+h.scrollTop())*f,y=(w["lhs-y-end"]+h.scrollTop())*f+1,z=(w["rhs-y-start"]+i.scrollTop())*f,A=(w["rhs-y-end"]+i.scrollTop())*f+1,this.trace("draw","marker calculated",x,y,z,A),t.beginPath(),t.fillStyle=this.settings.fgcolor,t.strokeStyle="#000",t.lineWidth=.5,t.fillRect(1.5,x,4.5,Math.max(y-x,5)),t.strokeRect(1.5,x,4.5,Math.max(y-x,5)),u.beginPath(),u.fillStyle=this.settings.fgcolor,u.strokeStyle="#000",u.lineWidth=.5,u.fillRect(1.5,z,4.5,Math.max(A-z,5)),u.strokeRect(1.5,z,4.5,Math.max(A-z,5))}t.fillStyle="rgba(0, 0, 200, 0.5)",u.fillStyle="rgba(0, 0, 200, 0.5)";var B=m.height()*f,C=h.scrollTop()/e*m.height();this.trace("draw","cls.height",m.height()),this.trace("draw","lhs_scroller.scrollTop()",h.scrollTop()),this.trace("draw","gutter_height",e),this.trace("draw","visible_page_ratio",f),this.trace("draw","from",C,"to",B),t.fillRect(1.5,C,4.5,B),u.fillRect(1.5,C,4.5,B),m.click(function(a){var b=a.pageY-q.top-B/2,c=Math.max(0,b/o.height*h.get(0).scrollHeight);h.scrollTop(c)}),n.click(function(a){var b=a.pageY-r.top-B/2,c=Math.max(0,b/p.height*i.get(0).scrollHeight);i.scrollTop(c)})},trace:function(a){this.settings._debug.indexOf(a)>=0&&(arguments[0]=a+":",console.log(this,[].slice.apply(arguments)))}}),$.pluginMaker=function(a){$.fn[a.prototype.name]=function(b){var c=$.makeArray(arguments),d=c.slice(1),e=undefined;this.each(function(){var f=$.data(this,a.prototype.name);if(f){if(typeof b=="string")e=f[b].apply(f,d);else if(f.update)return alert("here"),f.update.apply(f,c)}else new a(this,b)});if(e!=undefined)return e}},$.pluginMaker(Mgly.mergely)
+Mgly={},Object.size=function(a){var b=0,c;for(c in a)a.hasOwnProperty(c)&&b++;return b},Mgly.LCS=function(a,b){this.length=this._lcs(a,b);var c=[];a=a.split(""),b=b.split(""),a.unshift(""),b.unshift(""),this.C=c,this.x=a,this.y=b;var d=0,e=0;for(d=0;d<a.length+1;++d){c[d]=[];for(e=0;e<b.length+1;++e)c[d][e]=0}for(d=1;d<a.length+1;++d)for(e=1;e<b.length+1;++e)a[d-1]==b[e-1]?c[d][e]=c[d-1][e-1]+1:c[d][e]=Math.max(c[d][e-1],c[d-1][e]);this.ready=1},Mgly.LCS.prototype.clear=function(){this.ready=0},Mgly.LCS.prototype._diff=function(a,b,c,d){var e=this.x,f=this.y,g=this.C;this.ready&&a>0&&b>0&&e[a]==f[b]?this._diff(a-1,b-1,c,d):b>0&&(a==0||g[a][b-1]>=g[a-1][b])?(this._diff(a,b-1,c,d),c&&c(b-1,f[b])):a>0&&(b==0||g[a][b-1]<g[a-1][b])&&(this._diff(a-1,b,c,d),d&&d(a-1,e[a]))},Mgly.LCS.prototype.diff=function(a,b){this._diff(this.x.length-1,this.y.length-1,a,b)},Mgly.LCS.prototype._lcs=function(c,d){var e=0,f=Array(c.length);for(a=0;a<=c.length;a++){f[a]=Array(d.length);for(b=0;b<=d.length;b++)f[a][b]=0}for(var g=0;g<c.length;g++)for(var h=0;h<d.length;h++)c[g]==d[h]?(f[g][h]==0?f[g+1][h+1]=1:f[g+1][h+1]=f[g][h]+1,f[g+1][h+1]>e&&(e=f[g+1][h+1])):f[g+1][h+1]=0;return e},Mgly.diff=function(a,b,c){this.diff_codes={},this.max_code=0;var d=a.split("\n"),e=b.split("\n");a.length==0&&(d=[]),b.length==0&&(e=[]);var f=new Object;f.data=this._diff_codes(d),f.modified={},f.length=Object.size(f.data);var g=new Object;g.data=this._diff_codes(e),g.modified={},g.length=Object.size(g.data);var h=f.length+g.length+1,i=Array(2*h+2),j=Array(2*h+2);this._lcs(f,0,f.length,g,0,g.length,j,i),this._optimize(f),this._optimize(g),this.items=this._create_diffs(f,g),c&&(this.lhs_lines=d,this.rhs_lines=e)},Mgly.diff.prototype.changes=function(){return this.items},Mgly.diff.prototype.normal_form=function(){var a="";for(var b in this.items){var c=this.items[b],d="",e="",f="c";c.lhs_deleted_count==0&&c.rhs_inserted_count>0?f="a":c.lhs_deleted_count>0&&c.rhs_inserted_count==0&&(f="d"),c.lhs_deleted_count==1?d=c.lhs_start+1:c.lhs_deleted_count==0?d=c.lhs_start:d=c.lhs_start+1+","+(c.lhs_start+c.lhs_deleted_count),c.rhs_inserted_count==1?e=c.rhs_start+1:c.rhs_inserted_count==0?e=c.rhs_start:e=c.rhs_start+1+","+(c.rhs_start+c.rhs_inserted_count),a+=d+f+e+"\n";if(this.rhs_lines&&this.lhs_lines){for(var g=c.lhs_start;g<c.lhs_start+c.lhs_deleted_count;++g)a+="< "+this.lhs_lines[g]+"\n";c.rhs_inserted_count&&c.lhs_deleted_count&&(a+="---\n");for(var g=c.rhs_start;g<c.rhs_start+c.rhs_inserted_count;++g)a+="> "+this.rhs_lines[g]+"\n"}}return a},Mgly.diff.prototype._diff_codes=function(a){var b=this.max_code,c={};for(var d=0;d<a.length;++d){var e=a[d],f=this.diff_codes[e];f!=undefined?c[d]=f:(this.max_code++,this.diff_codes[e]=this.max_code,c[d]=this.max_code)}return c},Mgly.diff.prototype._lcs=function(a,b,c,d,e,f,g,h){while(b<c&&e<f&&a.data[b]==d.data[e])++b,++e;while(b<c&&e<f&&a.data[c-1]==d.data[f-1])--c,--f;if(b==c)while(e<f)d.modified[e++]=!0;else if(e==f)while(b<c)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)}},Mgly.diff.prototype._sms=function(a,b,c,d,e,f,g,h){var i=a.length+d.length+1,j=b-e,k=c-f,l=c-b-(f-e),m=(l&1)!=0,n=i-j,o=i-k,p=(c-b+f-e)/2+1;h[n+j+1]=b,g[o+k-1]=c;var q=new Object;for(var r=0;r<=p;++r){for(var s=j-r;s<=j+r;s+=2){var t,u;s==j-r?t=h[n+s+1]:(t=h[n+s-1]+1,s<j+r&&h[n+s+1]>=t&&(t=h[n+s+1])),u=t-s;while(t<c&&u<f&&a.data[t]==d.data[u])t++,u++;h[n+s]=t;if(m&&k-r<s&&s<k+r&&g[o+s]<=h[n+s])return q.x=h[n+s],q.y=h[n+s]-s,q}for(var s=k-r;s<=k+r;s+=2){var t,u;s==k+r?t=g[o+s-1]:(t=g[o+s+1]-1,s>k-r&&g[o+s-1]<t&&(t=g[o+s-1])),u=t-s;while(t>b&&u>e&&a.data[t-1]==d.data[u-1])t--,u--;g[o+s]=t;if(!m&&j-r<=s&&s<=j+r&&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."},Mgly.diff.prototype._optimize=function(a){var b=0,c=0;while(b<a.length){while(b<a.length&&(a.modified[b]==undefined||a.modified[b]==0))b++;c=b;while(c<a.length&&a.modified[c]==1)c++;c<a.length&&a.data[b]==a.data[c]?(a.modified[b]=!1,a.modified[c]=!0):b=c}},Mgly.diff.prototype._create_diffs=function(a,b){var c=[],d=0,e=0,f=0,g=0;while(f<a.length||g<b.length)if(f<a.length&&!a.modified[f]&&g<b.length&&!b.modified[g])f++,g++;else{d=f,e=g;while(f<a.length&&(g>=b.length||a.modified[f]))f++;while(g<b.length&&(f>=a.length||b.modified[g]))g++;if(d<f||e<g){var h=new Object;h.lhs_start=d,h.rhs_start=e,h.lhs_deleted_count=f-d,h.rhs_inserted_count=g-e,c.push(h)}}return c},Mgly.mergely=function(a,b){a&&this.init(a,b)},$.extend(Mgly.mergely.prototype,{name:"mergely",init:function(a,b){this.settings={autoresize:!0,fadein:"fast",editor_width:"400px",editor_height:"400px",resize_timeout:500,change_timeout:150,fgcolor:"#4ba3fa",bgcolor:"#eee",lhs:function(a){},rhs:function(a){},loaded:function(){},height:function(a){return a-20},width:function(a){return a},resize:function(){var b=$(a).parent().width(),c=$(window).height();this.width&&(b=this.width(b)),this.height&&(c=this.height(c));var d=b/2-16-8,e=c,f=$(a);f.find(".mergely-column, .CodeMirror-scroll").css({width:d+"px"}),f.find(".mergely-column, .mergely-canvas, .mergely-margin, .mergely-column textarea, .CodeMirror-scroll").css({height:e+"px"}),f.find(".mergely-canvas").css({height:e+"px"}),f.find(".mergely-column textarea").css({width:d+"px"}),f.css({width:b+"px",height:c+"px"}),f.css("display")=="none"&&(this.fadein!=0?f.fadeIn(this.fadein):f.show(),this.loaded&&this.loaded()),this.resized&&this.resized()},_debug:"calc",resized:function(){}},this.cmsettings={mode:"text/plain",readOnly:!1,lineWrapping:!1,lineNumbers:!0},this.element=$(a),b.cmsettings&&$.extend(this.cmsettings,b.cmsettings),b&&$.extend(this.settings,b),this.element.bind("destroyed",$.proxy(this.teardown,this)),$.data(a,this.name,this),this._setup(a)},bind:function(){var a=this;this.editor=[];var b=jQuery.extend({onChange:function(){a._changing(a.id+"-lhs",a.id+"-rhs")},onScroll:function(){a._scrolling(a.id+"-lhs")}},this.cmsettings);this.editor[this.id+"-lhs"]=CodeMirror.fromTextArea($("#"+this.id+"-lhs").get(0),b);var c=jQuery.extend({onChange:function(){a._changing(a.id+"-lhs",a.id+"-rhs")},onScroll:function(){a._scrolling(a.id+"-rhs")}},this.cmsettings);this.editor[this.id+"-rhs"]=CodeMirror.fromTextArea($("#"+this.id+"-rhs").get(0),c);var d=null;$(window).resize(function(){d&&clearTimeout(d),d=setTimeout(function(){a.em_height=null,a.settings.resize&&a.settings.resize(),a.editor[a.id+"-lhs"].refresh(),a.editor[a.id+"-rhs"].refresh(),a._changing(a.id+"-lhs",a.id+"-rhs")},a.settings.resize_timeout)})},unbind:function(){this.editor[this.id+"-lhs"].toTextArea(),this.editor[this.id+"-rhs"].toTextArea()},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)},swap:function(){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"];a=="lhs"?b.setValue(c.getValue()):c.setValue(b.getValue())},get:function(a){var b=this.editor[this.id+"-"+a],c=b.getValue();return c==undefined?"":c},clear:function(a){var b=this.editor[this.id+"-"+a];b.setValue("")},search:function(a,b){var c=this.editor[this.id+"-lhs"],d=this.editor[this.id+"-rhs"],e;a=="lhs"?e=c:e=d;if(e.getSelection().length==0||this.prev_query[a]!=b)this.cursor[this.id]=e.getSearchCursor(b,{line:0,ch:0},!1),this.prev_query[a]=b;this.cursor[this.id].findNext()?e.setSelection(this.cursor[this.id].from(),this.cursor[this.id].to()):this.cursor[this.id]=e.getSearchCursor(b,{line:0,ch:0},!1)},resize:function(){this.settings.resize(),this._changing(this.id+"-lhs",this.id+"-rhs")},diff:function(){var a=this.editor[this.id+"-lhs"].getValue(),b=this.editor[this.id+"-rhs"].getValue(),c=new Mgly.diff(a,b,retain_lines=!0);return c.normal_form()},_setup:function(a){$(this.element).hide(),this.id=$(a).attr("id");var b=this.settings.editor_height,c=this.settings.editor_width;this.changed_timeout=null,this.change_funcs=[],this.prev_query=[],this.cursor=[],this.change_exp=new RegExp(/(\d+(?:,\d+)?)([acd])(\d+(?:,\d+)?)/);var d,e;if($.button!=undefined)d='<button title="Merge left"></button>',e='<button title="Merge right"></button>';else{var f="width:1em;height:1em;background-color:#888;cursor:pointer;text-align:center;color:#eee;border:1px solid: #222;margin-right:5px;";d='<div style="'+f+'" title="Merge left">&lt;</div>',e='<div style="'+f+'" title="Merge right">&gt;</div>'}this.merge_right_button=$(e),this.merge_left_button=$(d),this.merge_right_button.corner&&this.merge_right_button.corner("3px"),this.merge_left_button.corner&&this.merge_left_button.corner("3px"),$(this.element).append($('<div class="mergely-margin" style="height: '+b+'"><canvas id="'+this.id+'-lhs-margin" width="8" height="'+b+'"></canvas></div>')),$(this.element).append($('<div style="width:'+c+"; height:"+b+'" id="'+this.id+'-editor-lhs" class="mergely-column"><textarea style="" id="'+this.id+'-lhs"></textarea></div>')),$(this.element).append($('<div class="mergely-canvas" style="height: '+b+'"><canvas id="'+this.id+"-lhs-"+this.id+'-rhs-canvas" width="28" height="'+b+'"></canvas></div>')),$(this.element).append($('<div style="width:'+c+"; height:"+b+'" id="'+this.id+'-editor-rhs" class="mergely-column"><textarea style="" id="'+this.id+'-rhs"></textarea></div>')),$(this.element).append($('<div class="mergely-margin" style="height: '+b+'"><canvas id="'+this.id+'-rhs-margin" width="8" height="'+b+'"></canvas></div>')),this.bind(),this.settings.lhs&&this.settings.lhs(this.editor[this.id+"-lhs"].setValue),this.settings.rhs&&this.settings.rhs(this.editor[this.id+"-rhs"].setValue),$(window).resize();var g="#"+this.id+" .CodeMirror-gutter-text { padding: 5px 0 0 0; }"+"#"+this.id+" .CodeMirror-lines pre, "+"#"+this.id+" .CodeMirror-gutter-text pre { line-height: 18px; }";this.settings.autoresize&&(g+=this.id+" .CodeMirror-scroll { height: 100%; overflow: auto; }"),$('<style type="text/css">'+g+"</style>").appendTo("head")},_scrolling:function(a){var b=$(this.editor[a].getScrollerElement());this.midway==undefined&&(this.midway=(b.height()/2+b.offset().top).toFixed(2));var c=this.editor[a].coordsChar({x:0,y:this.midway}),d=b.scrollTop(),e=b.scrollLeft();this.trace("scroll","midway",this.midway),this.trace("scroll","midline",c),this.trace("scroll","top_to",d),this.trace("scroll","left_to",e);for(var f in this.editor){if(a==f)continue;var g=a.replace(this.id+"-",""),h=f.replace(this.id+"-",""),i=0,j=null;for(var k in this.changes){var l=this.changes[k];c.line>=l[g+"-line-from"]&&(j=l,c.line>=j[g+"-line-to"]&&(i+=l[g+"-y-end"]-l[g+"-y-start"]-(l[h+"-y-end"]-l[h+"-y-start"])))}var m=!0;j&&(this.trace("scroll","last visible change",j),j[g+"-line-from"]<c.line&&j[g+"-line-to"]>c.line&&(m=!1));if(m){this.trace("scroll","scrolling other side",d-i);var b=$(this.editor[f].getScrollerElement());b.scrollTop(d-i).scrollLeft(e)}else this.trace("scroll","not scrolling other side");this._calculate_offsets(this.id+"-lhs",this.id+"-rhs",this.changes),this._draw_diff(this.id+"-lhs",this.id+"-rhs",this.changes),this.trace("scroll","scrolled")}},_changing:function(a,b){var c=this;this.changed_timeout!=null&&clearTimeout(this.changed_timeout),this.changed_timeout=setTimeout(function(){c._changed(a,b)},this.settings.change_timeout)},_changed:function(a,b){for(var c in this.editor){var d=this.editor[c];d.operation(function(){for(var a=0,b=d.lineCount();a<b;++a)d.clearMarker(a),d.setLineClass(a,null)})}for(var e in this.change_funcs){var f=this.change_funcs[e];f.clear!=undefined?f.clear():f()}this._diff(a,b)},_diff:function(a,b){var c=this.editor[a].getValue(),d=this.editor[b].getValue(),e=new Mgly.diff(c,d);this.changes=this._parse_diff(a,b,e.normal_form()),this._calculate_offsets(a,b,this.changes),this._markup_changes(a,b,this.changes),this._draw_diff(a,b,this.changes)},_parse_diff:function(a,b,c){this.trace("diff","diff results:\n",c);var d=[],e=0,f=c.split(/\n/);for(var g=0;g<f.length;++g){if(f[g].length==0)continue;var h={},i=this.change_exp.exec(f[g]);if(i==null)continue;var j=i[1].split(",");h["lhs-line-from"]=j[0]-1,j.length==1?h["lhs-line-to"]=j[0]-1:h["lhs-line-to"]=j[1]-1;var k=i[3].split(",");h["rhs-line-from"]=k[0]-1,k.length==1?h["rhs-line-to"]=k[0]-1:h["rhs-line-to"]=k[1]-1,h.op=i[2],d[e++]=h,this.trace("diff","change",h)}return d},_calculate_offsets:function(a,b,c){if(this.draw_top_offset==null){var d=this.element.find(".CodeMirror-gutter-text pre").first(),e=d.offset().top;this.em_height=d.get(0).offsetHeight,this.draw_top_offset=6.5-e,this.em_height>0&&(this.draw_lhs_min=.5,this.draw_rhs_max=$("#"+a+"-"+b+"-canvas").width()-.5,this.draw_lhs_width=5,this.draw_rhs_width=5),this.trace("calc","change offsets calculated","top_offset",e)}for(var f in c){var g=c[f];g["lhs-y-start"]=this.draw_top_offset+this.editor[a].charCoords({line:g["lhs-line-from"],ch:0}).y,g["lhs-y-end"]=this.draw_top_offset+this.editor[a].charCoords({line:g["lhs-line-to"]+1,ch:0}).y,g["rhs-y-start"]=this.draw_top_offset+this.editor[b].charCoords({line:g["rhs-line-from"],ch:0}).y,g["rhs-y-end"]=this.draw_top_offset+this.editor[b].charCoords({line:g["rhs-line-to"]+1,ch:0}).y,g["op"]=="d"?g["rhs-y-start"]=g["rhs-y-end"]:g["op"]=="a"&&(g["lhs-y-start"]=g["lhs-y-end"]),this.trace("calc","change offsets calculated",f,g)}},_markup_changes:function(a,b,c){$(".merge-button").remove();var d=this.editor[a];d.operation(function(){for(var a in c){var b=c[a],e="mergely-"+b.op+"-start",f="mergely-"+b.op+"-end",g=e+" "+f;if(b["lhs-line-from"]==b["lhs-line-to"])b["op"]=="c"?d.setLineClass(b["lhs-line-from"],g):b["op"]=="a"?d.setLineClass(b["lhs-line-from"],f+"-lhs"):b["op"]=="d"&&d.setLineClass(b["lhs-line-from"],g+" mergely-c-rem");else{d.setLineClass(b["lhs-line-from"],e+(b["op"]=="d"?" mergely-c-rem":"")),d.setLineClass(b["lhs-line-to"],f+(b["op"]=="d"?" mergely-c-rem":""));if(b["op"]=="d")for(var h=b["lhs-line-from"]+1;h<b["lhs-line-to"];++h)d.setLineClass(h,"mergely-c-rem mergely-d-mid")}}});var d=this.editor[b];d.operation(function(){for(var a in c){var b=c[a],e="mergely-"+b.op+"-start",f="mergely-"+b.op+"-end",g=e+" "+f;if(b["rhs-line-from"]==b["rhs-line-to"])b["op"]=="c"?d.setLineClass(b["rhs-line-from"],g):b["op"]=="a"?d.setLineClass(b["rhs-line-from"],g):b["op"]=="d"&&d.setLineClass(b["rhs-line-from"],f+"-rhs");else{d.setLineClass(b["rhs-line-from"],e),d.setLineClass(b["rhs-line-to"],f);if(b["op"]=="a")for(var h=b["rhs-line-from"]+1;h<b["rhs-line-to"];++h)d.setLineClass(h,"mergely-c-add mergely-a-mid")}}});for(var e in c){var f=c[e],g="mergely-"+f.op+"-start",h="mergely-"+f.op+"-end",i=g+" "+h;if(!this.cmsettings.readOnly){var j=this.merge_right_button.clone();j.button&&j.button({icons:{primary:"ui-icon-triangle-1-e"},text:!1}),j.addClass("merge-button"),j.attr("id","merge-right-"+e);var k=this;$(j).get(0).onclick=function(c){return function(){var d=k.editor[a].lineInfo(c["lhs-line-to"]),e=k.editor[b].lineInfo(c["rhs-line-to"]),f=k.editor[a].getRange({line:c["lhs-line-from"],ch:0},{line:c["lhs-line-to"],ch:d.text.length});if(c["op"]=="c")k.editor[b].replaceRange(f,{line:c["rhs-line-from"],ch:0},{line:c["rhs-line-to"],ch:e.text.length});else if(c["op"]=="a"){var g=parseInt(c["rhs-line-from"]),h=parseInt(c["rhs-line-to"]);for(var i=h;i>=g;--i)k.editor[b].removeLine(i)}else f+="\n",k.editor[b].replaceRange(f,{line:c["rhs-line-from"]+1,ch:0});return k.editor[a].setValue(k.editor[a].getValue()),k.editor[b].setValue(k.editor[b].getValue()),!1}}(f),this.trace("markup","lhs adding button",f["lhs-line-from"]),this.editor[a].addWidget({line:f["lhs-line-from"],ch:0},j.get(0),!1,"over","right"),j=this.merge_left_button.clone(),j.button&&j.button({icons:{primary:"ui-icon-triangle-1-w"},text:!1}),j.addClass("merge-button"),j.attr("id","merge-left-"+e);var k=this;$(j).get(0).onclick=function(c){return function(){var d=k.editor[a].lineInfo(c["lhs-line-to"]),e=k.editor[b].lineInfo(c["rhs-line-to"]),f=k.editor[b].getRange({line:c["rhs-line-from"],ch:0},{line:c["rhs-line-to"],ch:e.text.length});if(c["op"]=="c")k.editor[a].replaceRange(f,{line:c["lhs-line-from"],ch:0},{line:c["lhs-line-to"],ch:d.text.length});else if(c["op"]=="d"){var g=parseInt(c["lhs-line-from"]),h=parseInt(c["lhs-line-to"]);for(var i=h;i>=g;--i)k.editor[a].removeLine(i)}else f+="\n",k.editor[a].replaceRange(f,{line:c["lhs-line-from"]+1,ch:0});return k.editor[a].setValue(k.editor[a].getValue()),k.editor[b].setValue(k.editor[b].getValue()),!1}}(f),this.trace("markup","rhs adding button",f["rhs-line-from"]),this.editor[b].addWidget({line:f["rhs-line-from"],ch:0},j.get(0),!1,"over","right")}if(f["op"]=="a"){var l=f["rhs-line-from"],m=f["rhs-line-to"],n=this.editor[b].lineInfo(m);if(n){var o=this.editor[b].markText({line:l,ch:0},{line:m,ch:n.text.length},"mergely-c-add");this.change_funcs.push(o)}continue}if(f["op"]=="d"){var l=f["lhs-line-from"],m=f["lhs-line-to"],n=this.editor[a].lineInfo(m);if(n){var o=this.editor[a].markText({line:l,ch:0},{line:m,ch:n.text.length},"mergely-c-rem");this.change_funcs.push(o)}continue}var k=this;for(var p=f["lhs-line-from"],q=f["rhs-line-from"],e=0;p>=0&&p<=f["lhs-line-to"]||q>=0&&q<=f["rhs-line-to"];++p,++q){if(q+e>f["rhs-line-to"]){var r=this.editor[a].getLine(p),o=this.editor[a].markText({line:p,ch:0},{line:p,ch:r.length},"mergely-c-rem");this.change_funcs.push(o);continue}if(p+e>f["lhs-line-to"]){var s=this.editor[b].getLine(q),o=this.editor[a].markText({line:q,ch:0},{line:q,ch:r.length},"mergely-c-add");this.change_funcs.push(o);continue}var r=this.editor[a].getLine(p),s=this.editor[b].getLine(q),t={line:-1,ch:-1},u={line:-1,ch:-1},v={line:-1,ch:-1},w={line:-1,ch:-1},x=new Mgly.LCS(r,s),y=Math.max(r.length,s.length);y==0&&(y=1);var z=1*x.length/y*100;z<10&&x.clear(),x.diff(added=function(a,c){if(v.ch<0)v.line=q,v.ch=a,w.line=q,w.ch=a;else if(a==w.ch+1)w.ch=a;else{if(v.ch>=0&&w.ch>=v.ch){w.ch+=1;var d=k.editor[b].markText(v,w,"mergely-c-add");k.change_funcs.push(d)}v.ch=-1,w.ch=-1,c!="\n"&&this.added(a,c)}},removed=function(b,c){if(t.ch<0)t.line=p,t.ch=b,u.line=p,u.ch=b;else if(b==u.ch+1)u.ch=b;else{if(t.ch>=0&&u.ch>=t.ch){u.ch+=1;var d=k.editor[a].markText(t,u,"mergely-c-rem");k.change_funcs.push(d)}t.ch=-1,u.ch=-1,c!="\n"&&this.removed(b,c)}});if(v.ch>=0&&w.ch>=v.ch){w.ch+=1;var o=this.editor[b].markText(v,w,"mergely-c-add");this.change_funcs.push(o)}if(t.ch>=0&&u.ch>=t.ch){u.ch+=1;var o=this.editor[a].markText(t,u,"mergely-c-rem");this.change_funcs.push(o)}}}},_draw_diff:function(a,b,c){var d=$(this.editor[a].getScrollerElement()).height(),e=$(this.editor[a].getScrollerElement()).children(":first-child").height(),f=d/e,g=d/e,h=$(this.editor[a].getScrollerElement()),i=$(this.editor[b].getScrollerElement()),j=this.editor[a].lineCount(),k=this.editor[b].lineCount();this.trace("draw","visible_page_height",d),this.trace("draw","gutter_height",e),this.trace("draw","visible_page_ratio",f),this.trace("draw","lhs-scroller-top",h.scrollTop()),this.trace("draw","rhs-scroller-top",i.scrollTop());var l=document.getElementById(a+"-"+b+"-canvas");if(l==undefined)throw"Failed to find: "+a+"-"+b+"-canvas";$.each($("canvas"),function(){$(this).get(0).height=d});var m=$("#"+this.id+"-lhs-margin"),n=$("#"+this.id+"-rhs-margin");m.unbind("click"),n.unbind("click");var o=m.get(0),p=n.get(0),q=$(m).offset(),r=$(n).offset(),s=l.getContext("2d"),t=o.getContext("2d"),u=p.getContext("2d");t.beginPath(),t.fillStyle=this.settings.bgcolor,t.strokeStyle="#888",t.fillRect(0,0,6.5,d),t.strokeRect(0,0,6.5,d),u.beginPath(),u.fillStyle=this.settings.bgcolor,u.strokeStyle="#888",u.fillRect(0,0,6.5,d),u.strokeRect(0,0,6.5,d);for(var v in c){var w=c[v],x=w["lhs-y-start"],y=w["lhs-y-end"],z=w["rhs-y-start"],A=w["rhs-y-end"];s.beginPath(),s.strokeStyle=this.settings.fgcolor,s.lineWidth=1,s.moveTo(this.draw_lhs_min,x),s.lineTo(this.draw_lhs_min+this.draw_lhs_width,x),s.lineTo(this.draw_lhs_min+this.draw_lhs_width,y+1),s.lineTo(this.draw_lhs_min,y+1),s.stroke(),s.moveTo(this.draw_rhs_max,z),s.lineTo(this.draw_rhs_max-this.draw_rhs_width,z),s.lineTo(this.draw_rhs_max-this.draw_rhs_width,A+1),s.lineTo(this.draw_rhs_max,A+1),s.stroke(),s.moveTo(this.draw_lhs_min+this.draw_lhs_width,x+(y+1-x)/2),s.lineTo(this.draw_rhs_max-this.draw_rhs_width,z+(A+1-z)/2),s.stroke(),this.trace("draw",w),x=(w["lhs-y-start"]+h.scrollTop())*f,y=(w["lhs-y-end"]+h.scrollTop())*f+1,z=(w["rhs-y-start"]+i.scrollTop())*f,A=(w["rhs-y-end"]+i.scrollTop())*f+1,this.trace("draw","marker calculated",x,y,z,A),t.beginPath(),t.fillStyle=this.settings.fgcolor,t.strokeStyle="#000",t.lineWidth=.5,t.fillRect(1.5,x,4.5,Math.max(y-x,5)),t.strokeRect(1.5,x,4.5,Math.max(y-x,5)),u.beginPath(),u.fillStyle=this.settings.fgcolor,u.strokeStyle="#000",u.lineWidth=.5,u.fillRect(1.5,z,4.5,Math.max(A-z,5)),u.strokeRect(1.5,z,4.5,Math.max(A-z,5))}t.fillStyle="rgba(0, 0, 200, 0.5)",u.fillStyle="rgba(0, 0, 200, 0.5)";var B=m.height()*f,C=h.scrollTop()/e*m.height();this.trace("draw","cls.height",m.height()),this.trace("draw","lhs_scroller.scrollTop()",h.scrollTop()),this.trace("draw","gutter_height",e),this.trace("draw","visible_page_ratio",f),this.trace("draw","from",C,"to",B),t.fillRect(1.5,C,4.5,B),u.fillRect(1.5,C,4.5,B),m.click(function(a){var b=a.pageY-q.top-B/2,c=Math.max(0,b/o.height*h.get(0).scrollHeight);h.scrollTop(c)}),n.click(function(a){var b=a.pageY-r.top-B/2,c=Math.max(0,b/p.height*i.get(0).scrollHeight);i.scrollTop(c)})},trace:function(a){this.settings._debug.indexOf(a)>=0&&(arguments[0]=a+":")}}),$.pluginMaker=function(a){$.fn[a.prototype.name]=function(b){var c=$.makeArray(arguments),d=c.slice(1),e=undefined;this.each(function(){var f=$.data(this,a.prototype.name);if(f){if(typeof b=="string")e=f[b].apply(f,d);else if(f.update)return alert("here"),f.update.apply(f,c)}else new a(this,b)});if(e!=undefined)return e}},$.pluginMaker(Mgly.mergely)

0 comments on commit ae02695

Please sign in to comment.
Something went wrong with that request. Please try again.