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 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 } | 800 } |
801 el.textContent = newMessage.linktext; | 801 el.textContent = newMessage.linktext; |
802 content.appendChild(el); | 802 content.appendChild(el); |
803 fixLinkUnderline(el); | 803 fixLinkUnderline(el); |
804 } | 804 } |
805 | 805 |
806 layoutSections(); | 806 layoutSections(); |
807 } | 807 } |
808 | 808 |
809 /** | 809 /** |
810 * Invoked when the link in the sync status section is clicked. | 810 * Invoked when the link in the sync promo or sync status section is clicked. |
811 */ | 811 */ |
812 function syncSectionLinkClicked(e) { | 812 function syncSectionLinkClicked(e) { |
813 chrome.send('SyncLinkClicked'); | 813 chrome.send('SyncLinkClicked'); |
814 e.preventDefault(); | 814 e.preventDefault(); |
815 } | 815 } |
816 | 816 |
817 /** | 817 /** |
818 * Invoked when link to start sync in the promo message is clicked, and Chrome | 818 * Invoked when link to start sync in the promo message is clicked, and Chrome |
819 * has already been synced to an account. | 819 * has already been synced to an account. |
820 */ | 820 */ |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 var notificationTimeout; | 928 var notificationTimeout; |
929 | 929 |
930 /* | 930 /* |
931 * Displays a message (either a string or a document fragment) in the | 931 * Displays a message (either a string or a document fragment) in the |
932 * notification slot at the top of the NTP. | 932 * notification slot at the top of the NTP. |
933 * @param {string|Node} message String or node to use as message. | 933 * @param {string|Node} message String or node to use as message. |
934 * @param {string} actionText The text to show as a link next to the message. | 934 * @param {string} actionText The text to show as a link next to the message. |
935 * @param {function=} opt_f Function to call when the user clicks the action | 935 * @param {function=} opt_f Function to call when the user clicks the action |
936 * link. | 936 * link. |
937 * @param {number=} opt_delay The time in milliseconds before hiding the | 937 * @param {number=} opt_delay The time in milliseconds before hiding the |
938 * i notification. | 938 * notification. |
| 939 * @param {boolean=} close If true, show a close link next to the notification. |
939 */ | 940 */ |
940 function showNotification(message, actionText, opt_f, opt_delay) { | 941 function showNotification(message, actionText, opt_f, opt_delay, opt_close) { |
| 942 // TODO(arv): Create a notification component. |
941 var notificationElement = $('notification'); | 943 var notificationElement = $('notification'); |
942 var f = opt_f || function() {}; | 944 var f = opt_f || function() {}; |
943 var delay = opt_delay || 10000; | 945 var delay = opt_delay || 10000; |
944 | 946 |
945 function show() { | 947 function show() { |
946 window.clearTimeout(notificationTimeout); | 948 window.clearTimeout(notificationTimeout); |
947 notificationElement.classList.add('show'); | 949 notificationElement.classList.add('show'); |
948 document.body.classList.add('notification-shown'); | 950 document.body.classList.add('notification-shown'); |
949 } | 951 } |
950 | 952 |
951 function delayedHide() { | 953 function delayedHide() { |
952 notificationTimeout = window.setTimeout(hideNotification, delay); | 954 notificationTimeout = window.setTimeout(hideNotification, delay); |
953 } | 955 } |
954 | 956 |
955 function doAction() { | 957 function doAction() { |
956 f(); | 958 f(); |
957 hideNotification(); | 959 hideNotification(); |
958 } | 960 } |
959 | 961 |
| 962 function closeNotification() { |
| 963 chrome.send('closePromo'); |
| 964 hideNotification(); |
| 965 } |
| 966 |
960 // Remove classList entries from previous notifications. | 967 // Remove classList entries from previous notifications. |
961 notification.classList.remove('first-run'); | 968 notification.classList.remove('first-run'); |
962 notification.classList.remove('promo'); | 969 notification.classList.remove('promo'); |
963 | 970 |
964 var messageContainer = notificationElement.firstElementChild; | 971 var messageContainer = notificationElement.firstElementChild; |
965 var actionLink = notificationElement.querySelector('.link-color'); | 972 var actionLink = notificationElement.querySelector('#action-link'); |
| 973 |
| 974 if (opt_close) { |
| 975 var closeLink = notificationElement.querySelector('#close-link'); |
| 976 closeLink.textContent = |
| 977 localStrings.getString('closefirstrunnotification'); |
| 978 closeLink.onclick = closeNotification; |
| 979 closeLink.onkeydown = handleIfEnterKey(closeNotification); |
| 980 closeLink.tabIndex = 1; |
| 981 } |
966 | 982 |
967 if (typeof message == 'string') { | 983 if (typeof message == 'string') { |
968 messageContainer.textContent = message; | 984 messageContainer.textContent = message; |
969 } else { | 985 } else { |
970 messageContainer.textContent = ''; // Remove all children. | 986 messageContainer.textContent = ''; // Remove all children. |
971 messageContainer.appendChild(message); | 987 messageContainer.appendChild(message); |
972 } | 988 } |
973 | 989 |
974 actionLink.textContent = actionText; | 990 actionLink.textContent = actionText; |
975 | 991 |
(...skipping 10 matching lines...) Expand all Loading... |
986 delayedHide(); | 1002 delayedHide(); |
987 } | 1003 } |
988 | 1004 |
989 /** | 1005 /** |
990 * Hides the notifier. | 1006 * Hides the notifier. |
991 */ | 1007 */ |
992 function hideNotification() { | 1008 function hideNotification() { |
993 var notificationElement = $('notification'); | 1009 var notificationElement = $('notification'); |
994 notificationElement.classList.remove('show'); | 1010 notificationElement.classList.remove('show'); |
995 document.body.classList.remove('notification-shown'); | 1011 document.body.classList.remove('notification-shown'); |
996 var actionLink = notificationElement.querySelector('.link-color'); | 1012 var actionLink = notificationElement.querySelector('#actionlink'); |
| 1013 var closeLink = notificationElement.querySelector('#closelink'); |
997 // Prevent tabbing to the hidden link. | 1014 // Prevent tabbing to the hidden link. |
998 actionLink.tabIndex = -1; | 1015 actionLink.tabIndex = -1; |
| 1016 closeLink.tabIndex = -1; |
999 // Setting tabIndex to -1 only prevents future tabbing to it. If, however, the | 1017 // Setting tabIndex to -1 only prevents future tabbing to it. If, however, the |
1000 // user switches window or a tab and then moves back to this tab the element | 1018 // user switches window or a tab and then moves back to this tab the element |
1001 // may gain focus. We therefore make sure that we blur the element so that the | 1019 // may gain focus. We therefore make sure that we blur the element so that the |
1002 // element focus is not restored when coming back to this window. | 1020 // element focus is not restored when coming back to this window. |
1003 actionLink.blur(); | 1021 actionLink.blur(); |
| 1022 closeLink.blur(); |
1004 } | 1023 } |
1005 | 1024 |
1006 function showFirstRunNotification() { | 1025 function showFirstRunNotification() { |
1007 showNotification(localStrings.getString('firstrunnotification'), | 1026 showNotification(localStrings.getString('firstrunnotification'), |
1008 localStrings.getString('closefirstrunnotification'), | 1027 localStrings.getString('closefirstrunnotification'), |
1009 null, 30000); | 1028 null, 30000); |
1010 var notificationElement = $('notification'); | 1029 var notificationElement = $('notification'); |
1011 notification.classList.add('first-run'); | 1030 notification.classList.add('first-run'); |
1012 } | 1031 } |
1013 | 1032 |
1014 function showPromoNotification() { | 1033 function showPromoNotification() { |
1015 showNotification(parseHtmlSubset(localStrings.getString('serverpromo')), | 1034 showNotification(parseHtmlSubset(localStrings.getString('serverpromo')), |
1016 localStrings.getString('closefirstrunnotification'), | 1035 localStrings.getString('syncpromotext'), |
1017 function () { chrome.send('closePromo'); }, | 1036 function () { chrome.send('SyncLinkClicked'); }, |
1018 60000); | 1037 60000, |
| 1038 true); |
1019 var notificationElement = $('notification'); | 1039 var notificationElement = $('notification'); |
1020 notification.classList.add('promo'); | 1040 notification.classList.add('promo'); |
1021 } | 1041 } |
1022 | 1042 |
1023 $('main').addEventListener('click', function(e) { | 1043 $('main').addEventListener('click', function(e) { |
1024 var p = e.target; | 1044 var p = e.target; |
1025 while (p && p.tagName != 'H2') { | 1045 while (p && p.tagName != 'H2') { |
1026 // In case the user clicks on a button we do not want to expand/collapse a | 1046 // In case the user clicks on a button we do not want to expand/collapse a |
1027 // section. | 1047 // section. |
1028 if (p.tagName == 'BUTTON') | 1048 if (p.tagName == 'BUTTON') |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1400 var promoLink = document.querySelector('#apps-promo-text1 a'); | 1420 var promoLink = document.querySelector('#apps-promo-text1 a'); |
1401 promoLink.id = 'apps-promo-link'; | 1421 promoLink.id = 'apps-promo-link'; |
1402 promoLink.href = localStrings.getString('web_store_url'); | 1422 promoLink.href = localStrings.getString('web_store_url'); |
1403 | 1423 |
1404 $('apps-promo-hide').addEventListener('click', function() { | 1424 $('apps-promo-hide').addEventListener('click', function() { |
1405 chrome.send('hideAppsPromo', []); | 1425 chrome.send('hideAppsPromo', []); |
1406 document.documentElement.classList.remove('apps-promo-visible'); | 1426 document.documentElement.classList.remove('apps-promo-visible'); |
1407 layoutSections(); | 1427 layoutSections(); |
1408 }); | 1428 }); |
1409 }); | 1429 }); |
OLD | NEW |