4 * This file contains the action key event definition that is used for accessibility handling within the Dock.
6 * @module moodle-core-dock
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.
15 * This event is subscribed to by dockitems.
16 * The on() method to subscribe allows specifying the desired trigger actions as JSON.
18 * This event can also be delegated if needed.
20 * @namespace M.core.dock
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',
31 * The keys to trigger on.
38 // (@todo: lrt/rtl/M.core_dock.cfg.orientation decision to assign arrow to meanings)
46 * @param {EventFacade} e
47 * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers
48 * @param {Object} args
50 _keyHandler: function(e, notifier, args) {
53 actObj = {collapse: true, expand: true, toggle: true, enter: true};
55 actObj = args.actions;
57 if (this._keys[e.keyCode] && actObj[this._keys[e.keyCode]]) {
58 e.action = this._keys[e.keyCode];
64 * Subscribes to events.
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
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) {
74 sub._detacher = node.on(this._event, this._keyHandler, this, notifier, {actions: false});
76 sub._detacher = node.on(this._event, this._keyHandler, this, notifier, sub.args[0]);
81 * Detaches an event listener
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
87 detach: function(node, sub) {
88 // detach our _detacher handle of the subscription made in on()
89 sub._detacher.detach();
93 * Creates a delegated event listener.
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.
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) {
104 sub._delegateDetacher = node.delegate(this._event, this._keyHandler, filter, this, notifier, {actions: false});
106 sub._delegateDetacher = node.delegate(this._event, this._keyHandler, filter, this, notifier, sub.args[0]);
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.
118 detachDelegate: function(node, sub) {
119 sub._delegateDetacher.detach();