Sha256: 3285cf6d9706f3ce48455b2011ee701149ec6153a9c310f7e061cb4fba9e1359

Contents?: true

Size: 1.36 KB

Versions: 27

Compression:

Stored size: 1.36 KB

Contents

window.Alchemy = {} if typeof(window.Alchemy) is 'undefined'

# Handles Alchemy hotkeys
#
Alchemy.bindedHotkeys = []

Alchemy.Hotkeys = (scope) ->

  # Unbind all previously registered hotkeys.
  unless scope
    $(document).off('keypress')
    for hotkey in Alchemy.bindedHotkeys
      key.unbind(hotkey)

  # Binds keyboard shortcuts to search fields.
  $search_fields = $('#search_field, #search_input_field', scope)
  $search_fields_clear = $('.search_field_clear, .js_filter_field_clear', scope)

  key 'alt+f', ->
    key.setScope('search')
    $search_fields.focus()
    false
  Alchemy.bindedHotkeys.push('alt+f')

  key 'esc', 'search', ->
    $search_fields_clear.click()
    $search_fields.blur()
  Alchemy.bindedHotkeys.push('esc')

  unless scope
    $(document).on 'keypress', (e) ->
      if !$(e.target).is('input, textarea') && String.fromCharCode(e.which) == '?'
        Alchemy.openDialog '/admin/help',
          title: Alchemy._t('help')
          size: '400x492'
        false
      else
        true

  # Binds click events to hotkeys.
  #
  # Simply add a data-alchemy-hotkey attribute to your link.
  # If a hotkey is triggered by user, the click event of the element gets triggerd.
  #
  $('[data-alchemy-hotkey]', scope).each ->
    $this = $(this)
    hotkey = $this.data('alchemy-hotkey')
    key hotkey, -> $this.click()
    Alchemy.bindedHotkeys.push(hotkey)

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
alchemy_cms-3.0.2 app/assets/javascripts/alchemy/alchemy.hotkeys.js.coffee
alchemy_cms-3.0.1 app/assets/javascripts/alchemy/alchemy.hotkeys.js.coffee
alchemy_cms-3.0.0 app/assets/javascripts/alchemy/alchemy.hotkeys.js.coffee
alchemy_cms-3.0.0.rc8 app/assets/javascripts/alchemy/alchemy.hotkeys.js.coffee
alchemy_cms-3.0.0.rc7 app/assets/javascripts/alchemy/alchemy.hotkeys.js.coffee
alchemy_cms-3.0.0.rc6 app/assets/javascripts/alchemy/alchemy.hotkeys.js.coffee
alchemy_cms-3.0.0.rc5 app/assets/javascripts/alchemy/alchemy.hotkeys.js.coffee