diff-online/lib/codemirror.min.js

4 lines
95 KiB
JavaScript
Raw Normal View History

2016-08-30 08:57:55 +03:00
window.CodeMirror=function(){"use strict";function w(a,c){if(!(this instanceof w))return new w(a,c);this.options=c=c||{};for(var d in Mc)!c.hasOwnProperty(d)&&Mc.hasOwnProperty(d)&&(c[d]=Mc[d]);I(c);var e="string"==typeof c.value?0:c.value.first,f=this.display=x(a,e);f.wrapper.CodeMirror=this,F(this),c.autofocus&&!o&&Db(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,draggingText:!1,highlight:new De},D(this),c.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap");var g=c.value;"string"==typeof g&&(g=new Rd(c.value,c.mode)),vb(this,Vd)(this,g),b&&setTimeout(Ne(Cb,this,!0),20),Fb(this);var h;try{h=document.activeElement==f.input}catch(i){}h||c.autofocus&&!o?setTimeout(Ne(_b,this),20):ac(this),vb(this,function(){for(var a in Lc)Lc.propertyIsEnumerable(a)&&Lc[a](this,c[a],Oc);for(var b=0;b<Sc.length;++b)Sc[b](this)})()}function x(a,b){var d={},f=d.input=Se("textarea",null,null,"position: absolute; padding: 0; width: 1px; height: 1em; outline: none;");e?f.style.width="1000px":f.setAttribute("wrap","off"),f.setAttribute("autocorrect","off"),f.setAttribute("autocapitalize","off"),d.inputDiv=Se("div",[f],null,"overflow: hidden; position: relative; width: 3px; height: 0px;"),d.scrollbarH=Se("div",[Se("div",null,null,"height: 1px")],"CodeMirror-hscrollbar"),d.scrollbarV=Se("div",[Se("div",null,null,"width: 1px")],"CodeMirror-vscrollbar"),d.scrollbarFiller=Se("div",null,"CodeMirror-scrollbar-filler"),d.lineDiv=Se("div"),d.selectionDiv=Se("div",null,null,"position: relative; z-index: 1"),d.cursor=Se("div","\xa0","CodeMirror-cursor"),d.otherCursor=Se("div","\xa0","CodeMirror-cursor CodeMirror-secondarycursor"),d.measure=Se("div",null,"CodeMirror-measure"),d.lineSpace=Se("div",[d.measure,d.selectionDiv,d.lineDiv,d.cursor,d.otherCursor],null,"position: relative; outline: none"),d.mover=Se("div",[Se("div",[d.lineSpace],"CodeMirror-lines")],null,"position: relative"),d.sizer=Se("div",[d.mover],"CodeMirror-sizer"),d.heightForcer=Se("div","\xa0",null,"position: absolute; height: "+Be+"px"),d.gutters=Se("div",null,"CodeMirror-gutters"),d.lineGutter=null;var g=Se("div",[d.sizer,d.heightForcer,d.gutters],null,"position: relative; min-height: 100%");return d.scroller=Se("div",[g],"CodeMirror-scroll"),d.scroller.setAttribute("tabIndex","-1"),d.wrapper=Se("div",[d.inputDiv,d.scrollbarH,d.scrollbarV,d.scrollbarFiller,d.scroller],"CodeMirror"),c&&(d.gutters.style.zIndex=-1,d.scroller.style.paddingRight=0),a.appendChild?a.appendChild(d.wrapper):a(d.wrapper),n&&(f.style.width="0px"),e||(d.scroller.draggable=!0),j?(d.inputDiv.style.height="1px",d.inputDiv.style.position="absolute"):c&&(d.scrollbarH.style.minWidth=d.scrollbarV.style.minWidth="18px"),d.viewOffset=d.lastSizeC=0,d.showingFrom=d.showingTo=b,d.lineNumWidth=d.lineNumInnerWidth=d.lineNumChars=null,d.prevInput="",d.alignWidgets=!1,d.pollingFast=!1,d.poll=new De,d.draggingText=!1,d.cachedCharWidth=d.cachedTextHeight=null,d.measureLineCache=[],d.measureLineCachePos=0,d.inaccurateSelection=!1,d.maxLine=null,d.maxLineLength=0,d.maxLineChanged=!1,d.wheelDX=d.wheelDY=d.wheelStartX=d.wheelStartY=null,d}function y(a){a.doc.mode=w.getMode(a.options,a.doc.modeOption),a.doc.iter(function(a){a.stateAfter&&(a.stateAfter=null),a.styles&&(a.styles=null)}),a.doc.frontier=a.doc.first,_(a,100),a.state.modeGen++,a.curOp&&yb(a)}function z(a){a.options.lineWrapping?(a.display.wrapper.className+=" CodeMirror-wrap",a.display.sizer.style.minWidth=""):(a.display.wrapper.className=a.display.wrapper.className.replace(" CodeMirror-wrap",""),H(a)),B(a),yb(a),ib(a),setTimeout(function(){J(a.display,a.doc.height)},100)}function A(a){var b=qb(a.display),c=a.options.lineWrapping,d=c&&Math.max(5,a.display.scroller.clientWidth/rb(a.display)-3);return function(e){return qd(a.doc,e)?0:c?(Math.ceil(e.text.length/d)||1)*b:b}}function B(a){var b=a.doc,c=A(a);b.iter(function(a){var b=c(a);b!=a.height&&Zd(a,b)})}function C(a){var b=Wc[a.options.keyMap].style;a.display.wrapper.className=a.display.wrapper.className.replace(/\s*cm-keymap-\S+/g,"")+(b?" cm-keymap-
break}var i=b.display,j=i.scroller;if(d&&!a&&!h&&null!=Rb)return f&&Ob(b,Math.max(0,Math.min(j.scrollTop+f*Rb,j.scrollHeight-j.clientHeight))),Pb(b,Math.max(0,Math.min(j.scrollLeft+d*Rb,j.scrollWidth-j.clientWidth))),oe(c),i.wheelStartX=null,void 0;if(f&&null!=Rb){var k=f*Rb,l=b.doc.scrollTop,m=l+i.wrapper.clientHeight;0>k?l=Math.max(0,l+k-50):m=Math.min(b.doc.height,m+k+50),P(b,[],{top:l,bottom:m})}20>Qb&&(null==i.wheelStartX?(i.wheelStartX=j.scrollLeft,i.wheelStartY=j.scrollTop,i.wheelDX=d,i.wheelDY=f,setTimeout(function(){if(null!=i.wheelStartX){var a=j.scrollLeft-i.wheelStartX,b=j.scrollTop-i.wheelStartY,c=b&&i.wheelDY&&b/i.wheelDY||a&&i.wheelDX&&a/i.wheelDX;i.wheelStartX=i.wheelStartY=null,c&&(Rb=(Rb*Qb+c)/(Qb+1),++Qb)}},200)):(i.wheelDX+=d,i.wheelDY+=f))}function Tb(a,b,c){if("string"==typeof b&&(b=Vc[b],!b))return!1;a.display.pollingFast&&Bb(a)&&(a.display.pollingFast=!1);var d=a.doc,e=d.sel.shift,f=!1;try{Eb(a)&&(a.state.suppressEdits=!0),c&&(d.sel.shift=!1),f=b(a)!=Ce}finally{d.sel.shift=e,a.state.suppressEdits=!1}return f}function Ub(a){var b=a.state.keyMaps.slice(0);return b.push(a.options.keyMap),a.options.extraKeys&&b.unshift(a.options.extraKeys),b}function Wb(a,b){var c=Xc(a.options.keyMap),e=c.auto;clearTimeout(Vb),e&&!Zc(b)&&(Vb=setTimeout(function(){Xc(a.options.keyMap)==c&&(a.options.keyMap=e.call?e.call(null,a):e)},50));var f=$c(b,!0),g=!1;if(!f)return!1;var h=Ub(a);return g=b.shiftKey?Yc("Shift-"+f,h,function(b){return Tb(a,b,!0)})||Yc(f,h,function(b){return"string"==typeof b&&/^go[A-Z]/.test(b)?Tb(a,b):void 0}):Yc(f,h,function(b){return Tb(a,b)}),"stop"==g&&(g=!1),g&&(oe(b),$(a),d&&(b.oldKeyCode=b.keyCode,b.keyCode=0)),g}function Xb(a,b,c){var d=Yc("'"+c+"'",Ub(a),function(b){return Tb(a,b,!0)});return d&&(oe(b),$(a)),d}function Zb(a){var c=this;if(c.state.focused||_b(c),b&&27==a.keyCode&&(a.returnValue=!1),!c.options.onKeyEvent||!c.options.onKeyEvent(c,ne(a))){var d=a.keyCode;c.doc.sel.shift=16==d||a.shiftKey;var e=Wb(c,a);h&&(Yb=e?d:null,!e&&88==d&&!df&&(p?a.metaKey:a.ctrlKey)&&c.replaceSelection(""))}}function $b(a){var b=this;if(!b.options.onKeyEvent||!b.options.onKeyEvent(b,ne(a))){var c=a.keyCode,d=a.charCode;if(h&&c==Yb)return Yb=null,oe(a),void 0;if(!(h&&(!a.which||a.which<10)||j)||!Wb(b,a)){var e=String.fromCharCode(null==d?c:d);this.options.electricChars&&this.doc.mode.electricChars&&this.options.smartIndent&&!Eb(this)&&this.doc.mode.electricChars.indexOf(e)>-1&&setTimeout(vb(b,function(){Fc(b,b.doc.sel.to.line,"smart")}),75),Xb(b,a,e)||Ab(b)}}}function _b(a){"nocursor"!=a.options.readOnly&&(a.state.focused||(ve(a,"focus",a),a.state.focused=!0,-1==a.display.wrapper.className.search(/\bCodeMirror-focused\b/)&&(a.display.wrapper.className+=" CodeMirror-focused"),Cb(a,!0)),zb(a),$(a))}function ac(a){a.state.focused&&(ve(a,"blur",a),a.state.focused=!1,a.display.wrapper.className=a.display.wrapper.className.replace(" CodeMirror-focused","")),clearInterval(a.display.blinker),setTimeout(function(){a.state.focused||(a.doc.sel.shift=!1)},150)}function cc(a,c){function k(){if(e.inputDiv.style.position="relative",e.input.style.cssText=j,d&&(e.scrollbarV.scrollTop=e.scroller.scrollTop=i),zb(a),null!=e.input.selectionStart&&(!b||d)){clearTimeout(bc);var c=e.input.value=" "+(pc(f.from,f.to)?"":e.input.value),g=0;e.prevInput=" ",e.input.selectionStart=1,e.input.selectionEnd=c.length;var h=function(){" "==e.prevInput&&0==e.input.selectionStart?vb(a,Vc.selectAll)(a):g++<10?bc=setTimeout(h,500):Cb(a)};bc=setTimeout(h,200)}}var e=a.display,f=a.doc.sel;if(!Gb(e,c)){var g=Hb(a,c),i=e.scroller.scrollTop;if(g&&!h){(pc(f.from,f.to)||qc(g,f.from)||!qc(g,f.to))&&vb(a,yc)(a.doc,g,g);var j=e.input.style.cssText;if(e.inputDiv.style.position="absolute",e.input.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(c.clientY-5)+"px; left: "+(c.clientX-5)+"px; z-index: 1000; background: white; outline: none;"+"border-width: 0; outline: none; overflow: hidden; opacity: .05; -ms-opacity: .05; filter: alpha(opacity=5);",Db(a),Cb(a,!0),pc(f.from,f.to)&&(e.input.value=e.prevInput=" "),t){qe(c);var l=function(){ue(
return!0}function Se(a,b,c,d){var e=document.createElement(a);if(c&&(e.className=c),d&&(e.style.cssText=d),"string"==typeof b)Ve(e,b);else if(b)for(var f=0;f<b.length;++f)e.appendChild(b[f]);return e}function Te(a){if(b)for(;a.firstChild;)a.removeChild(a.firstChild);else a.innerHTML="";return a}function Ue(a,b){return Te(a).appendChild(b)}function Ve(a,b){d?(a.innerHTML="",a.appendChild(document.createTextNode(b))):a.textContent=b}function We(a){return a.getBoundingClientRect()}function $e(a){if(null!=Ze)return Ze;var b=Se("div",null,null,"width: 50px; height: 50px; overflow-x: scroll");return Ue(a,b),b.offsetWidth&&(Ze=b.offsetHeight-b.clientHeight),Ze||0}function af(a){if(null==_e){var b=Se("span","\u200b");Ue(a,Se("span",[b,document.createTextNode("x")])),0!=a.firstChild.offsetHeight&&(_e=b.offsetWidth<=1&&b.offsetHeight>2&&!c)}return _e?Se("span","\u200b"):Se("span","\xa0",null,"display: inline-block; width: 1px; margin-right: -1px")}function ff(a,b,c,d){if(!a)return d(b,c,"ltr");for(var e=0;e<a.length;++e){var f=a[e];(f.from<c&&f.to>b||b==c&&f.to==b)&&d(Math.max(f.from,b),Math.min(f.to,c),1==f.level?"rtl":"ltr")}}function gf(a){return a.level%2?a.to:a.from}function hf(a){return a.level%2?a.from:a.to}function jf(a){var b=be(a);return b?gf(b[0]):0}function kf(a){var b=be(a);return b?hf(He(b)):a.text.length}function lf(a,b){var c=Wd(a.doc,b),d=pd(a.doc,c);d!=c&&(b=$d(d));var e=be(d),f=e?e[0].level%2?kf(d):jf(d):0;return oc(b,f)}function mf(a,b){for(var c,d;c=od(d=Wd(a.doc,b));)b=c.find().to.line;var e=be(d),f=e?e[0].level%2?jf(d):kf(d):d.text.length;return oc(b,f)}function nf(a,b,c,d){var e=be(a);if(!e)return of(a,b,c,d);for(var f=d?function(b,c){do b+=c;while(b>0&&Re.test(a.text.charAt(b)));return b}:function(a,b){return a+b},g=e[0].level,h=0;h<e.length;++h){var i=e[h],j=i.level%2==g;if(i.from<b&&i.to>b||j&&(i.from==b||i.to==b))break}for(var k=f(b,i.level%2?-c:c);null!=k;)if(i.level%2==g){if(!(k<i.from||k>i.to))break;i=e[h+=c],k=i&&(c>0==i.level%2?f(i.to,-1):f(i.from,1))}else if(k==gf(i))i=e[--h],k=i&&hf(i);else{if(k!=hf(i))break;i=e[++h],k=i&&gf(i)}return 0>k||k>a.text.length?null:k}function of(a,b,c,d){var e=b+c;if(d)for(;e>0&&Re.test(a.text.charAt(e));)e+=c;return 0>e||e>a.text.length?null:e}var a=/gecko\/\d/i.test(navigator.userAgent),b=/MSIE \d/.test(navigator.userAgent),c=b&&(null==document.documentMode||document.documentMode<8),d=b&&(null==document.documentMode||document.documentMode<9),e=/WebKit\//.test(navigator.userAgent),f=e&&/Qt\/\d+\.\d+/.test(navigator.userAgent),g=/Chrome\//.test(navigator.userAgent),h=/Opera\//.test(navigator.userAgent),i=/Apple Computer/.test(navigator.vendor),j=/KHTML\//.test(navigator.userAgent),k=/Mac OS X 1\d\D([7-9]|\d\d)\D/.test(navigator.userAgent),l=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent),m=/PhantomJS/.test(navigator.userAgent),n=/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent),o=n||/Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent),p=n||/Mac/.test(navigator.platform),q=/windows/i.test(navigator.platform),r=h&&navigator.userAgent.match(/Version\/(\d*\.\d*)/);r&&(r=Number(r[1]));var pb,Ib,Jb,s=p&&(f||h&&(null==r||12.11>r)),t=a||b&&!d,u=!1,v=!1,sb=0,Qb=0,Rb=null;b?Rb=-.53:a?Rb=15:g?Rb=-.7:i&&(Rb=-1/3);var Vb,bc,Yb=null;w.Pos=oc,w.prototype={focus:function(){window.focus(),Db(this),_b(this),Ab(this)},setOption:function(a,b){var c=this.options,d=c[a];(c[a]!=b||"mode"==a)&&(c[a]=b,Lc.hasOwnProperty(a)&&vb(this,Lc[a])(this,b,d))},getOption:function(a){return this.options[a]},getDoc:function(){return this.doc},addKeyMap:function(a){this.state.keyMaps.push(a)},removeKeyMap:function(a){for(var b=this.state.keyMaps,c=0;c<b.length;++c)if(("string"==typeof a?b[c].name:b[c])==a)return b.splice(c,1),!0},addOverlay:vb(null,function(a,b){var c=a.token?a:w.getMode(this.options,a);if(c.startState)throw new Error("Overlays may not be stateful.");this.state.overlays.push({mode:c,modeSpec:a,opaque:b&&b.opaque}),this.state.modeGen++,yb(this)}),removeOverlay:vb(null,function(a){for(var b=this.state.overlays,c=0;c<b.l
"1"==l&&"r"==n?j[k]="n":f.test(l)&&(n=l,"r"==l&&(j[k]="R"))}for(var k=1,m=j[0];b-1>k;++k){var l=j[k];"+"==l&&"1"==m&&"1"==j[k+1]?j[k]="1":","!=l||m!=j[k+1]||"1"!=m&&"n"!=m||(j[k]=m),m=l}for(var k=0;b>k;++k){var l=j[k];if(","==l)j[k]="N";else if("%"==l){for(var o=k+1;b>o&&"%"==j[o];++o);for(var p=k&&"!"==j[k-1]||b-1>o&&"1"==j[o]?"1":"N",q=k;o>q;++q)j[q]=p;k=o-1}}for(var k=0,n=i;b>k;++k){var l=j[k];"L"==n&&"1"==l?j[k]="L":f.test(l)&&(n=l)}for(var k=0;b>k;++k)if(e.test(j[k])){for(var o=k+1;b>o&&e.test(j[o]);++o);for(var r="L"==(k?j[k-1]:i),s="L"==(b-1>o?j[o]:i),p=r||s?"L":"R",q=k;o>q;++q)j[q]=p;k=o-1}for(var u,t=[],k=0;b>k;)if(g.test(j[k])){var v=k;for(++k;b>k&&g.test(j[k]);++k);t.push({from:v,to:k,level:0})}else{var w=k,x=t.length;for(++k;b>k&&"L"!=j[k];++k);for(var q=w;k>q;)if(h.test(j[q])){q>w&&t.splice(x,0,{from:w,to:q,level:1});var y=q;for(++q;k>q&&h.test(j[q]);++q);t.splice(x,0,{from:y,to:q,level:2}),w=q}else++q;k>w&&t.splice(x,0,{from:w,to:k,level:1})}return 1==t[0].level&&(u=a.match(/^\s+/))&&(t[0].from=u[0].length,t.unshift({from:0,to:u[0].length,level:0})),1==He(t).level&&(u=a.match(/\s+$/))&&(He(t).to-=u[0].length,t.push({from:b-u[0].length,to:b,level:0})),t[0].level!=He(t).level&&t.push({from:b,to:b,level:t[0].level}),t}}();return w.version="3.1",w}();