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

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

Issue 7124002: ntp4: notification area (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 9 years, 6 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 */ 77 */
78 function initialize() { 78 function initialize() {
79 // Load the current theme colors. 79 // Load the current theme colors.
80 themeChanged(); 80 themeChanged();
81 81
82 dotList = getRequiredElement('dot-list'); 82 dotList = getRequiredElement('dot-list');
83 pageList = getRequiredElement('page-list'); 83 pageList = getRequiredElement('page-list');
84 trash = getRequiredElement('trash'); 84 trash = getRequiredElement('trash');
85 trash.hidden = true; 85 trash.hidden = true;
86 86
87 document.querySelector('#notification button').onclick = function(e) {
88 hideNotification();
89 };
90
87 // Request data on the apps so we can fill them in. 91 // Request data on the apps so we can fill them in.
88 // Note that this is kicked off asynchronously. 'getAppsCallback' will be 92 // Note that this is kicked off asynchronously. 'getAppsCallback' will be
89 // invoked at some point after this function returns. 93 // invoked at some point after this function returns.
90 chrome.send('getApps'); 94 chrome.send('getApps');
91 95
92 // Prevent touch events from triggering any sort of native scrolling 96 // Prevent touch events from triggering any sort of native scrolling
93 document.addEventListener('touchmove', function(e) { 97 document.addEventListener('touchmove', function(e) {
94 e.preventDefault(); 98 e.preventDefault();
95 }, true); 99 }, true);
96 100
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 */ 368 */
365 function updateAttribution() { 369 function updateAttribution() {
366 var attribution = $('attribution'); 370 var attribution = $('attribution');
367 if (document.documentElement.getAttribute('hasattribution') == 'true') { 371 if (document.documentElement.getAttribute('hasattribution') == 'true') {
368 $('attribution-img').src = 372 $('attribution-img').src =
369 'chrome://theme/IDR_THEME_NTP_ATTRIBUTION?' + Date.now(); 373 'chrome://theme/IDR_THEME_NTP_ATTRIBUTION?' + Date.now();
370 attribution.hidden = false; 374 attribution.hidden = false;
371 } else { 375 } else {
372 attribution.hidden = true; 376 attribution.hidden = true;
373 } 377 }
378 }
374 379
380 /**
381 * Timeout ID.
382 * @type {number}
383 */
384 var notificationTimeout_ = 0;
385
386 /**
387 * Shows the notification bubble.
388 * @param {string} text The notification message.
389 * @param {Array.<{text: string, action: function()}>} links An array of
390 * records describing the links in the notification. Each record should
391 * have a 'text' attribute (the display string) and an 'action' attribute
392 * (a function to run when the link is activated).
393 */
394 function showNotification(text, links) {
395 window.clearTimeout(notificationTimeout_);
396 document.querySelector('#notification > span').textContent = text;
397
398 var linksBin = $('notificationLinks');
399 linksBin.textContent = '';
400 for (var i = 0; i < links.length; i++) {
401 var link = linksBin.ownerDocument.createElement('div');
402 link.textContent = links[i].text;
403 var action = links[i].action;
404 link.onclick = function(e) {
405 action();
406 hideNotification();
407 }
408 link.setAttribute('role', 'button');
409 link.setAttribute('tabindex', 0);
410 link.className = "linkButton";
411 linksBin.appendChild(link);
412 }
413
414 $('notification').classList.remove('inactive');
415 notificationTimeout_ = window.setTimeout(hideNotification, 10000);
416 }
417
418 /**
419 * Hide the notification bubble.
420 */
421 function hideNotification() {
422 $('notification').classList.add('inactive');
375 } 423 }
376 424
377 function setRecentlyClosedTabs(dataItems) { 425 function setRecentlyClosedTabs(dataItems) {
378 $('recently-closed-menu-button').dataItems = dataItems; 426 $('recently-closed-menu-button').dataItems = dataItems;
379 } 427 }
380 428
381 function setMostVisitedPages(data, firstRun, hasBlacklistedUrls) { 429 function setMostVisitedPages(data, firstRun, hasBlacklistedUrls) {
382 mostVisitedPage.data = data; 430 mostVisitedPage.data = data;
383 } 431 }
384 432
385 // Return an object with all the exports 433 // Return an object with all the exports
386 return { 434 return {
387 assert: assert, 435 assert: assert,
388 appsPrefChangeCallback: appsPrefChangeCallback, 436 appsPrefChangeCallback: appsPrefChangeCallback,
389 enterRearrangeMode: enterRearrangeMode, 437 enterRearrangeMode: enterRearrangeMode,
390 getAppsCallback: getAppsCallback, 438 getAppsCallback: getAppsCallback,
391 getCardSlider: getCardSlider, 439 getCardSlider: getCardSlider,
392 getAppsPageIndex: getAppsPageIndex, 440 getAppsPageIndex: getAppsPageIndex,
393 initialize: initialize, 441 initialize: initialize,
394 leaveRearrangeMode: leaveRearrangeMode, 442 leaveRearrangeMode: leaveRearrangeMode,
395 themeChanged: themeChanged, 443 themeChanged: themeChanged,
396 setRecentlyClosedTabs: setRecentlyClosedTabs, 444 setRecentlyClosedTabs: setRecentlyClosedTabs,
397 setMostVisitedPages: setMostVisitedPages, 445 setMostVisitedPages: setMostVisitedPages,
446 showNotification: showNotification,
398 }; 447 };
399 }); 448 });
400 449
401 // publish ntp globals 450 // publish ntp globals
402 // TODO(estade): update the content handlers to use ntp namespace instead of 451 // TODO(estade): update the content handlers to use ntp namespace instead of
403 // making these global. 452 // making these global.
404 var assert = ntp4.assert; 453 var assert = ntp4.assert;
405 var getAppsCallback = ntp4.getAppsCallback; 454 var getAppsCallback = ntp4.getAppsCallback;
406 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; 455 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback;
407 var themeChanged = ntp4.themeChanged; 456 var themeChanged = ntp4.themeChanged;
408 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; 457 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs;
409 var setMostVisitedPages = ntp4.setMostVisitedPages; 458 var setMostVisitedPages = ntp4.setMostVisitedPages;
410 459
411 document.addEventListener('DOMContentLoaded', ntp4.initialize); 460 document.addEventListener('DOMContentLoaded', ntp4.initialize);
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp4/new_tab.html ('k') | chrome/browser/ui/webui/ntp/ntp_resource_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698