gitlab-org--gitlab-foss/app/assets/javascripts/zen_mode.js.coffee

81 lines
1.8 KiB
CoffeeScript
Raw Normal View History

# 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
#
# ### 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: ->
@active_backdrop = null
@active_textarea = null
2014-09-11 12:19:49 -04:00
$(document).on 'click', '.js-zen-enter', (e) ->
e.preventDefault()
$(e.currentTarget).trigger('zen_mode:enter')
$(document).on 'click', '.js-zen-leave', (e) ->
e.preventDefault()
$(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
e.preventDefault()
$(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
# Prevent a user-resized textarea from persisting to fullscreen
@active_textarea.removeAttr('style')
@active_textarea.focus()
2014-09-19 11:32:23 -04:00
exit: ->
if @active_textarea
2014-09-11 12:19:49 -04:00
Mousetrap.unpause()
@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
scrollTo: (zen_area) ->
$.scrollTo(zen_area, 0, offset: -150)