code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function iterateBidiSections(order, from, to, f) {
if (!order) return f(from, to, "ltr");
var found = false;
for (var i = 0; i < order.length; ++i) {
var part = order[i];
if (part.from < to && part.to > from || from == to && part.to == from) {
f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr");
found = true;
}
}
if (!found) f(from, to, "ltr");
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
iterateBidiSections
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function lineRight(line) {
var order = getOrder(line);
if (!order) return line.text.length;
return bidiRight(lst(order));
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
lineRight
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function lineStart(cm, lineN) {
var line = getLine(cm.doc, lineN);
var visual = visualLine(line);
if (visual != line) lineN = lineNo(visual);
var order = getOrder(visual);
var ch = !order ? 0 : order[0].level % 2 ? lineRight(visual) : lineLeft(visual);
return Pos(lineN, ch);
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
lineStart
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function lineEnd(cm, lineN) {
var merged, line = getLine(cm.doc, lineN);
while (merged = collapsedSpanAtEnd(line)) {
line = merged.find(1, true).line;
lineN = null;
}
var order = getOrder(line);
var ch = !order ? line.text.length : order[0].level % 2 ? lineLeft(line) : lineRight(line);
return Pos(lineN == null ? lineNo(line) : lineN, ch);
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
lineEnd
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function lineStartSmart(cm, pos) {
var start = lineStart(cm, pos.line);
var line = getLine(cm.doc, start.line);
var order = getOrder(line);
if (!order || order[0].level == 0) {
var firstNonWS = Math.max(0, line.text.search(/\S/));
var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch;
return Pos(start.line, inWS ? 0 : firstNonWS);
}
return start;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
lineStartSmart
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function compareBidiLevel(order, a, b) {
var linedir = order[0].level;
if (a == linedir) return true;
if (b == linedir) return false;
return a < b;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
compareBidiLevel
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function getBidiPartAt(order, pos) {
bidiOther = null;
for (var i = 0, found; i < order.length; ++i) {
var cur = order[i];
if (cur.from < pos && cur.to > pos) return i;
if ((cur.from == pos || cur.to == pos)) {
if (found == null) {
found = i;
} else if (compareBidiLevel(order, cur.level, order[found].level)) {
if (cur.from != cur.to) bidiOther = found;
return i;
} else {
if (cur.from != cur.to) bidiOther = i;
return found;
}
}
}
return found;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
getBidiPartAt
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function moveInLine(line, pos, dir, byUnit) {
if (!byUnit) return pos + dir;
do pos += dir;
while (pos > 0 && isExtendingChar(line.text.charAt(pos)));
return pos;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
moveInLine
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function moveVisually(line, start, dir, byUnit) {
var bidi = getOrder(line);
if (!bidi) return moveLogically(line, start, dir, byUnit);
var pos = getBidiPartAt(bidi, start), part = bidi[pos];
var target = moveInLine(line, start, part.level % 2 ? -dir : dir, byUnit);
for (;;) {
if (target > part.from && target < part.to) return target;
if (target == part.from || target == part.to) {
if (getBidiPartAt(bidi, target) == pos) return target;
part = bidi[pos += dir];
return (dir > 0) == part.level % 2 ? part.to : part.from;
} else {
part = bidi[pos += dir];
if (!part) return null;
if ((dir > 0) == part.level % 2)
target = moveInLine(line, part.to, -1, byUnit);
else
target = moveInLine(line, part.from, 1, byUnit);
}
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
moveVisually
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function moveLogically(line, start, dir, byUnit) {
var target = start + dir;
if (byUnit) while (target > 0 && isExtendingChar(line.text.charAt(target))) target += dir;
return target < 0 || target > line.text.length ? null : target;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
moveLogically
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function charType(code) {
if (code <= 0xf7) return lowTypes.charAt(code);
else if (0x590 <= code && code <= 0x5f4) return "R";
else if (0x600 <= code && code <= 0x6ed) return arabicTypes.charAt(code - 0x600);
else if (0x6ee <= code && code <= 0x8ac) return "r";
else if (0x2000 <= code && code <= 0x200b) return "w";
else if (code == 0x200c) return "b";
else return "L";
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
charType
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function BidiSpan(level, from, to) {
this.level = level;
this.from = from; this.to = to;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
BidiSpan
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function blankLine(state) {
state.code = false;
return null;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
blankLine
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function getMode(name) {
if (CodeMirror.findModeByName) {
var found = CodeMirror.findModeByName(name);
if (found) name = found.mime || found.mimes[0];
}
var mode = CodeMirror.getMode(cmCfg, name);
return mode.name == "null" ? null : mode;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
getMode
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function switchInline(stream, state, f) {
state.f = state.inline = f;
return f(stream, state);
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
switchInline
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function switchBlock(stream, state, f) {
state.f = state.block = f;
return f(stream, state);
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
switchBlock
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function lineIsEmpty(line) {
return !line || !/\S/.test(line.string)
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
lineIsEmpty
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function blankLine(state) {
// Reset linkTitle state
state.linkTitle = false;
// Reset EM state
state.em = false;
// Reset STRONG state
state.strong = false;
// Reset strikethrough state
state.strikethrough = false;
// Reset state.quote
state.quote = 0;
// Reset state.indentedCode
state.indentedCode = false;
if (htmlModeMissing && state.f == htmlBlock) {
state.f = inlineNormal;
state.block = blockNormal;
}
// Reset state.trailingSpace
state.trailingSpace = 0;
state.trailingSpaceNewLine = false;
// Mark this line as blank
state.prevLine = state.thisLine
state.thisLine = null
return null;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
blankLine
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function blockNormal(stream, state) {
var sol = stream.sol();
var prevLineIsList = state.list !== false,
prevLineIsIndentedCode = state.indentedCode;
state.indentedCode = false;
if (prevLineIsList) {
if (state.indentationDiff >= 0) { // Continued list
if (state.indentationDiff < 4) { // Only adjust indentation if *not* a code block
state.indentation -= state.indentationDiff;
}
state.list = null;
} else if (state.indentation > 0) {
state.list = null;
} else { // No longer a list
state.list = false;
}
}
var match = null;
if (state.indentationDiff >= 4) {
stream.skipToEnd();
if (prevLineIsIndentedCode || lineIsEmpty(state.prevLine)) {
state.indentation -= 4;
state.indentedCode = true;
return tokenTypes.code;
} else {
return null;
}
} else if (stream.eatSpace()) {
return null;
} else if ((match = stream.match(atxHeaderRE)) && match[1].length <= 6) {
state.header = match[1].length;
if (modeCfg.highlightFormatting) state.formatting = "header";
state.f = state.inline;
return getType(state);
} else if (!lineIsEmpty(state.prevLine) && !state.quote && !prevLineIsList &&
!prevLineIsIndentedCode && (match = stream.match(setextHeaderRE))) {
state.header = match[0].charAt(0) == '=' ? 1 : 2;
if (modeCfg.highlightFormatting) state.formatting = "header";
state.f = state.inline;
return getType(state);
} else if (stream.eat('>')) {
state.quote = sol ? 1 : state.quote + 1;
if (modeCfg.highlightFormatting) state.formatting = "quote";
stream.eatSpace();
return getType(state);
} else if (stream.peek() === '[') {
return switchInline(stream, state, footnoteLink);
} else if (stream.match(hrRE, true)) {
state.hr = true;
return tokenTypes.hr;
} else if ((lineIsEmpty(state.prevLine) || prevLineIsList) && (stream.match(ulRE, false) || stream.match(olRE, false))) {
var listType = null;
if (stream.match(ulRE, true)) {
listType = 'ul';
} else {
stream.match(olRE, true);
listType = 'ol';
}
state.indentation = stream.column() + stream.current().length;
state.list = true;
// While this list item's marker's indentation
// is less than the deepest list item's content's indentation,
// pop the deepest list item indentation off the stack.
while (state.listStack && stream.column() < state.listStack[state.listStack.length - 1]) {
state.listStack.pop();
}
// Add this list item's content's indentation to the stack
state.listStack.push(state.indentation);
if (modeCfg.taskLists && stream.match(taskListRE, false)) {
state.taskList = true;
}
state.f = state.inline;
if (modeCfg.highlightFormatting) state.formatting = ["list", "list-" + listType];
return getType(state);
} else if (modeCfg.fencedCodeBlocks && (match = stream.match(fencedCodeRE, true))) {
state.fencedChars = match[1]
// try switching mode
state.localMode = getMode(match[2]);
if (state.localMode) state.localState = CodeMirror.startState(state.localMode);
state.f = state.block = local;
if (modeCfg.highlightFormatting) state.formatting = "code-block";
state.code = -1
return getType(state);
}
return switchInline(stream, state, state.inline);
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
blockNormal
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function htmlBlock(stream, state) {
var style = htmlMode.token(stream, state.htmlState);
if (!htmlModeMissing) {
var inner = CodeMirror.innerMode(htmlMode, state.htmlState)
if ((inner.mode.name == "xml" && inner.state.tagStart === null &&
(!inner.state.context && inner.state.tokenize.isInText)) ||
(state.md_inside && stream.current().indexOf(">") > -1)) {
state.f = inlineNormal;
state.block = blockNormal;
state.htmlState = null;
}
}
return style;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
htmlBlock
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function local(stream, state) {
if (state.fencedChars && stream.match(state.fencedChars, false)) {
state.localMode = state.localState = null;
state.f = state.block = leavingLocal;
return null;
} else if (state.localMode) {
return state.localMode.token(stream, state.localState);
} else {
stream.skipToEnd();
return tokenTypes.code;
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
local
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function leavingLocal(stream, state) {
stream.match(state.fencedChars);
state.block = blockNormal;
state.f = inlineNormal;
state.fencedChars = null;
if (modeCfg.highlightFormatting) state.formatting = "code-block";
state.code = 1
var returnType = getType(state);
state.code = 0
return returnType;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
leavingLocal
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function getType(state) {
var styles = [];
if (state.formatting) {
styles.push(tokenTypes.formatting);
if (typeof state.formatting === "string") state.formatting = [state.formatting];
for (var i = 0; i < state.formatting.length; i++) {
styles.push(tokenTypes.formatting + "-" + state.formatting[i]);
if (state.formatting[i] === "header") {
styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.header);
}
// Add `formatting-quote` and `formatting-quote-#` for blockquotes
// Add `error` instead if the maximum blockquote nesting depth is passed
if (state.formatting[i] === "quote") {
if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.quote);
} else {
styles.push("error");
}
}
}
}
if (state.taskOpen) {
styles.push("meta");
return styles.length ? styles.join(' ') : null;
}
if (state.taskClosed) {
styles.push("property");
return styles.length ? styles.join(' ') : null;
}
if (state.linkHref) {
styles.push(tokenTypes.linkHref, "url");
} else { // Only apply inline styles to non-url text
if (state.strong) { styles.push(tokenTypes.strong); }
if (state.em) { styles.push(tokenTypes.em); }
if (state.strikethrough) { styles.push(tokenTypes.strikethrough); }
if (state.linkText) { styles.push(tokenTypes.linkText); }
if (state.code) { styles.push(tokenTypes.code); }
}
if (state.header) { styles.push(tokenTypes.header, tokenTypes.header + "-" + state.header); }
if (state.quote) {
styles.push(tokenTypes.quote);
// Add `quote-#` where the maximum for `#` is modeCfg.maxBlockquoteDepth
if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
styles.push(tokenTypes.quote + "-" + state.quote);
} else {
styles.push(tokenTypes.quote + "-" + modeCfg.maxBlockquoteDepth);
}
}
if (state.list !== false) {
var listMod = (state.listStack.length - 1) % 3;
if (!listMod) {
styles.push(tokenTypes.list1);
} else if (listMod === 1) {
styles.push(tokenTypes.list2);
} else {
styles.push(tokenTypes.list3);
}
}
if (state.trailingSpaceNewLine) {
styles.push("trailing-space-new-line");
} else if (state.trailingSpace) {
styles.push("trailing-space-" + (state.trailingSpace % 2 ? "a" : "b"));
}
return styles.length ? styles.join(' ') : null;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
getType
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function handleText(stream, state) {
if (stream.match(textRE, true)) {
return getType(state);
}
return undefined;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
handleText
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function inlineNormal(stream, state) {
var style = state.text(stream, state);
if (typeof style !== 'undefined')
return style;
if (state.list) { // List marker (*, +, -, 1., etc)
state.list = null;
return getType(state);
}
if (state.taskList) {
var taskOpen = stream.match(taskListRE, true)[1] !== "x";
if (taskOpen) state.taskOpen = true;
else state.taskClosed = true;
if (modeCfg.highlightFormatting) state.formatting = "task";
state.taskList = false;
return getType(state);
}
state.taskOpen = false;
state.taskClosed = false;
if (state.header && stream.match(/^#+$/, true)) {
if (modeCfg.highlightFormatting) state.formatting = "header";
return getType(state);
}
// Get sol() value now, before character is consumed
var sol = stream.sol();
var ch = stream.next();
// Matches link titles present on next line
if (state.linkTitle) {
state.linkTitle = false;
var matchCh = ch;
if (ch === '(') {
matchCh = ')';
}
matchCh = (matchCh+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
var regex = '^\\s*(?:[^' + matchCh + '\\\\]+|\\\\\\\\|\\\\.)' + matchCh;
if (stream.match(new RegExp(regex), true)) {
return tokenTypes.linkHref;
}
}
// If this block is changed, it may need to be updated in GFM mode
if (ch === '`') {
var previousFormatting = state.formatting;
if (modeCfg.highlightFormatting) state.formatting = "code";
stream.eatWhile('`');
var count = stream.current().length
if (state.code == 0) {
state.code = count
return getType(state)
} else if (count == state.code) { // Must be exact
var t = getType(state)
state.code = 0
return t
} else {
state.formatting = previousFormatting
return getType(state)
}
} else if (state.code) {
return getType(state);
}
if (ch === '\\') {
stream.next();
if (modeCfg.highlightFormatting) {
var type = getType(state);
var formattingEscape = tokenTypes.formatting + "-escape";
return type ? type + " " + formattingEscape : formattingEscape;
}
}
if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) {
stream.match(/\[[^\]]*\]/);
state.inline = state.f = linkHref;
return tokenTypes.image;
}
if (ch === '[' && stream.match(/[^\]]*\](\(.*\)| ?\[.*?\])/, false)) {
state.linkText = true;
if (modeCfg.highlightFormatting) state.formatting = "link";
return getType(state);
}
if (ch === ']' && state.linkText && stream.match(/\(.*?\)| ?\[.*?\]/, false)) {
if (modeCfg.highlightFormatting) state.formatting = "link";
var type = getType(state);
state.linkText = false;
state.inline = state.f = linkHref;
return type;
}
if (ch === '<' && stream.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/, false)) {
state.f = state.inline = linkInline;
if (modeCfg.highlightFormatting) state.formatting = "link";
var type = getType(state);
if (type){
type += " ";
} else {
type = "";
}
return type + tokenTypes.linkInline;
}
if (ch === '<' && stream.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/, false)) {
state.f = state.inline = linkInline;
if (modeCfg.highlightFormatting) state.formatting = "link";
var type = getType(state);
if (type){
type += " ";
} else {
type = "";
}
return type + tokenTypes.linkEmail;
}
if (ch === '<' && stream.match(/^(!--|\w)/, false)) {
var end = stream.string.indexOf(">", stream.pos);
if (end != -1) {
var atts = stream.string.substring(stream.start, end);
if (/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(atts)) state.md_inside = true;
}
stream.backUp(1);
state.htmlState = CodeMirror.startState(htmlMode);
return switchBlock(stream, state, htmlBlock);
}
if (ch === '<' && stream.match(/^\/\w*?>/)) {
state.md_inside = false;
return "tag";
}
var ignoreUnderscore = false;
if (!modeCfg.underscoresBreakWords) {
if (ch === '_' && stream.peek() !== '_' && stream.match(/(\w)/, false)) {
var prevPos = stream.pos - 2;
if (prevPos >= 0) {
var prevCh = stream.string.charAt(prevPos);
if (prevCh !== '_' && prevCh.match(/(\w)/, false)) {
ignoreUnderscore = true;
}
}
}
}
if (ch === '*' || (ch === '_' && !ignoreUnderscore)) {
if (sol && stream.peek() === ' ') {
// Do nothing, surrounded by newline and space
} else if (state.strong === ch && stream.eat(ch)) { // Remove STRONG
if (modeCfg.highlightFormatting) state.formatting = "strong";
var t = getType(state);
state.strong = false;
return t;
} else if (!state.strong && stream.eat(ch)) { // Add STRONG
state.strong = ch;
if (modeCfg.highlightFormatting) state.formatting = "strong";
return getType(state);
} else if (state.em === ch) { // Remove EM
if (modeCfg.highlightFormatting) state.formatting = "em";
var t = getType(state);
state.em = false;
return t;
} else if (!state.em) { // Add EM
state.em = ch;
if (modeCfg.highlightFormatting) state.formatting = "em";
return getType(state);
}
} else if (ch === ' ') {
if (stream.eat('*') || stream.eat('_')) { // Probably surrounded by spaces
if (stream.peek() === ' ') { // Surrounded by spaces, ignore
return getType(state);
} else { // Not surrounded by spaces, back up pointer
stream.backUp(1);
}
}
}
if (modeCfg.strikethrough) {
if (ch === '~' && stream.eatWhile(ch)) {
if (state.strikethrough) {// Remove strikethrough
if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
var t = getType(state);
state.strikethrough = false;
return t;
} else if (stream.match(/^[^\s]/, false)) {// Add strikethrough
state.strikethrough = true;
if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
return getType(state);
}
} else if (ch === ' ') {
if (stream.match(/^~~/, true)) { // Probably surrounded by space
if (stream.peek() === ' ') { // Surrounded by spaces, ignore
return getType(state);
} else { // Not surrounded by spaces, back up pointer
stream.backUp(2);
}
}
}
}
if (ch === ' ') {
if (stream.match(/ +$/, false)) {
state.trailingSpace++;
} else if (state.trailingSpace) {
state.trailingSpaceNewLine = true;
}
}
return getType(state);
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
inlineNormal
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function linkInline(stream, state) {
var ch = stream.next();
if (ch === ">") {
state.f = state.inline = inlineNormal;
if (modeCfg.highlightFormatting) state.formatting = "link";
var type = getType(state);
if (type){
type += " ";
} else {
type = "";
}
return type + tokenTypes.linkInline;
}
stream.match(/^[^>]+/, true);
return tokenTypes.linkInline;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
linkInline
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function linkHref(stream, state) {
// Check if space, and return NULL if so (to avoid marking the space)
if(stream.eatSpace()){
return null;
}
var ch = stream.next();
if (ch === '(' || ch === '[') {
state.f = state.inline = getLinkHrefInside(ch === "(" ? ")" : "]", 0);
if (modeCfg.highlightFormatting) state.formatting = "link-string";
state.linkHref = true;
return getType(state);
}
return 'error';
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
linkHref
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function getLinkHrefInside(endChar) {
return function(stream, state) {
var ch = stream.next();
if (ch === endChar) {
state.f = state.inline = inlineNormal;
if (modeCfg.highlightFormatting) state.formatting = "link-string";
var returnState = getType(state);
state.linkHref = false;
return returnState;
}
stream.match(linkRE[endChar])
state.linkHref = true;
return getType(state);
};
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
getLinkHrefInside
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function footnoteLink(stream, state) {
if (stream.match(/^([^\]\\]|\\.)*\]:/, false)) {
state.f = footnoteLinkInside;
stream.next(); // Consume [
if (modeCfg.highlightFormatting) state.formatting = "link";
state.linkText = true;
return getType(state);
}
return switchInline(stream, state, inlineNormal);
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
footnoteLink
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function footnoteLinkInside(stream, state) {
if (stream.match(/^\]:/, true)) {
state.f = state.inline = footnoteUrl;
if (modeCfg.highlightFormatting) state.formatting = "link";
var returnType = getType(state);
state.linkText = false;
return returnType;
}
stream.match(/^([^\]\\]|\\.)+/, true);
return tokenTypes.linkText;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
footnoteLinkInside
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function footnoteUrl(stream, state) {
// Check if space, and return NULL if so (to avoid marking the space)
if(stream.eatSpace()){
return null;
}
// Match URL
stream.match(/^[^\s]+/, true);
// Check for link title
if (stream.peek() === undefined) { // End of line, set flag to check next line
state.linkTitle = true;
} else { // More content on line, check if link title
stream.match(/^(?:\s+(?:"(?:[^"\\]|\\\\|\\.)+"|'(?:[^'\\]|\\\\|\\.)+'|\((?:[^)\\]|\\\\|\\.)+\)))?/, true);
}
state.f = state.inline = inlineNormal;
return tokenTypes.linkHref + " url";
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
footnoteUrl
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function inText(stream, state) {
function chain(parser) {
state.tokenize = parser;
return parser(stream, state);
}
var ch = stream.next();
if (ch == "<") {
if (stream.eat("!")) {
if (stream.eat("[")) {
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
else return null;
} else if (stream.match("--")) {
return chain(inBlock("comment", "-->"));
} else if (stream.match("DOCTYPE", true, true)) {
stream.eatWhile(/[\w\._\-]/);
return chain(doctype(1));
} else {
return null;
}
} else if (stream.eat("?")) {
stream.eatWhile(/[\w\._\-]/);
state.tokenize = inBlock("meta", "?>");
return "meta";
} else {
type = stream.eat("/") ? "closeTag" : "openTag";
state.tokenize = inTag;
return "tag bracket";
}
} else if (ch == "&") {
var ok;
if (stream.eat("#")) {
if (stream.eat("x")) {
ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
} else {
ok = stream.eatWhile(/[\d]/) && stream.eat(";");
}
} else {
ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
}
return ok ? "atom" : "error";
} else {
stream.eatWhile(/[^&<]/);
return null;
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
inText
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function chain(parser) {
state.tokenize = parser;
return parser(stream, state);
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
chain
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function inTag(stream, state) {
var ch = stream.next();
if (ch == ">" || (ch == "/" && stream.eat(">"))) {
state.tokenize = inText;
type = ch == ">" ? "endTag" : "selfcloseTag";
return "tag bracket";
} else if (ch == "=") {
type = "equals";
return null;
} else if (ch == "<") {
state.tokenize = inText;
state.state = baseState;
state.tagName = state.tagStart = null;
var next = state.tokenize(stream, state);
return next ? next + " tag error" : "tag error";
} else if (/[\'\"]/.test(ch)) {
state.tokenize = inAttribute(ch);
state.stringStartCol = stream.column();
return state.tokenize(stream, state);
} else {
stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);
return "word";
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
inTag
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function inAttribute(quote) {
var closure = function(stream, state) {
while (!stream.eol()) {
if (stream.next() == quote) {
state.tokenize = inTag;
break;
}
}
return "string";
};
closure.isInAttribute = true;
return closure;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
inAttribute
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
closure = function(stream, state) {
while (!stream.eol()) {
if (stream.next() == quote) {
state.tokenize = inTag;
break;
}
}
return "string";
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
closure
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function inBlock(style, terminator) {
return function(stream, state) {
while (!stream.eol()) {
if (stream.match(terminator)) {
state.tokenize = inText;
break;
}
stream.next();
}
return style;
};
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
inBlock
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function doctype(depth) {
return function(stream, state) {
var ch;
while ((ch = stream.next()) != null) {
if (ch == "<") {
state.tokenize = doctype(depth + 1);
return state.tokenize(stream, state);
} else if (ch == ">") {
if (depth == 1) {
state.tokenize = inText;
break;
} else {
state.tokenize = doctype(depth - 1);
return state.tokenize(stream, state);
}
}
}
return "meta";
};
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
doctype
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function Context(state, tagName, startOfLine) {
this.prev = state.context;
this.tagName = tagName;
this.indent = state.indented;
this.startOfLine = startOfLine;
if (config.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent))
this.noIndent = true;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
Context
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function popContext(state) {
if (state.context) state.context = state.context.prev;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
popContext
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function maybePopContext(state, nextTagName) {
var parentTagName;
while (true) {
if (!state.context) {
return;
}
parentTagName = state.context.tagName;
if (!config.contextGrabbers.hasOwnProperty(parentTagName) ||
!config.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
return;
}
popContext(state);
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
maybePopContext
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function baseState(type, stream, state) {
if (type == "openTag") {
state.tagStart = stream.column();
return tagNameState;
} else if (type == "closeTag") {
return closeTagNameState;
} else {
return baseState;
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
baseState
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function tagNameState(type, stream, state) {
if (type == "word") {
state.tagName = stream.current();
setStyle = "tag";
return attrState;
} else {
setStyle = "error";
return tagNameState;
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
tagNameState
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function closeTagNameState(type, stream, state) {
if (type == "word") {
var tagName = stream.current();
if (state.context && state.context.tagName != tagName &&
config.implicitlyClosed.hasOwnProperty(state.context.tagName))
popContext(state);
if ((state.context && state.context.tagName == tagName) || config.matchClosing === false) {
setStyle = "tag";
return closeState;
} else {
setStyle = "tag error";
return closeStateErr;
}
} else {
setStyle = "error";
return closeStateErr;
}
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
closeTagNameState
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function closeState(type, _stream, state) {
if (type != "endTag") {
setStyle = "error";
return closeState;
}
popContext(state);
return baseState;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
closeState
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function closeStateErr(type, stream, state) {
setStyle = "error";
return closeState(type, stream, state);
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
closeStateErr
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function attrState(type, _stream, state) {
if (type == "word") {
setStyle = "attribute";
return attrEqState;
} else if (type == "endTag" || type == "selfcloseTag") {
var tagName = state.tagName, tagStart = state.tagStart;
state.tagName = state.tagStart = null;
if (type == "selfcloseTag" ||
config.autoSelfClosers.hasOwnProperty(tagName)) {
maybePopContext(state, tagName);
} else {
maybePopContext(state, tagName);
state.context = new Context(state, tagName, tagStart == state.indented);
}
return baseState;
}
setStyle = "error";
return attrState;
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
attrState
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function attrEqState(type, stream, state) {
if (type == "equals") return attrValueState;
if (!config.allowMissing) setStyle = "error";
return attrState(type, stream, state);
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
attrEqState
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function attrValueState(type, stream, state) {
if (type == "string") return attrContinuedState;
if (type == "word" && config.allowUnquoted) {setStyle = "string"; return attrState;}
setStyle = "error";
return attrState(type, stream, state);
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
attrValueState
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function attrContinuedState(type, stream, state) {
if (type == "string") return attrContinuedState;
return attrState(type, stream, state);
}
|
Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
attrContinuedState
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function addWord(word, rules) {
// Some dictionaries will list the same word multiple times with different rule sets.
if (!(word in dictionaryTable) || typeof dictionaryTable[word] != 'object') {
dictionaryTable[word] = [];
}
dictionaryTable[word].push(rules);
}
|
Parses the words out from the .dic file.
@param {String} data The data from the dictionary file.
@returns object The lookup table containing all of the words and
word forms from the dictionary.
|
addWord
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function fixShortcut(name) {
if(isMac) {
name = name.replace("Ctrl", "Cmd");
} else {
name = name.replace("Cmd", "Ctrl");
}
return name;
}
|
Fix shortcut. Mac use Command, others use Ctrl.
|
fixShortcut
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function getState(cm, pos) {
pos = pos || cm.getCursor("start");
var stat = cm.getTokenAt(pos);
if(!stat.type) return {};
var types = stat.type.split(" ");
var ret = {},
data, text;
for(var i = 0; i < types.length; i++) {
data = types[i];
if(data === "strong") {
ret.bold = true;
} else if(data === "variable-2") {
text = cm.getLine(pos.line);
if(/^\s*\d+\.\s/.test(text)) {
ret["ordered-list"] = true;
} else {
ret["unordered-list"] = true;
}
} else if(data === "atom") {
ret.quote = true;
} else if(data === "em") {
ret.italic = true;
} else if(data === "quote") {
ret.quote = true;
} else if(data === "strikethrough") {
ret.strikethrough = true;
} else if(data === "comment") {
ret.code = true;
} else if(data === "link") {
ret.link = true;
} else if(data === "tag") {
ret.image = true;
} else if(data.match(/^header(\-[1-6])?$/)) {
ret[data.replace("header", "heading")] = true;
}
}
return ret;
}
|
The state of CodeMirror at the given position.
|
getState
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function toggleFullScreen(editor) {
// Set fullscreen
var cm = editor.codemirror;
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
// Prevent scrolling on body during fullscreen active
if(cm.getOption("fullScreen")) {
saved_overflow = document.body.style.overflow;
document.body.style.overflow = "hidden";
} else {
document.body.style.overflow = saved_overflow;
}
// Update toolbar class
var wrap = cm.getWrapperElement();
if(!/fullscreen/.test(wrap.previousSibling.className)) {
wrap.previousSibling.className += " fullscreen";
} else {
wrap.previousSibling.className = wrap.previousSibling.className.replace(/\s*fullscreen\b/, "");
}
// Update toolbar button
var toolbarButton = editor.toolbarElements.fullscreen;
if(!/active/.test(toolbarButton.className)) {
toolbarButton.className += " active";
} else {
toolbarButton.className = toolbarButton.className.replace(/\s*active\s*/g, "");
}
// Hide side by side if needed
var sidebyside = cm.getWrapperElement().nextSibling;
if(/editor-preview-active-side/.test(sidebyside.className))
toggleSideBySide(editor);
}
|
Toggle full screen of the editor.
|
toggleFullScreen
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function toggleHeadingSmaller(editor) {
var cm = editor.codemirror;
_toggleHeading(cm, "smaller");
}
|
Action for toggling heading size: normal -> h1 -> h2 -> h3 -> h4 -> h5 -> h6 -> normal
|
toggleHeadingSmaller
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function toggleHeadingBigger(editor) {
var cm = editor.codemirror;
_toggleHeading(cm, "bigger");
}
|
Action for toggling heading size: normal -> h6 -> h5 -> h4 -> h3 -> h2 -> h1 -> normal
|
toggleHeadingBigger
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function cleanBlock(editor) {
var cm = editor.codemirror;
_cleanBlock(cm);
}
|
Action for clean block (remove headline, list, blockquote code, markers)
|
cleanBlock
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function isLocalStorageAvailable() {
if(typeof localStorage === "object") {
try {
localStorage.setItem("smde_localStorage", 1);
localStorage.removeItem("smde_localStorage");
} catch(e) {
return false;
}
} else {
return false;
}
return true;
}
|
Render editor to the given element.
|
isLocalStorageAvailable
|
javascript
|
sparksuite/simplemde-markdown-editor
|
debug/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/debug/simplemde.js
|
MIT
|
function fixShortcut(name) {
if(isMac) {
name = name.replace("Ctrl", "Cmd");
} else {
name = name.replace("Cmd", "Ctrl");
}
return name;
}
|
Fix shortcut. Mac use Command, others use Ctrl.
|
fixShortcut
|
javascript
|
sparksuite/simplemde-markdown-editor
|
src/js/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/src/js/simplemde.js
|
MIT
|
function getState(cm, pos) {
pos = pos || cm.getCursor("start");
var stat = cm.getTokenAt(pos);
if(!stat.type) return {};
var types = stat.type.split(" ");
var ret = {},
data, text;
for(var i = 0; i < types.length; i++) {
data = types[i];
if(data === "strong") {
ret.bold = true;
} else if(data === "variable-2") {
text = cm.getLine(pos.line);
if(/^\s*\d+\.\s/.test(text)) {
ret["ordered-list"] = true;
} else {
ret["unordered-list"] = true;
}
} else if(data === "atom") {
ret.quote = true;
} else if(data === "em") {
ret.italic = true;
} else if(data === "quote") {
ret.quote = true;
} else if(data === "strikethrough") {
ret.strikethrough = true;
} else if(data === "comment") {
ret.code = true;
} else if(data === "link") {
ret.link = true;
} else if(data === "tag") {
ret.image = true;
} else if(data.match(/^header(\-[1-6])?$/)) {
ret[data.replace("header", "heading")] = true;
}
}
return ret;
}
|
The state of CodeMirror at the given position.
|
getState
|
javascript
|
sparksuite/simplemde-markdown-editor
|
src/js/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/src/js/simplemde.js
|
MIT
|
function toggleFullScreen(editor) {
// Set fullscreen
var cm = editor.codemirror;
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
// Prevent scrolling on body during fullscreen active
if(cm.getOption("fullScreen")) {
saved_overflow = document.body.style.overflow;
document.body.style.overflow = "hidden";
} else {
document.body.style.overflow = saved_overflow;
}
// Update toolbar class
var wrap = cm.getWrapperElement();
if(!/fullscreen/.test(wrap.previousSibling.className)) {
wrap.previousSibling.className += " fullscreen";
} else {
wrap.previousSibling.className = wrap.previousSibling.className.replace(/\s*fullscreen\b/, "");
}
// Update toolbar button
var toolbarButton = editor.toolbarElements.fullscreen;
if(!/active/.test(toolbarButton.className)) {
toolbarButton.className += " active";
} else {
toolbarButton.className = toolbarButton.className.replace(/\s*active\s*/g, "");
}
// Hide side by side if needed
var sidebyside = cm.getWrapperElement().nextSibling;
if(/editor-preview-active-side/.test(sidebyside.className))
toggleSideBySide(editor);
}
|
Toggle full screen of the editor.
|
toggleFullScreen
|
javascript
|
sparksuite/simplemde-markdown-editor
|
src/js/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/src/js/simplemde.js
|
MIT
|
function toggleHeadingSmaller(editor) {
var cm = editor.codemirror;
_toggleHeading(cm, "smaller");
}
|
Action for toggling heading size: normal -> h1 -> h2 -> h3 -> h4 -> h5 -> h6 -> normal
|
toggleHeadingSmaller
|
javascript
|
sparksuite/simplemde-markdown-editor
|
src/js/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/src/js/simplemde.js
|
MIT
|
function toggleHeadingBigger(editor) {
var cm = editor.codemirror;
_toggleHeading(cm, "bigger");
}
|
Action for toggling heading size: normal -> h6 -> h5 -> h4 -> h3 -> h2 -> h1 -> normal
|
toggleHeadingBigger
|
javascript
|
sparksuite/simplemde-markdown-editor
|
src/js/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/src/js/simplemde.js
|
MIT
|
function cleanBlock(editor) {
var cm = editor.codemirror;
_cleanBlock(cm);
}
|
Action for clean block (remove headline, list, blockquote code, markers)
|
cleanBlock
|
javascript
|
sparksuite/simplemde-markdown-editor
|
src/js/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/src/js/simplemde.js
|
MIT
|
function isLocalStorageAvailable() {
if(typeof localStorage === "object") {
try {
localStorage.setItem("smde_localStorage", 1);
localStorage.removeItem("smde_localStorage");
} catch(e) {
return false;
}
} else {
return false;
}
return true;
}
|
Render editor to the given element.
|
isLocalStorageAvailable
|
javascript
|
sparksuite/simplemde-markdown-editor
|
src/js/simplemde.js
|
https://github.com/sparksuite/simplemde-markdown-editor/blob/master/src/js/simplemde.js
|
MIT
|
App = (props) => {
const listsByPath = require('../utils/lists').listsByPath;
let children = props.children;
// If we're on either a list or an item view
let currentList, currentSection;
if (props.params.listId) {
currentList = listsByPath[props.params.listId];
// If we're on a list path that doesn't exist (e.g. /keystone/gibberishasfw34afsd) this will
// be undefined
if (!currentList) {
children = (
<Container>
<p>List not found!</p>
<Link to={`${Keystone.adminPath}`}>
Go back home
</Link>
</Container>
);
} else {
// Get the current section we're in for the navigation
currentSection = Keystone.nav.by.list[currentList.key];
}
}
// Default current section key to dashboard
const currentSectionKey = (currentSection && currentSection.key) || 'dashboard';
return (
<div className={css(classes.wrapper)}>
<header>
<MobileNavigation
brand={Keystone.brand}
currentListKey={props.params.listId}
currentSectionKey={currentSectionKey}
sections={Keystone.nav.sections}
signoutUrl={Keystone.signoutUrl}
/>
<PrimaryNavigation
currentSectionKey={currentSectionKey}
brand={Keystone.brand}
sections={Keystone.nav.sections}
signoutUrl={Keystone.signoutUrl}
/>
{/* If a section is open currently, show the secondary nav */}
{(currentSection) ? (
<SecondaryNavigation
currentListKey={props.params.listId}
lists={currentSection.lists}
itemId={props.params.itemId}
/>
) : null}
</header>
<main className={css(classes.body)}>
{children}
</main>
<Footer
appversion={Keystone.appversion}
backUrl={Keystone.backUrl}
brand={Keystone.brand}
User={Keystone.User}
user={Keystone.user}
version={Keystone.version}
/>
</div>
);
}
|
The App component is the component that is rendered around all views, and
contains common things like navigation, footer, etc.
|
App
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/App.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/App.js
|
MIT
|
App = (props) => {
const listsByPath = require('../utils/lists').listsByPath;
let children = props.children;
// If we're on either a list or an item view
let currentList, currentSection;
if (props.params.listId) {
currentList = listsByPath[props.params.listId];
// If we're on a list path that doesn't exist (e.g. /keystone/gibberishasfw34afsd) this will
// be undefined
if (!currentList) {
children = (
<Container>
<p>List not found!</p>
<Link to={`${Keystone.adminPath}`}>
Go back home
</Link>
</Container>
);
} else {
// Get the current section we're in for the navigation
currentSection = Keystone.nav.by.list[currentList.key];
}
}
// Default current section key to dashboard
const currentSectionKey = (currentSection && currentSection.key) || 'dashboard';
return (
<div className={css(classes.wrapper)}>
<header>
<MobileNavigation
brand={Keystone.brand}
currentListKey={props.params.listId}
currentSectionKey={currentSectionKey}
sections={Keystone.nav.sections}
signoutUrl={Keystone.signoutUrl}
/>
<PrimaryNavigation
currentSectionKey={currentSectionKey}
brand={Keystone.brand}
sections={Keystone.nav.sections}
signoutUrl={Keystone.signoutUrl}
/>
{/* If a section is open currently, show the secondary nav */}
{(currentSection) ? (
<SecondaryNavigation
currentListKey={props.params.listId}
lists={currentSection.lists}
itemId={props.params.itemId}
/>
) : null}
</header>
<main className={css(classes.body)}>
{children}
</main>
<Footer
appversion={Keystone.appversion}
backUrl={Keystone.backUrl}
brand={Keystone.brand}
User={Keystone.User}
user={Keystone.user}
version={Keystone.version}
/>
</div>
);
}
|
The App component is the component that is rendered around all views, and
contains common things like navigation, footer, etc.
|
App
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/App.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/App.js
|
MIT
|
renderUser() {
const { User, user } = this.props;
if (!user) return null;
return (
<span>
<span> Signed in as </span>
<a
href={`${Keystone.adminPath}/${User.path}/${user.id}`}
tabIndex="-1"
className={css(classes.link)}
>
{user.name}
</a>
<span>.</span>
</span>
);
}
|
The global Footer, displays a link to the website and the current Keystone
version in use
|
renderUser
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Footer/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Footer/index.js
|
MIT
|
render() {
const { backUrl, brand, appversion, version } = this.props;
return (
<footer className={css(classes.footer)} data-keystone-footer>
<Container>
<a href={backUrl} tabIndex="-1" className={css(classes.link)}>
{brand + (appversion ? " " + appversion : "")}
</a>
<span> powered by </span>
<a
href="http://v4.keystonejs.com"
target="_blank"
className={css(classes.link)}
tabIndex="-1"
>
KeystoneJS
</a>
<span> version {version}.</span>
{this.renderUser()}
</Container>
</footer>
);
}
|
The global Footer, displays a link to the website and the current Keystone
version in use
|
render
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Footer/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Footer/index.js
|
MIT
|
getInitialState () {
return {
barIsVisible: false,
};
}
|
The mobile navigation, displayed on screens < 768px
|
getInitialState
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Mobile/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Mobile/index.js
|
MIT
|
componentDidMount () {
this.handleResize();
window.addEventListener('resize', this.handleResize);
}
|
The mobile navigation, displayed on screens < 768px
|
componentDidMount
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Mobile/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Mobile/index.js
|
MIT
|
componentWillUnmount () {
window.removeEventListener('resize', this.handleResize);
}
|
The mobile navigation, displayed on screens < 768px
|
componentWillUnmount
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Mobile/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Mobile/index.js
|
MIT
|
handleResize () {
this.setState({
barIsVisible: window.innerWidth < 768,
});
}
|
The mobile navigation, displayed on screens < 768px
|
handleResize
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Mobile/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Mobile/index.js
|
MIT
|
toggleMenu () {
this[this.state.menuIsVisible ? 'hideMenu' : 'showMenu']();
}
|
The mobile navigation, displayed on screens < 768px
|
toggleMenu
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Mobile/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Mobile/index.js
|
MIT
|
showMenu () {
this.setState({
menuIsVisible: true,
});
// Make the body unscrollable, so you can only scroll in the menu
document.body.style.overflow = 'hidden';
document.body.addEventListener('keyup', this.handleEscapeKey, false);
}
|
The mobile navigation, displayed on screens < 768px
|
showMenu
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Mobile/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Mobile/index.js
|
MIT
|
hideMenu () {
this.setState({
menuIsVisible: false,
});
// Make the body scrollable again
document.body.style.overflow = null;
document.body.removeEventListener('keyup', this.handleEscapeKey, false);
}
|
The mobile navigation, displayed on screens < 768px
|
hideMenu
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Mobile/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Mobile/index.js
|
MIT
|
handleEscapeKey (event) {
if (event.which === ESCAPE_KEY_CODE) {
this.hideMenu();
}
}
|
The mobile navigation, displayed on screens < 768px
|
handleEscapeKey
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Mobile/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Mobile/index.js
|
MIT
|
renderNavigation () {
if (!this.props.sections || !this.props.sections.length) return null;
return this.props.sections.map((section) => {
// Get the link and the classname
const href = section.lists[0].external ? section.lists[0].path : `${Keystone.adminPath}/${section.lists[0].path}`;
const className = (this.props.currentSectionKey && this.props.currentSectionKey === section.key) ? 'MobileNavigation__section is-active' : 'MobileNavigation__section';
// Render a SectionItem
return (
<MobileSectionItem
key={section.key}
className={className}
href={href}
lists={section.lists}
currentListKey={this.props.currentListKey}
onClick={this.toggleMenu}
>
{section.label}
</MobileSectionItem>
);
});
}
|
The mobile navigation, displayed on screens < 768px
|
renderNavigation
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Mobile/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Mobile/index.js
|
MIT
|
renderBlockout () {
if (!this.state.menuIsVisible) return null;
return <div className="MobileNavigation__blockout" onClick={this.toggleMenu} />;
}
|
The mobile navigation, displayed on screens < 768px
|
renderBlockout
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Mobile/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Mobile/index.js
|
MIT
|
renderMenu () {
if (!this.state.menuIsVisible) return null;
return (
<nav className="MobileNavigation__menu">
<div className="MobileNavigation__sections">
{this.renderNavigation()}
</div>
</nav>
);
}
|
The mobile navigation, displayed on screens < 768px
|
renderMenu
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Mobile/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Mobile/index.js
|
MIT
|
render () {
if (!this.state.barIsVisible) return null;
return (
<div className="MobileNavigation">
<div className="MobileNavigation__bar">
<button
type="button"
onClick={this.toggleMenu}
className="MobileNavigation__bar__button MobileNavigation__bar__button--menu"
>
<span className={'MobileNavigation__bar__icon octicon octicon-' + (this.state.menuIsVisible ? 'x' : 'three-bars')} />
</button>
<span className="MobileNavigation__bar__label">
{this.props.brand}
</span>
<a
href={this.props.signoutUrl}
className="MobileNavigation__bar__button MobileNavigation__bar__button--signout"
>
<span className="MobileNavigation__bar__icon octicon octicon-sign-out" />
</a>
</div>
<div className="MobileNavigation__bar--placeholder" />
<Transition
transitionName="MobileNavigation__menu"
transitionEnterTimeout={260}
transitionLeaveTimeout={200}
>
{this.renderMenu()}
</Transition>
<Transition
transitionName="react-transitiongroup-fade"
transitionEnterTimeout={0}
transitionLeaveTimeout={0}
>
{this.renderBlockout()}
</Transition>
</div>
);
}
|
The mobile navigation, displayed on screens < 768px
|
render
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Mobile/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Mobile/index.js
|
MIT
|
render () {
return (
<Link
className={this.props.className}
to={this.props.href}
onClick={this.props.onClick}
tabIndex="-1"
>
{this.props.children}
</Link>
);
}
|
A list item of the mobile navigation
|
render
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Mobile/ListItem.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Mobile/ListItem.js
|
MIT
|
getInitialState () {
return {};
}
|
The primary (i.e. uppermost) navigation on desktop. Renders all sections and
the home-, website- and signout buttons.
|
getInitialState
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Primary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Primary/index.js
|
MIT
|
componentDidMount () {
this.handleResize();
window.addEventListener('resize', this.handleResize);
}
|
The primary (i.e. uppermost) navigation on desktop. Renders all sections and
the home-, website- and signout buttons.
|
componentDidMount
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Primary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Primary/index.js
|
MIT
|
componentWillUnmount () {
window.removeEventListener('resize', this.handleResize);
}
|
The primary (i.e. uppermost) navigation on desktop. Renders all sections and
the home-, website- and signout buttons.
|
componentWillUnmount
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Primary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Primary/index.js
|
MIT
|
handleResize () {
this.setState({
navIsVisible: window.innerWidth >= 768,
});
}
|
The primary (i.e. uppermost) navigation on desktop. Renders all sections and
the home-, website- and signout buttons.
|
handleResize
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Primary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Primary/index.js
|
MIT
|
renderSignout () {
if (!this.props.signoutUrl) return null;
return (
<PrimaryNavItem
label="octicon-sign-out"
href={this.props.signoutUrl}
title="Sign Out"
>
<span className="octicon octicon-sign-out" />
</PrimaryNavItem>
);
}
|
The primary (i.e. uppermost) navigation on desktop. Renders all sections and
the home-, website- and signout buttons.
|
renderSignout
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Primary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Primary/index.js
|
MIT
|
renderBackButton () {
if (!Keystone.backUrl) return null;
return (
<PrimaryNavItem
label="octicon-globe"
href={Keystone.backUrl}
title={'Front page - ' + this.props.brand}
>
<span className="octicon octicon-globe" />
</PrimaryNavItem>
);
}
|
The primary (i.e. uppermost) navigation on desktop. Renders all sections and
the home-, website- and signout buttons.
|
renderBackButton
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Primary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Primary/index.js
|
MIT
|
renderFrontLink () {
return (
<ul className="app-nav app-nav--primary app-nav--right">
{this.renderBackButton()}
{this.renderSignout()}
</ul>
);
}
|
The primary (i.e. uppermost) navigation on desktop. Renders all sections and
the home-, website- and signout buttons.
|
renderFrontLink
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Primary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Primary/index.js
|
MIT
|
renderBrand () {
// TODO: support navbarLogo from keystone config
const { brand, currentSectionKey } = this.props;
const className = currentSectionKey === 'dashboard' ? 'primary-navbar__brand primary-navbar__item--active' : 'primary-navbar__brand';
return (
<PrimaryNavItem
className={className}
label="octicon-home"
title={'Dashboard - ' + brand}
to={Keystone.adminPath}
>
<span className="octicon octicon-home" />
</PrimaryNavItem>
);
}
|
The primary (i.e. uppermost) navigation on desktop. Renders all sections and
the home-, website- and signout buttons.
|
renderBrand
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Primary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Primary/index.js
|
MIT
|
renderNavigation () {
if (!this.props.sections || !this.props.sections.length) return null;
return this.props.sections.map((section) => {
// Get the link and the class name
const to = !section.lists[0].external && `${Keystone.adminPath}/${section.lists[0].path}`;
const href = section.lists[0].external && section.lists[0].path;
const isActive = this.props.currentSectionKey && this.props.currentSectionKey === section.key;
const className = isActive ? 'primary-navbar__item--active' : null;
return (
<PrimaryNavItem
active={isActive}
key={section.key}
label={section.label}
className={className}
to={to}
href={href}
>
{section.label}
</PrimaryNavItem>
);
});
}
|
The primary (i.e. uppermost) navigation on desktop. Renders all sections and
the home-, website- and signout buttons.
|
renderNavigation
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Primary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Primary/index.js
|
MIT
|
render () {
if (!this.state.navIsVisible) return null;
return (
<nav className="primary-navbar">
<Container clearFloatingChildren>
<ul className="app-nav app-nav--primary app-nav--left">
{this.renderBrand()}
{this.renderNavigation()}
</ul>
{this.renderFrontLink()}
</Container>
</nav>
);
}
|
The primary (i.e. uppermost) navigation on desktop. Renders all sections and
the home-, website- and signout buttons.
|
render
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Primary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Primary/index.js
|
MIT
|
PrimaryNavItem = ({ children, className, href, label, title, to, active }) => {
const itemClassName = classnames('primary-navbar__item', className);
const Button = to ? (
<Link
className="primary-navbar__link"
key={title}
tabIndex="-1"
title={title}
to={to}
// Block clicks on active link
onClick={(evt) => { if (active) evt.preventDefault(); }}
>
{children}
</Link>
) : (
<a
className="primary-navbar__link"
href={href}
key={title}
tabIndex="-1"
title={title}
>
{children}
</a>
);
return (
<li
className={itemClassName}
data-section-label={label}
>
{Button}
</li>
);
}
|
A item in the primary navigation. If it has a "to" prop it'll render a
react-router "Link", if it has a "href" prop it'll render a simple "a" tag
|
PrimaryNavItem
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Primary/NavItem.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Primary/NavItem.js
|
MIT
|
PrimaryNavItem = ({ children, className, href, label, title, to, active }) => {
const itemClassName = classnames('primary-navbar__item', className);
const Button = to ? (
<Link
className="primary-navbar__link"
key={title}
tabIndex="-1"
title={title}
to={to}
// Block clicks on active link
onClick={(evt) => { if (active) evt.preventDefault(); }}
>
{children}
</Link>
) : (
<a
className="primary-navbar__link"
href={href}
key={title}
tabIndex="-1"
title={title}
>
{children}
</a>
);
return (
<li
className={itemClassName}
data-section-label={label}
>
{Button}
</li>
);
}
|
A item in the primary navigation. If it has a "to" prop it'll render a
react-router "Link", if it has a "href" prop it'll render a simple "a" tag
|
PrimaryNavItem
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Primary/NavItem.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Primary/NavItem.js
|
MIT
|
getInitialState () {
return {};
}
|
The secondary navigation links to inidvidual lists of a section
|
getInitialState
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Secondary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Secondary/index.js
|
MIT
|
componentDidMount () {
this.handleResize();
window.addEventListener('resize', this.handleResize);
}
|
The secondary navigation links to inidvidual lists of a section
|
componentDidMount
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Secondary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Secondary/index.js
|
MIT
|
componentWillUnmount () {
window.removeEventListener('resize', this.handleResize);
}
|
The secondary navigation links to inidvidual lists of a section
|
componentWillUnmount
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Secondary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Secondary/index.js
|
MIT
|
handleResize () {
this.setState({
navIsVisible: this.props.lists && Object.keys(this.props.lists).length > 0 && window.innerWidth >= 768,
});
}
|
The secondary navigation links to inidvidual lists of a section
|
handleResize
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Secondary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Secondary/index.js
|
MIT
|
renderNavigation (lists) {
const navigation = Object.keys(lists).map((key) => {
const list = lists[key];
// Get the link and the classname
const href = list.external ? list.path : `${Keystone.adminPath}/${list.path}`;
const isActive = this.props.currentListKey && this.props.currentListKey === list.path;
const className = isActive ? 'active' : null;
const onClick = (evt) => {
// If it's the currently active navigation item and we're not on the item view,
// clear the query params on click
if (isActive && !this.props.itemId) {
evt.preventDefault();
this.props.dispatch(
setActiveList(this.props.currentList, this.props.currentListKey)
);
}
};
return (
<SecondaryNavItem
key={list.path}
path={list.path}
className={className}
href={href}
onClick={onClick}
>
{list.label}
</SecondaryNavItem>
);
});
return (
<ul className="app-nav app-nav--secondary app-nav--left">
{navigation}
</ul>
);
}
|
The secondary navigation links to inidvidual lists of a section
|
renderNavigation
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Secondary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Secondary/index.js
|
MIT
|
onClick = (evt) => {
// If it's the currently active navigation item and we're not on the item view,
// clear the query params on click
if (isActive && !this.props.itemId) {
evt.preventDefault();
this.props.dispatch(
setActiveList(this.props.currentList, this.props.currentListKey)
);
}
}
|
The secondary navigation links to inidvidual lists of a section
|
onClick
|
javascript
|
keystonejs/keystone-classic
|
admin/client/App/components/Navigation/Secondary/index.js
|
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Secondary/index.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.