| 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 * @param {string|Node} message String or node to use as message. |
| 801 * @param {string} actionText The text to show as a link next to the message. |
| 802 * @param {function=} opt_f Function to call when the user clicks the action |
| 803 * link. |
| 804 * @param {number=} opt_delay The time in milliseconds before hiding the |
| 805 * i notification. |
| 806 */ |
| 807 function showNotification(message, actionText, opt_f, opt_delay) { |
| 798 var notificationElement = $('notification'); | 808 var notificationElement = $('notification'); |
| 799 var f = opt_f || function() {}; | 809 var f = opt_f || function() {}; |
| 800 var delay = opt_delay || 10000; | 810 var delay = opt_delay || 10000; |
| 801 | 811 |
| 802 function show() { | 812 function show() { |
| 803 window.clearTimeout(notificationTimeout); | 813 window.clearTimeout(notificationTimeout); |
| 804 notificationElement.classList.add('show'); | 814 notificationElement.classList.add('show'); |
| 805 document.body.classList.add('notification-shown'); | 815 document.body.classList.add('notification-shown'); |
| 806 } | 816 } |
| 807 | 817 |
| 808 function delayedHide() { | 818 function delayedHide() { |
| 809 notificationTimeout = window.setTimeout(hideNotification, delay); | 819 notificationTimeout = window.setTimeout(hideNotification, delay); |
| 810 } | 820 } |
| 811 | 821 |
| 812 function doAction() { | 822 function doAction() { |
| 813 f(); | 823 f(); |
| 814 hideNotification(); | 824 hideNotification(); |
| 815 } | 825 } |
| 816 | 826 |
| 817 // Remove any possible first-run trails. | 827 // Remove classList entries from previous notifications. |
| 818 notification.classList.remove('first-run'); | 828 notification.classList.remove('first-run'); |
| 829 notification.classList.remove('promo'); |
| 830 |
| 831 var notificationNode = notificationElement.firstElementChild; |
| 832 notificationNode.removeChild(notificationNode.firstChild); |
| 819 | 833 |
| 820 var actionLink = notificationElement.querySelector('.link-color'); | 834 var actionLink = notificationElement.querySelector('.link-color'); |
| 821 notificationElement.firstElementChild.textContent = text; | 835 |
| 836 if (typeof message == 'string') |
| 837 notificationElement.firstElementChild.textContent = message; |
| 838 else |
| 839 notificationElement.firstElementChild.appendChild(message); |
| 840 |
| 822 actionLink.textContent = actionText; | 841 actionLink.textContent = actionText; |
| 823 | 842 |
| 824 actionLink.onclick = doAction; | 843 actionLink.onclick = doAction; |
| 825 actionLink.onkeydown = handleIfEnterKey(doAction); | 844 actionLink.onkeydown = handleIfEnterKey(doAction); |
| 826 notificationElement.onmouseover = show; | 845 notificationElement.onmouseover = show; |
| 827 notificationElement.onmouseout = delayedHide; | 846 notificationElement.onmouseout = delayedHide; |
| 828 actionLink.onfocus = show; | 847 actionLink.onfocus = show; |
| 829 actionLink.onblur = delayedHide; | 848 actionLink.onblur = delayedHide; |
| 830 // Enable tabbing to the link now that it is shown. | 849 // Enable tabbing to the link now that it is shown. |
| 831 actionLink.tabIndex = 0; | 850 actionLink.tabIndex = 0; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 852 } | 871 } |
| 853 | 872 |
| 854 function showFirstRunNotification() { | 873 function showFirstRunNotification() { |
| 855 showNotification(localStrings.getString('firstrunnotification'), | 874 showNotification(localStrings.getString('firstrunnotification'), |
| 856 localStrings.getString('closefirstrunnotification'), | 875 localStrings.getString('closefirstrunnotification'), |
| 857 null, 30000); | 876 null, 30000); |
| 858 var notificationElement = $('notification'); | 877 var notificationElement = $('notification'); |
| 859 notification.classList.add('first-run'); | 878 notification.classList.add('first-run'); |
| 860 } | 879 } |
| 861 | 880 |
| 881 function showPromoNotification() { |
| 882 showNotification(parseHtmlSubset(localStrings.getString('serverpromo')), |
| 883 localStrings.getString('closefirstrunnotification'), |
| 884 function () { chrome.send('closePromo'); }, |
| 885 60000); |
| 886 var notificationElement = $('notification'); |
| 887 notification.classList.add('promo'); |
| 888 } |
| 889 |
| 862 $('main').addEventListener('click', function(e) { | 890 $('main').addEventListener('click', function(e) { |
| 863 var p = e.target; | 891 var p = e.target; |
| 864 while (p && p.tagName != 'H2') { | 892 while (p && p.tagName != 'H2') { |
| 865 // In case the user clicks on a button we do not want to expand/collapse a | 893 // In case the user clicks on a button we do not want to expand/collapse a |
| 866 // section. | 894 // section. |
| 867 if (p.tagName == 'BUTTON') | 895 if (p.tagName == 'BUTTON') |
| 868 return; | 896 return; |
| 869 p = p.parentNode; | 897 p = p.parentNode; |
| 870 } | 898 } |
| 871 | 899 |
| (...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 | 1211 // Remove class name in a timeout so that changes done in this JS thread are |
| 1184 // not animated. | 1212 // not animated. |
| 1185 window.setTimeout(function() { | 1213 window.setTimeout(function() { |
| 1186 mostVisited.ensureSmallGridCorrect(); | 1214 mostVisited.ensureSmallGridCorrect(); |
| 1187 maybeDoneLoading(); | 1215 maybeDoneLoading(); |
| 1188 }, 1); | 1216 }, 1); |
| 1189 | 1217 |
| 1190 // Only show the first run notification if first run. | 1218 // Only show the first run notification if first run. |
| 1191 if (firstRun) { | 1219 if (firstRun) { |
| 1192 showFirstRunNotification(); | 1220 showFirstRunNotification(); |
| 1221 } else if (localStrings.getString('serverpromo')) { |
| 1222 showPromoNotification(); |
| 1193 } | 1223 } |
| 1194 } | 1224 } |
| 1195 | 1225 |
| 1196 function maybeDoneLoading() { | 1226 function maybeDoneLoading() { |
| 1197 if (mostVisited.data && apps.loaded) | 1227 if (mostVisited.data && apps.loaded) |
| 1198 document.body.classList.remove('loading'); | 1228 document.body.classList.remove('loading'); |
| 1199 } | 1229 } |
| 1200 | 1230 |
| 1201 function isDoneLoading() { | 1231 function isDoneLoading() { |
| 1202 return !document.body.classList.contains('loading'); | 1232 return !document.body.classList.contains('loading'); |
| 1203 } | 1233 } |
| 1204 | 1234 |
| 1205 // Initialize the apps promo. | 1235 // Initialize the apps promo. |
| 1206 document.addEventListener('DOMContentLoaded', function() { | 1236 document.addEventListener('DOMContentLoaded', function() { |
| 1207 var promoText1 = $('apps-promo-text1'); | 1237 var promoText1 = $('apps-promo-text1'); |
| 1208 promoText1.innerHTML = promoText1.textContent; | 1238 promoText1.innerHTML = promoText1.textContent; |
| 1209 | 1239 |
| 1210 var promoLink = promoText1.querySelector('a'); | 1240 var promoLink = promoText1.querySelector('a'); |
| 1211 promoLink.id = 'apps-promo-link'; | 1241 promoLink.id = 'apps-promo-link'; |
| 1212 promoLink.href = localStrings.getString('web_store_url'); | 1242 promoLink.href = localStrings.getString('web_store_url'); |
| 1213 | 1243 |
| 1214 $('apps-promo-hide').addEventListener('click', function() { | 1244 $('apps-promo-hide').addEventListener('click', function() { |
| 1215 chrome.send('hideAppsPromo', []); | 1245 chrome.send('hideAppsPromo', []); |
| 1216 document.documentElement.classList.remove('apps-promo-visible'); | 1246 document.documentElement.classList.remove('apps-promo-visible'); |
| 1217 layoutSections(); | 1247 layoutSections(); |
| 1218 }); | 1248 }); |
| 1219 }); | 1249 }); |
| OLD | NEW |