diff options
author | Alfredo Sumaran <alfredo@gitlab.com> | 2016-05-13 18:57:03 +0300 |
---|---|---|
committer | Alfredo Sumaran <alfredo@gitlab.com> | 2016-05-20 23:58:36 +0300 |
commit | ab96ca2bf1ae72817ff5cedf1792c8f7563ebdef (patch) | |
tree | acd247a2f19a43a2686bbec797fcec93f7846738 /app/assets/javascripts/blob | |
parent | 79620c501da19bfda5818b8dca75b6ec9c10e762 (diff) |
Dropdown implementation
Diffstat (limited to 'app/assets/javascripts/blob')
-rw-r--r-- | app/assets/javascripts/blob/blob_gitignore_selector.js.coffee | 51 | ||||
-rw-r--r-- | app/assets/javascripts/blob/edit_blob.js.coffee | 2 |
2 files changed, 24 insertions, 29 deletions
diff --git a/app/assets/javascripts/blob/blob_gitignore_selector.js.coffee b/app/assets/javascripts/blob/blob_gitignore_selector.js.coffee index 2112f5c855a..cc8a497d081 100644 --- a/app/assets/javascripts/blob/blob_gitignore_selector.js.coffee +++ b/app/assets/javascripts/blob/blob_gitignore_selector.js.coffee @@ -1,10 +1,10 @@ -class @BlobGitIgnoreSelector +class @BlobGitignoreSelector constructor: (opts) -> { @dropdown @editor - @wrapper = @dropdown.parents('.gitignore-selector') - @fileNameInput = $('#file_name') + @$wrapper = @dropdown.closest('.gitignore-selector') + @$filenameInput = $('#file_name') @data = @dropdown.data('filenames') } = opts @@ -13,51 +13,46 @@ class @BlobGitIgnoreSelector filterable: true, selectable: true, search: - fields: ['text'] - clicked: @onClick.bind(@) + fields: ['name'] + clicked: @onClick + text: (gitignore) -> + gitignore.name ) - @toggleGitIgnoreSelector() + @toggleGitignoreSelector() @bindEvents() bindEvents: -> - @fileNameInput + @$filenameInput .on 'keyup blur', (e) => - @toggleGitIgnoreSelector() + @toggleGitignoreSelector() - toggleGitIgnoreSelector: -> - filename = @fileNameInput.val() or $('.editor-file-name').text().trim() - @wrapper.toggleClass 'hidden', filename isnt '.gitignore' + toggleGitignoreSelector: -> + filename = @$filenameInput.val() or $('.editor-file-name').text().trim() + @$wrapper.toggleClass 'hidden', filename isnt '.gitignore' - onClick: (item, el, e) -> + onClick: (item, el, e) => e.preventDefault() - @requestIgnoreFile(item.text) + @requestIgnoreFile(item.name) requestIgnoreFile: (name) -> - Api.gitIgnoreText name, @requestIgnoreFileSuccess.bind(@) + Api.gitignoreText name, @requestIgnoreFileSuccess.bind(@) requestIgnoreFileSuccess: (gitignore) -> - @editor.setValue(gitignore.content, -1) - - # Move cursor position to end of file - row = @editor.session.getLength() - 1 - column = @editor.session.getLine(row).length - @editor.gotoLine(row + 1, column) + @editor.setValue(gitignore.content, 1) @editor.focus() -class @BlobGitIgnoreSelectors +class @BlobGitignoreSelectors constructor: (opts) -> - _this = @ - { - @dropdowns = $('.js-gitignore-selector') + @$dropdowns = $('.js-gitignore-selector') @editor } = opts - @dropdowns.each -> - $dropdown = $(@) + @$dropdowns.each (i, dropdown) => + $dropdown = $(dropdown) - new BlobGitIgnoreSelector( + new BlobGitignoreSelector( dropdown: $dropdown, - editor: _this.editor + editor: @editor ) diff --git a/app/assets/javascripts/blob/edit_blob.js.coffee b/app/assets/javascripts/blob/edit_blob.js.coffee index f2efeb3960a..79141e768b8 100644 --- a/app/assets/javascripts/blob/edit_blob.js.coffee +++ b/app/assets/javascripts/blob/edit_blob.js.coffee @@ -13,7 +13,7 @@ class @EditBlob @initModePanesAndLinks() new BlobLicenseSelector(@editor) - new BlobGitIgnoreSelectors(editor: @editor) + new BlobGitignoreSelectors(editor: @editor) initModePanesAndLinks: -> @$editModePanes = $(".js-edit-mode-pane") |