BigW Consortium Gitlab

Commit e8a26546 by Douwe Maan

Satisfy eslint

parent c463dfb6
/* eslint-disable class-methods-use-this */ /* eslint-disable class-methods-use-this, object-shorthand, no-unused-vars, no-use-before-define, no-new, max-len, no-restricted-syntax, guard-for-in, no-continue */
/*jshint esversion: 6 */ /* jshint esversion: 6 */
/*= require lib/utils/common_utils */ /*= require lib/utils/common_utils */
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
TaskListFilter: { TaskListFilter: {
'input[type=checkbox].task-list-item-checkbox'(el, text) { 'input[type=checkbox].task-list-item-checkbox'(el, text) {
return `[${el.checked ? 'x' : ' '}]`; return `[${el.checked ? 'x' : ' '}]`;
} },
}, },
ReferenceFilter: { ReferenceFilter: {
'a.gfm:not([data-link=true])'(el, text) { 'a.gfm:not([data-link=true])'(el, text) {
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
}, },
VideoLinkFilter: { VideoLinkFilter: {
'.video-container'(el, text) { '.video-container'(el, text) {
let videoEl = el.querySelector('video'); const videoEl = el.querySelector('video');
if (!videoEl) return false; if (!videoEl) return false;
return CopyAsGFM.nodeToGFM(videoEl); return CopyAsGFM.nodeToGFM(videoEl);
...@@ -66,22 +66,22 @@ ...@@ -66,22 +66,22 @@
}, },
MathFilter: { MathFilter: {
'pre.code.math[data-math-style=display]'(el, text) { 'pre.code.math[data-math-style=display]'(el, text) {
return '```math\n' + text.trim() + '\n```'; return `\`\`\`math\n${text.trim()}\n\`\`\``;
}, },
'code.code.math[data-math-style=inline]'(el, text) { 'code.code.math[data-math-style=inline]'(el, text) {
return '$`' + text + '`$'; return `$\`${text}\`$`;
}, },
'span.katex-display span.katex-mathml'(el, text) { 'span.katex-display span.katex-mathml'(el, text) {
let mathAnnotation = el.querySelector('annotation[encoding="application/x-tex"]'); const mathAnnotation = el.querySelector('annotation[encoding="application/x-tex"]');
if (!mathAnnotation) return false; if (!mathAnnotation) return false;
return '```math\n' + CopyAsGFM.nodeToGFM(mathAnnotation) + '\n```'; return `\`\`\`math\n${CopyAsGFM.nodeToGFM(mathAnnotation)}\n\`\`\``;
}, },
'span.katex-mathml'(el, text) { 'span.katex-mathml'(el, text) {
let mathAnnotation = el.querySelector('annotation[encoding="application/x-tex"]'); const mathAnnotation = el.querySelector('annotation[encoding="application/x-tex"]');
if (!mathAnnotation) return false; if (!mathAnnotation) return false;
return '$`' + CopyAsGFM.nodeToGFM(mathAnnotation) + '`$'; return `$\`${CopyAsGFM.nodeToGFM(mathAnnotation)}\`$`;
}, },
'span.katex-html'(el, text) { 'span.katex-html'(el, text) {
// We don't want to include the content of this element in the copied text. // We don't want to include the content of this element in the copied text.
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
}, },
'annotation[encoding="application/x-tex"]'(el, text) { 'annotation[encoding="application/x-tex"]'(el, text) {
return text.trim(); return text.trim();
} },
}, },
SyntaxHighlightFilter: { SyntaxHighlightFilter: {
'pre.code.highlight'(el, text) { 'pre.code.highlight'(el, text) {
...@@ -97,7 +97,7 @@ ...@@ -97,7 +97,7 @@
if (lang === 'plaintext') { if (lang === 'plaintext') {
lang = ''; lang = '';
} }
return '```' + lang + '\n' + text.trim() + '\n```'; return `\`\`\`${lang}\n${text.trim()}\n\`\`\``;
}, },
'pre > code'(el, text) { 'pre > code'(el, text) {
// Don't wrap code blocks in `` // Don't wrap code blocks in ``
...@@ -107,18 +107,18 @@ ...@@ -107,18 +107,18 @@
MarkdownFilter: { MarkdownFilter: {
'code'(el, text) { 'code'(el, text) {
let backtickCount = 1; let backtickCount = 1;
let backtickMatch = text.match(/`+/); const backtickMatch = text.match(/`+/);
if (backtickMatch) { if (backtickMatch) {
backtickCount = backtickMatch[0].length + 1; backtickCount = backtickMatch[0].length + 1;
} }
let backticks = new Array(backtickCount + 1).join('`'); const backticks = new Array(backtickCount + 1).join('`');
let spaceOrNoSpace = backtickCount > 1 ? ' ' : ''; const spaceOrNoSpace = backtickCount > 1 ? ' ' : '';
return backticks + spaceOrNoSpace + text + spaceOrNoSpace + backticks; return backticks + spaceOrNoSpace + text + spaceOrNoSpace + backticks;
}, },
'blockquote'(el, text) { 'blockquote'(el, text) {
return text.trim().split('\n').map((s) => `> ${s}`.trim()).join('\n'); return text.trim().split('\n').map(s => `> ${s}`.trim()).join('\n');
}, },
'img'(el, text) { 'img'(el, text) {
return `![${el.getAttribute('alt')}](${el.getAttribute('src')})`; return `![${el.getAttribute('alt')}](${el.getAttribute('src')})`;
...@@ -131,15 +131,14 @@ ...@@ -131,15 +131,14 @@
return `[${text}](${el.getAttribute('href')})`; return `[${text}](${el.getAttribute('href')})`;
}, },
'li'(el, text) { 'li'(el, text) {
let lines = text.trim().split('\n'); const lines = text.trim().split('\n');
let firstLine = '- ' + lines.shift(); const firstLine = `- ${lines.shift()}`;
// Add two spaces to the front of subsequent list items lines, or leave the line entirely blank. // Add two spaces to the front of subsequent list items lines,
let nextLines = lines.map(function(s) { // or leave the line entirely blank.
if (s.trim().length === 0) { const nextLines = lines.map((s) => {
return ''; if (s.trim().length === 0) return '';
} else {
return ` ${s}`; return ` ${s}`;
}
}); });
return `${firstLine}\n${nextLines.join('\n')}`; return `${firstLine}\n${nextLines.join('\n')}`;
...@@ -185,13 +184,13 @@ ...@@ -185,13 +184,13 @@
return '-----'; return '-----';
}, },
'table'(el, text) { 'table'(el, text) {
let theadText = CopyAsGFM.nodeToGFM(el.querySelector('thead')); const theadText = CopyAsGFM.nodeToGFM(el.querySelector('thead'));
let tbodyText = CopyAsGFM.nodeToGFM(el.querySelector('tbody')); const tbodyText = CopyAsGFM.nodeToGFM(el.querySelector('tbody'));
return theadText + tbodyText; return theadText + tbodyText;
}, },
'thead'(el, text) { 'thead'(el, text) {
let cells = _.map(el.querySelectorAll('th'), function(cell) { const cells = _.map(el.querySelectorAll('th'), (cell) => {
let chars = CopyAsGFM.nodeToGFM(cell).trim().length; let chars = CopyAsGFM.nodeToGFM(cell).trim().length;
let before = ''; let before = '';
...@@ -206,24 +205,24 @@ ...@@ -206,24 +205,24 @@
after = ':'; after = ':';
chars -= 1; chars -= 1;
break; break;
default:
break;
} }
chars = Math.max(chars, 0); chars = Math.max(chars, 0);
let middle = new Array(chars + 1).join('-'); const middle = new Array(chars + 1).join('-');
return before + middle + after; return before + middle + after;
}); });
return text + `| ${cells.join(' | ')} |`; return `${text}| ${cells.join(' | ')} |`;
}, },
'tr'(el, text) { 'tr'(el, text) {
let cells = _.map(el.querySelectorAll('td, th'), function(cell) { const cells = _.map(el.querySelectorAll('td, th'), cell => CopyAsGFM.nodeToGFM(cell).trim());
return CopyAsGFM.nodeToGFM(cell).trim();
});
return `| ${cells.join(' | ')} |`; return `| ${cells.join(' | ')} |`;
}, },
} },
}; };
class CopyAsGFM { class CopyAsGFM {
...@@ -233,24 +232,24 @@ ...@@ -233,24 +232,24 @@
} }
handleCopy(e) { handleCopy(e) {
let clipboardData = e.originalEvent.clipboardData; const clipboardData = e.originalEvent.clipboardData;
if (!clipboardData) return; if (!clipboardData) return;
let documentFragment = window.gl.utils.getSelectedFragment(); const documentFragment = window.gl.utils.getSelectedFragment();
if (!documentFragment) return; if (!documentFragment) return;
e.preventDefault(); e.preventDefault();
clipboardData.setData('text/plain', documentFragment.textContent); clipboardData.setData('text/plain', documentFragment.textContent);
let gfm = CopyAsGFM.nodeToGFM(documentFragment); const gfm = CopyAsGFM.nodeToGFM(documentFragment);
clipboardData.setData('text/x-gfm', gfm); clipboardData.setData('text/x-gfm', gfm);
} }
handlePaste(e) { handlePaste(e) {
let clipboardData = e.originalEvent.clipboardData; const clipboardData = e.originalEvent.clipboardData;
if (!clipboardData) return; if (!clipboardData) return;
let gfm = clipboardData.getData('text/x-gfm'); const gfm = clipboardData.getData('text/x-gfm');
if (!gfm) return; if (!gfm) return;
e.preventDefault(); e.preventDefault();
...@@ -263,21 +262,21 @@ ...@@ -263,21 +262,21 @@
return node.textContent; return node.textContent;
} }
let text = this.innerGFM(node); const text = this.innerGFM(node);
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
return text; return text;
} }
for (let filter in gfmRules) { for (const filter in gfmRules) {
let rules = gfmRules[filter]; const rules = gfmRules[filter];
for (let selector in rules) { for (const selector in rules) {
let func = rules[selector]; const func = rules[selector];
if (!window.gl.utils.nodeMatchesSelector(node, selector)) continue; if (!window.gl.utils.nodeMatchesSelector(node, selector)) continue;
let result = func(node, text); const result = func(node, text);
if (result === false) continue; if (result === false) continue;
return result; return result;
...@@ -288,16 +287,16 @@ ...@@ -288,16 +287,16 @@
} }
static innerGFM(parentNode) { static innerGFM(parentNode) {
let nodes = parentNode.childNodes; const nodes = parentNode.childNodes;
let clonedParentNode = parentNode.cloneNode(true); const clonedParentNode = parentNode.cloneNode(true);
let clonedNodes = Array.prototype.slice.call(clonedParentNode.childNodes, 0); const clonedNodes = Array.prototype.slice.call(clonedParentNode.childNodes, 0);
for (let i = 0; i < nodes.length; i++) { for (let i = 0; i < nodes.length; i += 1) {
let node = nodes[i]; const node = nodes[i];
let clonedNode = clonedNodes[i]; const clonedNode = clonedNodes[i];
let text = this.nodeToGFM(node); const text = this.nodeToGFM(node);
// `clonedNode.replaceWith(text)` is not yet widely supported // `clonedNode.replaceWith(text)` is not yet widely supported
clonedNode.parentNode.replaceChild(document.createTextNode(text), clonedNode); clonedNode.parentNode.replaceChild(document.createTextNode(text), clonedNode);
......
...@@ -163,34 +163,34 @@ ...@@ -163,34 +163,34 @@
w.gl.utils.getSelectedFragment = () => { w.gl.utils.getSelectedFragment = () => {
if (!window.getSelection) return null; if (!window.getSelection) return null;
let selection = window.getSelection(); const selection = window.getSelection();
if (!selection.rangeCount || selection.rangeCount === 0) return null; if (!selection.rangeCount || selection.rangeCount === 0) return null;
let documentFragment = selection.getRangeAt(0).cloneContents(); const documentFragment = selection.getRangeAt(0).cloneContents();
if (!documentFragment) return null; if (!documentFragment) return null;
if (documentFragment.textContent.length === 0) return null; if (documentFragment.textContent.length === 0) return null;
return documentFragment; return documentFragment;
} };
w.gl.utils.insertText = (target, text) => { w.gl.utils.insertText = (target, text) => {
// Firefox doesn't support `document.execCommand('insertText', false, text)` on textareas // Firefox doesn't support `document.execCommand('insertText', false, text)` on textareas
let selectionStart = target.selectionStart; const selectionStart = target.selectionStart;
let selectionEnd = target.selectionEnd; const selectionEnd = target.selectionEnd;
let value = target.value; const value = target.value;
let textBefore = value.substring(0, selectionStart); const textBefore = value.substring(0, selectionStart);
let textAfter = value.substring(selectionEnd, value.length); const textAfter = value.substring(selectionEnd, value.length);
let newText = textBefore + text + textAfter; const newText = textBefore + text + textAfter;
target.value = newText; target.value = newText;
target.selectionStart = target.selectionEnd = selectionStart + text.length; target.selectionStart = target.selectionEnd = selectionStart + text.length;
} };
w.gl.utils.nodeMatchesSelector = (node, selector) => { w.gl.utils.nodeMatchesSelector = (node, selector) => {
let matches = Element.prototype.matches || const matches = Element.prototype.matches ||
Element.prototype.matchesSelector || Element.prototype.matchesSelector ||
Element.prototype.mozMatchesSelector || Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector || Element.prototype.msMatchesSelector ||
...@@ -210,9 +210,9 @@ ...@@ -210,9 +210,9 @@
parentNode.appendChild(node); parentNode.appendChild(node);
} }
let matchingNodes = parentNode.querySelectorAll(selector); const matchingNodes = parentNode.querySelectorAll(selector);
return Array.prototype.indexOf.call(matchingNodes, node) !== -1; return Array.prototype.indexOf.call(matchingNodes, node) !== -1;
} };
})(window); })(window);
}).call(this); }).call(this);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment