[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yui/src/dock/js/ -> actionkey.js (source)

   1  /**
   2   * Dock JS.
   3   *
   4   * This file contains the action key event definition that is used for accessibility handling within the Dock.
   5   *
   6   * @module moodle-core-dock
   7   */
   8  
   9  /**
  10   * A 'dock:actionkey' Event.
  11   * The event consists of the left arrow, right arrow, enter and space keys.
  12   * More keys can be mapped to action meanings.
  13   * actions: collapse , expand, toggle, enter.
  14   *
  15   * This event is subscribed to by dockitems.
  16   * The on() method to subscribe allows specifying the desired trigger actions as JSON.
  17   *
  18   * This event can also be delegated if needed.
  19   *
  20   * @namespace M.core.dock
  21   * @class ActionKey
  22   */
  23  Y.Event.define("dock:actionkey", {
  24      // Webkit and IE repeat keydown when you hold down arrow keys.
  25      // Opera links keypress to page scroll; others keydown.
  26      // Firefox prevents page scroll via preventDefault() on either
  27      // keydown or keypress.
  28      _event: (Y.UA.webkit || Y.UA.ie) ? 'keydown' : 'keypress',
  29  
  30      /**
  31       * The keys to trigger on.
  32       * @property _keys
  33       */
  34      _keys: {
  35          // arrows
  36          '37': 'collapse',
  37          '39': 'expand',
  38          // (@todo: lrt/rtl/M.core_dock.cfg.orientation decision to assign arrow to meanings)
  39          '32': 'toggle',
  40          '13': 'enter'
  41      },
  42  
  43      /**
  44       * Handles key events
  45       * @method _keyHandler
  46       * @param {EventFacade} e
  47       * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers
  48       * @param {Object} args
  49       */
  50      _keyHandler: function(e, notifier, args) {
  51          var actObj;
  52          if (!args.actions) {
  53              actObj = {collapse: true, expand: true, toggle: true, enter: true};
  54          } else {
  55              actObj = args.actions;
  56          }
  57          if (this._keys[e.keyCode] && actObj[this._keys[e.keyCode]]) {
  58              e.action = this._keys[e.keyCode];
  59              notifier.fire(e);
  60          }
  61      },
  62  
  63      /**
  64       * Subscribes to events.
  65       * @method on
  66       * @param {Node} node The node this subscription was applied to.
  67       * @param {Subscription} sub The object tracking this subscription.
  68       * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers
  69       */
  70      on: function(node, sub, notifier) {
  71          // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions).
  72          if (sub.args === null) {
  73              // no actions given
  74              sub._detacher = node.on(this._event, this._keyHandler, this, notifier, {actions: false});
  75          } else {
  76              sub._detacher = node.on(this._event, this._keyHandler, this, notifier, sub.args[0]);
  77          }
  78      },
  79  
  80      /**
  81       * Detaches an event listener
  82       * @method detach
  83       * @param {Node} node The node this subscription was applied to.
  84       * @param {Subscription} sub The object tracking this subscription.
  85       * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers
  86       */
  87      detach: function(node, sub) {
  88          // detach our _detacher handle of the subscription made in on()
  89          sub._detacher.detach();
  90      },
  91  
  92      /**
  93       * Creates a delegated event listener.
  94       * @method delegate
  95       * @param {Node} node The node this subscription was applied to.
  96       * @param {Subscription} sub The object tracking this subscription.
  97       * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers
  98       * @param {String|function} filter Selector string or function that accpets an event object and returns null.
  99       */
 100      delegate: function(node, sub, notifier, filter) {
 101          // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions).
 102          if (sub.args === null) {
 103              // no actions given
 104              sub._delegateDetacher = node.delegate(this._event, this._keyHandler, filter, this, notifier, {actions: false});
 105          } else {
 106              sub._delegateDetacher = node.delegate(this._event, this._keyHandler, filter, this, notifier, sub.args[0]);
 107          }
 108      },
 109  
 110      /**
 111       * Detaches a delegated event listener.
 112       * @method detachDelegate
 113       * @param {Node} node The node this subscription was applied to.
 114       * @param {Subscription} sub The object tracking this subscription.
 115       * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers
 116       * @param {String|function} filter Selector string or function that accpets an event object and returns null.
 117       */
 118      detachDelegate: function(node, sub) {
 119          sub._delegateDetacher.detach();
 120      }
 121  });


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1