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

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

Issue 7672012: Support for promo in ntp4. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' 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
« no previous file with comments | « chrome/browser/resources/ntp4/new_tab.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 infoBubble.anchorNode = mostVisitedPage.navigationDot; 200 infoBubble.anchorNode = mostVisitedPage.navigationDot;
201 infoBubble.text = localStrings.getString('ntp4_intro_message'); 201 infoBubble.text = localStrings.getString('ntp4_intro_message');
202 infoBubble.show(); 202 infoBubble.show();
203 203
204 chrome.send('introMessageSeen'); 204 chrome.send('introMessageSeen');
205 } 205 }
206 206
207 bookmarksPage = new ntp4.BookmarksPage(); 207 bookmarksPage = new ntp4.BookmarksPage();
208 appendTilePage(bookmarksPage, localStrings.getString('bookmarksPage')); 208 appendTilePage(bookmarksPage, localStrings.getString('bookmarksPage'));
209 chrome.send('getBookmarksData'); 209 chrome.send('getBookmarksData');
210
211 var serverpromo = localStrings.getString('serverpromo');
212 if (serverpromo) {
213 showNotification(parseHtmlSubset(serverpromo), [], function() {
214 chrome.send('closePromo');
215 }, 60000);
216 }
210 } 217 }
211 218
212 /** 219 /**
213 * Simple common assertion API 220 * Simple common assertion API
214 * @param {*} condition The condition to test. Note that this may be used to 221 * @param {*} condition The condition to test. Note that this may be used to
215 * test whether a value is defined or not, and we don't want to force a 222 * test whether a value is defined or not, and we don't want to force a
216 * cast to Boolean. 223 * cast to Boolean.
217 * @param {string=} opt_message A message to use in any error. 224 * @param {string=} opt_message A message to use in any error.
218 */ 225 */
219 function assert(condition, opt_message) { 226 function assert(condition, opt_message) {
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 /** 645 /**
639 * Shows the notification bubble. 646 * Shows the notification bubble.
640 * @param {string} text The notification message. 647 * @param {string} text The notification message.
641 * @param {Array.<{text: string, action: function()}>} links An array of 648 * @param {Array.<{text: string, action: function()}>} links An array of
642 * records describing the links in the notification. Each record should 649 * records describing the links in the notification. Each record should
643 * have a 'text' attribute (the display string) and an 'action' attribute 650 * have a 'text' attribute (the display string) and an 'action' attribute
644 * (a function to run when the link is activated). 651 * (a function to run when the link is activated).
645 * @param {Function} opt_closeHandler The callback invoked if the user 652 * @param {Function} opt_closeHandler The callback invoked if the user
646 * manually dismisses the notification. 653 * manually dismisses the notification.
647 */ 654 */
648 function showNotification(text, links, opt_closeHandler) { 655 function showNotification(text, links, opt_closeHandler, opt_timeout) {
649 window.clearTimeout(notificationTimeout_); 656 window.clearTimeout(notificationTimeout_);
650 document.querySelector('#notification > span').textContent = text; 657
658 var span = document.querySelector('#notification > span');
659 if (typeof text == 'string') {
Evan Stade 2011/08/19 20:43:23 name of text param and documentation needs updatin
achuithb 2011/08/19 21:30:28 Done.
660 span.textContent = text;
661 } else {
662 span.textContent = ''; // Remove all children.
663 span.appendChild(text);
664 }
651 665
652 var linksBin = $('notificationLinks'); 666 var linksBin = $('notificationLinks');
653 linksBin.textContent = ''; 667 linksBin.textContent = '';
654 for (var i = 0; i < links.length; i++) { 668 for (var i = 0; i < links.length; i++) {
655 var link = linksBin.ownerDocument.createElement('div'); 669 var link = linksBin.ownerDocument.createElement('div');
656 link.textContent = links[i].text; 670 link.textContent = links[i].text;
657 var action = links[i].action; 671 var action = links[i].action;
658 link.onclick = function(e) { 672 link.onclick = function(e) {
659 action(); 673 action();
660 hideNotification(); 674 hideNotification();
661 } 675 }
662 link.setAttribute('role', 'button'); 676 link.setAttribute('role', 'button');
663 link.setAttribute('tabindex', 0); 677 link.setAttribute('tabindex', 0);
664 link.className = "linkButton"; 678 link.className = "linkButton";
665 linksBin.appendChild(link); 679 linksBin.appendChild(link);
666 } 680 }
667 681
668 document.querySelector('#notification button').onclick = function(e) { 682 document.querySelector('#notification button').onclick = function(e) {
669 if (opt_closeHandler) 683 if (opt_closeHandler)
670 opt_closeHandler(); 684 opt_closeHandler();
671 hideNotification(); 685 hideNotification();
672 }; 686 };
673 687
688 var timeout = opt_timeout || 10000;
674 $('notification').classList.remove('inactive'); 689 $('notification').classList.remove('inactive');
675 notificationTimeout_ = window.setTimeout(hideNotification, 10000); 690 notificationTimeout_ = window.setTimeout(hideNotification, timeout);
676 } 691 }
677 692
678 /** 693 /**
679 * Hide the notification bubble. 694 * Hide the notification bubble.
680 */ 695 */
681 function hideNotification() { 696 function hideNotification() {
682 $('notification').classList.add('inactive'); 697 $('notification').classList.add('inactive');
683 } 698 }
684 699
685 function setRecentlyClosedTabs(dataItems) { 700 function setRecentlyClosedTabs(dataItems) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 // TODO(estade): update the content handlers to use ntp namespace instead of 755 // TODO(estade): update the content handlers to use ntp namespace instead of
741 // making these global. 756 // making these global.
742 var assert = ntp4.assert; 757 var assert = ntp4.assert;
743 var getAppsCallback = ntp4.getAppsCallback; 758 var getAppsCallback = ntp4.getAppsCallback;
744 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; 759 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback;
745 var themeChanged = ntp4.themeChanged; 760 var themeChanged = ntp4.themeChanged;
746 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; 761 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs;
747 var setMostVisitedPages = ntp4.setMostVisitedPages; 762 var setMostVisitedPages = ntp4.setMostVisitedPages;
748 763
749 document.addEventListener('DOMContentLoaded', ntp4.initialize); 764 document.addEventListener('DOMContentLoaded', ntp4.initialize);
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp4/new_tab.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698