| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 args.unshift.apply(args, boundArgs); | 63 args.unshift.apply(args, boundArgs); |
| 64 return fn.apply(selfObj, args); | 64 return fn.apply(selfObj, args); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 var loading = true; | 68 var loading = true; |
| 69 var mostVisitedData = []; | 69 var mostVisitedData = []; |
| 70 var gotMostVisited = false; | 70 var gotMostVisited = false; |
| 71 var gotShownSections = false; | 71 var gotShownSections = false; |
| 72 | 72 |
| 73 function mostVisitedPages(data) { | 73 function mostVisitedPages(data, firstRun) { |
| 74 logEvent('received most visited pages'); | 74 logEvent('received most visited pages'); |
| 75 | 75 |
| 76 // We append the class name with the "filler" so that we can style fillers | 76 // We append the class name with the "filler" so that we can style fillers |
| 77 // differently. | 77 // differently. |
| 78 var maxItems = 8; | 78 var maxItems = 8; |
| 79 data.length = Math.min(maxItems, data.length); | 79 data.length = Math.min(maxItems, data.length); |
| 80 var len = data.length; | 80 var len = data.length; |
| 81 for (var i = len; i < maxItems; i++) { | 81 for (var i = len; i < maxItems; i++) { |
| 82 data[i] = {filler: true}; | 82 data[i] = {filler: true}; |
| 83 } | 83 } |
| 84 | 84 |
| 85 mostVisitedData = data; | 85 mostVisitedData = data; |
| 86 renderMostVisited(data); | 86 renderMostVisited(data); |
| 87 | 87 |
| 88 gotMostVisited = true; | 88 gotMostVisited = true; |
| 89 onDataLoaded(); | 89 onDataLoaded(); |
| 90 |
| 91 // Only show the first run notification if first run. |
| 92 if (firstRun) { |
| 93 showFirstRunNotification(); |
| 94 } |
| 90 } | 95 } |
| 91 | 96 |
| 92 function downloadsList(data) { | 97 function downloadsList(data) { |
| 93 logEvent('received downloads'); | 98 logEvent('received downloads'); |
| 94 | 99 |
| 95 // We should only show complete downloads. | 100 // We should only show complete downloads. |
| 96 data = data.filter(function(d) { | 101 data = data.filter(function(d) { |
| 97 d.type = 'download'; | 102 d.type = 'download'; |
| 98 d.timestamp = d.started; | 103 d.timestamp = d.started; |
| 99 return d.state == 'COMPLETE'; | 104 return d.state == 'COMPLETE'; |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 // Make sure we do not use a timer during load since it slows down the UI. | 799 // Make sure we do not use a timer during load since it slows down the UI. |
| 795 f(); | 800 f(); |
| 796 } else { | 801 } else { |
| 797 // The duration of all transitions are 500ms | 802 // The duration of all transitions are 500ms |
| 798 window.setTimeout(f, 500); | 803 window.setTimeout(f, 500); |
| 799 } | 804 } |
| 800 } | 805 } |
| 801 | 806 |
| 802 // Notification | 807 // Notification |
| 803 | 808 |
| 804 function showNotification(text, actionText, f) { | 809 |
| 810 var notificationTimeout; |
| 811 |
| 812 function showNotification(text, actionText, opt_f) { |
| 805 var notificationElement = $('notification'); | 813 var notificationElement = $('notification'); |
| 814 |
| 815 function show() { |
| 816 window.clearTimeout(notificationTimeout); |
| 817 addClass(notificationElement, 'show'); |
| 818 } |
| 819 |
| 820 function delayedHide() { |
| 821 notificationTimeout = window.setTimeout(hideNotification, 10000); |
| 822 } |
| 823 |
| 824 function doAction() { |
| 825 if (opt_f) { |
| 826 opt_f(); |
| 827 } |
| 828 hideNotification(); |
| 829 } |
| 830 |
| 831 // Remove any possible first-run trails. |
| 832 removeClass(notification, 'first-run'); |
| 833 |
| 806 var actionLink = notificationElement.querySelector('.link'); | 834 var actionLink = notificationElement.querySelector('.link'); |
| 807 notificationElement.firstElementChild.textContent = text; | 835 notificationElement.firstElementChild.textContent = text; |
| 836 actionLink.textContent = actionText; |
| 808 | 837 |
| 809 actionLink.textContent = actionText; | 838 actionLink.onclick = doAction; |
| 810 actionLink.onclick = function() { | 839 actionLink.onkeydown = handleIfEnterKey(doAction); |
| 811 f(); | 840 notificationElement.onmouseover = show; |
| 812 removeClass(notificationElement, 'show'); | 841 notificationElement.onmouseout = delayedHide; |
| 813 // Since we have a :hover rule to not hide the notification banner when the | 842 actionLink.onfocus = show; |
| 814 // mouse is over we need force it to hide. We remove the hide class after | 843 actionLink.onblur = delayedHide; |
| 815 // a short timeout to allow the banner to be shown again. | 844 |
| 816 addClass(notificationElement, 'hide'); | 845 show(); |
| 817 afterTransition(function() { | 846 delayedHide(); |
| 818 removeClass(notificationElement, 'hide'); | |
| 819 }) | |
| 820 }; | |
| 821 addClass(notificationElement, 'show'); | |
| 822 window.setTimeout(function() { | |
| 823 removeClass(notificationElement, 'show'); | |
| 824 }, 10000); | |
| 825 } | 847 } |
| 826 | 848 |
| 849 function hideNotification() { |
| 850 var notificationElement = $('notification'); |
| 851 removeClass(notificationElement, 'show'); |
| 852 } |
| 853 |
| 854 function showFirstRunNotification() { |
| 855 showNotification(localStrings.getString('firstrunnotification'), |
| 856 localStrings.getString('closefirstrunnotification')); |
| 857 var notificationElement = $('notification'); |
| 858 addClass(notification, 'first-run'); |
| 859 } |
| 860 |
| 861 |
| 827 /** | 862 /** |
| 828 * This handles the option menu. | 863 * This handles the option menu. |
| 829 * @param {Element} button The button element. | 864 * @param {Element} button The button element. |
| 830 * @param {Element} menu The menu element. | 865 * @param {Element} menu The menu element. |
| 831 * @constructor | 866 * @constructor |
| 832 */ | 867 */ |
| 833 function OptionMenu(button, menu) { | 868 function OptionMenu(button, menu) { |
| 834 this.button = button; | 869 this.button = button; |
| 835 this.menu = menu; | 870 this.menu = menu; |
| 836 this.button.onmousedown = bind(this.handleMouseDown, this); | 871 this.button.onmousedown = bind(this.handleMouseDown, this); |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1358 el.addEventListener('dragover', bind(this.handleDragOver, this)); | 1393 el.addEventListener('dragover', bind(this.handleDragOver, this)); |
| 1359 el.addEventListener('dragleave', bind(this.handleDragLeave, this)); | 1394 el.addEventListener('dragleave', bind(this.handleDragLeave, this)); |
| 1360 el.addEventListener('drop', bind(this.handleDrop, this)); | 1395 el.addEventListener('drop', bind(this.handleDrop, this)); |
| 1361 el.addEventListener('dragend', bind(this.handleDragEnd, this)); | 1396 el.addEventListener('dragend', bind(this.handleDragEnd, this)); |
| 1362 el.addEventListener('drag', bind(this.handleDrag, this)); | 1397 el.addEventListener('drag', bind(this.handleDrag, this)); |
| 1363 el.addEventListener('mousedown', bind(this.handleMouseDown, this)); | 1398 el.addEventListener('mousedown', bind(this.handleMouseDown, this)); |
| 1364 } | 1399 } |
| 1365 }; | 1400 }; |
| 1366 | 1401 |
| 1367 dnd.init(); | 1402 dnd.init(); |
| OLD | NEW |