2014-12-12 10:05:35 -08:00
|
|
|
# see GitHub issue #11
|
|
|
|
($ document).on "submit", "form#edit_user", (evt) ->
|
|
|
|
if ($ "input#user_current_password").val().length == 0
|
|
|
|
evt.preventDefault()
|
2014-12-29 04:52:19 -08:00
|
|
|
$("button[data-target=#modal-passwd]").trigger 'click'
|
|
|
|
|
|
|
|
|
|
|
|
# Profile pic
|
|
|
|
($ document).on 'change', 'input#user_profile_picture[type=file]', ->
|
|
|
|
input = ($ this)[0]
|
|
|
|
|
2014-12-29 07:29:46 -08:00
|
|
|
($ '#profile-picture-crop-controls').slideUp 400, ->
|
|
|
|
if input.files and input.files[0]
|
|
|
|
fr = new FileReader()
|
|
|
|
($ fr).on 'load', (e) ->
|
|
|
|
cropper = ($ '#profile-picture-cropper')
|
|
|
|
preview = ($ '#profile-picture-preview')
|
|
|
|
|
|
|
|
cropper.on 'load', ->
|
|
|
|
side = if cropper[0].naturalWidth > cropper[0].naturalHeight
|
|
|
|
cropper[0].naturalHeight
|
2014-12-29 04:52:19 -08:00
|
|
|
else
|
2014-12-29 07:29:46 -08:00
|
|
|
cropper[0].naturalWidth
|
|
|
|
|
|
|
|
cropper.guillotine
|
|
|
|
width: side
|
|
|
|
height: side
|
|
|
|
onChange: (data, action) ->
|
|
|
|
console.log data
|
2014-12-29 07:39:27 -08:00
|
|
|
($ '#crop_x').val Math.floor(data.x / data.scale)
|
|
|
|
($ '#crop_y').val Math.floor(data.y / data.scale)
|
|
|
|
($ '#crop_w').val Math.floor(data.w / data.scale)
|
|
|
|
($ '#crop_h').val Math.floor(data.h / data.scale)
|
|
|
|
# rx = 100 / data.w
|
|
|
|
# ry = 100 / data.h
|
|
|
|
# ($ '#profile-picture-preview').css
|
|
|
|
# width: Math.round(rx * preview[0].naturalWidth) + 'px'
|
|
|
|
# height: Math.round(ry * preview[0].naturalHeight) + 'px'
|
|
|
|
# marginLeft: '-' + Math.round(rx * data.x) + 'px'
|
|
|
|
# marginTop: '-' + Math.round(ry * data.y) + 'px'
|
2014-12-29 07:29:46 -08:00
|
|
|
|
|
|
|
($ '#cropper-zoom-out').click -> cropper.guillotine 'zoomOut'
|
|
|
|
($ '#cropper-zoom-in').click -> cropper.guillotine 'zoomIn'
|
2014-12-29 04:52:19 -08:00
|
|
|
($ '#profile-picture-crop-controls').slideDown()
|
|
|
|
|
2014-12-29 07:29:46 -08:00
|
|
|
cropper.attr 'src', e.target.result
|
|
|
|
|
|
|
|
fr.readAsDataURL(input.files[0])
|