| OLD | NEW |
| 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 = {}; | |
| 15 | |
| 16 function tips(data) { | |
| 17 logEvent('received tips'); | |
| 18 tipCache = data; | |
| 19 renderTip(); | |
| 20 } | |
| 21 | |
| 22 function createTip(data) { | |
| 23 if (data.length) { | |
| 24 if (data[0].set_homepage_tip) { | |
| 25 var homepageButton = document.createElement('button'); | |
| 26 homepageButton.className = 'link'; | |
| 27 homepageButton.textContent = data[0].set_homepage_tip; | |
| 28 homepageButton.addEventListener('click', setAsHomePageLinkClicked); | |
| 29 return homepageButton; | |
| 30 } else { | |
| 31 try { | |
| 32 return parseHtmlSubset(data[0].tip_html_text); | |
| 33 } catch (parseErr) { | |
| 34 console.error('Error parsing tips: ' + parseErr.message); | |
| 35 } | |
| 36 } | |
| 37 } | |
| 38 // Return an empty DF in case of failure. | |
| 39 return document.createDocumentFragment(); | |
| 40 } | |
| 41 | |
| 42 function clearTipLine() { | |
| 43 var tipElement = $('tip-line'); | |
| 44 // There should always be only one tip. | |
| 45 tipElement.textContent = ''; | |
| 46 tipElement.removeEventListener('click', setAsHomePageLinkClicked); | |
| 47 } | |
| 48 | |
| 49 function renderTip() { | |
| 50 clearTipLine(); | |
| 51 var tipElement = $('tip-line'); | |
| 52 tipElement.appendChild(createTip(tipCache)); | |
| 53 fixLinkUnderlines(tipElement); | |
| 54 } | |
| 55 | |
| 56 function recentlyClosedTabs(data) { | 14 function recentlyClosedTabs(data) { |
| 57 logEvent('received recently closed tabs'); | 15 logEvent('received recently closed tabs'); |
| 58 // We need to store the recent items so we can update the layout on a resize. | 16 // We need to store the recent items so we can update the layout on a resize. |
| 59 recentItems = data; | 17 recentItems = data; |
| 60 renderRecentlyClosed(); | 18 renderRecentlyClosed(); |
| 61 } | 19 } |
| 62 | 20 |
| 63 var recentItems = []; | 21 var recentItems = []; |
| 64 | 22 |
| 65 function renderRecentlyClosed() { | 23 function renderRecentlyClosed() { |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 * The sync code is not yet built by default on all platforms so we have to | 798 * The sync code is not yet built by default on all platforms so we have to |
| 841 * make sure we don't send the initial sync message to the backend unless the | 799 * make sure we don't send the initial sync message to the backend unless the |
| 842 * backend told us that the sync code is present. | 800 * backend told us that the sync code is present. |
| 843 */ | 801 */ |
| 844 function callGetSyncMessageIfSyncIsPresent() { | 802 function callGetSyncMessageIfSyncIsPresent() { |
| 845 if (document.documentElement.getAttribute('syncispresent') == 'true') { | 803 if (document.documentElement.getAttribute('syncispresent') == 'true') { |
| 846 chrome.send('GetSyncMessage'); | 804 chrome.send('GetSyncMessage'); |
| 847 } | 805 } |
| 848 } | 806 } |
| 849 | 807 |
| 850 function setAsHomePageLinkClicked(e) { | |
| 851 chrome.send('setHomePage'); | |
| 852 e.preventDefault(); | |
| 853 } | |
| 854 | |
| 855 function onHomePageSet(data) { | |
| 856 showNotification(data[0], data[1]); | |
| 857 // Removes the "make this my home page" tip. | |
| 858 clearTipLine(); | |
| 859 } | |
| 860 | |
| 861 function hideAllMenus() { | 808 function hideAllMenus() { |
| 862 optionMenu.hide(); | 809 optionMenu.hide(); |
| 863 } | 810 } |
| 864 | 811 |
| 865 window.addEventListener('blur', hideAllMenus); | 812 window.addEventListener('blur', hideAllMenus); |
| 866 window.addEventListener('keydown', function(e) { | 813 window.addEventListener('keydown', function(e) { |
| 867 if (e.keyIdentifier == 'Alt' || e.keyIdentifier == 'Meta') { | 814 if (e.keyIdentifier == 'Alt' || e.keyIdentifier == 'Meta') { |
| 868 hideAllMenus(); | 815 hideAllMenus(); |
| 869 } | 816 } |
| 870 }, true); | 817 }, true); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 window.setTimeout(function() { | 877 window.setTimeout(function() { |
| 931 mostVisited.ensureSmallGridCorrect(); | 878 mostVisited.ensureSmallGridCorrect(); |
| 932 document.body.classList.remove('loading'); | 879 document.body.classList.remove('loading'); |
| 933 }, 1); | 880 }, 1); |
| 934 | 881 |
| 935 // Only show the first run notification if first run. | 882 // Only show the first run notification if first run. |
| 936 if (firstRun) { | 883 if (firstRun) { |
| 937 showFirstRunNotification(); | 884 showFirstRunNotification(); |
| 938 } | 885 } |
| 939 } | 886 } |
| 940 | |
| 941 // Log clicked links from the tips section. | |
| 942 document.addEventListener('click', function(e) { | |
| 943 var tipLinks = document.querySelectorAll('#tip-line a'); | |
| 944 for (var i = 0, tipLink; tipLink = tipLinks[i]; i++) { | |
| 945 if (tipLink.contains(e.target)) { | |
| 946 chrome.send('metrics', ['NTPTip_' + tipLink.href]); | |
| 947 break; | |
| 948 } | |
| 949 } | |
| 950 }); | |
| OLD | NEW |