Commit 647f28bd authored by Alfredo Sumaran's avatar Alfredo Sumaran

Make it generic

parent bc705979
...@@ -10,28 +10,32 @@ class GitLabCrop ...@@ -10,28 +10,32 @@ class GitLabCrop
# Set defaults # Set defaults
{ {
@form = @fileInput.parents('form')
@filename = '.js-avatar-filename'
@previewImage = $('.avatar-image .avatar')
@modalCrop = '.modal-profile-crop'
@exportWidth = 200 @exportWidth = 200
@exportHeight = 200 @exportHeight = 200
@cropBoxWidth = 200 @cropBoxWidth = 200
@cropBoxHeight = 200 @cropBoxHeight = 200
@form = @fileInput.parents('form')
# Button where user clicks to open file dialog # Required params
# If not passed as argument let's pick a default one @filename
@pickImageEl = @fileInput.parent().find('.js-choose-user-avatar-button') @previewImage
@uploadImageBtn = $('.js-upload-user-avatar') @modalCrop
@pickImageEl
@uploadImageBtn
@modalCropImg
} = opts } = opts
# Ensure needed elements are jquery objects # 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 @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]') @cropActionsBtn = @modalCrop.find('[data-method]')
@bindEvents() @bindEvents()
......
...@@ -23,7 +23,15 @@ class @Profile ...@@ -23,7 +23,15 @@ class @Profile
@bindEvents() @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: -> bindEvents: ->
@form.on 'submit', @onSubmitForm @form.on 'submit', @onSubmitForm
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment