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'
|
|
|
|
|
2015-05-10 22:58:24 -07:00
|
|
|
readImage = (file, callback) ->
|
|
|
|
fr = new FileReader()
|
|
|
|
fr.addEventListener "load", (e) ->
|
|
|
|
callback e.target.result
|
|
|
|
fr.readAsBinaryString file
|
|
|
|
|
|
|
|
freeURL = () ->
|
|
|
|
|
|
|
|
if window.URL? or window.webkitURL?
|
|
|
|
readImage = (file, callback) ->
|
|
|
|
callback (window.URL || window.webkitURL).createObjectURL file
|
|
|
|
freeURL = (url) ->
|
|
|
|
URL.revokeObjectURL url
|
|
|
|
|
2014-12-29 04:52:19 -08:00
|
|
|
|
|
|
|
# Profile pic
|
|
|
|
($ document).on 'change', 'input#user_profile_picture[type=file]', ->
|
2015-05-10 22:58:24 -07:00
|
|
|
input = this
|
2014-12-29 04:52:19 -08:00
|
|
|
|
2014-12-29 07:29:46 -08:00
|
|
|
($ '#profile-picture-crop-controls').slideUp 400, ->
|
|
|
|
if input.files and input.files[0]
|
2015-05-10 22:58:24 -07:00
|
|
|
readImage input.files[0], (src) ->
|
2014-12-29 07:29:46 -08:00
|
|
|
cropper = ($ '#profile-picture-cropper')
|
|
|
|
preview = ($ '#profile-picture-preview')
|
|
|
|
|
2014-12-29 08:22:43 -08:00
|
|
|
updateVars = (data, action) ->
|
2020-05-02 09:45:11 -07:00
|
|
|
($ '#profile_picture_x').val Math.floor(data.x / data.scale)
|
|
|
|
($ '#profile_picture_y').val Math.floor(data.y / data.scale)
|
|
|
|
($ '#profile_picture_w').val Math.floor(data.w / data.scale)
|
|
|
|
($ '#profile_picture_h').val Math.floor(data.h / data.scale)
|
2014-12-29 08:22:43 -08:00
|
|
|
# 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.on 'load', ->
|
2015-05-10 22:58:24 -07:00
|
|
|
if ({}.toString).call(src) == "[object URL]"
|
|
|
|
freeURL src
|
|
|
|
|
2014-12-29 07:29:46 -08:00
|
|
|
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
|
2014-12-29 08:22:43 -08:00
|
|
|
onChange: updateVars
|
|
|
|
|
|
|
|
updateVars cropper.guillotine('getData'), 'drag' # just because
|
2014-12-29 07:29:46 -08:00
|
|
|
|
2015-05-08 09:20:57 -07:00
|
|
|
unless ($ '#profile-picture-crop-controls')[0].dataset.bound?
|
|
|
|
($ '#cropper-zoom-out').click -> cropper.guillotine 'zoomOut'
|
|
|
|
($ '#cropper-zoom-in').click -> cropper.guillotine 'zoomIn'
|
|
|
|
($ '#profile-picture-crop-controls')[0].dataset.bound = true
|
2014-12-29 04:52:19 -08:00
|
|
|
($ '#profile-picture-crop-controls').slideDown()
|
|
|
|
|
2015-05-10 22:58:24 -07:00
|
|
|
cropper.attr 'src', src
|
2015-05-08 08:44:16 -07:00
|
|
|
|
|
|
|
($ document).on 'change', 'input#user_profile_header[type=file]', ->
|
2015-05-10 22:58:24 -07:00
|
|
|
input = this
|
2015-05-08 08:44:16 -07:00
|
|
|
|
|
|
|
($ '#profile-header-crop-controls').slideUp 400, ->
|
|
|
|
if input.files and input.files[0]
|
2015-05-10 22:58:24 -07:00
|
|
|
readImage input.files[0], (src) ->
|
2015-05-08 08:44:16 -07:00
|
|
|
cropper = ($ '#profile-header-cropper')
|
|
|
|
preview = ($ '#profile-header-preview')
|
|
|
|
|
|
|
|
updateVars = (data, action) ->
|
2020-05-02 09:45:11 -07:00
|
|
|
($ '#profile_header_x').val Math.floor(data.x / data.scale)
|
|
|
|
($ '#profile_header_y').val Math.floor(data.y / data.scale)
|
|
|
|
($ '#profile_header_w').val Math.floor(data.w / data.scale)
|
|
|
|
($ '#profile_header_h').val Math.floor(data.h / data.scale)
|
2015-05-08 08:44:16 -07:00
|
|
|
|
|
|
|
cropper.on 'load', ->
|
2015-05-10 22:58:24 -07:00
|
|
|
if ({}.toString).call(src) == "[object URL]"
|
|
|
|
freeURL src
|
|
|
|
|
2015-05-08 08:44:16 -07:00
|
|
|
cropper.guillotine
|
|
|
|
width: 1500
|
2015-05-08 08:49:10 -07:00
|
|
|
height: 350
|
2015-05-08 08:44:16 -07:00
|
|
|
onChange: updateVars
|
|
|
|
|
2015-05-08 08:49:10 -07:00
|
|
|
updateVars cropper.guillotine('getData'), 'drag'
|
2015-05-08 08:44:16 -07:00
|
|
|
|
2015-05-08 09:20:57 -07:00
|
|
|
unless ($ '#profile-header-crop-controls')[0].dataset.bound?
|
|
|
|
($ '#cropper-header-zoom-out').click -> cropper.guillotine 'zoomOut'
|
|
|
|
($ '#cropper-header-zoom-in').click -> cropper.guillotine 'zoomIn'
|
|
|
|
($ '#profile-header-crop-controls')[0].dataset.bound = true
|
2015-05-08 08:44:16 -07:00
|
|
|
($ '#profile-header-crop-controls').slideDown()
|
|
|
|
|
2015-05-10 22:58:24 -07:00
|
|
|
cropper.attr 'src', src
|
2015-08-25 11:27:06 -07:00
|
|
|
|
|
|
|
# theming
|
|
|
|
|
2020-05-08 16:57:20 -07:00
|
|
|
previewStyle = null
|
2015-08-25 11:27:06 -07:00
|
|
|
|
2020-05-04 08:26:18 -07:00
|
|
|
$(document).ready ->
|
2020-05-08 16:57:20 -07:00
|
|
|
previewStyle = document.createElement 'style'
|
|
|
|
document.body.appendChild previewStyle
|
|
|
|
|
|
|
|
previewTimeout = null
|
|
|
|
|
2020-05-04 08:26:18 -07:00
|
|
|
$('#update_theme .color').each ->
|
|
|
|
$this = $ this
|
|
|
|
this.value = '#' + getHexColorFromThemeValue(this.value)
|
|
|
|
|
|
|
|
$this.minicolors
|
|
|
|
control: 'hue'
|
|
|
|
defaultValue: this.value
|
|
|
|
letterCase: 'lowercase'
|
|
|
|
position: 'bottom left'
|
|
|
|
theme: 'bootstrap'
|
|
|
|
inline: false
|
|
|
|
change: ->
|
|
|
|
clearTimeout previewTimeout
|
|
|
|
previewTimeout = setTimeout(previewTheme, 1000)
|
|
|
|
true
|
|
|
|
|
|
|
|
$(document).on 'click', 'a.theme_preset', (event) ->
|
|
|
|
preset = [].concat themePresets[this.dataset.preset]
|
|
|
|
$('#update_theme .color').each ->
|
|
|
|
$(this).minicolors 'value', '#' + getHexColorFromThemeValue(preset.shift())
|
|
|
|
|
2015-08-25 11:27:06 -07:00
|
|
|
previewTheme = ->
|
|
|
|
payload = {}
|
|
|
|
|
|
|
|
$('#update_theme').find('.color').each ->
|
|
|
|
n = this.name.substr 6, this.name.length - 7
|
|
|
|
payload[n] = parseInt this.value.substr(1, 6), 16
|
|
|
|
|
2020-05-04 08:26:18 -07:00
|
|
|
generateTheme payload
|
2015-08-25 11:27:06 -07:00
|
|
|
|
|
|
|
null
|
|
|
|
|
2020-05-04 08:26:18 -07:00
|
|
|
generateTheme = (payload) ->
|
|
|
|
theme_attribute_map = {
|
|
|
|
'primary_color': 'primary',
|
|
|
|
'primary_text': 'primary-text',
|
|
|
|
'danger_color': 'danger',
|
|
|
|
'danger_text': 'danger-text',
|
|
|
|
'warning_color': 'warning',
|
|
|
|
'warning_text': 'warning-text',
|
|
|
|
'info_color': 'info',
|
|
|
|
'info_text': 'info-text',
|
|
|
|
'success_color': 'success',
|
|
|
|
'success_text': 'success-text',
|
2020-05-04 17:02:16 -07:00
|
|
|
'dark_color': 'dark',
|
|
|
|
'dark_text': 'dark-text',
|
|
|
|
'light_color': 'light',
|
|
|
|
'light_text': 'light-text',
|
|
|
|
'raised_background': 'raised-bg',
|
|
|
|
'raised_accent': 'raised-accent',
|
2020-05-04 08:26:18 -07:00
|
|
|
'background_color': 'background',
|
2020-05-04 17:02:16 -07:00
|
|
|
'body_text': 'body-text',
|
2020-05-04 08:26:18 -07:00
|
|
|
'input_color': 'input-bg',
|
2020-05-04 17:02:16 -07:00
|
|
|
'input_text': 'input-text',
|
|
|
|
'muted_text': 'muted-text'
|
2020-05-04 08:26:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
body = ":root {\n"
|
|
|
|
|
|
|
|
(Object.keys(payload)).forEach (plKey) ->
|
|
|
|
if theme_attribute_map[plKey]
|
|
|
|
if theme_attribute_map[plKey].includes 'text'
|
|
|
|
hex = getHexColorFromThemeValue(payload[plKey])
|
|
|
|
body += "--#{theme_attribute_map[plKey]}: #{getDecimalTripletsFromHex(hex)};\n"
|
|
|
|
else
|
|
|
|
body += "--#{theme_attribute_map[plKey]}: ##{getHexColorFromThemeValue(payload[plKey])};\n"
|
|
|
|
|
|
|
|
body += "}"
|
|
|
|
|
|
|
|
previewStyle.innerHTML = body
|
|
|
|
|
|
|
|
getHexColorFromThemeValue = (themeValue) ->
|
|
|
|
return ('000000' + parseInt(themeValue).toString(16)).substr(-6, 6)
|
|
|
|
|
|
|
|
getDecimalTripletsFromHex = (hex) ->
|
|
|
|
return hex.match(/.{1,2}/g).map((value) -> parseInt(value, 16)).join(', ')
|
|
|
|
|
2015-08-25 11:27:06 -07:00
|
|
|
themePresets = {
|
2015-08-26 16:56:07 -07:00
|
|
|
rs: [0x5E35B1, 0xFFFFFF, 0xFF0039, 0xFFFFFF, 0x3FB618, 0xFFFFFF, 0xFF7518, 0xFFFFFF, 0x9954BB, 0xFFFFFF, 0x222222, 0xEEEEEE, 0xF9F9F9, 0x151515, 0x5E35B1, 0xFFFFFF, 0x222222, 0xbbbbbb, 0xFFFFFF, 0x000000, 0x5E35B1],
|
|
|
|
dc: [0x141414, 0xeeeeee, 0x362222, 0xeeeeee, 0x1d2e1d, 0xeeeeee, 0x404040, 0xeeeeee, 0xb8b8b8, 0x3b3b3b, 0x303030, 0xEEEEEE, 0x202020, 0xeeeeee, 0x9c9a9a, 0x363636, 0xe6e6e6, 0xbbbbbb, 0x383838, 0xebebeb, 0x787676],
|
|
|
|
lc: [0xebebeb, 0x111111, 0xf76363, 0x111111, 0x8aff94, 0x111111, 0xffbd7f, 0x111111, 0x474747, 0xc4c4c4, 0xcfcfcf, 0x111111, 0xdfdfdf, 0x111111, 0x636565, 0xc9c9c9, 0x191919, 0x444444, 0xc7c7c7, 0x141414, 0x878989]
|
2015-08-25 11:27:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$(document).on 'submit', '#update_theme', (event) ->
|
|
|
|
$this = $ this
|
|
|
|
$this.find('.color').each ->
|
|
|
|
this.value = parseInt this.value.substr(1, 6), 16
|
|
|
|
true
|