OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <include src="../uber/uber_utils.js"> | 5 <include src="../uber/uber_utils.js"> |
6 | 6 |
7 /////////////////////////////////////////////////////////////////////////////// | 7 /////////////////////////////////////////////////////////////////////////////// |
8 // Globals: | 8 // Globals: |
9 /** @const */ var RESULTS_PER_PAGE = 150; | 9 /** @const */ var RESULTS_PER_PAGE = 150; |
10 /** @const */ var MAX_SEARCH_DEPTH_MONTHS = 18; | 10 /** @const */ var MAX_SEARCH_DEPTH_MONTHS = 18; |
(...skipping 17 matching lines...) Expand all Loading... | |
28 } | 28 } |
29 | 29 |
30 function findAncestorWithClass(node, className) { | 30 function findAncestorWithClass(node, className) { |
31 while ((node = node.parentNode)) { | 31 while ((node = node.parentNode)) { |
32 if (node.classList.contains(className)) return node; | 32 if (node.classList.contains(className)) return node; |
33 } | 33 } |
34 return null; | 34 return null; |
35 } | 35 } |
36 | 36 |
37 // TODO(glen): Get rid of these global references, replace with a controller | 37 // TODO(glen): Get rid of these global references, replace with a controller |
38 // or just make the classes own more of the page. | 38 // or just make the classes own more of the page. |
Dan Beam
2012/04/30 17:11:30
this probably shouldn't be indented, but it's also
| |
39 var historyModel; | 39 var historyModel; |
40 var historyView; | 40 var historyView; |
41 var localStrings; | |
42 var pageState; | 41 var pageState; |
43 var deleteQueue = []; | 42 var deleteQueue = []; |
44 var selectionAnchor = -1; | 43 var selectionAnchor = -1; |
45 var activePage = null; | 44 var activePage = null; |
46 | 45 |
47 /** @const */ var MenuButton = cr.ui.MenuButton; | 46 /** @const */ var MenuButton = cr.ui.MenuButton; |
48 /** @const */ var Command = cr.ui.Command; | 47 /** @const */ var Command = cr.ui.Command; |
49 /** @const */ var Menu = cr.ui.Menu; | 48 /** @const */ var Menu = cr.ui.Menu; |
50 | 49 |
51 function createDropDownBgImage(canvasName, colorSpec) { | 50 function createDropDownBgImage(canvasName, colorSpec) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 * @return {Node} A DOM node to represent the history entry or search result. | 116 * @return {Node} A DOM node to represent the history entry or search result. |
118 */ | 117 */ |
119 Page.prototype.getResultDOM = function(searchResultFlag) { | 118 Page.prototype.getResultDOM = function(searchResultFlag) { |
120 var node = createElementWithClassName('li', 'entry'); | 119 var node = createElementWithClassName('li', 'entry'); |
121 var time = createElementWithClassName('div', 'time'); | 120 var time = createElementWithClassName('div', 'time'); |
122 var entryBox = createElementWithClassName('label', 'entry-box'); | 121 var entryBox = createElementWithClassName('label', 'entry-box'); |
123 var domain = createElementWithClassName('div', 'domain'); | 122 var domain = createElementWithClassName('div', 'domain'); |
124 | 123 |
125 var dropDown = createElementWithClassName('button', 'drop-down'); | 124 var dropDown = createElementWithClassName('button', 'drop-down'); |
126 dropDown.value = 'Open action menu'; | 125 dropDown.value = 'Open action menu'; |
127 dropDown.title = localStrings.getString('actionMenuDescription'); | 126 dropDown.title = loadTimeData.getString('actionMenuDescription'); |
128 dropDown.setAttribute('menu', '#action-menu'); | 127 dropDown.setAttribute('menu', '#action-menu'); |
129 cr.ui.decorate(dropDown, MenuButton); | 128 cr.ui.decorate(dropDown, MenuButton); |
130 | 129 |
131 // Checkbox is always created, but only visible on hover & when checked. | 130 // Checkbox is always created, but only visible on hover & when checked. |
132 var checkbox = document.createElement('input'); | 131 var checkbox = document.createElement('input'); |
133 checkbox.type = 'checkbox'; | 132 checkbox.type = 'checkbox'; |
134 checkbox.id = 'checkbox-' + this.id_; | 133 checkbox.id = 'checkbox-' + this.id_; |
135 checkbox.time = this.time.getTime(); | 134 checkbox.time = this.time.getTime(); |
136 checkbox.addEventListener('click', checkboxClicked); | 135 checkbox.addEventListener('click', checkboxClicked); |
137 time.appendChild(checkbox); | 136 time.appendChild(checkbox); |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 HistoryView.prototype.displayResults_ = function() { | 678 HistoryView.prototype.displayResults_ = function() { |
680 var results = this.model_.getNumberedRange( | 679 var results = this.model_.getNumberedRange( |
681 this.pageIndex_ * RESULTS_PER_PAGE, | 680 this.pageIndex_ * RESULTS_PER_PAGE, |
682 this.pageIndex_ * RESULTS_PER_PAGE + RESULTS_PER_PAGE); | 681 this.pageIndex_ * RESULTS_PER_PAGE + RESULTS_PER_PAGE); |
683 | 682 |
684 var searchText = this.model_.getSearchText(); | 683 var searchText = this.model_.getSearchText(); |
685 if (searchText) { | 684 if (searchText) { |
686 // Add a header for the search results, if there isn't already one. | 685 // Add a header for the search results, if there isn't already one. |
687 if (!this.resultDiv_.querySelector('h3')) { | 686 if (!this.resultDiv_.querySelector('h3')) { |
688 var header = document.createElement('h3'); | 687 var header = document.createElement('h3'); |
689 header.textContent = localStrings.getStringF('searchresultsfor', | 688 header.textContent = loadTimeData.getStringF('searchresultsfor', |
690 searchText); | 689 searchText); |
691 this.resultDiv_.appendChild(header); | 690 this.resultDiv_.appendChild(header); |
692 } | 691 } |
693 | 692 |
694 var searchResults = createElementWithClassName('ol', 'search-results'); | 693 var searchResults = createElementWithClassName('ol', 'search-results'); |
695 for (var i = 0, page; page = results[i]; i++) { | 694 for (var i = 0, page; page = results[i]; i++) { |
696 if (!page.isRendered) { | 695 if (!page.isRendered) { |
697 searchResults.appendChild(page.getResultDOM(true)); | 696 searchResults.appendChild(page.getResultDOM(true)); |
698 this.setPageRendered_(page); | 697 this.setPageRendered_(page); |
699 } | 698 } |
700 } | 699 } |
701 this.resultDiv_.appendChild(searchResults); | 700 this.resultDiv_.appendChild(searchResults); |
702 } else { | 701 } else { |
703 var resultsFragment = document.createDocumentFragment(); | 702 var resultsFragment = document.createDocumentFragment(); |
704 var lastTime = Math.infinity; | 703 var lastTime = Math.infinity; |
705 var dayResults; | 704 var dayResults; |
706 for (var i = 0, page; page = results[i]; i++) { | 705 for (var i = 0, page; page = results[i]; i++) { |
707 if (page.isRendered) { | 706 if (page.isRendered) { |
708 continue; | 707 continue; |
709 } | 708 } |
710 // Break across day boundaries and insert gaps for browsing pauses. | 709 // Break across day boundaries and insert gaps for browsing pauses. |
711 // Create a dayResults element to contain results for each day | 710 // Create a dayResults element to contain results for each day |
712 var thisTime = page.time.getTime(); | 711 var thisTime = page.time.getTime(); |
713 | 712 |
714 if ((i == 0 && page.continued) || !page.continued) { | 713 if ((i == 0 && page.continued) || !page.continued) { |
715 var day = createElementWithClassName('h3', 'day'); | 714 var day = createElementWithClassName('h3', 'day'); |
716 day.appendChild(document.createTextNode(page.dateRelativeDay)); | 715 day.appendChild(document.createTextNode(page.dateRelativeDay)); |
717 if (i == 0 && page.continued) { | 716 if (i == 0 && page.continued) { |
718 day.appendChild(document.createTextNode(' ' + | 717 day.appendChild(document.createTextNode(' ' + |
719 localStrings.getString('cont'))); | 718 loadTimeData.getString('cont'))); |
720 } | 719 } |
721 | 720 |
722 // If there is an existing dayResults element, append it. | 721 // If there is an existing dayResults element, append it. |
723 if (dayResults) { | 722 if (dayResults) { |
724 resultsFragment.appendChild(dayResults); | 723 resultsFragment.appendChild(dayResults); |
725 } | 724 } |
726 resultsFragment.appendChild(day); | 725 resultsFragment.appendChild(day); |
727 dayResults = createElementWithClassName('ol', 'day-results'); | 726 dayResults = createElementWithClassName('ol', 'day-results'); |
728 } else if (lastTime - thisTime > BROWSING_GAP_TIME) { | 727 } else if (lastTime - thisTime > BROWSING_GAP_TIME) { |
729 if (dayResults) { | 728 if (dayResults) { |
(...skipping 19 matching lines...) Expand all Loading... | |
749 | 748 |
750 /** | 749 /** |
751 * Update the pagination tools. | 750 * Update the pagination tools. |
752 * @private | 751 * @private |
753 */ | 752 */ |
754 HistoryView.prototype.displayNavBar_ = function() { | 753 HistoryView.prototype.displayNavBar_ = function() { |
755 this.pageDiv_.textContent = ''; | 754 this.pageDiv_.textContent = ''; |
756 | 755 |
757 if (this.pageIndex_ > 0) { | 756 if (this.pageIndex_ > 0) { |
758 this.pageDiv_.appendChild( | 757 this.pageDiv_.appendChild( |
759 this.createPageNav_(0, localStrings.getString('newest'))); | 758 this.createPageNav_(0, loadTimeData.getString('newest'))); |
760 this.pageDiv_.appendChild( | 759 this.pageDiv_.appendChild( |
761 this.createPageNav_(this.pageIndex_ - 1, | 760 this.createPageNav_(this.pageIndex_ - 1, |
762 localStrings.getString('newer'))); | 761 loadTimeData.getString('newer'))); |
763 } | 762 } |
764 | 763 |
765 // TODO(feldstein): this causes the navbar to not show up when your first | 764 // TODO(feldstein): this causes the navbar to not show up when your first |
766 // page has the exact amount of results as RESULTS_PER_PAGE. | 765 // page has the exact amount of results as RESULTS_PER_PAGE. |
767 if (this.model_.getSize() > (this.pageIndex_ + 1) * RESULTS_PER_PAGE) { | 766 if (this.model_.getSize() > (this.pageIndex_ + 1) * RESULTS_PER_PAGE) { |
768 this.pageDiv_.appendChild( | 767 this.pageDiv_.appendChild( |
769 this.createPageNav_(this.pageIndex_ + 1, | 768 this.createPageNav_(this.pageIndex_ + 1, |
770 localStrings.getString('older'))); | 769 loadTimeData.getString('older'))); |
771 } | 770 } |
772 }; | 771 }; |
773 | 772 |
774 /** | 773 /** |
775 * Make a DOM object representation of a page navigation link. | 774 * Make a DOM object representation of a page navigation link. |
776 * @param {number} page The page index the navigation element should link to | 775 * @param {number} page The page index the navigation element should link to |
777 * @param {string} name The text content of the link | 776 * @param {string} name The text content of the link |
778 * @return {HTMLAnchorElement} the pagination link | 777 * @return {HTMLAnchorElement} the pagination link |
779 * @private | 778 * @private |
780 */ | 779 */ |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
920 // Document Functions: | 919 // Document Functions: |
921 /** | 920 /** |
922 * Window onload handler, sets up the page. | 921 * Window onload handler, sets up the page. |
923 */ | 922 */ |
924 function load() { | 923 function load() { |
925 uber.onContentFrameLoaded(); | 924 uber.onContentFrameLoaded(); |
926 | 925 |
927 var searchField = $('search-field'); | 926 var searchField = $('search-field'); |
928 searchField.focus(); | 927 searchField.focus(); |
929 | 928 |
930 localStrings = new LocalStrings(); | |
931 historyModel = new HistoryModel(); | 929 historyModel = new HistoryModel(); |
932 historyView = new HistoryView(historyModel); | 930 historyView = new HistoryView(historyModel); |
933 pageState = new PageState(historyModel, historyView); | 931 pageState = new PageState(historyModel, historyView); |
934 | 932 |
935 // Create default view. | 933 // Create default view. |
936 var hashData = pageState.getHashData(); | 934 var hashData = pageState.getHashData(); |
937 historyView.setSearch(hashData.q, hashData.p); | 935 historyView.setSearch(hashData.q, hashData.p); |
938 | 936 |
939 $('search-form').onsubmit = function() { | 937 $('search-form').onsubmit = function() { |
940 setSearch(searchField.value); | 938 setSearch(searchField.value); |
941 return false; | 939 return false; |
942 }; | 940 }; |
943 | 941 |
944 $('remove-page').addEventListener('activate', function(e) { | 942 $('remove-page').addEventListener('activate', function(e) { |
945 activePage.removeFromHistory_(); | 943 activePage.removeFromHistory_(); |
946 activePage = null; | 944 activePage = null; |
947 }); | 945 }); |
948 $('more-from-site').addEventListener('activate', function(e) { | 946 $('more-from-site').addEventListener('activate', function(e) { |
949 activePage.showMoreFromSite_(); | 947 activePage.showMoreFromSite_(); |
950 activePage = null; | 948 activePage = null; |
951 }); | 949 }); |
952 | 950 |
953 var title = localStrings.getString('title'); | 951 var title = loadTimeData.getString('title'); |
954 uber.invokeMethodOnParent('setTitle', {title: title}); | 952 uber.invokeMethodOnParent('setTitle', {title: title}); |
955 | 953 |
956 window.addEventListener('message', function(e) { | 954 window.addEventListener('message', function(e) { |
957 if (e.data.method == 'frameSelected') | 955 if (e.data.method == 'frameSelected') |
958 searchField.focus(); | 956 searchField.focus(); |
959 }); | 957 }); |
960 } | 958 } |
961 | 959 |
962 /** | 960 /** |
963 * TODO(glen): Get rid of this function. | 961 * TODO(glen): Get rid of this function. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1044 } | 1042 } |
1045 var link = findAncestorWithClass(checkbox, 'entry-box').querySelector('a'); | 1043 var link = findAncestorWithClass(checkbox, 'entry-box').querySelector('a'); |
1046 checkbox.disabled = true; | 1044 checkbox.disabled = true; |
1047 link.classList.add('to-be-removed'); | 1045 link.classList.add('to-be-removed'); |
1048 disabledItems.push(checkbox); | 1046 disabledItems.push(checkbox); |
1049 urls.push(link.href); | 1047 urls.push(link.href); |
1050 } | 1048 } |
1051 if (urls.length > 0) { | 1049 if (urls.length > 0) { |
1052 queue.push([date, urls]); | 1050 queue.push([date, urls]); |
1053 } | 1051 } |
1054 if (checked.length > 0 && confirm(localStrings.getString('deletewarning'))) { | 1052 if (checked.length > 0 && confirm(loadTimeData.getString('deletewarning'))) { |
1055 for (var i = 0; i < queue.length; i++) { | 1053 for (var i = 0; i < queue.length; i++) { |
1056 // Reload the page when the final entry has been deleted. | 1054 // Reload the page when the final entry has been deleted. |
1057 var callback = i == 0 ? reloadHistory : null; | 1055 var callback = i == 0 ? reloadHistory : null; |
1058 | 1056 |
1059 queueURLsForDeletion(queue[i][0], queue[i][1], callback); | 1057 queueURLsForDeletion(queue[i][0], queue[i][1], callback); |
1060 } | 1058 } |
1061 deleteNextInQueue(); | 1059 deleteNextInQueue(); |
1062 } else { | 1060 } else { |
1063 // If the remove is cancelled, return the checkboxes to their | 1061 // If the remove is cancelled, return the checkboxes to their |
1064 // enabled, non-line-through state. | 1062 // enabled, non-line-through state. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1192 historyView.reload(); | 1190 historyView.reload(); |
1193 } | 1191 } |
1194 | 1192 |
1195 // Add handlers to HTML elements. | 1193 // Add handlers to HTML elements. |
1196 document.addEventListener('DOMContentLoaded', load); | 1194 document.addEventListener('DOMContentLoaded', load); |
1197 | 1195 |
1198 // This event lets us enable and disable menu items before the menu is shown. | 1196 // This event lets us enable and disable menu items before the menu is shown. |
1199 document.addEventListener('canExecute', function(e) { | 1197 document.addEventListener('canExecute', function(e) { |
1200 e.canExecute = true; | 1198 e.canExecute = true; |
1201 }); | 1199 }); |
OLD | NEW |