Updated drag and drop thumbnails.
[chromium-blink-merge.git] / chrome / browser / resources / ntp4 / dot_list.js
blobf445ed30add3ceffa9872ae07e5c316acab7e0ca
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.
5 /**
6 * @fileoverview DotList implementation
7 */
9 cr.define('ntp', function() {
10 'use strict';
12 /**
13 * Live list of the navigation dots.
14 * @type {!NodeList|undefined}
16 var navDots;
18 /**
19 * Creates a new DotList object.
20 * @constructor
21 * @extends {HTMLUListElement}
23 var DotList = cr.ui.define('ul');
25 DotList.prototype = {
26 __proto__: HTMLUListElement.prototype,
28 /** @override */
29 decorate: function() {
30 this.addEventListener('keydown', this.onKeyDown_.bind(this));
31 navDots = this.getElementsByClassName('dot');
34 /**
35 * Live list of the navigation dots.
36 * @type {!NodeList|undefined}
38 get dots() {
39 return navDots;
42 /**
43 * Handler for key events on the dot list. These keys will change the focus
44 * element.
45 * @param {Event} e The KeyboardEvent.
47 onKeyDown_: function(e) {
48 if (e.metaKey || e.shiftKey || e.altKey || e.ctrlKey)
49 return;
51 var direction = 0;
52 if (e.keyIdentifier == 'Left')
53 direction = -1;
54 else if (e.keyIdentifier == 'Right')
55 direction = 1;
56 else
57 return;
59 var focusDot = this.querySelector('.dot:focus');
60 if (!focusDot)
61 return;
62 var focusIndex = Array.prototype.indexOf.call(navDots, focusDot);
63 var newFocusIndex = focusIndex + direction;
64 if (focusIndex == newFocusIndex)
65 return;
67 newFocusIndex = (newFocusIndex + navDots.length) % navDots.length;
68 navDots[newFocusIndex].tabIndex = 3;
69 navDots[newFocusIndex].focus();
70 focusDot.tabIndex = -1;
72 e.stopPropagation();
73 e.preventDefault();
77 return {
78 DotList: DotList
80 });