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 | 10 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 // Visit, private: ------------------------------------------------------------ | 168 // Visit, private: ------------------------------------------------------------ |
169 | 169 |
170 /** | 170 /** |
171 * Extracts and returns the domain (and subdomains) from a URL. | 171 * Extracts and returns the domain (and subdomains) from a URL. |
172 * @param {string} url The url. | 172 * @param {string} url The url. |
173 * @return {string} The domain. An empty string is returned if no domain can | 173 * @return {string} The domain. An empty string is returned if no domain can |
174 * be found. | 174 * be found. |
175 * @private | 175 * @private |
176 */ | 176 */ |
177 Visit.prototype.getDomainFromURL_ = function(url) { | 177 Visit.prototype.getDomainFromURL_ = function(url) { |
178 var domain = url.replace(/^.+:\/\//, '').match(/[^/]+/); | 178 // TODO(sergiu): Extract the domain from the C++ side and send it here. |
| 179 var domain = url.replace(/^.+?:\/\//, '').match(/[^/]+/); |
179 return domain ? domain[0] : ''; | 180 return domain ? domain[0] : ''; |
180 }; | 181 }; |
181 | 182 |
182 /** | 183 /** |
183 * Add child text nodes to a node such that occurrences of the specified text is | 184 * Add child text nodes to a node such that occurrences of the specified text is |
184 * highlighted. | 185 * highlighted. |
185 * @param {Node} node The node under which new text nodes will be made as | 186 * @param {Node} node The node under which new text nodes will be made as |
186 * children. | 187 * children. |
187 * @param {string} content Text to be added beneath |node| as one or more | 188 * @param {string} content Text to be added beneath |node| as one or more |
188 * text nodes. | 189 * text nodes. |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 * @param {Array} results A list of results. | 400 * @param {Array} results A list of results. |
400 */ | 401 */ |
401 HistoryModel.prototype.addResults = function(info, results) { | 402 HistoryModel.prototype.addResults = function(info, results) { |
402 $('loading-spinner').hidden = true; | 403 $('loading-spinner').hidden = true; |
403 this.inFlight_ = false; | 404 this.inFlight_ = false; |
404 this.isQueryFinished_ = info.finished; | 405 this.isQueryFinished_ = info.finished; |
405 this.queryCursor_ = info.cursor; | 406 this.queryCursor_ = info.cursor; |
406 this.queryStartTime = info.queryStartTime; | 407 this.queryStartTime = info.queryStartTime; |
407 this.queryEndTime = info.queryEndTime; | 408 this.queryEndTime = info.queryEndTime; |
408 | 409 |
409 // If the results are not for the current search term there's nothing more | 410 // If the results are not for the current search term then there is nothing |
410 // to do. | 411 // more to do. |
411 if (info.term != this.searchText_) | 412 if (info.term != this.searchText_) |
412 return; | 413 return; |
413 | 414 |
414 // If necessary, sort the results from newest to oldest. | 415 // If necessary, sort the results from newest to oldest. |
415 if (!results.sorted) | 416 if (!results.sorted) |
416 results.sort(function(a, b) { return b.time - a.time; }); | 417 results.sort(function(a, b) { return b.time - a.time; }); |
417 | 418 |
418 var lastVisit = this.visits_.slice(-1)[0]; | 419 var lastVisit = this.visits_.slice(-1)[0]; |
419 var lastDay = lastVisit ? lastVisit.dateRelativeDay : null; | 420 var lastDay = lastVisit ? lastVisit.dateRelativeDay : null; |
420 | 421 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 * Record that the given visit has been rendered. | 831 * Record that the given visit has been rendered. |
831 * @param {Visit} visit The visit that was rendered. | 832 * @param {Visit} visit The visit that was rendered. |
832 * @private | 833 * @private |
833 */ | 834 */ |
834 HistoryView.prototype.setVisitRendered_ = function(visit) { | 835 HistoryView.prototype.setVisitRendered_ = function(visit) { |
835 visit.isRendered = true; | 836 visit.isRendered = true; |
836 this.currentVisits_.push(visit); | 837 this.currentVisits_.push(visit); |
837 }; | 838 }; |
838 | 839 |
839 /** | 840 /** |
840 * This function generates and adds the grouped visits DOM for a certain | 841 * Generates and adds the grouped visits DOM for a certain domain. This |
841 * domain. This includes the clickable arrow and domain name and the visit | 842 * includes the clickable arrow and domain name and the visit entries for |
842 * entries for that domain. | 843 * that domain. |
843 * @param {Element} results DOM object to which to add the elements. | 844 * @param {Element} results DOM object to which to add the elements. |
844 * @param {string} domain Current domain name. | 845 * @param {string} domain Current domain name. |
845 * @param {Array} domainVisits Array of visits for this domain. | 846 * @param {Array} domainVisits Array of visits for this domain. |
846 * @private | 847 * @private |
847 */ | 848 */ |
848 HistoryView.prototype.getGroupedVisitsDOM_ = function( | 849 HistoryView.prototype.getGroupedVisitsDOM_ = function( |
849 results, domain, domainVisits) { | 850 results, domain, domainVisits) { |
850 // Add a new domain entry. | 851 // Add a new domain entry. |
851 var siteResults = results.appendChild( | 852 var siteResults = results.appendChild( |
852 createElementWithClassName('li', 'site-entry')); | 853 createElementWithClassName('li', 'site-entry')); |
853 // Make a wrapper that will contain the arrow, the favicon and the domain. | 854 // Make a wrapper that will contain the arrow, the favicon and the domain. |
854 var siteDomainWrapper = siteResults.appendChild( | 855 var siteDomainWrapper = siteResults.appendChild( |
855 createElementWithClassName('div', 'site-domain-wrapper')); | 856 createElementWithClassName('div', 'site-domain-wrapper')); |
856 var siteArrow = siteDomainWrapper.appendChild( | 857 var siteArrow = siteDomainWrapper.appendChild( |
857 createElementWithClassName('div', 'site-domain-arrow collapse')); | 858 createElementWithClassName('div', 'site-domain-arrow collapse')); |
858 siteArrow.textContent = '►'; | 859 siteArrow.textContent = '►'; |
859 var siteDomain = siteDomainWrapper.appendChild( | 860 var siteDomain = siteDomainWrapper.appendChild( |
860 createElementWithClassName('div', 'site-domain')); | 861 createElementWithClassName('div', 'site-domain')); |
861 var numberOfVisits = createElementWithClassName('span', 'number-visits'); | 862 var numberOfVisits = createElementWithClassName('span', 'number-visits'); |
862 numberOfVisits.textContent = loadTimeData.getStringF('numbervisits', | 863 numberOfVisits.textContent = loadTimeData.getStringF('numbervisits', |
863 domainVisits.length); | 864 domainVisits.length); |
864 siteDomain.textContent = domain; | 865 var domainElement = document.createElement('span'); |
| 866 domainElement.textContent = domain; |
| 867 siteDomain.appendChild(domainElement); |
865 siteDomain.appendChild(numberOfVisits); | 868 siteDomain.appendChild(numberOfVisits); |
866 siteResults.appendChild(siteDomainWrapper); | 869 siteResults.appendChild(siteDomainWrapper); |
867 var resultsList = siteResults.appendChild( | 870 var resultsList = siteResults.appendChild( |
868 createElementWithClassName('ol', 'site-results')); | 871 createElementWithClassName('ol', 'site-results')); |
869 | 872 |
870 domainVisits[0].addFaviconToElement_(siteDomain); | 873 domainVisits[0].addFaviconToElement_(siteDomain); |
871 | 874 |
872 siteDomainWrapper.addEventListener('click', toggleHandler); | 875 siteDomainWrapper.addEventListener('click', toggleHandler); |
873 // Collapse until it gets toggled. | 876 // Collapse until it gets toggled. |
874 resultsList.style.height = 0; | 877 resultsList.style.height = 0; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 visitsByDomain[domain] = []; | 935 visitsByDomain[domain] = []; |
933 domains.push(domain); | 936 domains.push(domain); |
934 } | 937 } |
935 visitsByDomain[domain].push(visit); | 938 visitsByDomain[domain].push(visit); |
936 } | 939 } |
937 var sortByVisits = function(a, b) { | 940 var sortByVisits = function(a, b) { |
938 return visitsByDomain[b].length - visitsByDomain[a].length; | 941 return visitsByDomain[b].length - visitsByDomain[a].length; |
939 }; | 942 }; |
940 domains.sort(sortByVisits); | 943 domains.sort(sortByVisits); |
941 | 944 |
942 for (var i = 0, domain; domain = domains[i]; i++) { | 945 for (var i = 0, domain; domain = domains[i]; i++) |
943 this.getGroupedVisitsDOM_(results, domain, visitsByDomain[domain]); | 946 this.getGroupedVisitsDOM_(results, domain, visitsByDomain[domain]); |
944 } | |
945 }; | 947 }; |
946 | 948 |
947 /** | 949 /** |
948 * Adds the results for a month. | 950 * Adds the results for a month. |
949 * @param {Array} visits Visits returned by the query. | 951 * @param {Array} visits Visits returned by the query. |
950 * @param {Element} parentElement Element to which to add the results to. | 952 * @param {Element} parentElement Element to which to add the results to. |
951 * @private | 953 * @private |
952 */ | 954 */ |
953 HistoryView.prototype.addMonthResults_ = function(visits, parentElement) { | 955 HistoryView.prototype.addMonthResults_ = function(visits, parentElement) { |
954 if (visits.length == 0) | 956 if (visits.length == 0) |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1534 historyView.reload(); | 1536 historyView.reload(); |
1535 } | 1537 } |
1536 | 1538 |
1537 // Add handlers to HTML elements. | 1539 // Add handlers to HTML elements. |
1538 document.addEventListener('DOMContentLoaded', load); | 1540 document.addEventListener('DOMContentLoaded', load); |
1539 | 1541 |
1540 // This event lets us enable and disable menu items before the menu is shown. | 1542 // This event lets us enable and disable menu items before the menu is shown. |
1541 document.addEventListener('canExecute', function(e) { | 1543 document.addEventListener('canExecute', function(e) { |
1542 e.canExecute = true; | 1544 e.canExecute = true; |
1543 }); | 1545 }); |
OLD | NEW |