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 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 782 } | 782 } |
| 783 el.textContent = newMessage.linktext; | 783 el.textContent = newMessage.linktext; |
| 784 content.appendChild(el); | 784 content.appendChild(el); |
| 785 fixLinkUnderline(el); | 785 fixLinkUnderline(el); |
| 786 } | 786 } |
| 787 | 787 |
| 788 layoutSections(); | 788 layoutSections(); |
| 789 } | 789 } |
| 790 | 790 |
| 791 /** | 791 /** |
| 792 * Invoked when the link in the sync status section is clicked. | 792 * Invoked when the link in the sync promo or sync status section is clicked. |
| 793 */ | 793 */ |
| 794 function syncSectionLinkClicked(e) { | 794 function syncSectionLinkClicked(e) { |
| 795 chrome.send('SyncLinkClicked'); | 795 chrome.send('SyncLinkClicked'); |
| 796 e.preventDefault(); | 796 e.preventDefault(); |
| 797 } | 797 } |
| 798 | 798 |
| 799 /** | 799 /** |
| 800 * Invoked when link to start sync in the promo message is clicked, and Chrome | 800 * Invoked when link to start sync in the promo message is clicked, and Chrome |
| 801 * has already been synced to an account. | 801 * has already been synced to an account. |
| 802 */ | 802 */ |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 910 var notificationTimeout; | 910 var notificationTimeout; |
| 911 | 911 |
| 912 /* | 912 /* |
| 913 * Displays a message (either a string or a document fragment) in the | 913 * Displays a message (either a string or a document fragment) in the |
| 914 * notification slot at the top of the NTP. | 914 * notification slot at the top of the NTP. |
| 915 * @param {string|Node} message String or node to use as message. | 915 * @param {string|Node} message String or node to use as message. |
| 916 * @param {string} actionText The text to show as a link next to the message. | 916 * @param {string} actionText The text to show as a link next to the message. |
| 917 * @param {function=} opt_f Function to call when the user clicks the action | 917 * @param {function=} opt_f Function to call when the user clicks the action |
| 918 * link. | 918 * link. |
| 919 * @param {number=} opt_delay The time in milliseconds before hiding the | 919 * @param {number=} opt_delay The time in milliseconds before hiding the |
| 920 * i notification. | 920 * notification. |
| 921 * @param {bool=} close If true, show a close link next to the notification. | |
|
arv (Not doing code reviews)
2011/01/24 18:15:11
boolean
Miranda Callahan
2011/01/24 18:39:22
Done.
| |
| 921 */ | 922 */ |
| 922 function showNotification(message, actionText, opt_f, opt_delay) { | 923 function showNotification(message, actionText, opt_f, opt_delay, opt_close) { |
|
arv (Not doing code reviews)
2011/01/24 18:15:11
I think we should create a component for this soon
Miranda Callahan
2011/01/24 18:39:22
Done.
| |
| 923 var notificationElement = $('notification'); | 924 var notificationElement = $('notification'); |
| 924 var f = opt_f || function() {}; | 925 var f = opt_f || function() {}; |
| 925 var delay = opt_delay || 10000; | 926 var delay = opt_delay || 10000; |
| 926 | 927 |
| 927 function show() { | 928 function show() { |
| 928 window.clearTimeout(notificationTimeout); | 929 window.clearTimeout(notificationTimeout); |
| 929 notificationElement.classList.add('show'); | 930 notificationElement.classList.add('show'); |
| 930 document.body.classList.add('notification-shown'); | 931 document.body.classList.add('notification-shown'); |
| 931 } | 932 } |
| 932 | 933 |
| 933 function delayedHide() { | 934 function delayedHide() { |
| 934 notificationTimeout = window.setTimeout(hideNotification, delay); | 935 notificationTimeout = window.setTimeout(hideNotification, delay); |
| 935 } | 936 } |
| 936 | 937 |
| 937 function doAction() { | 938 function doAction() { |
| 938 f(); | 939 f(); |
| 939 hideNotification(); | 940 hideNotification(); |
| 940 } | 941 } |
| 941 | 942 |
| 943 function closeNotification() { | |
| 944 chrome.send('closePromo'); | |
| 945 hideNotification(); | |
| 946 } | |
| 947 | |
| 942 // Remove classList entries from previous notifications. | 948 // Remove classList entries from previous notifications. |
| 943 notification.classList.remove('first-run'); | 949 notification.classList.remove('first-run'); |
| 944 notification.classList.remove('promo'); | 950 notification.classList.remove('promo'); |
| 945 | 951 |
| 946 var messageContainer = notificationElement.firstElementChild; | 952 var messageContainer = notificationElement.firstElementChild; |
| 947 var actionLink = notificationElement.querySelector('.link-color'); | 953 var actionLink = notificationElement.querySelector('#actionlink'); |
| 954 | |
| 955 if (opt_close) { | |
| 956 var closeLink = notificationElement.querySelector('#closelink'); | |
| 957 closeLink.textContent = | |
| 958 localStrings.getString('closefirstrunnotification'); | |
| 959 closeLink.onclick = closeNotification; | |
| 960 closeLink.onkeydown = handleIfEnterKey(closeNotification); | |
| 961 closeLink.tabIndex = 1; | |
| 962 } | |
| 948 | 963 |
| 949 if (typeof message == 'string') { | 964 if (typeof message == 'string') { |
| 950 messageContainer.textContent = message; | 965 messageContainer.textContent = message; |
| 951 } else { | 966 } else { |
| 952 messageContainer.textContent = ''; // Remove all children. | 967 messageContainer.textContent = ''; // Remove all children. |
| 953 messageContainer.appendChild(message); | 968 messageContainer.appendChild(message); |
| 954 } | 969 } |
| 955 | 970 |
| 956 actionLink.textContent = actionText; | 971 actionLink.textContent = actionText; |
| 957 | 972 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 968 delayedHide(); | 983 delayedHide(); |
| 969 } | 984 } |
| 970 | 985 |
| 971 /** | 986 /** |
| 972 * Hides the notifier. | 987 * Hides the notifier. |
| 973 */ | 988 */ |
| 974 function hideNotification() { | 989 function hideNotification() { |
| 975 var notificationElement = $('notification'); | 990 var notificationElement = $('notification'); |
| 976 notificationElement.classList.remove('show'); | 991 notificationElement.classList.remove('show'); |
| 977 document.body.classList.remove('notification-shown'); | 992 document.body.classList.remove('notification-shown'); |
| 978 var actionLink = notificationElement.querySelector('.link-color'); | 993 var actionLink = notificationElement.querySelector('#actionlink'); |
| 994 var closeLink = notificationElement.querySelector('#closelink'); | |
| 979 // Prevent tabbing to the hidden link. | 995 // Prevent tabbing to the hidden link. |
| 980 actionLink.tabIndex = -1; | 996 actionLink.tabIndex = -1; |
| 997 closeLink.tabIndex = -1; | |
| 981 // Setting tabIndex to -1 only prevents future tabbing to it. If, however, the | 998 // Setting tabIndex to -1 only prevents future tabbing to it. If, however, the |
| 982 // user switches window or a tab and then moves back to this tab the element | 999 // user switches window or a tab and then moves back to this tab the element |
| 983 // may gain focus. We therefore make sure that we blur the element so that the | 1000 // may gain focus. We therefore make sure that we blur the element so that the |
| 984 // element focus is not restored when coming back to this window. | 1001 // element focus is not restored when coming back to this window. |
| 985 actionLink.blur(); | 1002 actionLink.blur(); |
| 1003 closeLink.blur(); | |
| 986 } | 1004 } |
| 987 | 1005 |
| 988 function showFirstRunNotification() { | 1006 function showFirstRunNotification() { |
| 989 showNotification(localStrings.getString('firstrunnotification'), | 1007 showNotification(localStrings.getString('firstrunnotification'), |
| 990 localStrings.getString('closefirstrunnotification'), | 1008 localStrings.getString('closefirstrunnotification'), |
| 991 null, 30000); | 1009 null, 30000); |
| 992 var notificationElement = $('notification'); | 1010 var notificationElement = $('notification'); |
| 993 notification.classList.add('first-run'); | 1011 notification.classList.add('first-run'); |
| 994 } | 1012 } |
| 995 | 1013 |
| 996 function showPromoNotification() { | 1014 function showPromoNotification() { |
| 997 showNotification(parseHtmlSubset(localStrings.getString('serverpromo')), | 1015 showNotification(parseHtmlSubset(localStrings.getString('serverpromo')), |
| 998 localStrings.getString('closefirstrunnotification'), | 1016 localStrings.getString('syncpromotext'), |
| 999 function () { chrome.send('closePromo'); }, | 1017 function () { chrome.send('SyncLinkClicked'); }, |
| 1000 60000); | 1018 60000, |
| 1019 true); | |
| 1001 var notificationElement = $('notification'); | 1020 var notificationElement = $('notification'); |
| 1002 notification.classList.add('promo'); | 1021 notification.classList.add('promo'); |
| 1003 } | 1022 } |
| 1004 | 1023 |
| 1005 $('main').addEventListener('click', function(e) { | 1024 $('main').addEventListener('click', function(e) { |
| 1006 var p = e.target; | 1025 var p = e.target; |
| 1007 while (p && p.tagName != 'H2') { | 1026 while (p && p.tagName != 'H2') { |
| 1008 // In case the user clicks on a button we do not want to expand/collapse a | 1027 // In case the user clicks on a button we do not want to expand/collapse a |
| 1009 // section. | 1028 // section. |
| 1010 if (p.tagName == 'BUTTON') | 1029 if (p.tagName == 'BUTTON') |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1382 var promoLink = document.querySelector('#apps-promo-text1 a'); | 1401 var promoLink = document.querySelector('#apps-promo-text1 a'); |
| 1383 promoLink.id = 'apps-promo-link'; | 1402 promoLink.id = 'apps-promo-link'; |
| 1384 promoLink.href = localStrings.getString('web_store_url'); | 1403 promoLink.href = localStrings.getString('web_store_url'); |
| 1385 | 1404 |
| 1386 $('apps-promo-hide').addEventListener('click', function() { | 1405 $('apps-promo-hide').addEventListener('click', function() { |
| 1387 chrome.send('hideAppsPromo', []); | 1406 chrome.send('hideAppsPromo', []); |
| 1388 document.documentElement.classList.remove('apps-promo-visible'); | 1407 document.documentElement.classList.remove('apps-promo-visible'); |
| 1389 layoutSections(); | 1408 layoutSections(); |
| 1390 }); | 1409 }); |
| 1391 }); | 1410 }); |
| OLD | NEW |