Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: chrome/browser/resources/ntp4/new_tab.js

Issue 7481023: Adding notifications for new sync types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with trunk. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 */ 615 */
620 var notificationTimeout_ = 0; 616 var notificationTimeout_ = 0;
621 617
622 /** 618 /**
623 * Shows the notification bubble. 619 * Shows the notification bubble.
624 * @param {string} text The notification message. 620 * @param {string} text The notification message.
625 * @param {Array.<{text: string, action: function()}>} links An array of 621 * @param {Array.<{text: string, action: function()}>} links An array of
626 * records describing the links in the notification. Each record should 622 * records describing the links in the notification. Each record should
627 * have a 'text' attribute (the display string) and an 'action' attribute 623 * have a 'text' attribute (the display string) and an 'action' attribute
628 * (a function to run when the link is activated). 624 * (a function to run when the link is activated).
625 * @param {Function} opt_closeHandler The callback invoked if the user
626 * manually dismisses the notification.
629 */ 627 */
630 function showNotification(text, links) { 628 function showNotification(text, links, opt_closeHandler) {
631 window.clearTimeout(notificationTimeout_); 629 window.clearTimeout(notificationTimeout_);
632 document.querySelector('#notification > span').textContent = text; 630 document.querySelector('#notification > span').textContent = text;
633 631
634 var linksBin = $('notificationLinks'); 632 var linksBin = $('notificationLinks');
635 linksBin.textContent = ''; 633 linksBin.textContent = '';
636 for (var i = 0; i < links.length; i++) { 634 for (var i = 0; i < links.length; i++) {
637 var link = linksBin.ownerDocument.createElement('div'); 635 var link = linksBin.ownerDocument.createElement('div');
638 link.textContent = links[i].text; 636 link.textContent = links[i].text;
639 var action = links[i].action; 637 var action = links[i].action;
640 link.onclick = function(e) { 638 link.onclick = function(e) {
641 action(); 639 action();
642 hideNotification(); 640 hideNotification();
643 } 641 }
644 link.setAttribute('role', 'button'); 642 link.setAttribute('role', 'button');
645 link.setAttribute('tabindex', 0); 643 link.setAttribute('tabindex', 0);
646 link.className = "linkButton"; 644 link.className = "linkButton";
647 linksBin.appendChild(link); 645 linksBin.appendChild(link);
648 } 646 }
649 647
648 document.querySelector('#notification button').onclick = function(e) {
649 if (opt_closeHandler)
650 opt_closeHandler();
651 hideNotification();
652 };
653
650 $('notification').classList.remove('inactive'); 654 $('notification').classList.remove('inactive');
651 notificationTimeout_ = window.setTimeout(hideNotification, 10000); 655 notificationTimeout_ = window.setTimeout(hideNotification, 10000);
652 } 656 }
653 657
654 /** 658 /**
655 * Hide the notification bubble. 659 * Hide the notification bubble.
656 */ 660 */
657 function hideNotification() { 661 function hideNotification() {
658 $('notification').classList.add('inactive'); 662 $('notification').classList.add('inactive');
659 } 663 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 // TODO(estade): update the content handlers to use ntp namespace instead of 715 // TODO(estade): update the content handlers to use ntp namespace instead of
712 // making these global. 716 // making these global.
713 var assert = ntp4.assert; 717 var assert = ntp4.assert;
714 var getAppsCallback = ntp4.getAppsCallback; 718 var getAppsCallback = ntp4.getAppsCallback;
715 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; 719 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback;
716 var themeChanged = ntp4.themeChanged; 720 var themeChanged = ntp4.themeChanged;
717 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; 721 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs;
718 var setMostVisitedPages = ntp4.setMostVisitedPages; 722 var setMostVisitedPages = ntp4.setMostVisitedPages;
719 723
720 document.addEventListener('DOMContentLoaded', ntp4.initialize); 724 document.addEventListener('DOMContentLoaded', ntp4.initialize);
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp4/most_visited_page.js ('k') | chrome/browser/sync/profile_sync_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698