OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 New tab page | 6 * @fileoverview New tab page |
7 * This is the main code for the new tab page used by touch-enabled Chrome | 7 * This is the main code for the new tab page used by touch-enabled Chrome |
8 * browsers. For now this is still a prototype. | 8 * browsers. For now this is still a prototype. |
9 */ | 9 */ |
10 | 10 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // When a new app has been installed, we will be opened with a hash value | 138 // When a new app has been installed, we will be opened with a hash value |
139 // that corresponds to the new app ID. | 139 // that corresponds to the new app ID. |
140 var hash = location.hash; | 140 var hash = location.hash; |
141 if (hash && hash.indexOf('#app-id=') == 0) { | 141 if (hash && hash.indexOf('#app-id=') == 0) { |
142 highlightAppId = hash.split('=')[1]; | 142 highlightAppId = hash.split('=')[1]; |
143 // Clear the hash so if the user bookmarks this page, they'll just get | 143 // Clear the hash so if the user bookmarks this page, they'll just get |
144 // chrome://newtab/. | 144 // chrome://newtab/. |
145 window.history.replaceState({}, '', '/'); | 145 window.history.replaceState({}, '', '/'); |
146 } | 146 } |
147 | 147 |
148 document.querySelector('#notification button').onclick = function(e) { | |
149 hideNotification(); | |
150 }; | |
151 | |
152 // Request data on the apps so we can fill them in. | 148 // Request data on the apps so we can fill them in. |
153 // Note that this is kicked off asynchronously. 'getAppsCallback' will be | 149 // Note that this is kicked off asynchronously. 'getAppsCallback' will be |
154 // invoked at some point after this function returns. | 150 // invoked at some point after this function returns. |
155 chrome.send('getApps'); | 151 chrome.send('getApps'); |
156 | 152 |
157 // Prevent touch events from triggering any sort of native scrolling | 153 // Prevent touch events from triggering any sort of native scrolling |
158 document.addEventListener('touchmove', function(e) { | 154 document.addEventListener('touchmove', function(e) { |
159 e.preventDefault(); | 155 e.preventDefault(); |
160 }, true); | 156 }, true); |
161 | 157 |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 */ | 614 */ |
619 var notificationTimeout_ = 0; | 615 var notificationTimeout_ = 0; |
620 | 616 |
621 /** | 617 /** |
622 * Shows the notification bubble. | 618 * Shows the notification bubble. |
623 * @param {string} text The notification message. | 619 * @param {string} text The notification message. |
624 * @param {Array.<{text: string, action: function()}>} links An array of | 620 * @param {Array.<{text: string, action: function()}>} links An array of |
625 * records describing the links in the notification. Each record should | 621 * records describing the links in the notification. Each record should |
626 * have a 'text' attribute (the display string) and an 'action' attribute | 622 * have a 'text' attribute (the display string) and an 'action' attribute |
627 * (a function to run when the link is activated). | 623 * (a function to run when the link is activated). |
| 624 * @param {Function} opt_closeHandler The callback invoked if the user |
| 625 * manually dismisses the notification. |
628 */ | 626 */ |
629 function showNotification(text, links) { | 627 function showNotification(text, links, opt_closeHandler) { |
630 window.clearTimeout(notificationTimeout_); | 628 window.clearTimeout(notificationTimeout_); |
631 document.querySelector('#notification > span').textContent = text; | 629 document.querySelector('#notification > span').textContent = text; |
632 | 630 |
633 var linksBin = $('notificationLinks'); | 631 var linksBin = $('notificationLinks'); |
634 linksBin.textContent = ''; | 632 linksBin.textContent = ''; |
635 for (var i = 0; i < links.length; i++) { | 633 for (var i = 0; i < links.length; i++) { |
636 var link = linksBin.ownerDocument.createElement('div'); | 634 var link = linksBin.ownerDocument.createElement('div'); |
637 link.textContent = links[i].text; | 635 link.textContent = links[i].text; |
638 var action = links[i].action; | 636 var action = links[i].action; |
639 link.onclick = function(e) { | 637 link.onclick = function(e) { |
640 action(); | 638 action(); |
641 hideNotification(); | 639 hideNotification(); |
642 } | 640 } |
643 link.setAttribute('role', 'button'); | 641 link.setAttribute('role', 'button'); |
644 link.setAttribute('tabindex', 0); | 642 link.setAttribute('tabindex', 0); |
645 link.className = "linkButton"; | 643 link.className = "linkButton"; |
646 linksBin.appendChild(link); | 644 linksBin.appendChild(link); |
647 } | 645 } |
648 | 646 |
| 647 document.querySelector('#notification button').onclick = function(e) { |
| 648 if (opt_closeHandler) |
| 649 opt_closeHandler(); |
| 650 hideNotification(); |
| 651 }; |
| 652 |
649 $('notification').classList.remove('inactive'); | 653 $('notification').classList.remove('inactive'); |
650 notificationTimeout_ = window.setTimeout(hideNotification, 10000); | 654 notificationTimeout_ = window.setTimeout(hideNotification, 10000); |
651 } | 655 } |
652 | 656 |
653 /** | 657 /** |
654 * Hide the notification bubble. | 658 * Hide the notification bubble. |
655 */ | 659 */ |
656 function hideNotification() { | 660 function hideNotification() { |
657 $('notification').classList.add('inactive'); | 661 $('notification').classList.add('inactive'); |
658 } | 662 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 // TODO(estade): update the content handlers to use ntp namespace instead of | 714 // TODO(estade): update the content handlers to use ntp namespace instead of |
711 // making these global. | 715 // making these global. |
712 var assert = ntp4.assert; | 716 var assert = ntp4.assert; |
713 var getAppsCallback = ntp4.getAppsCallback; | 717 var getAppsCallback = ntp4.getAppsCallback; |
714 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; | 718 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; |
715 var themeChanged = ntp4.themeChanged; | 719 var themeChanged = ntp4.themeChanged; |
716 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; | 720 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; |
717 var setMostVisitedPages = ntp4.setMostVisitedPages; | 721 var setMostVisitedPages = ntp4.setMostVisitedPages; |
718 | 722 |
719 document.addEventListener('DOMContentLoaded', ntp4.initialize); | 723 document.addEventListener('DOMContentLoaded', ntp4.initialize); |
OLD | NEW |