orbit-basic/app/assets/javascripts/ckeditor/plugins/codemirror/js/codemirror.addons.min.js

32 lines
14 KiB
JavaScript

(function(){function k(c){for(var e={name:"autoCloseBrackets",Backspace:function(a){if(a.somethingSelected())return CodeMirror.Pass;var f=a.getCursor(),b=a.getLine(f.line);if(f.ch&&f.ch<b.length&&0==c.indexOf(b.slice(f.ch-1,f.ch+1))%2)a.replaceRange("",CodeMirror.Pos(f.line,f.ch-1),CodeMirror.Pos(f.line,f.ch+1));else return CodeMirror.Pass}},b="",a=0;a<c.length;a+=2)(function(a,f){function c(a){var b=a.getCursor();if(a.getRange(b,CodeMirror.Pos(b.line,b.ch+1))!=f||a.somethingSelected())return CodeMirror.Pass;
a.execCommand("goCharRight")}a!=f&&(b=b+f);e["'"+a+"'"]=function(e){if(a=="'"&&e.getTokenAt(e.getCursor()).type=="comment")return CodeMirror.Pass;if(e.somethingSelected()){var l=e.getSelection();e.replaceSelection(a+l+f)}else if(a!=f||c(e)==CodeMirror.Pass){var l=e.getCursor(),h=CodeMirror.Pos(l.line,l.ch+1),m=e.getLine(l.line),n=m.charAt(l.ch);if(m.length==l.ch||b.indexOf(n)>=0||g.test(n))e.replaceSelection(a+f,{head:h,anchor:h});else return CodeMirror.Pass}};a!=f&&(e["'"+f+"'"]=c)})(c.charAt(a),
c.charAt(a+1));return e}var g=/\s/;CodeMirror.defineOption("autoCloseBrackets",!1,function(c,e,b){b=b&&b!=CodeMirror.Init;e&&!b?c.addKeyMap(k(typeof e=="string"?e:"()[]{}''\"\"")):!e&&b&&c.removeKeyMap("autoCloseBrackets")})})();
(function(){function k(b,a){var d=b.getCursor(),f=b.getTokenAt(d),j=CodeMirror.innerMode(b.getMode(),f.state),i=j.state,l,h;if("xml"!=j.mode.name)return CodeMirror.Pass;var m=b.getOption("autoCloseTags"),n="html"==j.mode.configuration,j="object"==typeof m&&m.dontCloseTags||n&&c,m="object"==typeof m&&m.indentTags||n&&e;if(">"==a&&i.tagName){if(h=i.tagName,f.end>d.ch&&(h=h.slice(0,h.length-f.end+d.ch)),l=h.toLowerCase(),"tag"==f.type&&"closeTag"==i.type||f.string.indexOf("/")==f.string.length-1||j&&
-1<g(j,l))return CodeMirror.Pass;i=(f=m&&-1<g(m,l))?CodeMirror.Pos(d.line+1,0):CodeMirror.Pos(d.line,d.ch+1);b.replaceSelection(">"+(f?"\n\n":"")+"</"+h+">",{head:i,anchor:i});f&&(b.indentLine(d.line+1),b.indentLine(d.line+2))}else if("/"==a&&"<"==f.string)(h=i.context&&i.context.tagName)&&b.replaceSelection("/"+h+">","end");else return CodeMirror.Pass}function g(b,a){if(b.indexOf)return b.indexOf(a);for(var d=0,f=b.length;d<f;++d)if(b[d]==a)return d;return-1}CodeMirror.defineOption("autoCloseTags",
!1,function(b,a,d){if(a&&(d==CodeMirror.Init||!d)){d={name:"autoCloseTags"};(typeof a!="object"||a.whenClosing)&&(d["'/'"]=function(a){return k(a,"/")});(typeof a!="object"||a.whenOpening)&&(d["'>'"]=function(a){return k(a,">")});b.addKeyMap(d)}else!a&&d!=CodeMirror.Init&&d&&b.removeKeyMap("autoCloseTags")});var c="area base br col command embed hr img input keygen link meta param source track wbr".split(" "),e="applet blockquote body button div dl fieldset form frameset h1 h2 h3 h4 h5 h6 head html iframe layer legend object ol p select table ul".split(" ")})();
(function(){function k(e){var b=e.getCursor(),a=e.getTokenAt(b),d=CodeMirror.innerMode(e.getMode(),a.state).mode,f,c,i,l;if("comment"==a.type&&d.blockCommentStart&&(c=a.string.indexOf(d.blockCommentEnd),i=e.getRange(CodeMirror.Pos(b.line,0),CodeMirror.Pos(b.line,a.end)),-1==c||c!=a.string.length-d.blockCommentEnd.length))if(0==a.string.indexOf(d.blockCommentStart)){if(f=i.slice(0,a.start),!/^\s*$/.test(f)){f="";for(b=0;b<a.start;++b)f+=" "}}else-1!=(l=i.indexOf(d.blockCommentContinue))&&l+d.blockCommentContinue.length>
a.start&&/^\s*$/.test(i.slice(0,l))&&(f=i.slice(0,l));if(null!=f)e.replaceSelection("\n"+f+d.blockCommentContinue,"end");else return CodeMirror.Pass}for(var g=["clike","css","javascript"],c=0;c<g.length;++c)CodeMirror.extendMode(g[c],{blockCommentStart:"/*",blockCommentEnd:"*/",blockCommentContinue:" * "});CodeMirror.defineOption("continueComments",null,function(e,b,a){a&&a!=CodeMirror.Init&&e.removeKeyMap("continueComment");a={name:"continueComment"};a["string"==typeof b?b:"Enter"]=k;e.addKeyMap(a)})})();
(function(){function k(f){function d(c,g,l){var j,h,m,k,n;if(c.text){if(j=q?0:c.text.length-1,h=q?c.text.length:-1,c.text.length>e)return null;m=1E3>c.text.length;for(null!=l&&(j=l+r);j!=h;j+=r)if(k=c.text.charAt(j),t.test(k)&&(!m||f.getTokenAt(b(g,j+1)).type==u))if(n=a[k],">"==n.charAt(1)==q)s.push(k);else{if(s.pop()!=n.charAt(0))return{pos:j,match:!1};if(!s.length)return{pos:j,match:!0}}}}var e=f.state._matchBrackets.maxScanLineLength||1E4,c=f.getCursor(),g=f.getLineHandle(c.line),m=c.ch-1,n=0<=
m&&a[g.text.charAt(m)]||a[g.text.charAt(++m)],k,p;if(!n)return null;var q=">"==n.charAt(1),r=q?1:-1,u=f.getTokenAt(b(c.line,m+1)).type,s=[g.text.charAt(m)],t=/[(){}[\]]/,n=c.line;for(p=q?Math.min(n+100,f.lineCount()):Math.max(-1,n-100);n!=p&&!(k=n==c.line?d(g,n,m):d(f.getLineHandle(n),n),k);n+=r);return{from:b(c.line,m),to:k&&b(n,k.pos),match:k&&k.match}}function g(a,d){var c=a.state._matchBrackets.maxHighlightLineLength||1E3,g=k(a);if(g&&!(a.getLine(g.from.line).length>c)&&(!g.to||!(a.getLine(g.to.line).length>
c))){var c=g.match?"CodeMirror-matchingbracket":"CodeMirror-nonmatchingbracket",h=a.markText(g.from,b(g.from.line,g.from.ch+1),{className:c}),m=g.to&&a.markText(g.to,b(g.to.line,g.to.ch+1),{className:c});if(e&&a.state.focused&&a.display.input.focus(),g=function(){a.operation(function(){h.clear();m&&m.clear()})},d)setTimeout(g,800);else return g}}function c(a){a.operation(function(){d&&(d(),d=null);a.somethingSelected()||(d=g(a,!1))})}var e=/MSIE \d/.test(navigator.userAgent)&&(null==document.documentMode||
8>document.documentMode),b=CodeMirror.Pos,a={"(":")>",")":"(<","[":"]>","]":"[<","{":"}>","}":"{<"},d=null;CodeMirror.defineOption("matchBrackets",!1,function(a,b,d){if(d&&d!=CodeMirror.Init&&a.off("cursorActivity",c),b){a.state._matchBrackets=typeof b=="object"?b:{};a.on("cursorActivity",c)}});CodeMirror.defineExtension("matchBrackets",function(){g(this,!0)});CodeMirror.defineExtension("findMatchingBracket",function(){return k(this)})})();
CodeMirror.newFoldFunction=function(k,g){if(null==g&&(g="↔"),"string"==typeof g){var c=document.createTextNode(g),g=document.createElement("span");g.appendChild(c);g.className="CodeMirror-foldmarker"}return function(c,b){var a,d,f,j,i;if("number"==typeof b&&(b=CodeMirror.Pos(b,0)),a=k(c,b),a){d=c.findMarksAt(a.from);for(j=f=0;j<d.length;++j)d[j].__isFold&&(++f,d[j].clear());f||(d=g.cloneNode(!0),CodeMirror.on(d,"mousedown",function(){i.clear()}),i=c.markText(a.from,a.to,{replacedWith:d,clearOnEnter:!0,
__isFold:!0}))}}};
CodeMirror.braceRangeFinder=function(k,g){for(var c=g.line,e=k.getLine(c),b=e.length,a,d,f,j,i,l,h,m,n;0<b;){i=e.lastIndexOf("{",b);var o="{",p="}";if(i<g.ch){if(i=e.lastIndexOf("[",b),i<g.ch)break;o="[";p="]"}if(d=k.getTokenAt(CodeMirror.Pos(c,i+1)).type,!/^(comment|string)/.test(d)){a=i;break}b=i-1}if(null!=a&&!(e.lastIndexOf(o)>a)){e=1;b=k.lineCount();i=c+1;a:for(;i<b;++i){l=k.getLine(i);for(h=0;!(m=l.indexOf(o,h),n=l.indexOf(p,h),0>m&&(m=l.length),0>n&&(n=l.length),h=Math.min(m,n),h==l.length);){if(k.getTokenAt(CodeMirror.Pos(i,
h+1)).type==d)if(h==m)++e;else if(!--e){f=i;j=h;break a}++h}}if(null!=f&&f!=c+1)return{from:CodeMirror.Pos(c,a+1),to:CodeMirror.Pos(f,j)}}};
CodeMirror.tagRangeFinder=function(){var k=RegExp("<(/?)([A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD][A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD-:.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*)","g");return function(g,c){function e(){if(!(d>=g.lastLine()))return f=
0,j=g.getLine(++d),!0}function b(){for(var a,b,d;;){if(a=j.indexOf(">",f),-1==a)if(e())continue;else break;return b=j.lastIndexOf("/",a),d=-1<b&&/^\s*$/.test(j.slice(b+1,a)),f=a+1,d?"selfClose":"regular"}}function a(){for(;;){k.lastIndex=f;var a=k.exec(j);if(!a)if(e())continue;else break;return f=a.index+a[0].length,a}}for(var d=c.line,f=c.ch,j=g.getLine(d),i=[],l,h,m;;){if(h=a(),!h||d!=c.line||!(m=b()))return;if(!h[1]&&"selfClose"!=m){i.push(h[2]);l=f;break}}for(;;){var n=a(),o=d,p=f-(n?n[0].length:
0);if(!n||!(m=b()))break;if("selfClose"!=m)if(n[1]){for(h=i.length-1;0<=h;--h)if(i[h]==n[2]){i.length=h;break}if(!i.length)return{from:CodeMirror.Pos(c.line,l),to:CodeMirror.Pos(o,p)}}else i.push(n[2])}}}();
(function(){CodeMirror.defineExtension("autoFormatAll",function(k,g){for(var c=this,e=c.getMode(),b=c.getRange(k,g).split("\n"),a=CodeMirror.copyState(e,c.getTokenAt(k).state),d=c.getOption("tabSize"),f="",j=0,i=0==k.ch,l,h=0;h<b.length;++h){for(l=new CodeMirror.StringStream(b[h],d);!l.eol();){var m=CodeMirror.innerMode(e,a),n=e.token(l,a),o=l.current();l.start=l.pos;(!i||/\S/.test(o))&&(f+=o,i=!1);if(!i&&m.mode.newlineAfterToken&&m.mode.newlineAfterToken(n,o,l.string.slice(l.pos)||b[h+1]||"",m.state))f+=
"\n",i=!0,++j}!l.pos&&e.blankLine&&e.blankLine(a);!i&&h<b.length-1&&(f+="\n",i=!0,++j)}c.operation(function(){c.replaceRange(f,k,g);for(var a=k.line+1,b=k.line+j;a<=b;++a)c.indentLine(a,"smart");c.setCursor({line:0,ch:0})})})})();
(function(){function k(g){for(var c=[/for\s*?\((.*?)\)/g,/&#?[a-z0-9]+;[\s\S]/g,/\"(.*?)((\")|$)/g,/\/\*(.*?)(\*\/|$)/g,/^\/\/.*/g],e=[],b,a,d=0;d<c.length;d++)for(b=0;b<g.length;)if(a=g.substr(b).match(c[d]),null!=a)e.push({start:b+a.index,end:b+a.index+a[0].length}),b+=a.index+Math.max(1,a[0].length);else break;return e.sort(function(a,b){return a.start-b.start}),e}CodeMirror.extendMode("css",{commentStart:"/*",commentEnd:"*/",newlineAfterToken:function(g,c){return/^[;{}]$/.test(c)}});CodeMirror.extendMode("javascript",
{commentStart:"/*",commentEnd:"*/",wordWrapChars:[";","\\{","\\}"],autoFormatLineBreaks:function(g){var c=0,e=this.jsonMode?function(a){return a.replace(/([,{])/g,"$1\n").replace(/}/g,"\n}")}:function(a){return a.replace(/(;|\{|\})([^\r\n;])/g,"$1\n$2")},b=k(g),a="",d;if(null!=b){for(d=0;d<b.length;d++)b[d].start>c&&(a+=e(g.substring(c,b[d].start)),c=b[d].start),b[d].start<=c&&b[d].end>=c&&(a+=g.substring(c,b[d].end),c=b[d].end);c<g.length&&(a+=e(g.substr(c)))}else a=e(g);return a.replace(/^\n*|\n*$/,
"")}});CodeMirror.extendMode("xml",{commentStart:"<\!--",commentEnd:"--\>",noBreak:!1,noBreakEmpty:null,tagType:"",tagName:"",isXML:!1,newlineAfterToken:function(g,c,e){var b=!1,a=null,d="",f;if(this.isXML="xml"==this.configuration?!0:!1,"comment"==g||/<\!--/.test(e))return!1;if("tag"==g){if(0==c.indexOf("<")&&0==!c.indexOf("</")&&(this.tagType="open",a=c.match(/^<\s*?([\w]+?)$/i),this.tagName=null!=a?a[1]:"",d=this.tagName.toLowerCase(),-1!="|label|li|option|textarea|title|a|b|bdi|bdo|big|center|cite|del|em|font|i|img|ins|s|small|span|strike|strong|sub|sup|u|".indexOf("|"+
d+"|")&&(this.noBreak=!0)),0==c.indexOf(">")&&"open"==this.tagType)return(this.tagType="",f=this.isXML?"[^<]*?":"",RegExp("^"+f+"</s*?"+this.tagName+"s*?>","i").test(e))?(this.noBreak=!1,this.isXML||(this.tagName=""),!1):(b=this.noBreak,this.noBreak=!1,b?!1:!0);if(0==c.indexOf("</")&&(this.tagType="close",a=c.match(/^<\/\s*?([\w]+?)$/i),null!=a&&(d=a[1].toLowerCase()),-1!="|a|b|bdi|bdo|big|center|cite|del|em|font|i|img|ins|s|small|span|strike|strong|sub|sup|u|".indexOf("|"+d+"|")&&(this.noBreak=!0)),
0==c.indexOf(">")&&"close"==this.tagType)return(this.tagType="",0==e.indexOf("<")&&(a=e.match(/^<\/?\s*?([\w]+?)(\s|>)/i),d=null!=a?a[1].toLowerCase():"",-1=="|label|li|option|textarea|title|a|b|bdi|bdo|big|center|cite|del|em|font|i|img|ins|s|small|span|strike|strong|sub|sup|u|".indexOf("|"+d+"|")))?(this.noBreak=!1,!0):(b=this.noBreak,this.noBreak=!1,b?!1:!0)}return 0==e.indexOf("<")?(this.noBreak=!1,this.isXML&&""!=this.tagName)?(this.tagName="",!1):(a=e.match(/^<\/?\s*?([\w]+?)(\s|>)/i),d=null!=
a?a[1].toLowerCase():"",-1!="|label|li|option|textarea|title|a|b|bdi|bdo|big|center|cite|del|em|font|i|img|ins|s|small|span|strike|strong|sub|sup|u|".indexOf("|"+d+"|")?!1:!0):!1}});CodeMirror.defineExtension("commentRange",function(g,c,e){var b=this,a=CodeMirror.innerMode(b.getMode(),b.getTokenAt(c).state).mode;b.operation(function(){if(g)b.replaceRange(a.commentEnd,e),b.replaceRange(a.commentStart,c),c.line==e.line&&c.ch==e.ch&&b.setCursor(c.line,c.ch+a.commentStart.length);else{var d=b.getRange(c,
e),f=d.indexOf(a.commentStart),j=d.lastIndexOf(a.commentEnd);-1<f&&-1<j&&j>f&&(d=d.substr(0,f)+d.substring(f+a.commentStart.length,j)+d.substr(j+a.commentEnd.length));b.replaceRange(d,c,e)}})});CodeMirror.defineExtension("autoIndentRange",function(g,c){var e=this;this.operation(function(){for(var b=g.line;b<=c.line;b++)e.indentLine(b,"smart")})});CodeMirror.defineExtension("autoFormatRange",function(g,c){for(var e=this,b=e.getMode(),a=e.getRange(g,c).split("\n"),d=CodeMirror.copyState(b,e.getTokenAt(g).state),
f=e.getOption("tabSize"),j="",i=0,l=0==g.ch,h,m=0;m<a.length;++m){for(h=new CodeMirror.StringStream(a[m],f);!h.eol();){var k=CodeMirror.innerMode(b,d),o=b.token(h,d),p=h.current();h.start=h.pos;(!l||/\S/.test(p))&&(j+=p,l=!1);if(!l&&k.mode.newlineAfterToken&&k.mode.newlineAfterToken(o,p,h.string.slice(h.pos)||a[m+1]||"",k.state))j+="\n",l=!0,++i}!h.pos&&b.blankLine&&b.blankLine(d);!l&&m<a.length-1&&(j+="\n",l=!0,++i)}e.operation(function(){e.replaceRange(j,g,c);for(var a=g.line+1,b=g.line+i;a<=b;++a)e.indentLine(a,
"smart");e.setSelection(g,e.getCursor(!1))})})})();
(function(){function k(a){this.minChars="object"==typeof a&&a.minChars||e;this.style="object"==typeof a&&a.style||b;this.overlay=null}function g(a){a.operation(function(){var b=a.state.matchHighlighter,f;(b.overlay&&(a.removeOverlay(b.overlay),b.overlay=null),a.somethingSelected())&&((f=a.getSelection().replace(/^\s+|\s+$/g,""),f.length<b.minChars)||a.addOverlay(b.overlay=c(f,b.style)))})}function c(a,b){return{token:function(c){if(c.match(a))return b;c.next();c.skipTo(a.charAt(0))||c.skipToEnd()}}}
var e=2,b="matchhighlight";CodeMirror.defineOption("highlightSelectionMatches",!1,function(a,b,c){var c=c&&c!=CodeMirror.Init,e;if(b&&!c){a.state.matchHighlighter=new k(b);a.on("cursorActivity",g)}else!b&&c&&(e=a.state.matchHighlighter.overlay,e&&a.removeOverlay(e),a.state.matchHighlighter=null,a.off("cursorActivity",g))})})();