1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * @fileoverview DotList implementation
9 cr
.define('ntp', function() {
13 * Live list of the navigation dots.
14 * @type {!NodeList|undefined}
19 * Creates a new DotList object.
21 * @extends {HTMLUListElement}
23 var DotList
= cr
.ui
.define('ul');
26 __proto__
: HTMLUListElement
.prototype,
29 decorate: function() {
30 this.addEventListener('keydown', this.onKeyDown_
.bind(this));
31 navDots
= this.getElementsByClassName('dot');
35 * Live list of the navigation dots.
36 * @type {!NodeList|undefined}
43 * Handler for key events on the dot list. These keys will change the focus
45 * @param {Event} e The KeyboardEvent.
47 onKeyDown_: function(e
) {
48 if (e
.metaKey
|| e
.shiftKey
|| e
.altKey
|| e
.ctrlKey
)
52 if (e
.keyIdentifier
== 'Left')
54 else if (e
.keyIdentifier
== 'Right')
59 var focusDot
= this.querySelector('.dot:focus');
62 var focusIndex
= Array
.prototype.indexOf
.call(navDots
, focusDot
);
63 var newFocusIndex
= focusIndex
+ direction
;
64 if (focusIndex
== newFocusIndex
)
67 newFocusIndex
= (newFocusIndex
+ navDots
.length
) % navDots
.length
;
68 navDots
[newFocusIndex
].tabIndex
= 3;
69 navDots
[newFocusIndex
].focus();
70 focusDot
.tabIndex
= -1;