| OLD | NEW |
| 1 | 1 |
| 2 // Helpers | 2 // Helpers |
| 3 | 3 |
| 4 function $(id) { | 4 function $(id) { |
| 5 return document.getElementById(id); | 5 return document.getElementById(id); |
| 6 } | 6 } |
| 7 | 7 |
| 8 // TODO(arv): Remove these when classList is available in HTML5. | 8 // TODO(arv): Remove these when classList is available in HTML5. |
| 9 // https://bugs.webkit.org/show_bug.cgi?id=20709 | 9 // https://bugs.webkit.org/show_bug.cgi?id=20709 |
| 10 function hasClass(el, name) { | 10 function hasClass(el, name) { |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 * 'SyncLinkClicked'). | 723 * 'SyncLinkClicked'). |
| 724 * linkurl: the URL to use as the element's href (only used if linkurlisset is | 724 * linkurl: the URL to use as the element's href (only used if linkurlisset is |
| 725 * true). | 725 * true). |
| 726 */ | 726 */ |
| 727 function syncMessageChanged(newMessage) { | 727 function syncMessageChanged(newMessage) { |
| 728 var syncStatusElement = $('sync-status'); | 728 var syncStatusElement = $('sync-status'); |
| 729 var style = syncStatusElement.style; | 729 var style = syncStatusElement.style; |
| 730 | 730 |
| 731 // Hide the section if the message is emtpy. | 731 // Hide the section if the message is emtpy. |
| 732 if (!newMessage.syncsectionisvisible) { | 732 if (!newMessage.syncsectionisvisible) { |
| 733 style.opacity = style.height = 0; | |
| 734 return; | 733 return; |
| 735 } | 734 } |
| 736 style.height = ''; | 735 style.display = 'block'; |
| 737 style.opacity = 1; | |
| 738 | 736 |
| 739 // Set the sync section background color based on the state. | 737 // Set the sync section background color based on the state. |
| 740 if (newMessage.msgtype == "error") { | 738 if (newMessage.msgtype == 'error') { |
| 741 style.backgroundColor = "tomato"; | 739 style.backgroundColor = 'tomato'; |
| 742 } else if (newMessage.msgtype == "presynced") { | |
| 743 style.backgroundColor = "greenyellow"; | |
| 744 } else { | 740 } else { |
| 745 style.backgroundColor = "#CAFF70"; | 741 style.backgroundColor = ''; |
| 746 } | 742 } |
| 747 | 743 |
| 748 // Set the text for the header and sync message. | 744 // Set the text for the header and sync message. |
| 749 var titleElement = syncStatusElement.firstElementChild; | 745 var titleElement = syncStatusElement.firstElementChild; |
| 750 titleElement.textContent = newMessage.title; | 746 titleElement.textContent = newMessage.title; |
| 751 var messageElement = titleElement.nextElementSibling; | 747 var messageElement = titleElement.nextElementSibling; |
| 752 messageElement.textContent = newMessage.msg; | 748 messageElement.textContent = newMessage.msg; |
| 753 | 749 |
| 754 // Set up the link if we should show one or hide it otherwise. | 750 // Remove what comes after the message |
| 755 var linkContainer = messageElement.nextElementSibling; | 751 while (messageElement.nextSibling) { |
| 756 var containerStyle = linkContainer.style; | 752 syncStatusElement.removeChild(messageElement.nextSibling); |
| 757 var linkElement = linkContainer.firstElementChild; | 753 } |
| 758 linkElement.removeEventListener('click', syncSectionLinkClicked); | |
| 759 | 754 |
| 760 // TODO(idana): when we don't have an URL to set, using an href is not a good | |
| 761 // idea because the user will still be able to right click on the link and | |
| 762 // open the empty href in a new tab/window. | |
| 763 // | |
| 764 // See http://code.google.com/p/chromium/issues/detail?id=19538 for more info | |
| 765 // about how to fix this. | |
| 766 linkElement.href = ''; | |
| 767 containerStyle.display = 'none'; | |
| 768 if (newMessage.linkisvisible) { | 755 if (newMessage.linkisvisible) { |
| 769 containerStyle.display = ''; | 756 var el; |
| 770 linkElement.textContent = newMessage.linktext; | |
| 771 // We don't listen to click events if the backend specified a target URL | |
| 772 // for the link. | |
| 773 if (newMessage.linkurlisset) { | 757 if (newMessage.linkurlisset) { |
| 774 linkElement.href = newMessage.linkurl; | 758 // Use a link |
| 759 el = document.createElement('a'); |
| 760 el.href = newMessage.linkurl; |
| 775 } else { | 761 } else { |
| 776 linkElement.addEventListener('click', syncSectionLinkClicked); | 762 el = document.createElement('button'); |
| 763 el.className = 'link'; |
| 764 el.addEventListener('click', syncSectionLinkClicked); |
| 777 } | 765 } |
| 766 el.textContent = newMessage.linktext; |
| 767 syncStatusElement.appendChild(el); |
| 778 } | 768 } |
| 779 } | 769 } |
| 780 | 770 |
| 781 /** | 771 /** |
| 782 * Invoked when the link in the sync status section is clicked. | 772 * Invoked when the link in the sync status section is clicked. |
| 783 */ | 773 */ |
| 784 function syncSectionLinkClicked(e) { | 774 function syncSectionLinkClicked(e) { |
| 785 chrome.send('SyncLinkClicked'); | 775 chrome.send('SyncLinkClicked'); |
| 786 e.preventDefault(); | 776 e.preventDefault(); |
| 787 } | 777 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 $('themecss').href = 'chrome://theme/css/newtab.css?' + Date.now(); | 809 $('themecss').href = 'chrome://theme/css/newtab.css?' + Date.now(); |
| 820 updateAttribution(); | 810 updateAttribution(); |
| 821 } | 811 } |
| 822 | 812 |
| 823 function updateAttribution() { | 813 function updateAttribution() { |
| 824 $('attribution-img').src = 'chrome://theme/theme_ntp_attribution?' + | 814 $('attribution-img').src = 'chrome://theme/theme_ntp_attribution?' + |
| 825 Date.now(); | 815 Date.now(); |
| 826 } | 816 } |
| 827 | 817 |
| 828 function bookmarkBarAttached() { | 818 function bookmarkBarAttached() { |
| 829 document.documentElement.setAttribute("bookmarkbarattached", "true"); | 819 document.documentElement.setAttribute('bookmarkbarattached', 'true'); |
| 830 } | 820 } |
| 831 | 821 |
| 832 function bookmarkBarDetached() { | 822 function bookmarkBarDetached() { |
| 833 document.documentElement.setAttribute("bookmarkbarattached", "false"); | 823 document.documentElement.setAttribute('bookmarkbarattached', 'false'); |
| 834 } | 824 } |
| 835 | 825 |
| 836 function viewLog() { | 826 function viewLog() { |
| 837 var lines = []; | 827 var lines = []; |
| 838 var start = log[0][1]; | 828 var start = log[0][1]; |
| 839 | 829 |
| 840 for (var i = 0; i < log.length; i++) { | 830 for (var i = 0; i < log.length; i++) { |
| 841 lines.push((log[i][1] - start) + ': ' + log[i][0]); | 831 lines.push((log[i][1] - start) + ': ' + log[i][0]); |
| 842 } | 832 } |
| 843 | 833 |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1349 // This link allows user to make new tab page as homepage from the new tab | 1339 // This link allows user to make new tab page as homepage from the new tab |
| 1350 // page itself (without going to Options dialog box). | 1340 // page itself (without going to Options dialog box). |
| 1351 document.addEventListener('DOMContentLoaded', showSetAsHomepageLink); | 1341 document.addEventListener('DOMContentLoaded', showSetAsHomepageLink); |
| 1352 | 1342 |
| 1353 /** | 1343 /** |
| 1354 * The sync code is not yet built by default on all platforms so we have to | 1344 * The sync code is not yet built by default on all platforms so we have to |
| 1355 * make sure we don't send the initial sync message to the backend unless the | 1345 * make sure we don't send the initial sync message to the backend unless the |
| 1356 * backend told us that the sync code is present. | 1346 * backend told us that the sync code is present. |
| 1357 */ | 1347 */ |
| 1358 function callGetSyncMessageIfSyncIsPresent() { | 1348 function callGetSyncMessageIfSyncIsPresent() { |
| 1359 if (document.documentElement.getAttribute("syncispresent") == "true") { | 1349 if (document.documentElement.getAttribute('syncispresent') == 'true') { |
| 1360 chrome.send('GetSyncMessage'); | 1350 chrome.send('GetSyncMessage'); |
| 1361 } | 1351 } |
| 1362 } | 1352 } |
| 1363 | 1353 |
| 1364 function setAsHomePageLinkClicked() { | 1354 function setAsHomePageLinkClicked(e) { |
| 1365 chrome.send('SetHomepageLinkClicked'); | 1355 chrome.send('SetHomepageLinkClicked'); |
| 1356 e.preventDefault(); |
| 1366 } | 1357 } |
| 1367 | 1358 |
| 1368 function showSetAsHomepageLink() { | 1359 function showSetAsHomepageLink() { |
| 1369 var setAsHomepageElement = $('set-as-homepage'); | 1360 var setAsHomepageElement = $('set-as-homepage'); |
| 1370 var style = setAsHomepageElement.style; | 1361 var style = setAsHomepageElement.style; |
| 1371 if (document.documentElement.getAttribute("showsetashomepage") != "true") { | 1362 if (document.documentElement.getAttribute('showsetashomepage') != 'true') { |
| 1372 // Hide the section (if new tab page is already homepage). | 1363 // Hide the section (if new tab page is already homepage). |
| 1373 style.opacity = style.height = 0; | |
| 1374 return; | 1364 return; |
| 1375 } | 1365 } |
| 1376 | 1366 |
| 1377 style.height = ''; | 1367 style.display = 'block'; |
| 1378 style.opacity = 1; | 1368 var buttonElement = setAsHomepageElement.firstElementChild; |
| 1379 var spanElement = setAsHomepageElement.firstElementChild; | 1369 buttonElement.addEventListener('click', setAsHomePageLinkClicked); |
| 1380 var linkElement = spanElement.firstElementChild; | |
| 1381 if (!linkElement) { | |
| 1382 linkElement = document.createElement('a'); | |
| 1383 linkElement.href = ''; | |
| 1384 linkElement.textContent = localStrings.getString('makethishomepage'); | |
| 1385 linkElement.addEventListener('click', setAsHomePageLinkClicked); | |
| 1386 spanElement.appendChild(linkElement); | |
| 1387 } | |
| 1388 } | 1370 } |
| 1389 | 1371 |
| 1390 function hideAllMenus() { | 1372 function hideAllMenus() { |
| 1391 optionMenu.hide(); | 1373 optionMenu.hide(); |
| 1392 } | 1374 } |
| 1393 | 1375 |
| 1394 window.addEventListener('blur', hideAllMenus); | 1376 window.addEventListener('blur', hideAllMenus); |
| 1395 window.addEventListener('keydown', function(e) { | 1377 window.addEventListener('keydown', function(e) { |
| 1396 if (e.keyIdentifier == 'Alt' || e.keyIdentifier == 'Meta') { | 1378 if (e.keyIdentifier == 'Alt' || e.keyIdentifier == 'Meta') { |
| 1397 hideAllMenus(); | 1379 hideAllMenus(); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1668 case Node.DOCUMENT_FRAGMENT_NODE: | 1650 case Node.DOCUMENT_FRAGMENT_NODE: |
| 1669 case Node.TEXT_NODE: | 1651 case Node.TEXT_NODE: |
| 1670 break; | 1652 break; |
| 1671 | 1653 |
| 1672 default: | 1654 default: |
| 1673 throw Error('Node type ' + node.nodeType + ' is not supported'); | 1655 throw Error('Node type ' + node.nodeType + ' is not supported'); |
| 1674 } | 1656 } |
| 1675 }); | 1657 }); |
| 1676 return df; | 1658 return df; |
| 1677 } | 1659 } |
| 1660 |
| 1661 updateAttribution(); |
| OLD | NEW |