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

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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 } 637 }
631 638
632 /** 639 /**
633 * Timeout ID. 640 * Timeout ID.
634 * @type {number} 641 * @type {number}
635 */ 642 */
636 var notificationTimeout_ = 0; 643 var notificationTimeout_ = 0;
637 644
638 /** 645 /**
639 * Shows the notification bubble. 646 * Shows the notification bubble.
640 * @param {string} text The notification message. 647 * @param {string|Node} message The notification message or node to use as
648 * message.
641 * @param {Array.<{text: string, action: function()}>} links An array of 649 * @param {Array.<{text: string, action: function()}>} links An array of
642 * records describing the links in the notification. Each record should 650 * records describing the links in the notification. Each record should
643 * have a 'text' attribute (the display string) and an 'action' attribute 651 * have a 'text' attribute (the display string) and an 'action' attribute
644 * (a function to run when the link is activated). 652 * (a function to run when the link is activated).
645 * @param {Function} opt_closeHandler The callback invoked if the user 653 * @param {Function} opt_closeHandler The callback invoked if the user
646 * manually dismisses the notification. 654 * manually dismisses the notification.
647 */ 655 */
648 function showNotification(text, links, opt_closeHandler) { 656 function showNotification(message, links, opt_closeHandler, opt_timeout) {
649 window.clearTimeout(notificationTimeout_); 657 window.clearTimeout(notificationTimeout_);
650 document.querySelector('#notification > span').textContent = text; 658
659 var span = document.querySelector('#notification > span');
660 if (typeof message == 'string') {
661 span.textContent = message;
662 } else {
663 span.textContent = ''; // Remove all children.
664 span.appendChild(message);
665 }
651 666
652 var linksBin = $('notificationLinks'); 667 var linksBin = $('notificationLinks');
653 linksBin.textContent = ''; 668 linksBin.textContent = '';
654 for (var i = 0; i < links.length; i++) { 669 for (var i = 0; i < links.length; i++) {
655 var link = linksBin.ownerDocument.createElement('div'); 670 var link = linksBin.ownerDocument.createElement('div');
656 link.textContent = links[i].text; 671 link.textContent = links[i].text;
657 var action = links[i].action; 672 var action = links[i].action;
658 link.onclick = function(e) { 673 link.onclick = function(e) {
659 action(); 674 action();
660 hideNotification(); 675 hideNotification();
661 } 676 }
662 link.setAttribute('role', 'button'); 677 link.setAttribute('role', 'button');
663 link.setAttribute('tabindex', 0); 678 link.setAttribute('tabindex', 0);
664 link.className = "linkButton"; 679 link.className = "linkButton";
665 linksBin.appendChild(link); 680 linksBin.appendChild(link);
666 } 681 }
667 682
668 document.querySelector('#notification button').onclick = function(e) { 683 document.querySelector('#notification button').onclick = function(e) {
669 if (opt_closeHandler) 684 if (opt_closeHandler)
670 opt_closeHandler(); 685 opt_closeHandler();
671 hideNotification(); 686 hideNotification();
672 }; 687 };
673 688
689 var timeout = opt_timeout || 10000;
674 $('notification').classList.remove('inactive'); 690 $('notification').classList.remove('inactive');
675 notificationTimeout_ = window.setTimeout(hideNotification, 10000); 691 notificationTimeout_ = window.setTimeout(hideNotification, timeout);
676 } 692 }
677 693
678 /** 694 /**
679 * Hide the notification bubble. 695 * Hide the notification bubble.
680 */ 696 */
681 function hideNotification() { 697 function hideNotification() {
682 $('notification').classList.add('inactive'); 698 $('notification').classList.add('inactive');
683 } 699 }
684 700
685 function setRecentlyClosedTabs(dataItems) { 701 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 756 // TODO(estade): update the content handlers to use ntp namespace instead of
741 // making these global. 757 // making these global.
742 var assert = ntp4.assert; 758 var assert = ntp4.assert;
743 var getAppsCallback = ntp4.getAppsCallback; 759 var getAppsCallback = ntp4.getAppsCallback;
744 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; 760 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback;
745 var themeChanged = ntp4.themeChanged; 761 var themeChanged = ntp4.themeChanged;
746 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; 762 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs;
747 var setMostVisitedPages = ntp4.setMostVisitedPages; 763 var setMostVisitedPages = ntp4.setMostVisitedPages;
748 764
749 document.addEventListener('DOMContentLoaded', ntp4.initialize); 765 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