summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfredo Sumaran <alfredo@gitlab.com>2016-03-17 14:59:43 -0500
committerAlfredo Sumaran <alfredo@gitlab.com>2016-03-17 15:02:42 -0500
commit647f28bd1d92eabe239a7f0f4a65eb100c0cda73 (patch)
treeca3fbcd3a51c6c9bd14110b8f33482001e9e997b
parentbc70597908c2aa144472b28c891306a6d9390c34 (diff)
downloadgitlab-ce-647f28bd1d92eabe239a7f0f4a65eb100c0cda73.tar.gz
Make it generic
-rw-r--r--app/assets/javascripts/gl_crop.js.coffee26
-rw-r--r--app/assets/javascripts/profile.js.coffee10
2 files changed, 24 insertions, 12 deletions
diff --git a/app/assets/javascripts/gl_crop.js.coffee b/app/assets/javascripts/gl_crop.js.coffee
index 6ab0afc184f..137d025ed26 100644
--- a/app/assets/javascripts/gl_crop.js.coffee
+++ b/app/assets/javascripts/gl_crop.js.coffee
@@ -10,28 +10,32 @@ class GitLabCrop
# Set defaults
{
- @form = @fileInput.parents('form')
- @filename = '.js-avatar-filename'
- @previewImage = $('.avatar-image .avatar')
- @modalCrop = '.modal-profile-crop'
@exportWidth = 200
@exportHeight = 200
@cropBoxWidth = 200
@cropBoxHeight = 200
+ @form = @fileInput.parents('form')
- # Button where user clicks to open file dialog
- # If not passed as argument let's pick a default one
- @pickImageEl = @fileInput.parent().find('.js-choose-user-avatar-button')
- @uploadImageBtn = $('.js-upload-user-avatar')
+ # Required params
+ @filename
+ @previewImage
+ @modalCrop
+ @pickImageEl
+ @uploadImageBtn
+ @modalCropImg
} = opts
# Ensure needed elements are jquery objects
- @filename = if _.isString(@filename) then @$(@filename) else @filename
+ # If selector is provided we will convert them to a jQuery Object
+ @filename = @$(@filename)
+ @previewImage = @$(@previewImage)
+ @pickImageEl = @$(@pickImageEl)
- # Modal usually is outside the wrapper element
+ # Modal elements usually are outside the @form element
@modalCrop = if _.isString(@modalCrop) then $(@modalCrop) else @modalCrop
+ @uploadImageBtn = if _.isString(@uploadImageBtn) then $(@uploadImageBtn) else @uploadImageBtn
+ @modalCropImg = if _.isString(@modalCropImg) then $(@modalCropImg) else @modalCropImg
- @modalCropImg = $('.modal-profile-crop-image')
@cropActionsBtn = @modalCrop.find('[data-method]')
@bindEvents()
diff --git a/app/assets/javascripts/profile.js.coffee b/app/assets/javascripts/profile.js.coffee
index f81d7dd6e69..2fcc6dfd56e 100644
--- a/app/assets/javascripts/profile.js.coffee
+++ b/app/assets/javascripts/profile.js.coffee
@@ -23,7 +23,15 @@ class @Profile
@bindEvents()
- @avatarGlCrop = $('.js-user-avatar-input').glCrop().data 'glcrop'
+ cropOpts =
+ filename: '.js-avatar-filename'
+ previewImage: '.avatar-image .avatar'
+ modalCrop: '.modal-profile-crop'
+ pickImageEl: '.js-choose-user-avatar-button'
+ uploadImageBtn: '.js-upload-user-avatar'
+ modalCropImg: '.modal-profile-crop-image'
+
+ @avatarGlCrop = $('.js-user-avatar-input').glCrop(cropOpts).data 'glcrop'
bindEvents: ->
@form.on 'submit', @onSubmitForm