OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Page switcher | 6 * @fileoverview Page switcher |
7 * This is the class for the left and right navigation arrows that switch | 7 * This is the class for the left and right navigation arrows that switch |
8 * between pages. | 8 * between pages. |
9 */ | 9 */ |
10 cr.define('ntp', function() { | 10 cr.define('ntp', function() { |
11 | 11 |
12 /** | 12 /** |
13 * @constructor | 13 * @constructor |
14 * @extends {HTMLButtonElement} | 14 * @extends {HTMLButtonElement} |
15 */ | 15 */ |
16 function PageSwitcher() { | 16 function PageSwitcher() {} |
17 } | |
18 | 17 |
19 PageSwitcher.prototype = { | 18 PageSwitcher.prototype = { |
20 __proto__: HTMLButtonElement.prototype, | 19 __proto__: HTMLButtonElement.prototype, |
21 | 20 |
22 decorate: function(el) { | 21 decorate: function(el) { |
23 el.__proto__ = PageSwitcher.prototype; | 22 el.__proto__ = PageSwitcher.prototype; |
24 | 23 |
25 el.addEventListener('click', el.activate_); | 24 el.addEventListener('click', el.activate_); |
26 | 25 |
27 el.direction_ = el.id == 'page-switcher-start' ? -1 : 1; | 26 el.direction_ = el.id == 'page-switcher-start' ? -1 : 1; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 var currentDot = dots[currentIndex]; | 64 var currentDot = dots[currentIndex]; |
66 var nextDot = dots[nextCardIndex]; | 65 var nextDot = dots[nextCardIndex]; |
67 if (!currentDot || !nextDot) { | 66 if (!currentDot || !nextDot) { |
68 this.setAttribute('aria-label', ''); // Dots not initialised yet. | 67 this.setAttribute('aria-label', ''); // Dots not initialised yet. |
69 return; | 68 return; |
70 } | 69 } |
71 | 70 |
72 var currentPageTitle = currentDot.displayTitle; | 71 var currentPageTitle = currentDot.displayTitle; |
73 var nextPageTitle = nextDot.displayTitle; | 72 var nextPageTitle = nextDot.displayTitle; |
74 var msgName = (currentPageTitle == nextPageTitle) ? | 73 var msgName = (currentPageTitle == nextPageTitle) ? |
75 'page_switcher_same_title' : 'page_switcher_change_title'; | 74 'page_switcher_same_title' : |
| 75 'page_switcher_change_title'; |
76 var ariaLabel = loadTimeData.getStringF(msgName, nextPageTitle); | 76 var ariaLabel = loadTimeData.getStringF(msgName, nextPageTitle); |
77 this.setAttribute('aria-label', ariaLabel); | 77 this.setAttribute('aria-label', ariaLabel); |
78 }, | 78 }, |
79 | 79 |
80 shouldAcceptDrag: function(e) { | 80 shouldAcceptDrag: function(e) { |
81 // Only allow page switching when a drop could happen on the page being | 81 // Only allow page switching when a drop could happen on the page being |
82 // switched to. | 82 // switched to. |
83 var nextPage = ntp.getCardSlider().getCardAtIndex(this.nextCardIndex_()); | 83 var nextPage = ntp.getCardSlider().getCardAtIndex(this.nextCardIndex_()); |
84 return nextPage.shouldAcceptDrag(e); | 84 return nextPage.shouldAcceptDrag(e); |
85 }, | 85 }, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 }; | 150 }; |
151 | 151 |
152 /** @const */ | 152 /** @const */ |
153 var initializePageSwitcher = PageSwitcher.prototype.decorate; | 153 var initializePageSwitcher = PageSwitcher.prototype.decorate; |
154 | 154 |
155 return { | 155 return { |
156 initializePageSwitcher: initializePageSwitcher, | 156 initializePageSwitcher: initializePageSwitcher, |
157 PageSwitcher: PageSwitcher | 157 PageSwitcher: PageSwitcher |
158 }; | 158 }; |
159 }); | 159 }); |
OLD | NEW |