2016-01-08 23:33:08 -05:00
|
|
|
# Zen Mode (full screen) textarea
|
|
|
|
#
|
|
|
|
#= provides zen_mode:enter
|
|
|
|
#= provides zen_mode:leave
|
|
|
|
#
|
|
|
|
#= require jquery.scrollTo
|
2015-05-21 01:25:18 -04:00
|
|
|
#= require dropzone
|
|
|
|
#= require mousetrap
|
|
|
|
#= require mousetrap/pause
|
2016-01-08 23:33:08 -05:00
|
|
|
#
|
|
|
|
# ### Events
|
|
|
|
#
|
|
|
|
# `zen_mode:enter`
|
|
|
|
#
|
|
|
|
# Fired when the "Edit in fullscreen" link is clicked.
|
|
|
|
#
|
|
|
|
# **Synchronicity** Sync
|
|
|
|
# **Bubbles** Yes
|
|
|
|
# **Cancelable** No
|
|
|
|
# **Target** a.js-zen-enter
|
|
|
|
#
|
|
|
|
# `zen_mode:leave`
|
|
|
|
#
|
|
|
|
# Fired when the "Leave Fullscreen" link is clicked.
|
|
|
|
#
|
|
|
|
# **Synchronicity** Sync
|
|
|
|
# **Bubbles** Yes
|
|
|
|
# **Cancelable** No
|
|
|
|
# **Target** a.js-zen-leave
|
|
|
|
#
|
2014-09-11 12:19:49 -04:00
|
|
|
class @ZenMode
|
|
|
|
constructor: ->
|
2016-01-08 23:33:08 -05:00
|
|
|
@active_backdrop = null
|
|
|
|
@active_textarea = null
|
2014-09-11 12:19:49 -04:00
|
|
|
|
2016-01-08 23:33:08 -05:00
|
|
|
$(document).on 'click', '.js-zen-enter', (e) ->
|
2015-01-15 03:15:12 -05:00
|
|
|
e.preventDefault()
|
2016-01-08 23:33:08 -05:00
|
|
|
$(e.currentTarget).trigger('zen_mode:enter')
|
2015-01-15 03:15:12 -05:00
|
|
|
|
2016-01-08 23:33:08 -05:00
|
|
|
$(document).on 'click', '.js-zen-leave', (e) ->
|
2015-01-15 03:15:12 -05:00
|
|
|
e.preventDefault()
|
2016-01-08 23:33:08 -05:00
|
|
|
$(e.currentTarget).trigger('zen_mode:leave')
|
|
|
|
|
|
|
|
$(document).on 'zen_mode:enter', (e) =>
|
|
|
|
@enter(e.target.parentNode)
|
|
|
|
$(document).on 'zen_mode:leave', (e) =>
|
|
|
|
@exit()
|
|
|
|
|
|
|
|
$(document).on 'keydown', (e) ->
|
|
|
|
if e.keyCode == 27 # Esc
|
2014-09-20 12:15:36 -04:00
|
|
|
e.preventDefault()
|
2016-01-08 23:33:08 -05:00
|
|
|
$(document).trigger('zen_mode:leave')
|
|
|
|
|
|
|
|
enter: (backdrop) ->
|
|
|
|
Mousetrap.pause()
|
|
|
|
|
|
|
|
@active_backdrop = $(backdrop)
|
|
|
|
@active_backdrop.addClass('fullscreen')
|
|
|
|
|
|
|
|
@active_textarea = @active_backdrop.find('textarea')
|
2014-09-11 12:19:49 -04:00
|
|
|
|
2015-09-04 16:35:01 -04:00
|
|
|
# Prevent a user-resized textarea from persisting to fullscreen
|
2016-01-08 23:33:08 -05:00
|
|
|
@active_textarea.removeAttr('style')
|
|
|
|
@active_textarea.focus()
|
2014-09-19 11:32:23 -04:00
|
|
|
|
2016-01-08 23:33:08 -05:00
|
|
|
exit: ->
|
|
|
|
if @active_textarea
|
2014-09-11 12:19:49 -04:00
|
|
|
Mousetrap.unpause()
|
2016-01-08 23:33:08 -05:00
|
|
|
|
|
|
|
@active_textarea.closest('.zen-backdrop').removeClass('fullscreen')
|
|
|
|
|
|
|
|
@scrollTo(@active_textarea)
|
|
|
|
|
|
|
|
@active_textarea = null
|
|
|
|
@active_backdrop = null
|
|
|
|
|
2014-10-01 10:40:30 -04:00
|
|
|
Dropzone.forElement('.div-dropzone').enable()
|
2015-05-21 01:25:18 -04:00
|
|
|
|
2016-01-08 23:33:08 -05:00
|
|
|
scrollTo: (zen_area) ->
|
|
|
|
$.scrollTo(zen_area, 0, offset: -150)
|