debian-mirror-gitlab/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-09-11 14:41:01 +05:30
#= 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
#
2015-09-11 14:41:01 +05:30
class @ZenMode
2015-04-26 12:48:37 +05:30
constructor: ->
@active_backdrop = null
@active_textarea = null
2015-04-26 12:48:37 +05:30
$(document).on 'click', '.js-zen-enter', (e) ->
2015-04-26 12:48:37 +05:30
e.preventDefault()
$(e.currentTarget).trigger('zen_mode:enter')
2015-04-26 12:48:37 +05:30
$(document).on 'click', '.js-zen-leave', (e) ->
2015-04-26 12:48:37 +05:30
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
2015-04-26 12:48:37 +05:30
e.preventDefault()
$(document).trigger('zen_mode:leave')
enter: (backdrop) ->
Mousetrap.pause()
@active_backdrop = $(backdrop)
@active_backdrop.addClass('fullscreen')
@active_textarea = @active_backdrop.find('textarea')
2015-04-26 12:48:37 +05:30
2015-09-25 12:07:36 +05:30
# Prevent a user-resized textarea from persisting to fullscreen
@active_textarea.removeAttr('style')
@active_textarea.focus()
2015-04-26 12:48:37 +05:30
exit: ->
if @active_textarea
2015-04-26 12:48:37 +05:30
Mousetrap.unpause()
@active_textarea.closest('.zen-backdrop').removeClass('fullscreen')
@scrollTo(@active_textarea)
@active_textarea = null
@active_backdrop = null
2015-04-26 12:48:37 +05:30
Dropzone.forElement('.div-dropzone').enable()
scrollTo: (zen_area) ->
$.scrollTo(zen_area, 0, offset: -150)