2015-05-21 01:25:18 -04:00
|
|
|
#= require dropzone
|
|
|
|
#= require mousetrap
|
|
|
|
#= require mousetrap/pause
|
|
|
|
|
2014-09-11 12:19:49 -04:00
|
|
|
class @ZenMode
|
|
|
|
constructor: ->
|
|
|
|
@active_zen_area = null
|
|
|
|
@active_checkbox = null
|
2014-09-21 15:06:38 -04:00
|
|
|
@scroll_position = 0
|
|
|
|
|
|
|
|
$(window).scroll =>
|
|
|
|
if not @active_checkbox
|
|
|
|
@scroll_position = window.pageYOffset
|
2014-09-11 12:19:49 -04:00
|
|
|
|
2015-01-15 03:15:12 -05:00
|
|
|
$('body').on 'click', '.zen-enter-link', (e) =>
|
|
|
|
e.preventDefault()
|
2015-05-25 23:27:20 -04:00
|
|
|
$(e.currentTarget).closest('.zennable').find('.zen-toggle-comment').prop('checked', true).change()
|
2015-01-15 03:15:12 -05:00
|
|
|
|
|
|
|
$('body').on 'click', '.zen-leave-link', (e) =>
|
|
|
|
e.preventDefault()
|
2015-05-25 23:27:20 -04:00
|
|
|
$(e.currentTarget).closest('.zennable').find('.zen-toggle-comment').prop('checked', false).change()
|
2015-01-15 03:15:12 -05:00
|
|
|
|
|
|
|
$('body').on 'change', '.zen-toggle-comment', (e) =>
|
2014-09-19 11:32:23 -04:00
|
|
|
checkbox = e.currentTarget
|
2014-09-11 12:19:49 -04:00
|
|
|
if checkbox.checked
|
2014-09-21 15:06:38 -04:00
|
|
|
# Disable other keyboard shortcuts in ZEN mode
|
2014-09-11 12:19:49 -04:00
|
|
|
Mousetrap.pause()
|
2015-05-25 23:51:08 -04:00
|
|
|
@updateActiveZenArea(checkbox)
|
2014-09-11 12:19:49 -04:00
|
|
|
else
|
|
|
|
@exitZenMode()
|
|
|
|
|
|
|
|
$(document).on 'keydown', (e) =>
|
2015-05-21 01:25:18 -04:00
|
|
|
if e.keyCode is 27 # Esc
|
2014-09-11 12:19:49 -04:00
|
|
|
@exitZenMode()
|
2014-09-20 12:15:36 -04:00
|
|
|
e.preventDefault()
|
2014-09-11 12:19:49 -04:00
|
|
|
|
2015-05-25 23:51:08 -04:00
|
|
|
updateActiveZenArea: (checkbox) =>
|
2014-09-11 12:19:49 -04:00
|
|
|
@active_checkbox = $(checkbox)
|
|
|
|
@active_checkbox.prop('checked', true)
|
|
|
|
@active_zen_area = @active_checkbox.parent().find('textarea')
|
2015-09-04 16:35:01 -04:00
|
|
|
# Prevent a user-resized textarea from persisting to fullscreen
|
|
|
|
@active_zen_area.removeAttr('style')
|
2014-09-11 12:19:49 -04:00
|
|
|
@active_zen_area.focus()
|
2014-09-19 11:32:23 -04:00
|
|
|
|
2014-09-11 12:19:49 -04:00
|
|
|
exitZenMode: =>
|
|
|
|
if @active_zen_area isnt null
|
|
|
|
Mousetrap.unpause()
|
|
|
|
@active_checkbox.prop('checked', false)
|
|
|
|
@active_zen_area = null
|
|
|
|
@active_checkbox = null
|
2015-05-21 01:25:18 -04:00
|
|
|
@restoreScroll(@scroll_position)
|
2014-10-01 10:40:30 -04:00
|
|
|
# Enable dropzone when leaving ZEN mode
|
|
|
|
Dropzone.forElement('.div-dropzone').enable()
|
2015-05-21 01:25:18 -04:00
|
|
|
|
|
|
|
restoreScroll: (y) ->
|
|
|
|
window.scrollTo(window.pageXOffset, y)
|