diff --git a/index.html b/index.html index 6c99df9..58e0894 100644 --- a/index.html +++ b/index.html @@ -40,8 +40,9 @@ } $(document).ready(function () { $('#compare').mergely({ - width: 'auto', - height: '400', + editor_width: 'auto', + editor_height: '400', + license: 'lgpl-separate-notice', cmsettings: { readOnly: false, lineWrapping: true, diff --git a/lib/mergely.css b/lib/mergely.css index e924203..23cf4ec 100644 --- a/lib/mergely.css +++ b/lib/mergely.css @@ -1,9 +1,3 @@ -/** - * Copyright (c) 2014 by Jamie Peabody, http://www.mergely.com - * All rights reserved. - * Version: 3.3.7 2014-08-17 - */ - /* required */ .mergely-column textarea { width: 80px; height: 200px; } .mergely-column { float: left; } @@ -12,22 +6,26 @@ /* resizeable */ .mergely-resizer { width: 100%; height: 100%; } +.mergely-full-screen-0 { position: absolute; top: 0; bottom: 0; left: 0; right: 0; overflow: hidden; } +.mergely-full-screen-8 { position: absolute; top: 8px; bottom: 8px; left: 8px; right: 8px; overflow: hidden; } /* style configuration */ .mergely-column { border: 1px solid #ccc; } .mergely-active { border: 1px solid #a3d1ff; } +.mergely.a,.mergely.d,.mergely.c { color: #000; } + .mergely.a.rhs.start { border-top: 1px solid #a3d1ff; } .mergely.a.lhs.start.end, .mergely.a.rhs.end { border-bottom: 1px solid #a3d1ff; } .mergely.a.rhs { background-color: #ddeeff; } -.mergely.a.lhs.start.end.first { border-bottom: 0; border-top: 1px solid #a3d1ff; } +.mergely.a.lhs.start.end.first { border-bottom-width: 0; border-top: 1px solid #a3d1ff; } -.mergely.d.lhs { background-color: #edc0c0; } +.mergely.d.lhs { background-color: #ffe9e9; } .mergely.d.lhs.end, -.mergely.d.rhs.start.end { border-bottom: 1px solid #ff7f7f; } -.mergely.d.rhs.start.end.first { border-bottom: 0; border-top: 1px solid #ff7f7f; } -.mergely.d.lhs.start { border-top: 1px solid #ff7f7f; } +.mergely.d.rhs.start.end { border-bottom: 1px solid #f8e8e8; } +.mergely.d.rhs.start.end.first { border-bottom-width: 0; border-top: 1px solid #f8e8e8; } +.mergely.d.lhs.start { border-top: 1px solid #f8e8e8; } .mergely.c.lhs, .mergely.c.rhs { background-color: #fafafa; } @@ -37,4 +35,17 @@ .mergely.c.rhs.end { border-bottom: 1px solid #a3a3a3; } .mergely.ch.a.rhs { background-color: #ddeeff; } -.mergely.ch.d.lhs { background-color: #edc0c0; text-decoration: line-through; color: #888; } +.mergely.ch.d.lhs { background-color: #ffe9e9; text-decoration: line-through; color: red !important; } + +.mergely.current.start { border-top: 1px solid #000 !important; } +.mergely.current.end { border-bottom: 1px solid #000 !important; } +.mergely.current.lhs.a.start.end, +.mergely.current.rhs.d.start.end { border-top-width: 0 !important; } + +.mergely.current.lhs.a.start.end.empty, +.mergely.current.rhs.d.start.end.empty { border-top-width: 1px !important; border-bottom-width: 0px !important; } + +.mergely.current.CodeMirror-linenumber { color: #F9F9F9; font-weight: bold; background-color: #777; } +.CodeMirror-linenumber { cursor: pointer; } +.CodeMirror-code { color: #717171; } +span.CodeMirror-selectedtext { background: none !important; } diff --git a/lib/mergely.min.js b/lib/mergely.min.js index fcfe5f9..5b2e0dd 100644 --- a/lib/mergely.min.js +++ b/lib/mergely.min.js @@ -1,6 +1 @@ -/** - * Copyright (c) 2014 by Jamie Peabody, http://www.mergely.com - * All rights reserved. - * Version: 3.3.7 2014-08-17 - */ -Mgly={},Mgly.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()},Mgly.ChangeExpression=new RegExp(/(^(?![><-])*\d+(?:,\d+)?)([acd])(\d+(?:,\d+)?)/),Mgly.DiffParser=function(a){for(var b=[],c=0,d=a.split(/\n/),e=0;e0&&"c"==h.op&&(e+=1),b(e,e+i.length)}if("d"!=h.op){e=c.getLines("rhs").slice(0,h["rhs-line-from"]).join(" ").length,f=h["rhs-line-to"]+1;var j=c.getLines("rhs").slice(h["rhs-line-from"],f).join(" ");"a"==h.op?j+=" ":e>0&&"c"==h.op&&(e+=1),a(e,e+j.length)}}}}),Mgly.CodeifyText=function(a){this._max_code=0,this._diff_codes={},this.ctxs={},this.options={ignorews:!1},jQuery.extend(this,a),this.lhs=a.lhs.split("\n"),this.rhs=a.rhs.split("\n")},jQuery.extend(Mgly.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){this._max_code;for(var d=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){for(var 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;for(var q={x:0,y:0},r=0;p>=r;++r){for(var s=j-r;j+r>=s;s+=2){var t,u;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(var s=k-r;k+r>=s;s+=2){var t,u;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}}),Mgly.mergely=function(a,b){a&&this.init(a,b)},jQuery.extend(Mgly.mergely.prototype,{name:"mergely",init:function(a,b){this.diffView=new Mgly.CodeMirrorDiffView(a,b),this.bind(a)},bind:function(a){this.diffView.bind(a)}}),Mgly.CodeMirrorDiffView=function(a,b){CodeMirror.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)},jQuery.extend(Mgly.CodeMirrorDiffView.prototype,{init:function(a,b){this.settings={autoupdate:!0,autoresize:!0,rhs_margin:"right",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(){},rhs:function(){},loaded:function(){},_auto_width:function(a){return a},resize:function(b){var c=b?16:0,d=jQuery(a).parent().width()+c;"auto"==this.width?d=this._auto_width(d):(d=this.width,this.editor_width=d),"auto"==this.height?h=jQuery(a).parent().height():(h=this.height,this.editor_height=h);var e=d/2-16-8,f=h,g=jQuery(a);g.find(".mergely-column").css({width:e+"px"}),g.find(".mergely-column, .mergely-canvas, .mergely-margin, .mergely-column textarea, .CodeMirror-scroll, .cm-s-default").css({height:f+"px"}),g.find(".mergely-canvas").css({height:f+"px"}),g.find(".mergely-column textarea").css({width:e+"px"}),g.css({width:d,height:h,clear:"both"}),"none"==g.css("display")&&(0!=this.fadein?g.fadeIn(this.fadein):g.show(),this.loaded&&this.loaded()),this.resized&&this.resized()},_debug:"",resized:function(){}};var c={mode:"text/plain",readOnly:!1,lineWrapping:!1,lineNumbers:!0,gutters:["merge","CodeMirror-linenumbers"]};this.lhs_cmsettings={},this.rhs_cmsettings={},this.element=jQuery(a),b&&b.cmsettings&&jQuery.extend(this.lhs_cmsettings,c,b.cmsettings,b.lhs_cmsettings),b&&b.cmsettings&&jQuery.extend(this.rhs_cmsettings,c,b.cmsettings,b.rhs_cmsettings),b&&jQuery.extend(this.settings,b),this.element.bind("destroyed",jQuery.proxy(this.teardown,this)),jQuery.data(a,"mergely",this)},unbind:function(){null!=this.changed_timeout&&clearTimeout(this.changed_timeout),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)},update:function(){this._changing(this.id+"-lhs",this.id+"-rhs")},unmarkup:function(){this._clear()},scrollToDiff:function(a){this.changes.length&&(this._current_diff="next"==a?Math.min(++this._current_diff,this.changes.length-1):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())},options:function(a){if(!a)return this.settings;if(jQuery.extend(this.settings,a),this.settings.autoresize&&this.resize(),this.settings.autoupdate&&this.update(),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?jQuery(this.element).find(".mergely-margin").css({display:"block"}):jQuery(this.element).find(".mergely-margin").css({display:"none"}))},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 Mgly.diff(a,b,this.settings);return c.normal_form()},bind:function(a){jQuery(this.element).hide(),this.id=jQuery(a).attr("id");var b=this.settings.editor_height,c=this.settings.editor_width;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 d,e;if(void 0!=jQuery.button)d='',e='';else{var f="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;";d='
<
',e='
>
'}this.merge_rhs_button=jQuery(e),this.merge_lhs_button=jQuery(d),jQuery(this.element).append(jQuery('
')),jQuery(this.element).append(jQuery('
')),jQuery(this.element).append(jQuery('
'));var g=jQuery('
');this.settings.sidebar||jQuery(this.element).find(".mergely-margin").css({display:"none"}),"left"==this.settings.rhs_margin&&jQuery(this.element).append(g),jQuery(this.element).append(jQuery('
')),"left"!=this.settings.rhs_margin&&jQuery(this.element).append(g);var h="#"+this.id+" .CodeMirror-gutter-text { padding: 5px 0 0 0; }"+"#"+this.id+" .CodeMirror-lines pre, "+"#"+this.id+" .CodeMirror-gutter-text pre { line-height: 18px; }"+".CodeMirror-linewidget { overflow: hidden; };";this.settings.autoresize&&(h+=this.id+" .CodeMirror-scroll { height: 100%; overflow: auto; }"),h+="\n.CodeMirror { line-height: 18px; }",jQuery('").appendTo("head");var i=jQuery("#"+this.id+"-rhs").get(0);if(!i)return console.error("rhs textarea not defined - Mergely not initialized properly"),void 0;var j=jQuery("#"+this.id+"-lhs").get(0);if(!i)return console.error("lhs textarea not defined - Mergely not initialized properly"),void 0;var k=this;if(this.editor=[],this.editor[this.id+"-lhs"]=CodeMirror.fromTextArea(j,this.lhs_cmsettings),this.editor[this.id+"-rhs"]=CodeMirror.fromTextArea(i,this.rhs_cmsettings),this.editor[this.id+"-lhs"].on("change",function(){k.settings.autoupdate&&k._changing(k.id+"-lhs",k.id+"-rhs")}),this.editor[this.id+"-lhs"].on("scroll",function(){k._scrolling(k.id+"-lhs")}),this.editor[this.id+"-rhs"].on("change",function(){k.settings.autoupdate&&k._changing(k.id+"-lhs",k.id+"-rhs")}),this.editor[this.id+"-rhs"].on("scroll",function(){k._scrolling(k.id+"-rhs")}),this.settings.autoresize){var l=null,m=function(a){k.settings.resize&&k.settings.resize(a),k.editor[k.id+"-lhs"].refresh(),k.editor[k.id+"-rhs"].refresh(),k.settings.autoupdate&&k._changing(k.id+"-lhs",k.id+"-rhs")};jQuery(window).resize(function(){l&&clearTimeout(l),l=setTimeout(m,k.settings.resize_timeout)}),m(!0)}if(this.settings.lhs){var n=this.editor[this.id+"-lhs"].getDoc().setValue;this.settings.lhs(n.bind(this.editor[this.id+"-lhs"].getDoc()))}if(this.settings.rhs){var n=this.editor[this.id+"-rhs"].getDoc().setValue;this.settings.rhs(n.bind(this.editor[this.id+"-rhs"].getDoc()))}},_scroll_to_change:function(a){if(a){var b=this,c=b.editor[b.id+"-lhs"],d=b.editor[b.id+"-rhs"],e=1*c.getScrollerElement().offsetHeight/2;c.setCursor(Math.max(a["lhs-line-from"],0),0),d.setCursor(Math.max(a["rhs-line-from"],0),0),c.scrollTo(null,0),d.scrollTo(null,0),b._calculate_offsets(b.id+"-lhs",b.id+"-rhs",[a]),c.scrollTo(null,Math.max(a["lhs-y-start"]-e,0)),d.scrollTo(null,Math.max(a["rhs-y-start"]-e,0))}},_scrolling:function(a){if(this._skipscroll[a]===!0)return this._skipscroll[a]=!1,void 0;var b=jQuery(this.editor[a].getScrollerElement());void 0==this.midway&&(this.midway=(b.height()/2+b.offset().top).toFixed(2));var c=this.editor[a].coordsChar({left:0,top:this.midway}),d=b.scrollTop(),e=b.scrollLeft();this.trace("scroll","side",a),this.trace("scroll","midway",this.midway),this.trace("scroll","midline",c),this.trace("scroll","top_to",d),this.trace("scroll","left_to",e);var f=this.id+"-lhs",g=this.id+"-rhs";for(var h in this.editor)if(this.editor.hasOwnProperty(h)&&a!=h){for(var i=a.replace(this.id+"-",""),j=h.replace(this.id+"-",""),k=0,l=null,m=!1,n=0;n=o[i+"-line-from"]&&(l=o,c.line>=l[i+"-line-to"]&&(o.hasOwnProperty(i+"-y-start")&&o.hasOwnProperty(i+"-y-end")&&o.hasOwnProperty(j+"-y-start")&&o.hasOwnProperty(j+"-y-end")?k+=o[i+"-y-end"]-o[i+"-y-start"]-(o[j+"-y-end"]-o[j+"-y-start"]):m=!0))}var p=this.editor[h].getViewport(),q=!0;if(l&&(this.trace("scroll","last change before midline",l),c.line>=p.from&&c<=p.to&&(q=!1)),this.trace("scroll","scroll",q),q||m){this.trace("scroll","scrolling other side",d-k);var b=jQuery(this.editor[h].getScrollerElement());this._skipscroll[h]=!0,b.scrollTop(d-k).scrollLeft(e)}else this.trace("scroll","not scrolling other side");if(this.settings.autoupdate){var r=new Mgly.Timer;this._calculate_offsets(f,g,this.changes),this.trace("change","offsets time",r.stop()),this._markup_changes(f,g,this.changes),this.trace("change","markup time",r.stop()),this._draw_diff(f,g,this.changes),this.trace("change","draw time",r.stop())}this.trace("scroll","scrolled")}},_changing:function(a,b){this.trace("change","changing-timeout",this.changed_timeout);var c=this;null!=this.changed_timeout&&clearTimeout(this.changed_timeout),this.changed_timeout=setTimeout(function(){var d=new Mgly.Timer;c._changed(a,b),c.trace("change","total time",d.stop())},this.settings.change_timeout)},_changed:function(a,b){this._clear(),this._diff(a,b)},_clear:function(){var a=this;for(var b in this.editor)if(this.editor.hasOwnProperty(b)){var c=this.editor[b],d=a.chfns[b];c.operation(function(){for(var b=new Mgly.Timer,e=0,f=c.lineCount();f>e;++e)c.removeLineClass(e,"background");for(var e=0;ea.from&&b["lhs-line-to"]>a.to||b["rhs-line-from"]a.from&&b["rhs-line-to"]>a.to?!1:!0:!0},_set_top_offset:function(a){var b=this.editor[a].getScrollInfo().top;this.editor[a].scrollTo(null,0);var c=jQuery("#"+this.id+" .CodeMirror-measure").first(),d=c.offset().top-4;return d?(this.editor[a].scrollTo(null,b),this.draw_top_offset=.5-d,!0):!1},_calculate_offsets:function(a,b,c){if(null==this.em_height){if(!this._set_top_offset(a))return;this.em_height=this.editor[a].defaultTextHeight(),this.em_height||(console.warn("Failed to calculate offsets, using 18 by default"),this.em_height=18),this.draw_lhs_min=.5;var d=jQuery("#"+a+"-"+b+"-canvas");if(d.length||console.error("failed to find canvas","#"+a+"-"+b+"-canvas"),!d.width())return console.error("canvas width is 0"),void 0;this.draw_mid_width=jQuery("#"+a+"-"+b+"-canvas").width(),this.draw_rhs_max=this.draw_mid_width-.5,this.draw_lhs_width=5,this.draw_rhs_width=5,this.trace("calc","change offsets calculated",{top_offset:this.draw_top_offset,lhs_min:this.draw_lhs_min,rhs_max:this.draw_rhs_max,lhs_width:this.draw_lhs_width,rhs_width:this.draw_rhs_width})}for(var e=this.editor[a].charCoords({line:0}),f=this.editor[b].charCoords({line:0}),g=this._get_viewport(a,b),h=0;h=0?i["lhs-line-from"]:0,k=i["lhs-line-to"]>=0?i["lhs-line-to"]:0,l=i["rhs-line-from"]>=0?i["rhs-line-from"]:0,m=i["rhs-line-to"]>=0?i["rhs-line-to"]:0;if(this.editor[a].getOption("lineWrapping")||this.editor[a].getOption("lineWrapping")){var r=this.editor[a].cursorCoords({line:j,ch:0},"page"),s=this.editor[a].getLineHandle(j);n={top:r.top,bottom:r.top+s.height};var t=this.editor[a].cursorCoords({line:k,ch:0},"page"),u=this.editor[a].getLineHandle(k);o={top:t.top,bottom:t.top+u.height};var r=this.editor[b].cursorCoords({line:l,ch:0},"page"),v=this.editor[b].getLineHandle(l);p={top:r.top,bottom:r.top+v.height};var t=this.editor[b].cursorCoords({line:m,ch:0},"page"),w=this.editor[b].getLineHandle(m);q={top:t.top,bottom:t.top+w.height}}else n={top:e.top+j*this.em_height,bottom:e.bottom+j*this.em_height+2},o={top:e.top+k*this.em_height,bottom:e.bottom+k*this.em_height+2},p={top:f.top+l*this.em_height,bottom:f.bottom+l*this.em_height+2},q={top:f.top+m*this.em_height,bottom:f.bottom+m*this.em_height+2};"a"==i.op?l>0&&(n.top=n.bottom,n.bottom+=this.em_height,o=n):"d"==i.op&&j>0&&(p.top=p.bottom,p.bottom+=this.em_height,q=p),i["lhs-y-start"]=this.draw_top_offset+n.top,i["lhs-y-end"]="c"==i.op||"d"==i.op?this.draw_top_offset+o.bottom:this.draw_top_offset+o.top,i["rhs-y-start"]=this.draw_top_offset+p.top,i["rhs-y-end"]="c"==i.op||"a"==i.op?this.draw_top_offset+q.bottom:this.draw_top_offset+q.top,this.trace("calc","change calculated",h,i)}else delete i["lhs-y-start"],delete i["lhs-y-end"],delete i["rhs-y-start"],delete i["rhs-y-end"]}return c},_markup_changes:function(a,b,c){jQuery(".merge-button").remove();var d=this,e=this.editor[a],f=this.editor[b],g=new Mgly.Timer;e.operation(function(){for(var a=0;a=0?b["lhs-line-from"]:0,h=b["lhs-line-to"]>=0?b["lhs-line-to"]:0,i=b["rhs-line-from"]>=0?b["rhs-line-from"]:0;b["rhs-line-to"]>=0?b["rhs-line-to"]:0;var k=["mergely","lhs",b.op,"cid-"+a];if(e.addLineClass(g,"background","start"),e.addLineClass(h,"background","end"),0==g&&0==h&&0==i)e.addLineClass(g,"background",k.join(" ")),e.addLineClass(g,"background","first");else for(var l=g;h>=l;++l)e.addLineClass(l,"background",k.join(" ")),e.addLineClass(l,"background",k.join(" "));if(!f.getOption("readOnly")){var m=d.merge_rhs_button.clone();m.button&&m.button({icons:{primary:"ui-icon-triangle-1-e"},text:!1}),m.addClass("merge-button"),m.attr("id","merge-rhs-"+a),e.setGutterMarker(g,"merge",m.get(0))}}});var h=this._get_viewport(a,b);this.trace("change","markup lhs-editor time",g.stop()),f.operation(function(){for(var a=0;a=0?b["lhs-line-from"]:0;b["lhs-line-to"]>=0?b["lhs-line-to"]:0;var j=b["rhs-line-from"]>=0?b["rhs-line-from"]:0,k=b["rhs-line-to"]>=0?b["rhs-line-to"]:0;if(d._is_change_in_view(h,b)){var l=["mergely","rhs",b.op,"cid-"+a];if(f.addLineClass(j,"background","start"),f.addLineClass(k,"background","end"),0==j&&0==k&&0==g)f.addLineClass(j,"background",l.join(" ")),f.addLineClass(j,"background","first");else for(var m=j;k>=m;++m)f.addLineClass(m,"background",l.join(" ")),f.addLineClass(m,"background",l.join(" "));if(!e.getOption("readOnly")){var n=d.merge_lhs_button.clone();n.button&&n.button({icons:{primary:"ui-icon-triangle-1-w"},text:!1}),n.addClass("merge-button"),n.attr("id","merge-lhs-"+a),f.setGutterMarker(j,"merge",n.get(0))}}}}),this.trace("change","markup rhs-editor time",g.stop());for(var i=[],j=0;this.settings.lcs&&j=0?k["lhs-line-from"]:0,m=k["lhs-line-to"]>=0?k["lhs-line-to"]:0,n=k["rhs-line-from"]>=0?k["rhs-line-from"]:0,o=k["rhs-line-to"]>=0?k["rhs-line-to"]:0;if(this._is_change_in_view(h,k))if("d"==k.op){var p=l,q=m,r=e.lineInfo(q);r&&i.push([e,{line:p,ch:0},{line:q,ch:r.text.length},{className:"mergely ch d lhs"}])}else if("c"==k.op)for(var s=l,t=n,u=0;s>=0&&m>=s||t>=0&&o>=t;++s,++t)if(t+u>o){var v=e.getLine(s);i.push([e,{line:s,ch:0},{line:s,ch:v.length},{className:"mergely ch d lhs"}])}else if(s+u>m){var w=f.getLine(t);i.push([f,{line:t,ch:0},{line:t,ch:w.length},{className:"mergely ch a rhs"}])}else{var v=e.getLine(s),w=f.getLine(t),B=new Mgly.LCS(v,w);B.diff(function(a,b){i.push([f,{line:t,ch:a},{line:t,ch:b},{className:"mergely ch a rhs"}])},removed=function(a,b){i.push([e,{line:s,ch:a},{line:s,ch:b},{className:"mergely ch d lhs"}])})}}this.trace("change","LCS marktext time",g.stop()),e.operation(function(){for(var a=0;a=h;--j)f[c].removeLine(j);else if("lhs"==b)if("a"==a.op)for(var h=parseInt(a[c+"-line-from"]),i=parseInt(a[c+"-line-to"]),j=i;j>=h;--j)f[c].removeLine(j);else f[c].replaceRange(g,CodeMirror.Pos(a[c+"-line-from"]+1,0));f.lhs.setValue(f.lhs.getValue()),f.rhs.setValue(f.rhs.getValue()),this._scroll_to_change(a)}},_draw_info:function(a,b){var c=jQuery(this.editor[a].getScrollerElement()).height(),d=jQuery(this.editor[a].getScrollerElement()).children(":first-child").height(),e=document.getElementById(a+"-"+b+"-canvas");if(void 0==e)throw"Failed to find: "+a+"-"+b+"-canvas";var f=jQuery("#"+this.id+"-lhs-margin"),g=jQuery("#"+this.id+"-rhs-margin");return{visible_page_height:c,gutter_height:d,visible_page_ratio:c/d,margin_ratio:c/d,lhs_scroller:jQuery(this.editor[a].getScrollerElement()),rhs_scroller:jQuery(this.editor[b].getScrollerElement()),lhs_lines:this.editor[a].lineCount(),rhs_lines:this.editor[b].lineCount(),dcanvas:e,clhs:f,crhs:g,lhs_xyoffset:jQuery(f).offset(),rhs_xyoffset:jQuery(g).offset()}},_draw_diff:function(a,b,c){var d=this._draw_info(a,b),e=d.clhs.get(0),f=d.crhs.get(0),g=d.dcanvas.getContext("2d"),h=e.getContext("2d"),i=f.getContext("2d");this.trace("draw","visible_page_height",d.visible_page_height),this.trace("draw","gutter_height",d.gutter_height),this.trace("draw","visible_page_ratio",d.visible_page_ratio),this.trace("draw","lhs-scroller-top",d.lhs_scroller.scrollTop()),this.trace("draw","rhs-scroller-top",d.rhs_scroller.scrollTop()),jQuery.each(jQuery.find("#"+this.id+" canvas"),function(){jQuery(this).get(0).height=d.visible_page_height}),d.clhs.unbind("click"),d.crhs.unbind("click"),h.beginPath(),h.fillStyle=this.settings.bgcolor,h.strokeStyle="#888",h.fillRect(0,0,6.5,d.visible_page_height),h.strokeRect(0,0,6.5,d.visible_page_height),i.beginPath(),i.fillStyle=this.settings.bgcolor,i.strokeStyle="#888",i.fillRect(0,0,6.5,d.visible_page_height),i.strokeRect(0,0,6.5,d.visible_page_height);for(var j=this._get_viewport(a,b),k=0;k=s?g.lineTo(t+r,u):(g.arcTo(t+r,u,t+r,u+q,q),g.arcTo(t+r,u+s,t+r-q,u+s,q)),g.lineTo(t,u+s)),g.stroke(),r=this.draw_rhs_width,s=p-o-1,t=this.draw_rhs_max,u=o,g.moveTo(t,u),"Microsoft Internet Explorer"==navigator.appName?(g.lineTo(this.draw_rhs_max-this.draw_rhs_width,o),g.lineTo(this.draw_rhs_max-this.draw_rhs_width,p+1),g.lineTo(this.draw_rhs_max,p+1)):(0>=s?g.lineTo(t-r,u):(g.arcTo(t-r,u,t-r,u+q,q),g.arcTo(t-r,u+s,t-q,u+s,q)),g.lineTo(t,u+s)),g.stroke();var v=this.draw_lhs_min+this.draw_lhs_width,w=m+(n+1-m)/2,x=this.draw_rhs_max-this.draw_rhs_width,y=o+(p+1-o)/2;g.moveTo(v,w),w==y?g.lineTo(x,y):g.bezierCurveTo(v+12,w-3,x-12,y-3,x,y),g.stroke()}}h.fillStyle=this.settings.vpcolor,i.fillStyle=this.settings.vpcolor;var z=d.clhs.height()*d.visible_page_ratio,A=d.lhs_scroller.scrollTop()/d.gutter_height*d.clhs.height(),B=d.crhs.height()*d.visible_page_ratio,C=d.rhs_scroller.scrollTop()/d.gutter_height*d.crhs.height();this.trace("draw","cls.height",d.clhs.height()),this.trace("draw","lhs_scroller.scrollTop()",d.lhs_scroller.scrollTop()),this.trace("draw","gutter_height",d.gutter_height),this.trace("draw","visible_page_ratio",d.visible_page_ratio),this.trace("draw","lhs from",A,"lhs to",z),this.trace("draw","rhs from",C,"rhs to",B),h.fillRect(1.5,A,4.5,z),i.fillRect(1.5,C,4.5,B),d.clhs.click(function(a){var b=a.pageY-d.lhs_xyoffset.top-z/2,c=Math.max(0,b/e.height*d.lhs_scroller.get(0).scrollHeight);d.lhs_scroller.scrollTop(c)}),d.crhs.click(function(a){var b=a.pageY-d.rhs_xyoffset.top-B/2,c=Math.max(0,b/f.height*d.rhs_scroller.get(0).scrollHeight);d.rhs_scroller.scrollTop(c)})},trace:function(a){this.settings._debug.indexOf(a)>=0&&(arguments[0]=a+":",console.log([].slice.apply(arguments)))}}),jQuery.pluginMaker=function(a){jQuery.fn[a.prototype.name]=function(b){var c=jQuery.makeArray(arguments),d=c.slice(1),e=void 0;return this.each(function(){var f=jQuery.data(this,a.prototype.name);if(f){if("string"==typeof b)e=f[b].apply(f,d);else if(f.update)return f.update.apply(f,c)}else new a(this,b)}),void 0!=e?e:void 0}},jQuery.pluginMaker(Mgly.mergely); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("jQuery"),require("CodeMirror")):"function"==typeof define&&define.amd?define("mergely",["jQuery","CodeMirror"],e):"object"==typeof exports?exports.mergely=e(require("jQuery"),require("CodeMirror")):t.mergely=e(t.jQuery,t.CodeMirror)}(window,(function(t,e){return function(t){var e={};function i(s){if(e[s])return e[s].exports;var r=e[s]={i:s,l:!1,exports:{}};return t[s].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,s){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:s})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(s,r,function(e){return t[e]}.bind(null,r));return s},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=3)}([function(t,e){function i(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=i.ignorews,n=void 0!==r&&r,o=i.ignoreaccents,h=void 0!==o&&o,l=i.ignorecase,a=void 0!==l&&l;this.codeify=new s(t,e,{ignorews:n,ignoreaccents:h,ignorecase:a});var c={codes:this.codeify.getCodes("lhs"),modified:{}},d={codes:this.codeify.getCodes("rhs"),modified:{}},g=[],f=[];this._lcs(c,0,c.codes.length,d,0,d.codes.length,f,g),this._optimize(c),this._optimize(d),this.items=this._create_diffs(c,d)}function s(t,e,i){this._max_code=0,this._diff_codes={},this.ctxs={},this.options=i,this.lhs="string"==typeof t?t.split("\n"):t,this.rhs="string"==typeof e?e.split("\n"):e}i.prototype.changes=function(){return this.items},i.prototype.getLines=function(t){return this.codeify.getLines(t)},i.prototype.normal_form=function(){for(var t="",e=0;e0?s="a":i.lhs_deleted_count>0&&0==i.rhs_inserted_count&&(s="d"),t+=(1==i.lhs_deleted_count?i.lhs_start+1:0==i.lhs_deleted_count?i.lhs_start:i.lhs_start+1+","+(i.lhs_start+i.lhs_deleted_count))+s+(1==i.rhs_inserted_count?i.rhs_start+1:0==i.rhs_inserted_count?i.rhs_start:i.rhs_start+1+","+(i.rhs_start+i.rhs_inserted_count))+"\n";var r=this.getLines("lhs"),n=this.getLines("rhs");if(n&&r){var o=void 0;for(o=i.lhs_start;o "+n[o]+"\n"}}return t},i.prototype._lcs=function(t,e,i,s,r,n,o,h){for(;e=u&&(u=h[g+v+1])),m=u-v;uc-y&&o[f+k-1]e&&m>r&&t.codes[u-1]==s.codes[m-1];)u--,m--;if(o[f+k]=u,!d&&a-y<=k&&k<=a+y&&o[f+k]<=h[g+k])return _.x=h[g+k],_.y=h[g+k]-k,_}}throw"the algorithm should never come here."},i.prototype._optimize=function(t){for(var e=0,i=0;e=e.codes.length||t.modified[n]);)n++;for(;o=t.codes.length||e.modified[o]);)o++;(s<\-])*\d+(?:,\d+)?)([acd])(\d+(?:,\d+)?)/);t.exports=function(t){for(var e=[],s=0,r=t.split(/\n/),n=0;n',i='';else{var o="opacity:0.6;height:16px;background-color:#bfbfbf;cursor:pointer;text-align:center;color:#eee;border:1px solid #848484;margin-right:-15px;margin-top:-2px;";e='
<
',i='
>
'}this.merge_rhs_button=r(i),this.merge_lhs_button=r(e);var h=r('
'),l=r('
"));l.find("#lhs-margin").attr("id","".concat(this.id,"-lhs-margin"));var a=r("
'));a.eq(0).attr("id","".concat(this.id,"-editor-lhs")),a.find("#text-lhs").attr("id","".concat(this.id,"-lhs"));var c=r('
"));c.find("#mergely-canvas").attr("id","".concat(this.id,"-mergely-canvas")),c.find("#lhs-rhs-canvas").attr("id","".concat(this.id,"-lhs-").concat(this.id,"-rhs-canvas")),this.element.append(h),this.element.append(l),this.element.append(a),this.element.append(c);var d=r('
"));d.find("#rhs-margin").attr("id","".concat(this.id,"-rhs-margin")),"left"==this.settings.rhs_margin&&this.element.append(d);var g,f=r("
'));if(f.eq(0).attr("id","".concat(this.id,"-editor-rhs")),f.find("#text-rhs").attr("id","".concat(this.id,"-rhs")),this.element.append(f),"left"!=this.settings.rhs_margin&&this.element.append(d),this.settings.sidebar||this.element.find(".mergely-margin").css({display:"none"}),["lgpl-separate-notice","gpl-separate-notice","mpl-separate-notice","commercial"].indexOf(this.settings.license)<0){var p={lgpl:"GNU LGPL v3.0",gpl:"GNU GPL v3.0",mpl:"MPL 1.1"},u=p[this.settings.license];u||(u=p.lgpl);this.element.parent().height();var m=this.element.parent().width();this.element.find("#mergely-splash").css({position:"absolute",zIndex:"100",backgroundColor:"#fff",border:"1px solid black",height:"70px",width:"300px",left:(m-300)/2,padding:"10px 10px 0 10px",fontFamily:"arial",fontSize:"11px"}).append('

mergelyThis software is a Combined Work using Mergely and is covered by the '+u+' license. For the full license, see http://www.mergely.com/license.

'),r("body").one("click",(function(){r("#mergely-splash").fadeOut(100,"linear",(function(){r("#mergely-splash").remove()}))}))}try{g=this.element.find("#".concat(this.id,"-rhs")).get(0)}catch(t){}if(g){var _;try{_=this.element.find("#".concat(this.id,"-lhs")).get(0)}catch(t){}if(_){var y=r('