mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-16 08:06:08 +10:00
Fix Zen Mode not closing with ESC key ### What does this MR do? This MR fixes the ESC key not leaving Zen Mode (fullscreen). ### Why was this MR needed? This has been broken since GitLab v7.8. The `change` event for `zen-toggle-comment` was never fired. See: http://stackoverflow.com/questions/19505011/checkbox-checked-with-prop-does-not-fire-events-attached-to-change?answertab=votes#tab-top ### What are the relevant issue numbers? * Closes #1025 * Closes https://github.com/gitlabhq/gitlabhq/issues/9018 See merge request !710
49 lines
1.5 KiB
CoffeeScript
49 lines
1.5 KiB
CoffeeScript
class @ZenMode
|
|
constructor: ->
|
|
@active_zen_area = null
|
|
@active_checkbox = null
|
|
@scroll_position = 0
|
|
|
|
$(window).scroll =>
|
|
if not @active_checkbox
|
|
@scroll_position = window.pageYOffset
|
|
|
|
$('body').on 'click', '.zen-enter-link', (e) =>
|
|
e.preventDefault()
|
|
$(e.currentTarget).closest('.zennable').find('.zen-toggle-comment').prop('checked', true).change()
|
|
|
|
$('body').on 'click', '.zen-leave-link', (e) =>
|
|
e.preventDefault()
|
|
$(e.currentTarget).closest('.zennable').find('.zen-toggle-comment').prop('checked', false).change()
|
|
|
|
$('body').on 'change', '.zen-toggle-comment', (e) =>
|
|
checkbox = e.currentTarget
|
|
if checkbox.checked
|
|
# Disable other keyboard shortcuts in ZEN mode
|
|
Mousetrap.pause()
|
|
@updateActiveZenArea(checkbox)
|
|
else
|
|
@exitZenMode()
|
|
|
|
$(document).on 'keydown', (e) =>
|
|
if e.keyCode is $.ui.keyCode.ESCAPE
|
|
@exitZenMode()
|
|
e.preventDefault()
|
|
|
|
updateActiveZenArea: (checkbox) =>
|
|
@active_checkbox = $(checkbox)
|
|
@active_checkbox.prop('checked', true)
|
|
@active_zen_area = @active_checkbox.parent().find('textarea')
|
|
@active_zen_area.focus()
|
|
|
|
exitZenMode: =>
|
|
if @active_zen_area isnt null
|
|
Mousetrap.unpause()
|
|
@active_checkbox.prop('checked', false)
|
|
@active_zen_area = null
|
|
@active_checkbox = null
|
|
window.location.hash = ''
|
|
window.scrollTo(window.pageXOffset, @scroll_position)
|
|
# Enable dropzone when leaving ZEN mode
|
|
Dropzone.forElement('.div-dropzone').enable()
|