Skip to content
Snippets Groups Projects
Commit 094cafca authored by Phil Hughes's avatar Phil Hughes
Browse files

Removed GL Actions class

parent 7a1800fe
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -11,13 +11,6 @@ class @GLForm
@form.data 'gl-form', @
 
destroy: ->
# Destroy actions
actions = @form.data 'form-actions'
if actions?
actions.clearEventListeners()
@form.data 'form-actions', null
# Clean form listeners
@clearEventListeners()
@form.data 'gl-form', null
Loading
Loading
@@ -38,10 +31,6 @@ class @GLForm
 
autosize(@textarea)
 
# Setup action buttons
actions = new GLFormActions @form, @textarea
@form.data 'form-actions', actions
# form and textarea event listeners
@addEventListeners()
 
Loading
Loading
class @GLFormActions
constructor: (@form, @textarea) ->
@clearEventListeners()
@addEventListeners()
clearEventListeners: ->
@form.off 'click', '.js-toolbar-button'
addEventListeners: ->
@form.on 'click', '.js-toolbar-button', @toolbarButtonClick
toolbarButtonClick: (e) =>
$btn = $(e.currentTarget)
# Get the prefix from the button
prefix = $btn.data('prefix')
@addPrefixToTextarea(prefix)
addPrefixToTextarea: (prefix) ->
caretStart = @textarea.get(0).selectionStart
caretEnd = @textarea.get(0).selectionEnd
textEnd = @textarea.val().length
beforeSelection = @textarea.val().substring 0, caretStart
afterSelection = @textarea.val().substring caretEnd, textEnd
beforeSelectionSplit = beforeSelection.split ''
beforeSelectionLength = beforeSelection.length
# Get the last character in the before selection
beforeSelectionLastChar = beforeSelectionSplit[beforeSelectionLength - 1]
if beforeSelectionLastChar? and beforeSelectionLastChar isnt ''
# Append a white space char to the prefix if the previous char isn't a space
prefix = " #{prefix}"
# Update the textarea
@textarea.val beforeSelection + prefix + afterSelection
@textarea.get(0).setSelectionRange caretStart + prefix.length, caretEnd + prefix.length
# Focus the textarea
@textarea.focus()
@textarea.trigger('keyup')
.comment-toolbar.clearfix
%button.toolbar-button.js-toolbar-button{ type: 'button', data: { prefix: ':' }, tabindex: '-1' }
= icon('smile-o', class: 'toolbar-button-icon')
Emoji
.toolbar-text
Styling with
= link_to 'Markdown', help_page_path('markdown', 'markdown'), target: '_blank', tabindex: -1
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment