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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 themeChanged(); | 120 themeChanged(); |
121 | 121 |
122 dotList = getRequiredElement('dot-list'); | 122 dotList = getRequiredElement('dot-list'); |
123 pageList = getRequiredElement('page-list'); | 123 pageList = getRequiredElement('page-list'); |
124 trash = getRequiredElement('trash'); | 124 trash = getRequiredElement('trash'); |
125 new ntp4.Trash(trash); | 125 new ntp4.Trash(trash); |
126 | 126 |
127 shownPage = templateData['shown_page_type']; | 127 shownPage = templateData['shown_page_type']; |
128 shownPageIndex = templateData['shown_page_index']; | 128 shownPageIndex = templateData['shown_page_index']; |
129 | 129 |
130 document.querySelector('#notification button').onclick = function(e) { | |
131 hideNotification(); | |
132 }; | |
133 | |
134 // Request data on the apps so we can fill them in. | 130 // Request data on the apps so we can fill them in. |
135 // Note that this is kicked off asynchronously. 'getAppsCallback' will be | 131 // Note that this is kicked off asynchronously. 'getAppsCallback' will be |
136 // invoked at some point after this function returns. | 132 // invoked at some point after this function returns. |
137 chrome.send('getApps'); | 133 chrome.send('getApps'); |
138 | 134 |
139 // Prevent touch events from triggering any sort of native scrolling | 135 // Prevent touch events from triggering any sort of native scrolling |
140 document.addEventListener('touchmove', function(e) { | 136 document.addEventListener('touchmove', function(e) { |
141 e.preventDefault(); | 137 e.preventDefault(); |
142 }, true); | 138 }, true); |
143 | 139 |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 */ | 583 */ |
588 var notificationTimeout_ = 0; | 584 var notificationTimeout_ = 0; |
589 | 585 |
590 /** | 586 /** |
591 * Shows the notification bubble. | 587 * Shows the notification bubble. |
592 * @param {string} text The notification message. | 588 * @param {string} text The notification message. |
593 * @param {Array.<{text: string, action: function()}>} links An array of | 589 * @param {Array.<{text: string, action: function()}>} links An array of |
594 * records describing the links in the notification. Each record should | 590 * records describing the links in the notification. Each record should |
595 * have a 'text' attribute (the display string) and an 'action' attribute | 591 * have a 'text' attribute (the display string) and an 'action' attribute |
596 * (a function to run when the link is activated). | 592 * (a function to run when the link is activated). |
| 593 * @param {Function} opt_closeHandler The callback invoked if the user |
| 594 * manually dismisses the notification. |
597 */ | 595 */ |
598 function showNotification(text, links) { | 596 function showNotification(text, links, opt_closeHandler) { |
599 window.clearTimeout(notificationTimeout_); | 597 window.clearTimeout(notificationTimeout_); |
600 document.querySelector('#notification > span').textContent = text; | 598 document.querySelector('#notification > span').textContent = text; |
601 | 599 |
602 var linksBin = $('notificationLinks'); | 600 var linksBin = $('notificationLinks'); |
603 linksBin.textContent = ''; | 601 linksBin.textContent = ''; |
604 for (var i = 0; i < links.length; i++) { | 602 for (var i = 0; i < links.length; i++) { |
605 var link = linksBin.ownerDocument.createElement('div'); | 603 var link = linksBin.ownerDocument.createElement('div'); |
606 link.textContent = links[i].text; | 604 link.textContent = links[i].text; |
607 var action = links[i].action; | 605 var action = links[i].action; |
608 link.onclick = function(e) { | 606 link.onclick = function(e) { |
609 action(); | 607 action(); |
610 hideNotification(); | 608 hideNotification(); |
611 } | 609 } |
612 link.setAttribute('role', 'button'); | 610 link.setAttribute('role', 'button'); |
613 link.setAttribute('tabindex', 0); | 611 link.setAttribute('tabindex', 0); |
614 link.className = "linkButton"; | 612 link.className = "linkButton"; |
615 linksBin.appendChild(link); | 613 linksBin.appendChild(link); |
616 } | 614 } |
617 | 615 |
| 616 document.querySelector('#notification button').onclick = function(e) { |
| 617 if (opt_closeHandler) |
| 618 opt_closeHandler(); |
| 619 hideNotification(); |
| 620 }; |
| 621 |
618 $('notification').classList.remove('inactive'); | 622 $('notification').classList.remove('inactive'); |
619 notificationTimeout_ = window.setTimeout(hideNotification, 10000); | 623 notificationTimeout_ = window.setTimeout(hideNotification, 10000); |
620 } | 624 } |
621 | 625 |
622 /** | 626 /** |
623 * Hide the notification bubble. | 627 * Hide the notification bubble. |
624 */ | 628 */ |
625 function hideNotification() { | 629 function hideNotification() { |
626 $('notification').classList.add('inactive'); | 630 $('notification').classList.add('inactive'); |
627 } | 631 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 // TODO(estade): update the content handlers to use ntp namespace instead of | 683 // TODO(estade): update the content handlers to use ntp namespace instead of |
680 // making these global. | 684 // making these global. |
681 var assert = ntp4.assert; | 685 var assert = ntp4.assert; |
682 var getAppsCallback = ntp4.getAppsCallback; | 686 var getAppsCallback = ntp4.getAppsCallback; |
683 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; | 687 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; |
684 var themeChanged = ntp4.themeChanged; | 688 var themeChanged = ntp4.themeChanged; |
685 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; | 689 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; |
686 var setMostVisitedPages = ntp4.setMostVisitedPages; | 690 var setMostVisitedPages = ntp4.setMostVisitedPages; |
687 | 691 |
688 document.addEventListener('DOMContentLoaded', ntp4.initialize); | 692 document.addEventListener('DOMContentLoaded', ntp4.initialize); |
OLD | NEW |