| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 var oldShownSections = shownSections; | 181 var oldShownSections = shownSections; |
| 182 shownSections = mask; | 182 shownSections = mask; |
| 183 | 183 |
| 184 // Only invalidate most visited if needed. | 184 // Only invalidate most visited if needed. |
| 185 if ((mask & Section.THUMB) != (oldShownSections & Section.THUMB) || | 185 if ((mask & Section.THUMB) != (oldShownSections & Section.THUMB) || |
| 186 (mask & Section.LIST) != (oldShownSections & Section.LIST)) { | 186 (mask & Section.LIST) != (oldShownSections & Section.LIST)) { |
| 187 mostVisited.invalidate(); | 187 mostVisited.invalidate(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 mostVisited.updateDisplayMode(); | 190 mostVisited.updateDisplayMode(); |
| 191 layoutRecentlyClosed(); | 191 renderRecentlyClosed(); |
| 192 updateOptionMenu(); | 192 updateOptionMenu(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 gotShownSections = true; | 195 gotShownSections = true; |
| 196 onDataLoaded(); | 196 onDataLoaded(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 function saveShownSections() { | 199 function saveShownSections() { |
| 200 chrome.send('setShownSections', [String(shownSections)]); | 200 chrome.send('setShownSections', [String(shownSections)]); |
| 201 } | 201 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 // We're probably a background tab, so don't do anything. | 291 // We're probably a background tab, so don't do anything. |
| 292 return; | 292 return; |
| 293 } | 293 } |
| 294 | 294 |
| 295 var oldLayoutMode = layoutMode; | 295 var oldLayoutMode = layoutMode; |
| 296 layoutMode = useSmallGrid() ? LayoutMode.SMALL : LayoutMode.NORMAL | 296 layoutMode = useSmallGrid() ? LayoutMode.SMALL : LayoutMode.NORMAL |
| 297 | 297 |
| 298 if (layoutMode != oldLayoutMode){ | 298 if (layoutMode != oldLayoutMode){ |
| 299 mostVisited.invalidate(); | 299 mostVisited.invalidate(); |
| 300 mostVisited.layout(); | 300 mostVisited.layout(); |
| 301 layoutRecentlyClosed(); | 301 renderRecentlyClosed(); |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 | 304 |
| 305 /** | 305 /** |
| 306 * Bitmask for the different UI sections. | 306 * Bitmask for the different UI sections. |
| 307 * This matches the Section enum in ../dom_ui/shown_sections_handler.h | 307 * This matches the Section enum in ../dom_ui/shown_sections_handler.h |
| 308 * @enum {number} | 308 * @enum {number} |
| 309 */ | 309 */ |
| 310 var Section = { | 310 var Section = { |
| 311 THUMB: 1, | 311 THUMB: 1, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 322 // THUMBS and LIST are mutually exclusive. | 322 // THUMBS and LIST are mutually exclusive. |
| 323 if (section == Section.THUMB) { | 323 if (section == Section.THUMB) { |
| 324 // hide LIST | 324 // hide LIST |
| 325 shownSections &= ~Section.LIST; | 325 shownSections &= ~Section.LIST; |
| 326 mostVisited.invalidate(); | 326 mostVisited.invalidate(); |
| 327 } else if (section == Section.LIST) { | 327 } else if (section == Section.LIST) { |
| 328 // hide THUMB | 328 // hide THUMB |
| 329 shownSections &= ~Section.THUMB; | 329 shownSections &= ~Section.THUMB; |
| 330 mostVisited.invalidate(); | 330 mostVisited.invalidate(); |
| 331 } else { | 331 } else { |
| 332 layoutRecentlyClosed(); | 332 renderRecentlyClosed(); |
| 333 } | 333 } |
| 334 | 334 |
| 335 updateOptionMenu(); | 335 updateOptionMenu(); |
| 336 mostVisited.updateDisplayMode(); | 336 mostVisited.updateDisplayMode(); |
| 337 mostVisited.layout(); | 337 mostVisited.layout(); |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 | 340 |
| 341 function hideSection(section) { | 341 function hideSection(section) { |
| 342 if (section & shownSections) { | 342 if (section & shownSections) { |
| 343 shownSections &= ~section; | 343 shownSections &= ~section; |
| 344 | 344 |
| 345 if (section & Section.THUMB || section & Section.LIST) { | 345 if (section & Section.THUMB || section & Section.LIST) { |
| 346 mostVisited.invalidate(); | 346 mostVisited.invalidate(); |
| 347 } | 347 } |
| 348 | 348 |
| 349 if (section & Section.RECENT) { | 349 if (section & Section.RECENT) { |
| 350 layoutRecentlyClosed(); | 350 renderRecentlyClosed(); |
| 351 } | 351 } |
| 352 | 352 |
| 353 updateOptionMenu(); | 353 updateOptionMenu(); |
| 354 mostVisited.updateDisplayMode(); | 354 mostVisited.updateDisplayMode(); |
| 355 mostVisited.layout(); | 355 mostVisited.layout(); |
| 356 } | 356 } |
| 357 } | 357 } |
| 358 | 358 |
| 359 var mostVisited = { | 359 var mostVisited = { |
| 360 addPinnedUrl_: function(data, index) { | 360 addPinnedUrl_: function(data, index) { |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 function layoutRecentlyClosed() { | 670 function layoutRecentlyClosed() { |
| 671 var recentElement = $('recently-closed'); | 671 var recentElement = $('recently-closed'); |
| 672 var recentShown = shownSections & Section.RECENT; | 672 var recentShown = shownSections & Section.RECENT; |
| 673 var style = recentElement.style; | 673 var style = recentElement.style; |
| 674 | 674 |
| 675 if (!recentShown) { | 675 if (!recentShown) { |
| 676 style.opacity = style.height = 0; | 676 style.opacity = style.height = 0; |
| 677 } else { | 677 } else { |
| 678 style.opacity = style.height = ''; | 678 style.opacity = style.height = ''; |
| 679 | 679 |
| 680 // Show all items. | |
| 681 for (var i = 0, child; child = recentElement.children[i]; i++) { | |
| 682 child.style.display = ''; | |
| 683 } | |
| 684 | |
| 685 // We cannot use clientWidth here since the width has a transition. | 680 // We cannot use clientWidth here since the width has a transition. |
| 686 var spacing = 20; | 681 var spacing = 20; |
| 687 var headerEl = recentElement.firstElementChild; | 682 var headerEl = recentElement.firstElementChild; |
| 688 var navEl = recentElement.lastElementChild; | 683 var navEl = recentElement.lastElementChild; |
| 689 var navWidth = navEl.offsetWidth; | 684 var navWidth = navEl.offsetWidth; |
| 690 // Subtract 10 for the padding | 685 // Subtract 10 for the padding |
| 691 var availWidth = (useSmallGrid() ? 690 : 918) - navWidth - 10; | 686 var availWidth = (useSmallGrid() ? 690 : 918) - navWidth - 10; |
| 692 | 687 |
| 693 // Now go backwards and hide as many elements as needed. | 688 // Now go backwards and hide as many elements as needed. |
| 694 var elementsToHide = []; | 689 var elementsToHide = []; |
| 695 for (var el = navEl.previousElementSibling; el != headerEl; | 690 for (var el = navEl.previousElementSibling; el != headerEl; |
| 696 el = el.previousElementSibling) { | 691 el = el.previousElementSibling) { |
| 697 if (el.offsetLeft + el.offsetWidth + spacing > availWidth) { | 692 if (el.offsetLeft + el.offsetWidth + spacing > availWidth) { |
| 698 elementsToHide.push(el); | 693 elementsToHide.push(el); |
| 699 } | 694 } |
| 700 } | 695 } |
| 701 | 696 |
| 702 elementsToHide.forEach(function(el) { | 697 elementsToHide.forEach(function(el) { |
| 703 el.style.display = 'none'; | 698 el.parentNode.removeChild(el); |
| 704 }); | 699 }); |
| 705 } | 700 } |
| 706 } | 701 } |
| 707 | 702 |
| 708 /** | 703 /** |
| 709 * This function is called by the backend whenever the sync status section | 704 * This function is called by the backend whenever the sync status section |
| 710 * needs to be updated to reflect recent sync state changes. The backend passes | 705 * needs to be updated to reflect recent sync state changes. The backend passes |
| 711 * the new status information in the newMessage parameter. The state includes | 706 * the new status information in the newMessage parameter. The state includes |
| 712 * the following: | 707 * the following: |
| 713 * | 708 * |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 var actionLink = notificationElement.querySelector('.link'); | 907 var actionLink = notificationElement.querySelector('.link'); |
| 913 notificationElement.firstElementChild.textContent = text; | 908 notificationElement.firstElementChild.textContent = text; |
| 914 actionLink.textContent = actionText; | 909 actionLink.textContent = actionText; |
| 915 | 910 |
| 916 actionLink.onclick = doAction; | 911 actionLink.onclick = doAction; |
| 917 actionLink.onkeydown = handleIfEnterKey(doAction); | 912 actionLink.onkeydown = handleIfEnterKey(doAction); |
| 918 notificationElement.onmouseover = show; | 913 notificationElement.onmouseover = show; |
| 919 notificationElement.onmouseout = delayedHide; | 914 notificationElement.onmouseout = delayedHide; |
| 920 actionLink.onfocus = show; | 915 actionLink.onfocus = show; |
| 921 actionLink.onblur = delayedHide; | 916 actionLink.onblur = delayedHide; |
| 917 // Enable tabbing to the link now that it is shown. |
| 918 actionLink.tabIndex = 0; |
| 922 | 919 |
| 923 show(); | 920 show(); |
| 924 delayedHide(); | 921 delayedHide(); |
| 925 } | 922 } |
| 926 | 923 |
| 927 function hideNotification() { | 924 function hideNotification() { |
| 928 var notificationElement = $('notification'); | 925 var notificationElement = $('notification'); |
| 929 removeClass(notificationElement, 'show'); | 926 removeClass(notificationElement, 'show'); |
| 927 var actionLink = notificationElement.querySelector('.link'); |
| 928 // Prevent tabbing to the hidden link. |
| 929 actionLink.tabIndex = -1; |
| 930 } | 930 } |
| 931 | 931 |
| 932 function showFirstRunNotification() { | 932 function showFirstRunNotification() { |
| 933 showNotification(localStrings.getString('firstrunnotification'), | 933 showNotification(localStrings.getString('firstrunnotification'), |
| 934 localStrings.getString('closefirstrunnotification'), | 934 localStrings.getString('closefirstrunnotification'), |
| 935 null, 30000); | 935 null, 30000); |
| 936 var notificationElement = $('notification'); | 936 var notificationElement = $('notification'); |
| 937 addClass(notification, 'first-run'); | 937 addClass(notification, 'first-run'); |
| 938 } | 938 } |
| 939 | 939 |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1680 function fixLinkUnderline(el) { | 1680 function fixLinkUnderline(el) { |
| 1681 var span = document.createElement('span'); | 1681 var span = document.createElement('span'); |
| 1682 span.className = 'link-color'; | 1682 span.className = 'link-color'; |
| 1683 while (el.hasChildNodes()) { | 1683 while (el.hasChildNodes()) { |
| 1684 span.appendChild(el.firstChild); | 1684 span.appendChild(el.firstChild); |
| 1685 } | 1685 } |
| 1686 el.appendChild(span); | 1686 el.appendChild(span); |
| 1687 } | 1687 } |
| 1688 | 1688 |
| 1689 updateAttribution(); | 1689 updateAttribution(); |
| OLD | NEW |