OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 } | 1020 } |
1021 | 1021 |
1022 function doAction() { | 1022 function doAction() { |
1023 f(); | 1023 f(); |
1024 closeNotification(); | 1024 closeNotification(); |
1025 } | 1025 } |
1026 | 1026 |
1027 function closeNotification() { | 1027 function closeNotification() { |
1028 if (notification.classList.contains('promo')) | 1028 if (notification.classList.contains('promo')) |
1029 chrome.send('closePromo'); | 1029 chrome.send('closePromo'); |
| 1030 if (notification.classList.contains('syncnotify')) { |
| 1031 chrome.send('closeSyncNotification'); |
| 1032 // Make sure we don't reshow the notification now that it's closed. |
| 1033 syncNotificationHidden = true; |
| 1034 } |
1030 hideNotification(); | 1035 hideNotification(); |
1031 } | 1036 } |
1032 | 1037 |
1033 // Remove classList entries from previous notifications. | 1038 // Remove classList entries from previous notifications. |
1034 notification.classList.remove('first-run'); | 1039 notification.classList.remove('first-run'); |
1035 notification.classList.remove('promo'); | 1040 notification.classList.remove('promo'); |
| 1041 notification.classList.remove('syncnotify'); |
1036 | 1042 |
1037 var messageContainer = notificationElement.firstElementChild; | 1043 var messageContainer = notificationElement.firstElementChild; |
1038 var actionLink = notificationElement.querySelector('#action-link'); | 1044 var actionLink = notificationElement.querySelector('#action-link'); |
1039 var closeButton = notificationElement.querySelector('#notification-close'); | 1045 var closeButton = notificationElement.querySelector('#notification-close'); |
1040 | 1046 |
1041 // Remove any previous actionLink entry. | 1047 // Remove any previous actionLink entry. |
1042 actionLink.textContent = ''; | 1048 actionLink.textContent = ''; |
1043 | 1049 |
1044 $('notification-close').onclick = closeNotification; | 1050 $('notification-close').onclick = closeNotification; |
1045 | 1051 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 | 1102 |
1097 function showPromoNotification() { | 1103 function showPromoNotification() { |
1098 showNotification(parseHtmlSubset(localStrings.getString('serverpromo')), | 1104 showNotification(parseHtmlSubset(localStrings.getString('serverpromo')), |
1099 localStrings.getString('syncpromotext'), | 1105 localStrings.getString('syncpromotext'), |
1100 function () { chrome.send('SyncLinkClicked'); }, | 1106 function () { chrome.send('SyncLinkClicked'); }, |
1101 60000); | 1107 60000); |
1102 var notificationElement = $('notification'); | 1108 var notificationElement = $('notification'); |
1103 notification.classList.add('promo'); | 1109 notification.classList.add('promo'); |
1104 } | 1110 } |
1105 | 1111 |
| 1112 // Set to true by closeNotification() if the sync notification has been hidden |
| 1113 // by the user. |
| 1114 var syncNotificationHidden; |
| 1115 |
| 1116 function showSyncNotification() { |
| 1117 // Don't show the notification if it's already been hidden by the user. |
| 1118 if (syncNotificationHidden) |
| 1119 return; |
| 1120 showNotification(parseHtmlSubset(localStrings.getString( |
| 1121 'syncnotification')), |
| 1122 localStrings.getString('synclinktext'), |
| 1123 function () { chrome.send('SyncTypeLinkClicked'); }, |
| 1124 60000); |
| 1125 var notificationElement = $('notification'); |
| 1126 notification.classList.add('syncnotify'); |
| 1127 } |
| 1128 |
1106 $('main').addEventListener('click', function(e) { | 1129 $('main').addEventListener('click', function(e) { |
1107 var p = e.target; | 1130 var p = e.target; |
1108 while (p && p.tagName != 'H2') { | 1131 while (p && p.tagName != 'H2') { |
1109 // In case the user clicks on a button we do not want to expand/collapse a | 1132 // In case the user clicks on a button we do not want to expand/collapse a |
1110 // section. | 1133 // section. |
1111 if (p.tagName == 'BUTTON') | 1134 if (p.tagName == 'BUTTON') |
1112 return; | 1135 return; |
1113 p = p.parentNode; | 1136 p = p.parentNode; |
1114 } | 1137 } |
1115 | 1138 |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 // Remove class name in a timeout so that changes done in this JS thread are | 1479 // Remove class name in a timeout so that changes done in this JS thread are |
1457 // not animated. | 1480 // not animated. |
1458 window.setTimeout(function() { | 1481 window.setTimeout(function() { |
1459 mostVisited.ensureSmallGridCorrect(); | 1482 mostVisited.ensureSmallGridCorrect(); |
1460 maybeDoneLoading(); | 1483 maybeDoneLoading(); |
1461 }, 1); | 1484 }, 1); |
1462 | 1485 |
1463 if (localStrings.getString('serverpromo')) { | 1486 if (localStrings.getString('serverpromo')) { |
1464 showPromoNotification(); | 1487 showPromoNotification(); |
1465 } | 1488 } |
| 1489 |
| 1490 if (localStrings.getString('syncnotification')) { |
| 1491 showSyncNotification(); |
| 1492 } |
1466 } | 1493 } |
1467 | 1494 |
1468 function maybeDoneLoading() { | 1495 function maybeDoneLoading() { |
1469 if (mostVisited.data && apps.loaded) | 1496 if (mostVisited.data && apps.loaded) |
1470 document.body.classList.remove('loading'); | 1497 document.body.classList.remove('loading'); |
1471 } | 1498 } |
1472 | 1499 |
1473 function isDoneLoading() { | 1500 function isDoneLoading() { |
1474 return !document.body.classList.contains('loading'); | 1501 return !document.body.classList.contains('loading'); |
1475 } | 1502 } |
1476 | 1503 |
1477 document.addEventListener('DOMContentLoaded', function() { | 1504 document.addEventListener('DOMContentLoaded', function() { |
1478 cr.enablePlatformSpecificCSSRules(); | 1505 cr.enablePlatformSpecificCSSRules(); |
1479 | 1506 |
1480 // Initialize the listener for the "hide this" link on the apps promo. We do | 1507 // Initialize the listener for the "hide this" link on the apps promo. We do |
1481 // this outside of getAppsCallback because it only needs to be done once per | 1508 // this outside of getAppsCallback because it only needs to be done once per |
1482 // NTP load. | 1509 // NTP load. |
1483 $('apps-promo-hide').addEventListener('click', function() { | 1510 $('apps-promo-hide').addEventListener('click', function() { |
1484 chrome.send('hideAppsPromo', []); | 1511 chrome.send('hideAppsPromo', []); |
1485 document.documentElement.classList.remove('apps-promo-visible'); | 1512 document.documentElement.classList.remove('apps-promo-visible'); |
1486 layoutSections(); | 1513 layoutSections(); |
1487 }); | 1514 }); |
1488 }); | 1515 }); |
OLD | NEW |