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:
authorPhil Hughes <me@iamphill.com>2016-06-06 13:59:59 +0300
committerPhil Hughes <me@iamphill.com>2016-06-17 13:52:22 +0300
commit4140c4622f07d8a1793a77ecdf810fbc628568c7 (patch)
treeb9f6fff914d24ba1b89d27272ac11e6e15c2494b /app/assets/javascripts/lib
parentd5b331b76bb6838e121e54cdf50122023932576c (diff)
Made markdown buttons work on all markdown textareas
Selecting multiple rows & a list correctly creates the selected text into a list
Diffstat (limited to 'app/assets/javascripts/lib')
-rw-r--r--app/assets/javascripts/lib/text_utility.js.coffee36
1 files changed, 24 insertions, 12 deletions
diff --git a/app/assets/javascripts/lib/text_utility.js.coffee b/app/assets/javascripts/lib/text_utility.js.coffee
index 52ef001894c..bb2772dfed2 100644
--- a/app/assets/javascripts/lib/text_utility.js.coffee
+++ b/app/assets/javascripts/lib/text_utility.js.coffee
@@ -11,8 +11,18 @@
text.substring(textarea.selectionStart, textarea.selectionEnd)
gl.text.insertText = (textArea, text, tag, selected, wrap) ->
+ selectedSplit = selected.split('\n')
startChar = if not wrap and textArea.selectionStart > 0 then '\n' else ''
- insertText = "#{startChar}#{tag}#{selected}#{if wrap then tag else ' '}"
+
+ if selectedSplit.length > 1 and not wrap
+ insertText = selectedSplit.map((val) ->
+ if val.indexOf(tag) is 0
+ "#{val.replace(tag, '')}"
+ else
+ "#{tag}#{val}"
+ ).join('\n')
+ else
+ insertText = "#{startChar}#{tag}#{selected}#{if wrap then tag else ' '}"
if document.queryCommandSupported('insertText')
document.execCommand 'insertText', false, insertText
@@ -51,17 +61,19 @@
@insertText(textArea, text, tag, selected, wrap)
- gl.text.addListeners = ->
+ gl.text.init = (form) ->
self = @
- $('.js-md').on 'click', ->
- $this = $(@)
- self.updateText(
- $this.closest('.md-area').find('textarea'),
- $this.data('md-tag'),
- not $this.data('md-prepend')
- )
-
- gl.text.removeListeners = ->
- $('.js-md').off()
+ $('.js-md', form)
+ .off 'click'
+ .on 'click', ->
+ $this = $(@)
+ self.updateText(
+ $this.closest('.md-area').find('textarea'),
+ $this.data('md-tag'),
+ not $this.data('md-prepend')
+ )
+
+ gl.text.removeListeners = (form) ->
+ $('.js-md', form).off()
) window