mojio-js-sdk
Version:
Mojio javascript REST client.
1,800 lines (1,557 loc) • 340 kB
JavaScript
(function() {
var makePattern, surroundMatch;
window.fuzzy = function(pattern, items, options) {
var addMatch, after, appendMatch, before, doHighlight, flags, hasTextBeforeSeparator, i, ignorecase, ignorespace, inner, isMatch, item, len, len1, limit, matches, parts, post, postPart, postSep, postSepRegex, pre, prePart, preParts, preSep, preSepRegex, prependMatch, separate, separator;
if (options == null) {
options = {};
}
pre = options.pre, post = options.post, limit = options.limit, separator = options.separator, ignorecase = options.ignorecase, ignorespace = options.ignorespace, separate = options.separate;
if (ignorecase == null) {
ignorecase = true;
}
if (ignorespace == null) {
ignorespace = true;
}
if (separate == null) {
separate = false;
}
if (separate && !separator) {
throw new Error("You must pass a separator when options.separate is true.");
}
if (ignorespace) {
pattern = pattern.replace(/\s/g, "");
}
matches = [];
flags = (ignorecase && "i") || "";
doHighlight = pre && post;
addMatch = function(before, after, method) {
if (separate) {
return matches[method]([before, after]);
} else {
if (before) {
return matches[method](before + separator + after);
} else {
return matches[method](after);
}
}
};
appendMatch = function(before, after) {
return addMatch(before, after, "push");
};
prependMatch = function(before, after) {
return addMatch(before, after, "unshift");
};
if (separator) {
preParts = pattern.split(separator);
postPart = preParts.pop();
prePart = preParts.join(separator);
inner = _.map(preParts, (function(p) {
return makePattern(p);
}));
inner = inner.join(".*?" + separator + ".*?");
preSepRegex = new RegExp("^.*?" + inner + ".*?$", flags);
} else {
preParts = false;
postPart = pattern;
preSepRegex = false;
}
postSepRegex = new RegExp("^.*?" + (makePattern(postPart)) + ".*$", flags);
for (i = 0, len1 = items.length; i < len1; i++) {
item = items[i];
if (matches.length === limit) {
break;
}
hasTextBeforeSeparator = separator && !!~item.indexOf(separator);
if (!hasTextBeforeSeparator && item.indexOf(pattern) === 0) {
if (doHighlight) {
len = pattern.length;
prependMatch("", pre + item.slice(0, len) + post + item.slice(len));
} else {
prependMatch("", item);
}
continue;
}
if (hasTextBeforeSeparator) {
parts = item.split(separator);
preSep = parts.slice(0, -1).join(separator);
postSep = _.last(parts);
} else {
preSep = "";
postSep = item;
}
isMatch = !preSepRegex || preSepRegex.test(preSep);
isMatch && (isMatch = !postSepRegex || postSepRegex.test(postSep));
if (!isMatch) {
continue;
}
if (doHighlight) {
after = surroundMatch(postSep, postPart, pre, post, ignorecase);
if (hasTextBeforeSeparator) {
before = surroundMatch(preSep, prePart, pre, post, ignorecase);
appendMatch(before, after);
} else {
appendMatch("", after);
}
} else {
appendMatch(preSep, postSep);
}
}
return matches;
};
makePattern = function(pattern) {
var c, chars, i, len1, regex;
chars = pattern.split("");
regex = [];
for (i = 0, len1 = chars.length; i < len1; i++) {
c = chars[i];
c = c === "\\" ? "\\\\" : c;
regex.push("([" + c + "])");
}
return regex.join("[^/]*?");
};
surroundMatch = function(string, pattern, pre, post, ignorecase) {
var c, done, i, len1, nextChar, ref, sameChar;
done = "";
pattern = pattern.split("");
nextChar = pattern.shift();
ref = string.split("");
for (i = 0, len1 = ref.length; i < len1; i++) {
c = ref[i];
if (nextChar) {
sameChar = false;
if (ignorecase && c.toLowerCase() === nextChar.toLowerCase()) {
sameChar = true;
} else if (!ignorecase && c === nextChar) {
sameChar = true;
}
if (sameChar) {
done += "" + pre + c + post;
nextChar = pattern.shift();
continue;
}
}
done += c;
}
return done;
};
}).call(this);
/*
Syntax highlighting with language autodetection.
http://softwaremaniacs.org/soft/highlight/
*/
var hljs = new function() {
/* Utility functions */
function escape(value) {
return value.replace(/&/gm, '&').replace(/</gm, '<');
}
function langRe(language, value, global) {
return RegExp(
value,
'm' + (language.case_insensitive ? 'i' : '') + (global ? 'g' : '')
);
}
function findCode(pre) {
for (var i = 0; i < pre.childNodes.length; i++) {
var node = pre.childNodes[i];
if (node.nodeName == 'CODE')
return node;
if (!(node.nodeType == 3 && node.nodeValue.match(/\s+/)))
break;
}
}
function blockText(block, ignoreNewLines) {
var result = '';
for (var i = 0; i < block.childNodes.length; i++)
if (block.childNodes[i].nodeType == 3) {
var chunk = block.childNodes[i].nodeValue;
if (ignoreNewLines)
chunk = chunk.replace(/\n/g, '');
result += chunk;
} else if (block.childNodes[i].nodeName == 'BR')
result += '\n';
else
result += blockText(block.childNodes[i]);
// Thank you, MSIE...
if (/MSIE [678]/.test(navigator.userAgent))
result = result.replace(/\r/g, '\n');
return result;
}
function blockLanguage(block) {
var classes = block.className.split(/\s+/);
classes = classes.concat(block.parentNode.className.split(/\s+/));
for (var i = 0; i < classes.length; i++) {
var class_ = classes[i].replace(/^language-/, '');
if (languages[class_] || class_ == 'no-highlight') {
return class_;
}
}
}
/* Stream merging */
function nodeStream(node) {
var result = [];
(function (node, offset) {
for (var i = 0; i < node.childNodes.length; i++) {
if (node.childNodes[i].nodeType == 3)
offset += node.childNodes[i].nodeValue.length;
else if (node.childNodes[i].nodeName == 'BR')
offset += 1;
else if (node.childNodes[i].nodeType == 1) {
result.push({
event: 'start',
offset: offset,
node: node.childNodes[i]
});
offset = arguments.callee(node.childNodes[i], offset);
result.push({
event: 'stop',
offset: offset,
node: node.childNodes[i]
});
}
}
return offset;
})(node, 0);
return result;
}
function mergeStreams(stream1, stream2, value) {
var processed = 0;
var result = '';
var nodeStack = [];
function selectStream() {
if (stream1.length && stream2.length) {
if (stream1[0].offset != stream2[0].offset)
return (stream1[0].offset < stream2[0].offset) ? stream1 : stream2;
else {
/*
To avoid starting the stream just before it should stop the order is
ensured that stream1 always starts first and closes last:
if (event1 == 'start' && event2 == 'start')
return stream1;
if (event1 == 'start' && event2 == 'stop')
return stream2;
if (event1 == 'stop' && event2 == 'start')
return stream1;
if (event1 == 'stop' && event2 == 'stop')
return stream2;
... which is collapsed to:
*/
return stream2[0].event == 'start' ? stream1 : stream2;
}
} else {
return stream1.length ? stream1 : stream2;
}
}
function open(node) {
var result = '<' + node.nodeName.toLowerCase();
for (var i = 0; i < node.attributes.length; i++) {
var attribute = node.attributes[i];
result += ' ' + attribute.nodeName.toLowerCase();
if (attribute.value !== undefined && attribute.value !== false && attribute.value !== null) {
result += '="' + escape(attribute.value) + '"';
}
}
return result + '>';
}
while (stream1.length || stream2.length) {
var current = selectStream().splice(0, 1)[0];
result += escape(value.substr(processed, current.offset - processed));
processed = current.offset;
if ( current.event == 'start') {
result += open(current.node);
nodeStack.push(current.node);
} else if (current.event == 'stop') {
var node, i = nodeStack.length;
do {
i--;
node = nodeStack[i];
result += ('</' + node.nodeName.toLowerCase() + '>');
} while (node != current.node);
nodeStack.splice(i, 1);
while (i < nodeStack.length) {
result += open(nodeStack[i]);
i++;
}
}
}
return result + escape(value.substr(processed));
}
/* Initialization */
function compileModes() {
function compileMode(mode, language, is_default) {
if (mode.compiled)
return;
var group;
if (!is_default) {
mode.beginRe = langRe(language, mode.begin ? mode.begin : '\\B|\\b');
if (!mode.end && !mode.endsWithParent)
mode.end = '\\B|\\b';
if (mode.end)
mode.endRe = langRe(language, mode.end);
}
if (mode.illegal)
mode.illegalRe = langRe(language, mode.illegal);
if (mode.relevance === undefined)
mode.relevance = 1;
if (mode.keywords) {
mode.lexemsRe = langRe(language, mode.lexems || hljs.IDENT_RE, true);
for (var className in mode.keywords) {
if (!mode.keywords.hasOwnProperty(className))
continue;
if (mode.keywords[className] instanceof Object) {
group = mode.keywords[className];
} else {
group = mode.keywords;
className = 'keyword';
}
for (var keyword in group) {
if (!group.hasOwnProperty(keyword))
continue;
mode.keywords[keyword] = [className, group[keyword]];
}
}
}
if (!mode.contains) {
mode.contains = [];
}
// compiled flag is set before compiling submodes to avoid self-recursion
// (see lisp where quoted_list contains quoted_list)
mode.compiled = true;
for (var i = 0; i < mode.contains.length; i++) {
if (mode.contains[i] == 'self') {
mode.contains[i] = mode;
}
compileMode(mode.contains[i], language, false);
}
if (mode.starts) {
compileMode(mode.starts, language, false);
}
}
for (var i in languages) {
if (!languages.hasOwnProperty(i))
continue;
compileMode(languages[i].defaultMode, languages[i], true);
}
}
/*
Core highlighting function. Accepts a language name and a string with the
code to highlight. Returns an object with the following properties:
- relevance (int)
- keyword_count (int)
- value (an HTML string with highlighting markup)
*/
function highlight(language_name, value) {
if (!compileModes.called) {
compileModes();
compileModes.called = true;
}
function subMode(lexem, mode) {
for (var i = 0; i < mode.contains.length; i++) {
if (mode.contains[i].beginRe.test(lexem)) {
return mode.contains[i];
}
}
}
function endOfMode(mode_index, lexem) {
if (modes[mode_index].end && modes[mode_index].endRe.test(lexem))
return 1;
if (modes[mode_index].endsWithParent) {
var level = endOfMode(mode_index - 1, lexem);
return level ? level + 1 : 0;
}
return 0;
}
function isIllegal(lexem, mode) {
return mode.illegal && mode.illegalRe.test(lexem);
}
function compileTerminators(mode, language) {
var terminators = [];
for (var i = 0; i < mode.contains.length; i++) {
terminators.push(mode.contains[i].begin);
}
var index = modes.length - 1;
do {
if (modes[index].end) {
terminators.push(modes[index].end);
}
index--;
} while (modes[index + 1].endsWithParent);
if (mode.illegal) {
terminators.push(mode.illegal);
}
return langRe(language, '(' + terminators.join('|') + ')', true);
}
function eatModeChunk(value, index) {
var mode = modes[modes.length - 1];
if (!mode.terminators) {
mode.terminators = compileTerminators(mode, language);
}
mode.terminators.lastIndex = index;
var match = mode.terminators.exec(value);
if (match)
return [value.substr(index, match.index - index), match[0], false];
else
return [value.substr(index), '', true];
}
function keywordMatch(mode, match) {
var match_str = language.case_insensitive ? match[0].toLowerCase() : match[0];
var value = mode.keywords[match_str];
if (value && value instanceof Array)
return value;
return false;
}
function processKeywords(buffer, mode) {
buffer = escape(buffer);
if (!mode.keywords)
return buffer;
var result = '';
var last_index = 0;
mode.lexemsRe.lastIndex = 0;
var match = mode.lexemsRe.exec(buffer);
while (match) {
result += buffer.substr(last_index, match.index - last_index);
var keyword_match = keywordMatch(mode, match);
if (keyword_match) {
keyword_count += keyword_match[1];
result += '<span class="'+ keyword_match[0] +'">' + match[0] + '</span>';
} else {
result += match[0];
}
last_index = mode.lexemsRe.lastIndex;
match = mode.lexemsRe.exec(buffer);
}
return result + buffer.substr(last_index, buffer.length - last_index);
}
function processBuffer(buffer, mode) {
if (mode.subLanguage && languages[mode.subLanguage]) {
var result = highlight(mode.subLanguage, buffer);
keyword_count += result.keyword_count;
return result.value;
} else {
return processKeywords(buffer, mode);
}
}
function startNewMode(mode, lexem) {
var markup = mode.className?'<span class="' + mode.className + '">':'';
if (mode.returnBegin) {
result += markup;
mode.buffer = '';
} else if (mode.excludeBegin) {
result += escape(lexem) + markup;
mode.buffer = '';
} else {
result += markup;
mode.buffer = lexem;
}
modes.push(mode);
relevance += mode.relevance;
}
function processModeInfo(buffer, lexem, end) {
var current_mode = modes[modes.length - 1];
if (end) {
result += processBuffer(current_mode.buffer + buffer, current_mode);
return false;
}
var new_mode = subMode(lexem, current_mode);
if (new_mode) {
result += processBuffer(current_mode.buffer + buffer, current_mode);
startNewMode(new_mode, lexem);
return new_mode.returnBegin;
}
var end_level = endOfMode(modes.length - 1, lexem);
if (end_level) {
var markup = current_mode.className?'</span>':'';
if (current_mode.returnEnd) {
result += processBuffer(current_mode.buffer + buffer, current_mode) + markup;
} else if (current_mode.excludeEnd) {
result += processBuffer(current_mode.buffer + buffer, current_mode) + markup + escape(lexem);
} else {
result += processBuffer(current_mode.buffer + buffer + lexem, current_mode) + markup;
}
while (end_level > 1) {
markup = modes[modes.length - 2].className?'</span>':'';
result += markup;
end_level--;
modes.length--;
}
var last_ended_mode = modes[modes.length - 1];
modes.length--;
modes[modes.length - 1].buffer = '';
if (last_ended_mode.starts) {
startNewMode(last_ended_mode.starts, '');
}
return current_mode.returnEnd;
}
if (isIllegal(lexem, current_mode))
throw 'Illegal';
}
var language = languages[language_name];
var modes = [language.defaultMode];
var relevance = 0;
var keyword_count = 0;
var result = '';
try {
var mode_info, index = 0;
language.defaultMode.buffer = '';
do {
mode_info = eatModeChunk(value, index);
var return_lexem = processModeInfo(mode_info[0], mode_info[1], mode_info[2]);
index += mode_info[0].length;
if (!return_lexem) {
index += mode_info[1].length;
}
} while (!mode_info[2]);
if(modes.length > 1)
throw 'Illegal';
return {
relevance: relevance,
keyword_count: keyword_count,
value: result
};
} catch (e) {
if (e == 'Illegal') {
return {
relevance: 0,
keyword_count: 0,
value: escape(value)
};
} else {
throw e;
}
}
}
/*
Highlighting with language detection. Accepts a string with the code to
highlight. Returns an object with the following properties:
- language (detected language)
- relevance (int)
- keyword_count (int)
- value (an HTML string with highlighting markup)
- second_best (object with the same structure for second-best heuristically
detected language, may be absent)
*/
function highlightAuto(text) {
var result = {
keyword_count: 0,
relevance: 0,
value: escape(text)
};
var second_best = result;
for (var key in languages) {
if (!languages.hasOwnProperty(key))
continue;
var current = highlight(key, text);
current.language = key;
if (current.keyword_count + current.relevance > second_best.keyword_count + second_best.relevance) {
second_best = current;
}
if (current.keyword_count + current.relevance > result.keyword_count + result.relevance) {
second_best = result;
result = current;
}
}
if (second_best.language) {
result.second_best = second_best;
}
return result;
}
/*
Post-processing of the highlighted markup:
- replace TABs with something more useful
- replace real line-breaks with '<br>' for non-pre containers
*/
function fixMarkup(value, tabReplace, useBR) {
if (tabReplace) {
value = value.replace(/^((<[^>]+>|\t)+)/gm, function(match, p1, offset, s) {
return p1.replace(/\t/g, tabReplace);
});
}
if (useBR) {
value = value.replace(/\n/g, '<br>');
}
return value;
}
/*
Applies highlighting to a DOM node containing code. Accepts a DOM node and
two optional parameters for fixMarkup.
*/
function highlightBlock(block, tabReplace, useBR) {
var text = blockText(block, useBR);
var language = blockLanguage(block);
var result, pre;
if (language == 'no-highlight')
return;
if (language) {
result = highlight(language, text);
} else {
result = highlightAuto(text);
language = result.language;
}
var original = nodeStream(block);
if (original.length) {
pre = document.createElement('pre');
pre.innerHTML = result.value;
result.value = mergeStreams(original, nodeStream(pre), text);
}
result.value = fixMarkup(result.value, tabReplace, useBR);
var class_name = block.className;
if (!class_name.match('(\\s|^)(language-)?' + language + '(\\s|$)')) {
class_name = class_name ? (class_name + ' ' + language) : language;
}
if (/MSIE [678]/.test(navigator.userAgent) && block.tagName == 'CODE' && block.parentNode.tagName == 'PRE') {
// This is for backwards compatibility only. IE needs this strange
// hack becasue it cannot just cleanly replace <code> block contents.
pre = block.parentNode;
var container = document.createElement('div');
container.innerHTML = '<pre><code>' + result.value + '</code></pre>';
block = container.firstChild.firstChild;
container.firstChild.className = pre.className;
pre.parentNode.replaceChild(container.firstChild, pre);
} else {
block.innerHTML = result.value;
}
block.className = class_name;
block.result = {
language: language,
kw: result.keyword_count,
re: result.relevance
};
if (result.second_best) {
block.second_best = {
language: result.second_best.language,
kw: result.second_best.keyword_count,
re: result.second_best.relevance
};
}
}
/*
Applies highlighting to all <pre><code>..</code></pre> blocks on a page.
*/
function initHighlighting() {
if (initHighlighting.called)
return;
initHighlighting.called = true;
var pres = document.getElementsByTagName('pre');
for (var i = 0; i < pres.length; i++) {
var code = findCode(pres[i]);
if (code)
highlightBlock(code, hljs.tabReplace);
}
}
/*
Attaches highlighting to the page load event.
*/
function initHighlightingOnLoad() {
if (window.addEventListener) {
window.addEventListener('DOMContentLoaded', initHighlighting, false);
window.addEventListener('load', initHighlighting, false);
} else if (window.attachEvent)
window.attachEvent('onload', initHighlighting);
else
window.onload = initHighlighting;
}
var languages = {}; // a shortcut to avoid writing "this." everywhere
/* Interface definition */
this.LANGUAGES = languages;
this.highlight = highlight;
this.highlightAuto = highlightAuto;
this.fixMarkup = fixMarkup;
this.highlightBlock = highlightBlock;
this.initHighlighting = initHighlighting;
this.initHighlightingOnLoad = initHighlightingOnLoad;
// Common regexps
this.IDENT_RE = '[a-zA-Z][a-zA-Z0-9_]*';
this.UNDERSCORE_IDENT_RE = '[a-zA-Z_][a-zA-Z0-9_]*';
this.NUMBER_RE = '\\b\\d+(\\.\\d+)?';
this.C_NUMBER_RE = '\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)'; // 0x..., 0..., decimal, float
this.BINARY_NUMBER_RE = '\\b(0b[01]+)'; // 0b...
this.RE_STARTERS_RE = '!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~';
// Common modes
this.BACKSLASH_ESCAPE = {
begin: '\\\\.', relevance: 0
};
this.APOS_STRING_MODE = {
className: 'string',
begin: '\'', end: '\'',
illegal: '\\n',
contains: [this.BACKSLASH_ESCAPE],
relevance: 0
};
this.QUOTE_STRING_MODE = {
className: 'string',
begin: '"', end: '"',
illegal: '\\n',
contains: [this.BACKSLASH_ESCAPE],
relevance: 0
};
this.C_LINE_COMMENT_MODE = {
className: 'comment',
begin: '//', end: '$'
};
this.C_BLOCK_COMMENT_MODE = {
className: 'comment',
begin: '/\\*', end: '\\*/'
};
this.HASH_COMMENT_MODE = {
className: 'comment',
begin: '#', end: '$'
};
this.NUMBER_MODE = {
className: 'number',
begin: this.NUMBER_RE,
relevance: 0
};
this.C_NUMBER_MODE = {
className: 'number',
begin: this.C_NUMBER_RE,
relevance: 0
};
this.BINARY_NUMBER_MODE = {
className: 'number',
begin: this.BINARY_NUMBER_RE,
relevance: 0
};
// Utility functions
this.inherit = function(parent, obj) {
var result = {}
for (var key in parent)
result[key] = parent[key];
if (obj)
for (var key in obj)
result[key] = obj[key];
return result;
}
}();
/*
Language: CoffeeScript
Author: Dmytrii Nagirniak <dnagir@gmail.com>
Contributors: Oleg Efimov <efimovov@gmail.com>
Description: CoffeeScript is a programming language that transcompiles to JavaScript. For info about language see http://coffeescript.org/
*/
hljs.LANGUAGES.coffeescript = function() {
var keywords = {
'keyword': {
// JS keywords
'in': 1, 'if': 1, 'for': 1, 'while': 1, 'finally': 1,
'new': 1, 'do': 1, 'return': 1, 'else': 1,
'break': 1, 'catch': 1, 'instanceof': 1, 'throw': 1,
'try': 1, 'this': 1, 'switch': 1, 'continue': 1, 'typeof': 1,
'delete': 1, 'debugger': 1,
'class': 1, 'extends': 1, 'super': 1,
// Coffee keywords
'then': 1, 'unless': 1, 'until': 1, 'loop': 2, 'of': 2, 'by': 1, 'when': 2,
'and': 1, 'or': 1, 'is': 1, 'isnt': 2, 'not': 1
},
'literal': {
// JS literals
'true': 1, 'false': 1, 'null': 1, 'undefined': 1,
// Coffee literals
'yes': 1, 'no': 1, 'on': 1, 'off': 1
},
'reserved': {
'case': 1, 'default': 1, 'function': 1, 'var': 1, 'void': 1, 'with': 1,
'const': 1, 'let': 1, 'enum': 1, 'export': 1, 'import': 1, 'native': 1,
'__hasProp': 1 , '__extends': 1 , '__slice': 1 , '__bind': 1 , '__indexOf': 1
}
};
var JS_IDENT_RE = '[A-Za-z$_][0-9A-Za-z$_]*';
var COFFEE_QUOTE_STRING_SUBST_MODE = {
className: 'subst',
begin: '#\\{', end: '}',
keywords: keywords,
contains: [hljs.C_NUMBER_MODE, hljs.BINARY_NUMBER_MODE]
};
var COFFEE_QUOTE_STRING_MODE = {
className: 'string',
begin: '"', end: '"',
relevance: 0,
contains: [hljs.BACKSLASH_ESCAPE, COFFEE_QUOTE_STRING_SUBST_MODE]
};
var COFFEE_HEREDOC_MODE = {
className: 'string',
begin: '"""', end: '"""',
contains: [hljs.BACKSLASH_ESCAPE, COFFEE_QUOTE_STRING_SUBST_MODE]
};
var COFFEE_HERECOMMENT_MODE = {
className: 'comment',
begin: '###', end: '###'
};
var COFFEE_HEREGEX_MODE = {
className: 'regexp',
begin: '///', end: '///',
contains: [hljs.HASH_COMMENT_MODE]
};
var COFFEE_FUNCTION_DECLARATION_MODE = {
className: 'function',
begin: JS_IDENT_RE + '\\s*=\\s*(\\(.+\\))?\\s*[-=]>',
returnBegin: true,
contains: [
{
className: 'title',
begin: JS_IDENT_RE
},
{
className: 'params',
begin: '\\(', end: '\\)'
}
]
};
var COFFEE_EMBEDDED_JAVASCRIPT = {
className: 'javascript',
begin: '`', end: '`',
excludeBegin: true, excludeEnd: true,
subLanguage: 'javascript'
};
return {
defaultMode: {
keywords: keywords,
contains: [
// Numbers
hljs.C_NUMBER_MODE,
hljs.BINARY_NUMBER_MODE,
// Strings
hljs.APOS_STRING_MODE,
COFFEE_HEREDOC_MODE, // Should be before COFFEE_QUOTE_STRING_MODE for greater priority
COFFEE_QUOTE_STRING_MODE,
// Comments
COFFEE_HERECOMMENT_MODE, // Should be before hljs.HASH_COMMENT_MODE for greater priority
hljs.HASH_COMMENT_MODE,
// CoffeeScript specific modes
COFFEE_HEREGEX_MODE,
COFFEE_EMBEDDED_JAVASCRIPT,
COFFEE_FUNCTION_DECLARATION_MODE
]
}
};
}();
/*!
* jQuery JavaScript Library v1.8.1
* http://jquery.com/
*
* Includes Sizzle.js
* http://sizzlejs.com/
*
* Copyright 2012 jQuery Foundation and other contributors
* Released under the MIT license
* http://jquery.org/license
*
* Date: Thu Aug 30 2012 17:17:22 GMT-0400 (Eastern Daylight Time)
*/
(function( window, undefined ) {
var
// A central reference to the root jQuery(document)
rootjQuery,
// The deferred used on DOM ready
readyList,
// Use the correct document accordingly with window argument (sandbox)
document = window.document,
location = window.location,
navigator = window.navigator,
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,
// Map over the $ in case of overwrite
_$ = window.$,
// Save a reference to some core methods
core_push = Array.prototype.push,
core_slice = Array.prototype.slice,
core_indexOf = Array.prototype.indexOf,
core_toString = Object.prototype.toString,
core_hasOwn = Object.prototype.hasOwnProperty,
core_trim = String.prototype.trim,
// Define a local copy of jQuery
jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context, rootjQuery );
},
// Used for matching numbers
core_pnum = /[\-+]?(?:\d*\.|)\d+(?:[eE][\-+]?\d+|)/.source,
// Used for detecting and trimming whitespace
core_rnotwhite = /\S/,
core_rspace = /\s+/,
// Make sure we trim BOM and NBSP (here's looking at you, Safari 5.0 and IE)
rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
// A simple way to check for HTML strings
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
rquickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
// Match a standalone tag
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,
// JSON RegExp
rvalidchars = /^[\],:{}\s]*$/,
rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g,
rvalidescape = /\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,
rvalidtokens = /"[^"\\\r\n]*"|true|false|null|-?(?:\d\d*\.|)\d+(?:[eE][\-+]?\d+|)/g,
// Matches dashed string for camelizing
rmsPrefix = /^-ms-/,
rdashAlpha = /-([\da-z])/gi,
// Used by jQuery.camelCase as callback to replace()
fcamelCase = function( all, letter ) {
return ( letter + "" ).toUpperCase();
},
// The ready event handler and self cleanup method
DOMContentLoaded = function() {
if ( document.addEventListener ) {
document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
jQuery.ready();
} else if ( document.readyState === "complete" ) {
// we're here because readyState === "complete" in oldIE
// which is good enough for us to call the dom ready!
document.detachEvent( "onreadystatechange", DOMContentLoaded );
jQuery.ready();
}
},
// [[Class]] -> type pairs
class2type = {};
jQuery.fn = jQuery.prototype = {
constructor: jQuery,
init: function( selector, context, rootjQuery ) {
var match, elem, ret, doc;
// Handle $(""), $(null), $(undefined), $(false)
if ( !selector ) {
return this;
}
// Handle $(DOMElement)
if ( selector.nodeType ) {
this.context = this[0] = selector;
this.length = 1;
return this;
}
// Handle HTML strings
if ( typeof selector === "string" ) {
if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) {
// Assume that strings that start and end with <> are HTML and skip the regex check
match = [ null, selector, null ];
} else {
match = rquickExpr.exec( selector );
}
// Match html or make sure no context is specified for #id
if ( match && (match[1] || !context) ) {
// HANDLE: $(html) -> $(array)
if ( match[1] ) {
context = context instanceof jQuery ? context[0] : context;
doc = ( context && context.nodeType ? context.ownerDocument || context : document );
// scripts is true for back-compat
selector = jQuery.parseHTML( match[1], doc, true );
if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
this.attr.call( selector, context, true );
}
return jQuery.merge( this, selector );
// HANDLE: $(#id)
} else {
elem = document.getElementById( match[2] );
// Check parentNode to catch when Blackberry 4.6 returns
// nodes that are no longer in the document #6963
if ( elem && elem.parentNode ) {
// Handle the case where IE and Opera return items
// by name instead of ID
if ( elem.id !== match[2] ) {
return rootjQuery.find( selector );
}
// Otherwise, we inject the element directly into the jQuery object
this.length = 1;
this[0] = elem;
}
this.context = document;
this.selector = selector;
return this;
}
// HANDLE: $(expr, $(...))
} else if ( !context || context.jquery ) {
return ( context || rootjQuery ).find( selector );
// HANDLE: $(expr, context)
// (which is just equivalent to: $(context).find(expr)
} else {
return this.constructor( context ).find( selector );
}
// HANDLE: $(function)
// Shortcut for document ready
} else if ( jQuery.isFunction( selector ) ) {
return rootjQuery.ready( selector );
}
if ( selector.selector !== undefined ) {
this.selector = selector.selector;
this.context = selector.context;
}
return jQuery.makeArray( selector, this );
},
// Start with an empty selector
selector: "",
// The current version of jQuery being used
jquery: "1.8.1",
// The default length of a jQuery object is 0
length: 0,
// The number of elements contained in the matched element set
size: function() {
return this.length;
},
toArray: function() {
return core_slice.call( this );
},
// Get the Nth element in the matched element set OR
// Get the whole matched element set as a clean array
get: function( num ) {
return num == null ?
// Return a 'clean' array
this.toArray() :
// Return just the object
( num < 0 ? this[ this.length + num ] : this[ num ] );
},
// Take an array of elements and push it onto the stack
// (returning the new matched element set)
pushStack: function( elems, name, selector ) {
// Build a new jQuery matched element set
var ret = jQuery.merge( this.constructor(), elems );
// Add the old object onto the stack (as a reference)
ret.prevObject = this;
ret.context = this.context;
if ( name === "find" ) {
ret.selector = this.selector + ( this.selector ? " " : "" ) + selector;
} else if ( name ) {
ret.selector = this.selector + "." + name + "(" + selector + ")";
}
// Return the newly-formed element set
return ret;
},
// Execute a callback for every element in the matched set.
// (You can seed the arguments with an array of args, but this is
// only used internally.)
each: function( callback, args ) {
return jQuery.each( this, callback, args );
},
ready: function( fn ) {
// Add the callback
jQuery.ready.promise().done( fn );
return this;
},
eq: function( i ) {
i = +i;
return i === -1 ?
this.slice( i ) :
this.slice( i, i + 1 );
},
first: function() {
return this.eq( 0 );
},
last: function() {
return this.eq( -1 );
},
slice: function() {
return this.pushStack( core_slice.apply( this, arguments ),
"slice", core_slice.call(arguments).join(",") );
},
map: function( callback ) {
return this.pushStack( jQuery.map(this, function( elem, i ) {
return callback.call( elem, i, elem );
}));
},
end: function() {
return this.prevObject || this.constructor(null);
},
// For internal use only.
// Behaves like an Array's method, not like a jQuery method.
push: core_push,
sort: [].sort,
splice: [].splice
};
// Give the init function the jQuery prototype for later instantiation
jQuery.fn.init.prototype = jQuery.fn;
jQuery.extend = jQuery.fn.extend = function() {
var options, name, src, copy, copyIsArray, clone,
target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false;
// Handle a deep copy situation
if ( typeof target === "boolean" ) {
deep = target;
target = arguments[1] || {};
// skip the boolean and the target
i = 2;
}
// Handle case when target is a string or something (possible in deep copy)
if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
target = {};
}
// extend jQuery itself if only one argument is passed
if ( length === i ) {
target = this;
--i;
}
for ( ; i < length; i++ ) {
// Only deal with non-null/undefined values
if ( (options = arguments[ i ]) != null ) {
// Extend the base object
for ( name in options ) {
src = target[ name ];
copy = options[ name ];
// Prevent never-ending loop
if ( target === copy ) {
continue;
}
// Recurse if we're merging plain objects or arrays
if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
if ( copyIsArray ) {
copyIsArray = false;
clone = src && jQuery.isArray(src) ? src : [];
} else {
clone = src && jQuery.isPlainObject(src) ? src : {};
}
// Never move original objects, clone them
target[ name ] = jQuery.extend( deep, clone, copy );
// Don't bring in undefined values
} else if ( copy !== undefined ) {
target[ name ] = copy;
}
}
}
}
// Return the modified object
return target;
};
jQuery.extend({
noConflict: function( deep ) {
if ( window.$ === jQuery ) {
window.$ = _$;
}
if ( deep && window.jQuery === jQuery ) {
window.jQuery = _jQuery;
}
return jQuery;
},
// Is the DOM ready to be used? Set to true once it occurs.
isReady: false,
// A counter to track how many items to wait for before
// the ready event fires. See #6781
readyWait: 1,
// Hold (or release) the ready event
holdReady: function( hold ) {
if ( hold ) {
jQuery.readyWait++;
} else {
jQuery.ready( true );
}
},
// Handle when the DOM is ready
ready: function( wait ) {
// Abort if there are pending holds or we're already ready
if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
return;
}
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
if ( !document.body ) {
return setTimeout( jQuery.ready, 1 );
}
// Remember that the DOM is ready
jQuery.isReady = true;
// If a normal DOM Ready event fired, decrement, and wait if need be
if ( wait !== true && --jQuery.readyWait > 0 ) {
return;
}
// If there are functions bound, to execute
readyList.resolveWith( document, [ jQuery ] );
// Trigger any bound ready events
if ( jQuery.fn.trigger ) {
jQuery( document ).trigger("ready").off("ready");
}
},
// See test/unit/core.js for details concerning isFunction.
// Since version 1.3, DOM methods and functions like alert
// aren't supported. They return false on IE (#2968).
isFunction: function( obj ) {
return jQuery.type(obj) === "function";
},
isArray: Array.isArray || function( obj ) {
return jQuery.type(obj) === "array";
},
isWindow: function( obj ) {
return obj != null && obj == obj.window;
},
isNumeric: function( obj ) {
return !isNaN( parseFloat(obj) ) && isFinite( obj );
},
type: function( obj ) {
return obj == null ?
String( obj ) :
class2type[ core_toString.call(obj) ] || "object";
},
isPlainObject: function( obj ) {
// Must be an Object.
// Because of IE, we also have to check the presence of the constructor property.
// Make sure that DOM nodes and window objects don't pass through, as well
if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
return false;
}
try {
// Not own constructor property must be Object
if ( obj.constructor &&
!core_hasOwn.call(obj, "constructor") &&
!core_hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
return false;
}
} catch ( e ) {
// IE8,9 Will throw exceptions on certain host objects #9897
return false;
}
// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.
var key;
for ( key in obj ) {}
return key === undefined || core_hasOwn.call( obj, key );
},
isEmptyObject: function( obj ) {
var name;
for ( name in obj ) {
return false;
}
return true;
},
error: function( msg ) {
throw new Error( msg );
},
// data: string of html
// context (optional): If specified, the fragment will be created in this context, defaults to document
// scripts (optional): If true, will include scripts passed in the html string
parseHTML: function( data, context, scripts ) {
var parsed;
if ( !data || typeof data !== "string" ) {
return null;
}
if ( typeof context === "boolean" ) {
scripts = context;
context = 0;
}
context = context || document;
// Single tag
if ( (parsed = rsingleTag.exec( data )) ) {
return [ context.createElement( parsed[1] ) ];
}
parsed = jQuery.buildFragment( [ data ], context, scripts ? null : [] );
return jQuery.merge( [],
(parsed.cacheable ? jQuery.clone( parsed.fragment ) : parsed.fragment).childNodes );
},
parseJSON: function( data ) {
if ( !data || typeof data !== "string") {
return null;
}
// Make sure leading/trailing whitespace is removed (IE can't handle it)
data = jQuery.trim( data );
// Attempt to parse using the native JSON parser first
if ( window.JSON && window.JSON.parse ) {
return window.JSON.parse( data );
}
// Make sure the incoming data is actual JSON
// Logic borrowed from http://json.org/json2.js
if ( rvalidchars.test( data.replace( rvalidescape, "@" )
.replace( rvalidtokens, "]" )
.replace( rvalidbraces, "")) ) {
return ( new Function( "return " + data ) )();
}
jQuery.error( "Invalid JSON: " + data );
},
// Cross-browser xml parsing
parseXML: function( data ) {
var xml, tmp;
if ( !data || typeof data !== "string" ) {
return null;
}
try {
if ( window.DOMParser ) { // Standard
tmp = new DOMParser();
xml = tmp.parseFromString( data , "text/xml" );
} else { // IE
xml = new ActiveXObject( "Microsoft.XMLDOM" );
xml.async = "false";
xml.loadXML( data );
}
} catch( e ) {
xml = undefined;
}
if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) {
jQuery.error( "Invalid XML: " + data );
}
return xml;
},
noop: function() {},
// Evaluates a script in a global context
// Workarounds based on findings by Jim Driscoll
// http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
globalEval: function( data ) {
if ( data && core_rnotwhite.test( data ) ) {
// We use execScript on Internet Explorer
// We use an anonymous function so that context is window
// rather than jQuery in Firefox
( window.execScript || function( data ) {
window[ "eval" ].call( window, data );
} )( data );
}
},
// Convert dashed to camelCase; used by the css and data modules
// Microsoft forgot to hump their vendor prefix (#9572)
camelCase: function( string ) {
return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
},
nodeName: function( elem, name ) {
return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
},
// args is for internal usage only
each: function( obj, callback, args ) {
var name,
i = 0,
length = obj.length,
isObj = length === undefined || jQuery.isFunction( obj );
if ( args ) {
if ( isObj ) {
for ( name in obj ) {
if ( callback.apply( obj[ name ], args ) === false ) {
break;
}
}
} else {
for ( ; i < length; ) {
if ( callback.apply( obj[ i++ ], args ) === false ) {
break;
}
}
}
// A special, fast, case for the most common use of each
} else {
if ( isObj ) {
for ( name in obj ) {
if ( callback.call( obj[ name ], name, obj[ name ] ) === false ) {
break;
}
}
} else {
for ( ; i < length; ) {
if ( callback.call( obj[ i ], i, obj[ i++ ] ) === false ) {
break;
}
}
}
}
return obj;
},
// Use native String.trim function wherever possible
trim: core_trim && !core_trim.call("\uFEFF\xA0") ?
function( text ) {
return text == null ?
"" :
core_trim.call( text );
} :
// Otherwise use our own trimming functionality
function( text ) {
return text == null ?
"" :
text.toString().replace( rtrim, "" );
},
// results is for internal usage only
makeArray: function( arr, results ) {
var type,
ret = results || [];
if ( arr != null ) {
// The window, strings (and functions) also have 'length'
// Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
type = jQuery.type( arr );
if ( arr.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( arr ) ) {
core_push.call( ret, arr );
} else {
jQuery.merge( ret, arr );
}
}
return ret;
},
inArray: function( elem, arr, i ) {
var len;
if ( arr ) {
if ( core_indexOf ) {
return core_indexOf.call( arr, elem, i );
}
len = arr.length;
i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
for ( ; i < len; i++ ) {
// Skip accessing in sparse arrays
if ( i in arr && arr[ i ] === elem ) {
return i;
}
}
}
return -1;
},
merge: function( first, second ) {
var l = second.length,
i = first.length,
j = 0;
if ( typeof l === "number" ) {
for ( ; j < l; j++ ) {
first[ i++ ] = second[ j ];
}
} else {
while ( second[j] !== undefined ) {
first[ i++ ] = second[ j++ ];
}
}
first.length = i;
return first;
},
grep: function( elems, callback, inv ) {
var retVal,
ret = [],
i = 0,
length = elems.length;
inv = !!inv;
// Go through the array, only saving the items
// that pass the validator function
for ( ; i < length; i++ ) {
retVal = !!callback( elems[ i ], i );
if ( inv !== retVal ) {
ret.push( elems[ i ] );
}
}
return ret;
},
// arg is for internal usage only
map: function( elems, callback, arg ) {
var value, key,
ret = [],
i = 0,
length = elems.length,
// jquery objects are treated as arrays
isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;
// Go through the array, translating each of the items to their
if ( isArray ) {
for ( ; i < length; i++ ) {
value = callback( elems[ i ], i, arg );
if ( value != null ) {
ret[ ret.length ] = value;
}
}
// Go through every key on the object,
} else {
for ( key in elems ) {
value = callback( elems[ key ], key, arg );
if ( value != null ) {
ret[ ret.length ] = value;
}
}
}
// Flatten any nested arrays
return ret.concat.apply( [], ret );
},
// A global GUID counter for objects
guid: 1,
// Bind a function to a context, optionally partially applying any
// arguments.
proxy: function( fn, context ) {
var tmp, args, proxy;
if ( typeof context === "string" ) {
tmp = fn[ context ];
context = fn;
fn = tmp;
}
// Quick check to determine if target is callable, in the spec
// this throws a TypeError, but we will just return undefined.
if ( !jQuery.isFunction( fn ) ) {
return undefined;
}
// Simulated bind
args = core_slice.call( arguments, 2 );
proxy = function() {
return fn.apply( context, args.concat( core_slice.call( arguments ) ) );
};
// Set the guid of unique handler to the same of original handler, so it can be removed
proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
return proxy;
},
// Multifunctional method to get and set values of a collection
// The value/s can optionally be executed if it's a function
access: function( elems, fn, key, value, chainable, emptyGet, pass ) {
var exec,
bulk = key == null,
i = 0,
length = elems.length;
// Sets many values
if ( key && typeof key === "object" ) {
for ( i in key ) {
jQuery.access( elems, fn, i, key[i], 1, emptyGet, value );
}
chainable = 1;
// Sets one value
} else if ( value !== undefined ) {
// Optionally, function values get executed if exec is true
exec = pass === undefined && jQuery.isFunction( value );
if ( bulk ) {
// Bulk operations only iterate when executing function values
if ( exec ) {
exec = fn;
fn = function( elem, key, value ) {
return exec.call( jQuery( elem ), value );
};
// Otherwise they run against the entire set
} else {
fn.call( elems, value );
fn = null;
}
}
if ( fn ) {
for (; i < length; i++ ) {
fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
}
}
chainable = 1;
}
return chainable ?
elems :
// Gets
bulk ?
fn.call( elems ) :
length ? fn( elems[0], key ) : emptyGet;
},
now: function() {
return ( new Date() ).getTime();
}
});
jQuery.ready.promise = function( obj ) {
if ( !readyList ) {
readyList = jQuery.Deferred();
// Catch cases where $(document).ready() is called after the browser event has already occurred.
// we once tried to use readyState "interactive" here, but it caused issues like the one
// discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
if ( document.readyState === "complete" ) {
// Handle it asynchronously to allow scripts the opportunity to delay ready
setTimeout( jQuery.ready, 1 );
// Standards-based browsers support DOMContentLoaded
} else if ( document.addEventListener ) {
// Use the handy event callback
document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
// A fallback to window.onload, that will always work
window.addEventListener( "load", jQuery.ready, false );
// If IE event model is used
} else {
// Ensure firing before onload, maybe late but safe also for iframes
document.attachEvent( "onreadystatechange", DOMContentLoaded );
// A fallback to window.onload, that will always work
window.attachEvent( "onload", jQuery.ready );
// If IE and not a frame
// continually check to see if the document is ready
var top = false;
try {
top = window.frameElement == null && document.documentElement;
} catch(e) {}
if ( top && top.doScroll ) {
(function doScrollCheck() {
if ( !jQuery.isReady ) {
try {
// Use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
top.doScroll("left");
} catch(e) {
return setTimeout( doScrollCheck, 50 );
}
// and execute any waiting functions
jQuery.ready();
}
})();
}
}
}
return readyList.promise( obj );
};
// Populate t