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

Side by Side Diff: chrome/browser/resources/new_new_tab.js

Issue 2805089: Add bookmark promo to NTP on first run. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 var loading = true; 5 var loading = true;
6 6
7 function updateSimpleSection(id, section) { 7 function updateSimpleSection(id, section) {
8 if (shownSections & section) 8 if (shownSections & section)
9 $(id).classList.remove('hidden'); 9 $(id).classList.remove('hidden');
10 else 10 else
11 $(id).classList.add('hidden'); 11 $(id).classList.add('hidden');
12 } 12 }
13 13
14 var tipCache = {}; 14 var tipCache = {};
15 15
16 function tips(data) { 16 function tips(data) {
17 logEvent('received tips'); 17 logEvent('received tips');
18 tipCache = data; 18 tipCache = data;
19 renderTip(); 19 renderTip();
20 } 20 }
21 21
22 function createTip(data) { 22 function createTip(data) {
23 if (data.length) { 23 if (data.length) {
24 if (data[0].set_homepage_tip) { 24 if (data[0].set_homepage_tip) {
25 var homepageButton = document.createElement('button'); 25 var homepageButton = document.createElement('button');
26 homepageButton.className = 'link'; 26 homepageButton.className = 'link';
27 homepageButton.textContent = data[0].set_homepage_tip; 27 homepageButton.textContent = data[0].set_homepage_tip;
28 homepageButton.addEventListener('click', setAsHomePageLinkClicked); 28 homepageButton.addEventListener('click', setAsHomePageLinkClicked);
29 return homepageButton; 29 return homepageButton;
30 } else if (data[0].set_promo_tip) {
31 var promoMessage = document.createElement('span');
32 promoMessage.innerHTML = data[0].set_promo_tip;
33 var promoButton = promoMessage.querySelector('button');
34 promoButton.addEventListener('click', importBookmarksLinkClicked);
35 return promoMessage;
30 } else { 36 } else {
31 try { 37 try {
32 return parseHtmlSubset(data[0].tip_html_text); 38 return parseHtmlSubset(data[0].tip_html_text);
33 } catch (parseErr) { 39 } catch (parseErr) {
34 console.error('Error parsing tips: ' + parseErr.message); 40 console.error('Error parsing tips: ' + parseErr.message);
35 } 41 }
36 } 42 }
37 } 43 }
38 // Return an empty DF in case of failure. 44 // Return an empty DF in case of failure.
39 return document.createDocumentFragment(); 45 return document.createDocumentFragment();
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 var actionLink = notificationElement.querySelector('.link-color'); 440 var actionLink = notificationElement.querySelector('.link-color');
435 // Prevent tabbing to the hidden link. 441 // Prevent tabbing to the hidden link.
436 actionLink.tabIndex = -1; 442 actionLink.tabIndex = -1;
437 // Setting tabIndex to -1 only prevents future tabbing to it. If, however, the 443 // Setting tabIndex to -1 only prevents future tabbing to it. If, however, the
438 // user switches window or a tab and then moves back to this tab the element 444 // user switches window or a tab and then moves back to this tab the element
439 // may gain focus. We therefore make sure that we blur the element so that the 445 // may gain focus. We therefore make sure that we blur the element so that the
440 // element focus is not restored when coming back to this window. 446 // element focus is not restored when coming back to this window.
441 actionLink.blur(); 447 actionLink.blur();
442 } 448 }
443 449
444 function showFirstRunNotification() {
445 showNotification(localStrings.getString('firstrunnotification'),
446 localStrings.getString('closefirstrunnotification'),
447 null, 30000);
448 var notificationElement = $('notification');
449 notification.classList.add('first-run');
450 }
451
452 /** 450 /**
453 * This handles the option menu. 451 * This handles the option menu.
454 * @param {Element} button The button element. 452 * @param {Element} button The button element.
455 * @param {Element} menu The menu element. 453 * @param {Element} menu The menu element.
456 * @constructor 454 * @constructor
457 */ 455 */
458 function OptionMenu(button, menu) { 456 function OptionMenu(button, menu) {
459 this.button = button; 457 this.button = button;
460 this.menu = menu; 458 this.menu = menu;
461 this.button.onmousedown = bind(this.handleMouseDown, this); 459 this.button.onmousedown = bind(this.handleMouseDown, this);
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 if (document.documentElement.getAttribute('syncispresent') == 'true') { 843 if (document.documentElement.getAttribute('syncispresent') == 'true') {
846 chrome.send('GetSyncMessage'); 844 chrome.send('GetSyncMessage');
847 } 845 }
848 } 846 }
849 847
850 function setAsHomePageLinkClicked(e) { 848 function setAsHomePageLinkClicked(e) {
851 chrome.send('setHomePage'); 849 chrome.send('setHomePage');
852 e.preventDefault(); 850 e.preventDefault();
853 } 851 }
854 852
853 function importBookmarksLinkClicked(e) {
854 chrome.send('importBookmarks');
855 e.preventDefault();
856 }
857
855 function onHomePageSet(data) { 858 function onHomePageSet(data) {
856 showNotification(data[0], data[1]); 859 showNotification(data[0], data[1]);
857 // Removes the "make this my home page" tip. 860 // Removes the "make this my home page" tip.
858 clearTipLine(); 861 clearTipLine();
859 } 862 }
860 863
861 function hideAllMenus() { 864 function hideAllMenus() {
862 optionMenu.hide(); 865 optionMenu.hide();
863 } 866 }
864 867
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 mostVisited.layout(); 927 mostVisited.layout();
925 928
926 loading = false; 929 loading = false;
927 930
928 // Remove class name in a timeout so that changes done in this JS thread are 931 // Remove class name in a timeout so that changes done in this JS thread are
929 // not animated. 932 // not animated.
930 window.setTimeout(function() { 933 window.setTimeout(function() {
931 mostVisited.ensureSmallGridCorrect(); 934 mostVisited.ensureSmallGridCorrect();
932 document.body.classList.remove('loading'); 935 document.body.classList.remove('loading');
933 }, 1); 936 }, 1);
934
935 // Only show the first run notification if first run.
936 if (firstRun) {
937 showFirstRunNotification();
938 }
939 } 937 }
940 938
941 // Log clicked links from the tips section. 939 // Log clicked links from the tips section.
942 document.addEventListener('click', function(e) { 940 document.addEventListener('click', function(e) {
943 var tipLinks = document.querySelectorAll('#tip-line a'); 941 var tipLinks = document.querySelectorAll('#tip-line a');
944 for (var i = 0, tipLink; tipLink = tipLinks[i]; i++) { 942 for (var i = 0, tipLink; tipLink = tipLinks[i]; i++) {
945 if (tipLink.contains(e.target)) { 943 if (tipLink.contains(e.target)) {
946 chrome.send('metrics', ['NTPTip_' + tipLink.href]); 944 chrome.send('metrics', ['NTPTip_' + tipLink.href]);
947 break; 945 break;
948 } 946 }
949 } 947 }
950 }); 948 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/new_new_tab.css ('k') | chrome/browser/tab_contents/web_contents_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698