Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2018-10-10 09:25:43 +0300
committerMike Greiling <mike@pixelcog.com>2018-10-10 10:30:24 +0300
commitf7a3e8ff53449bc4ad4a19b3df5a6d19f391b180 (patch)
treeb5775fd537ba9c24f5551d93166253041b7fc58b /app/assets/javascripts/lib/utils/text_markdown.js
parent9867eaf3efb6102eb81704d815312737c7e444c1 (diff)
Prettify lib/utils modules
Diffstat (limited to 'app/assets/javascripts/lib/utils/text_markdown.js')
-rw-r--r--app/assets/javascripts/lib/utils/text_markdown.js74
1 files changed, 49 insertions, 25 deletions
diff --git a/app/assets/javascripts/lib/utils/text_markdown.js b/app/assets/javascripts/lib/utils/text_markdown.js
index df20785b178..e26a6b986be 100644
--- a/app/assets/javascripts/lib/utils/text_markdown.js
+++ b/app/assets/javascripts/lib/utils/text_markdown.js
@@ -8,12 +8,18 @@ function selectedText(text, textarea) {
function lineBefore(text, textarea) {
var split;
- split = text.substring(0, textarea.selectionStart).trim().split('\n');
+ split = text
+ .substring(0, textarea.selectionStart)
+ .trim()
+ .split('\n');
return split[split.length - 1];
}
function lineAfter(text, textarea) {
- return text.substring(textarea.selectionEnd).trim().split('\n')[0];
+ return text
+ .substring(textarea.selectionEnd)
+ .trim()
+ .split('\n')[0];
}
function blockTagText(text, textArea, blockTag, selected) {
@@ -27,7 +33,7 @@ function blockTagText(text, textArea, blockTag, selected) {
}
return selected;
} else {
- return blockTag + "\n" + selected + "\n" + blockTag;
+ return blockTag + '\n' + selected + '\n' + blockTag;
}
}
@@ -58,7 +64,14 @@ function moveCursor({ textArea, tag, wrapped, removedLastNewLine, select }) {
}
export function insertMarkdownText({ textArea, text, tag, blockTag, selected, wrap, select }) {
- var textToInsert, inserted, selectedSplit, startChar, removedLastNewLine, removedFirstNewLine, currentLineEmpty, lastNewLine;
+ var textToInsert,
+ inserted,
+ selectedSplit,
+ startChar,
+ removedLastNewLine,
+ removedFirstNewLine,
+ currentLineEmpty,
+ lastNewLine;
removedLastNewLine = false;
removedFirstNewLine = false;
currentLineEmpty = false;
@@ -94,21 +107,23 @@ export function insertMarkdownText({ textArea, text, tag, blockTag, selected, wr
if (blockTag != null && blockTag !== '') {
textToInsert = blockTagText(text, textArea, blockTag, selected);
} else {
- textToInsert = selectedSplit.map(function(val) {
- if (tag.indexOf(textPlaceholder) > -1) {
- return tag.replace(textPlaceholder, val);
- }
- if (val.indexOf(tag) === 0) {
- return "" + (val.replace(tag, ''));
- } else {
- return "" + tag + val;
- }
- }).join('\n');
+ textToInsert = selectedSplit
+ .map(function(val) {
+ if (tag.indexOf(textPlaceholder) > -1) {
+ return tag.replace(textPlaceholder, val);
+ }
+ if (val.indexOf(tag) === 0) {
+ return '' + val.replace(tag, '');
+ } else {
+ return '' + tag + val;
+ }
+ })
+ .join('\n');
}
} else if (tag.indexOf(textPlaceholder) > -1) {
textToInsert = tag.replace(textPlaceholder, selected);
} else {
- textToInsert = "" + startChar + tag + selected + (wrap ? tag : ' ');
+ textToInsert = '' + startChar + tag + selected + (wrap ? tag : ' ');
}
if (removedFirstNewLine) {
@@ -120,7 +135,13 @@ export function insertMarkdownText({ textArea, text, tag, blockTag, selected, wr
}
insertText(textArea, textToInsert);
- return moveCursor({ textArea, tag: tag.replace(textPlaceholder, selected), wrap, removedLastNewLine, select });
+ return moveCursor({
+ textArea,
+ tag: tag.replace(textPlaceholder, selected),
+ wrap,
+ removedLastNewLine,
+ select,
+ });
}
function updateText({ textArea, tag, blockTag, wrap, select }) {
@@ -138,15 +159,18 @@ function replaceRange(s, start, end, substitute) {
}
export function addMarkdownListeners(form) {
- return $('.js-md', form).off('click').on('click', function() {
- const $this = $(this);
- return updateText({
- textArea: $this.closest('.md-area').find('textarea'),
- tag: $this.data('mdTag'),
- blockTag: $this.data('mdBlock'),
- wrap: !$this.data('mdPrepend'),
- select: $this.data('mdSelect') });
- });
+ return $('.js-md', form)
+ .off('click')
+ .on('click', function() {
+ const $this = $(this);
+ return updateText({
+ textArea: $this.closest('.md-area').find('textarea'),
+ tag: $this.data('mdTag'),
+ blockTag: $this.data('mdBlock'),
+ wrap: !$this.data('mdPrepend'),
+ select: $this.data('mdSelect'),
+ });
+ });
}
export function removeMarkdownListeners(form) {