Chromium Code Reviews| 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 // To avoid creating tons of unnecessary nodes. We assume we cannot fit more | 5 // To avoid creating tons of unnecessary nodes. We assume we cannot fit more |
| 6 // than this many items in the miniview. | 6 // than this many items in the miniview. |
| 7 var MAX_MINIVIEW_ITEMS = 15; | 7 var MAX_MINIVIEW_ITEMS = 15; |
| 8 | 8 |
| 9 // Extra spacing at the top of the layout. | 9 // Extra spacing at the top of the layout. |
| 10 var LAYOUT_SPACING_TOP = 25; | 10 var LAYOUT_SPACING_TOP = 25; |
| (...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 787 // The duration of all transitions are .15s | 787 // The duration of all transitions are .15s |
| 788 window.setTimeout(f, 150); | 788 window.setTimeout(f, 150); |
| 789 } | 789 } |
| 790 } | 790 } |
| 791 | 791 |
| 792 // Notification | 792 // Notification |
| 793 | 793 |
| 794 | 794 |
| 795 var notificationTimeout; | 795 var notificationTimeout; |
| 796 | 796 |
| 797 function showNotification(text, actionText, opt_f, opt_delay) { | 797 /* |
| 798 * Displays a message (either a string or a document fragment) in the | |
| 799 * notification slot at the top of the NTP. | |
| 800 */ | |
| 801 function showNotification(message, actionText, opt_f, opt_delay) { | |
|
arv (Not doing code reviews)
2010/11/24 17:28:49
/**
* Displays a message in the notification slot
| |
| 798 var notificationElement = $('notification'); | 802 var notificationElement = $('notification'); |
| 799 var f = opt_f || function() {}; | 803 var f = opt_f || function() {}; |
| 800 var delay = opt_delay || 10000; | 804 var delay = opt_delay || 10000; |
| 801 | 805 |
| 802 function show() { | 806 function show() { |
| 803 window.clearTimeout(notificationTimeout); | 807 window.clearTimeout(notificationTimeout); |
| 804 notificationElement.classList.add('show'); | 808 notificationElement.classList.add('show'); |
| 805 document.body.classList.add('notification-shown'); | 809 document.body.classList.add('notification-shown'); |
| 806 } | 810 } |
| 807 | 811 |
| 808 function delayedHide() { | 812 function delayedHide() { |
| 809 notificationTimeout = window.setTimeout(hideNotification, delay); | 813 notificationTimeout = window.setTimeout(hideNotification, delay); |
| 810 } | 814 } |
| 811 | 815 |
| 812 function doAction() { | 816 function doAction() { |
| 813 f(); | 817 f(); |
| 814 hideNotification(); | 818 hideNotification(); |
| 815 } | 819 } |
| 816 | 820 |
| 817 // Remove any possible first-run trails. | 821 // Remove classList entries from previous notifications. |
| 818 notification.classList.remove('first-run'); | 822 notification.classList.remove('first-run'); |
| 823 notification.classList.remove('promo'); | |
| 824 | |
| 825 var notificationNode = notificationElement.firstElementChild; | |
| 826 notificationNode.removeChild(notificationNode.firstChild); | |
| 819 | 827 |
| 820 var actionLink = notificationElement.querySelector('.link-color'); | 828 var actionLink = notificationElement.querySelector('.link-color'); |
| 821 notificationElement.firstElementChild.textContent = text; | 829 |
| 830 if ((typeof message) == "string") | |
|
arv (Not doing code reviews)
2010/11/24 17:28:49
Single quotes and too many parens
if (typeof mess
| |
| 831 notificationElement.firstElementChild.textContent = message; | |
| 832 else | |
| 833 notificationElement.firstElementChild.appendChild(message); | |
| 834 | |
| 822 actionLink.textContent = actionText; | 835 actionLink.textContent = actionText; |
| 823 | 836 |
| 824 actionLink.onclick = doAction; | 837 actionLink.onclick = doAction; |
| 825 actionLink.onkeydown = handleIfEnterKey(doAction); | 838 actionLink.onkeydown = handleIfEnterKey(doAction); |
| 826 notificationElement.onmouseover = show; | 839 notificationElement.onmouseover = show; |
| 827 notificationElement.onmouseout = delayedHide; | 840 notificationElement.onmouseout = delayedHide; |
| 828 actionLink.onfocus = show; | 841 actionLink.onfocus = show; |
| 829 actionLink.onblur = delayedHide; | 842 actionLink.onblur = delayedHide; |
| 830 // Enable tabbing to the link now that it is shown. | 843 // Enable tabbing to the link now that it is shown. |
| 831 actionLink.tabIndex = 0; | 844 actionLink.tabIndex = 0; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 852 } | 865 } |
| 853 | 866 |
| 854 function showFirstRunNotification() { | 867 function showFirstRunNotification() { |
| 855 showNotification(localStrings.getString('firstrunnotification'), | 868 showNotification(localStrings.getString('firstrunnotification'), |
| 856 localStrings.getString('closefirstrunnotification'), | 869 localStrings.getString('closefirstrunnotification'), |
| 857 null, 30000); | 870 null, 30000); |
| 858 var notificationElement = $('notification'); | 871 var notificationElement = $('notification'); |
| 859 notification.classList.add('first-run'); | 872 notification.classList.add('first-run'); |
| 860 } | 873 } |
| 861 | 874 |
| 875 function showPromoNotification() { | |
| 876 showNotification(parseHtmlSubset(localStrings.getString('serverpromo')), | |
| 877 localStrings.getString('closefirstrunnotification'), | |
| 878 function () { chrome.send('closePromo'); }, | |
| 879 60000); | |
| 880 var notificationElement = $('notification'); | |
| 881 notification.classList.add('promo'); | |
| 882 } | |
| 883 | |
| 862 $('main').addEventListener('click', function(e) { | 884 $('main').addEventListener('click', function(e) { |
| 863 var p = e.target; | 885 var p = e.target; |
| 864 while (p && p.tagName != 'H2') { | 886 while (p && p.tagName != 'H2') { |
| 865 // In case the user clicks on a button we do not want to expand/collapse a | 887 // In case the user clicks on a button we do not want to expand/collapse a |
| 866 // section. | 888 // section. |
| 867 if (p.tagName == 'BUTTON') | 889 if (p.tagName == 'BUTTON') |
| 868 return; | 890 return; |
| 869 p = p.parentNode; | 891 p = p.parentNode; |
| 870 } | 892 } |
| 871 | 893 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1183 // Remove class name in a timeout so that changes done in this JS thread are | 1205 // Remove class name in a timeout so that changes done in this JS thread are |
| 1184 // not animated. | 1206 // not animated. |
| 1185 window.setTimeout(function() { | 1207 window.setTimeout(function() { |
| 1186 mostVisited.ensureSmallGridCorrect(); | 1208 mostVisited.ensureSmallGridCorrect(); |
| 1187 maybeDoneLoading(); | 1209 maybeDoneLoading(); |
| 1188 }, 1); | 1210 }, 1); |
| 1189 | 1211 |
| 1190 // Only show the first run notification if first run. | 1212 // Only show the first run notification if first run. |
| 1191 if (firstRun) { | 1213 if (firstRun) { |
| 1192 showFirstRunNotification(); | 1214 showFirstRunNotification(); |
| 1215 } else if (localStrings.getString('serverpromo')) { | |
| 1216 showPromoNotification(); | |
| 1193 } | 1217 } |
| 1194 } | 1218 } |
| 1195 | 1219 |
| 1196 function maybeDoneLoading() { | 1220 function maybeDoneLoading() { |
| 1197 if (mostVisited.data && apps.loaded) | 1221 if (mostVisited.data && apps.loaded) |
| 1198 document.body.classList.remove('loading'); | 1222 document.body.classList.remove('loading'); |
| 1199 } | 1223 } |
| 1200 | 1224 |
| 1201 function isDoneLoading() { | 1225 function isDoneLoading() { |
| 1202 return !document.body.classList.contains('loading'); | 1226 return !document.body.classList.contains('loading'); |
| 1203 } | 1227 } |
| 1204 | 1228 |
| 1205 // Initialize the apps promo. | 1229 // Initialize the apps promo. |
| 1206 document.addEventListener('DOMContentLoaded', function() { | 1230 document.addEventListener('DOMContentLoaded', function() { |
| 1207 var promoText1 = $('apps-promo-text1'); | 1231 var promoText1 = $('apps-promo-text1'); |
| 1208 promoText1.innerHTML = promoText1.textContent; | 1232 promoText1.innerHTML = promoText1.textContent; |
| 1209 | 1233 |
| 1210 var promoLink = promoText1.querySelector('a'); | 1234 var promoLink = promoText1.querySelector('a'); |
| 1211 promoLink.id = 'apps-promo-link'; | 1235 promoLink.id = 'apps-promo-link'; |
| 1212 promoLink.href = localStrings.getString('web_store_url'); | 1236 promoLink.href = localStrings.getString('web_store_url'); |
| 1213 | 1237 |
| 1214 $('apps-promo-hide').addEventListener('click', function() { | 1238 $('apps-promo-hide').addEventListener('click', function() { |
| 1215 chrome.send('hideAppsPromo', []); | 1239 chrome.send('hideAppsPromo', []); |
| 1216 document.documentElement.classList.remove('apps-promo-visible'); | 1240 document.documentElement.classList.remove('apps-promo-visible'); |
| 1217 layoutSections(); | 1241 layoutSections(); |
| 1218 }); | 1242 }); |
| 1219 }); | 1243 }); |
| OLD | NEW |