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,
28 decorate: function() {
29 this.addEventListener('keydown', this.onKeyDown_.bind(this));
30 navDots = this.getElementsByClassName('dot');
34 * Live list of the navigation dots.
35 * @type {!NodeList|undefined}
42 * Handler for key events on the dot list. These keys will change the focus
44 * @param {Event} e The KeyboardEvent.
46 onKeyDown_: function(e) {
47 if (e.metaKey || e.shiftKey || e.altKey || e.ctrlKey)
51 if (e.keyIdentifier == 'Left')
53 else if (e.keyIdentifier == 'Right')
58 var focusDot = this.querySelector('.dot:focus');
61 var focusIndex = Array.prototype.indexOf.call(navDots, focusDot);
62 var newFocusIndex = focusIndex + direction;
63 if (focusIndex == newFocusIndex)
66 newFocusIndex = (newFocusIndex + navDots.length) % navDots.length;
67 navDots[newFocusIndex].tabIndex = 3;
68 navDots[newFocusIndex].focus();
69 focusDot.tabIndex = -1;