| 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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 * Record that the given visit has been rendered. | 841 * Record that the given visit has been rendered. |
| 841 * @param {Visit} visit The visit that was rendered. | 842 * @param {Visit} visit The visit that was rendered. |
| 842 * @private | 843 * @private |
| 843 */ | 844 */ |
| 844 HistoryView.prototype.setVisitRendered_ = function(visit) { | 845 HistoryView.prototype.setVisitRendered_ = function(visit) { |
| 845 visit.isRendered = true; | 846 visit.isRendered = true; |
| 846 this.currentVisits_.push(visit); | 847 this.currentVisits_.push(visit); |
| 847 }; | 848 }; |
| 848 | 849 |
| 849 /** | 850 /** |
| 850 * This function generates and adds the grouped visits DOM for a certain | 851 * Generates and adds the grouped visits DOM for a certain domain. This |
| 851 * domain. This includes the clickable arrow and domain name and the visit | 852 * includes the clickable arrow and domain name and the visit entries for |
| 852 * entries for that domain. | 853 * that domain. |
| 853 * @param {Element} results DOM object to which to add the elements. | 854 * @param {Element} results DOM object to which to add the elements. |
| 854 * @param {string} domain Current domain name. | 855 * @param {string} domain Current domain name. |
| 855 * @param {Array} domainVisits Array of visits for this domain. | 856 * @param {Array} domainVisits Array of visits for this domain. |
| 856 * @private | 857 * @private |
| 857 */ | 858 */ |
| 858 HistoryView.prototype.getGroupedVisitsDOM_ = function( | 859 HistoryView.prototype.getGroupedVisitsDOM_ = function( |
| 859 results, domain, domainVisits) { | 860 results, domain, domainVisits) { |
| 860 // Add a new domain entry. | 861 // Add a new domain entry. |
| 861 var siteResults = results.appendChild( | 862 var siteResults = results.appendChild( |
| 862 createElementWithClassName('li', 'site-entry')); | 863 createElementWithClassName('li', 'site-entry')); |
| 863 // Make a wrapper that will contain the arrow, the favicon and the domain. | 864 // Make a wrapper that will contain the arrow, the favicon and the domain. |
| 864 var siteDomainWrapper = siteResults.appendChild( | 865 var siteDomainWrapper = siteResults.appendChild( |
| 865 createElementWithClassName('div', 'site-domain-wrapper')); | 866 createElementWithClassName('div', 'site-domain-wrapper')); |
| 866 var siteArrow = siteDomainWrapper.appendChild( | 867 var siteArrow = siteDomainWrapper.appendChild( |
| 867 createElementWithClassName('div', 'site-domain-arrow collapse')); | 868 createElementWithClassName('div', 'site-domain-arrow collapse')); |
| 868 siteArrow.textContent = '►'; | 869 siteArrow.textContent = '►'; |
| 869 var siteDomain = siteDomainWrapper.appendChild( | 870 var siteDomain = siteDomainWrapper.appendChild( |
| 870 createElementWithClassName('div', 'site-domain')); | 871 createElementWithClassName('div', 'site-domain')); |
| 871 var numberOfVisits = createElementWithClassName('span', 'number-visits'); | 872 var numberOfVisits = createElementWithClassName('span', 'number-visits'); |
| 872 numberOfVisits.textContent = loadTimeData.getStringF('numbervisits', | 873 numberOfVisits.textContent = loadTimeData.getStringF('numbervisits', |
| 873 domainVisits.length); | 874 domainVisits.length); |
| 874 siteDomain.textContent = domain; | 875 var domainElement = document.createElement('span'); |
| 876 domainElement.textContent = domain; |
| 877 siteDomain.appendChild(domainElement); |
| 875 siteDomain.appendChild(numberOfVisits); | 878 siteDomain.appendChild(numberOfVisits); |
| 876 siteResults.appendChild(siteDomainWrapper); | 879 siteResults.appendChild(siteDomainWrapper); |
| 877 var resultsList = siteResults.appendChild( | 880 var resultsList = siteResults.appendChild( |
| 878 createElementWithClassName('ol', 'site-results')); | 881 createElementWithClassName('ol', 'site-results')); |
| 879 | 882 |
| 880 domainVisits[0].addFaviconToElement_(siteDomain); | 883 domainVisits[0].addFaviconToElement_(siteDomain); |
| 881 | 884 |
| 882 siteDomainWrapper.addEventListener('click', toggleHandler); | 885 siteDomainWrapper.addEventListener('click', toggleHandler); |
| 883 // Collapse until it gets toggled. | 886 // Collapse until it gets toggled. |
| 884 resultsList.style.height = 0; | 887 resultsList.style.height = 0; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 visitsByDomain[domain] = []; | 945 visitsByDomain[domain] = []; |
| 943 domains.push(domain); | 946 domains.push(domain); |
| 944 } | 947 } |
| 945 visitsByDomain[domain].push(visit); | 948 visitsByDomain[domain].push(visit); |
| 946 } | 949 } |
| 947 var sortByVisits = function(a, b) { | 950 var sortByVisits = function(a, b) { |
| 948 return visitsByDomain[b].length - visitsByDomain[a].length; | 951 return visitsByDomain[b].length - visitsByDomain[a].length; |
| 949 }; | 952 }; |
| 950 domains.sort(sortByVisits); | 953 domains.sort(sortByVisits); |
| 951 | 954 |
| 952 for (var i = 0, domain; domain = domains[i]; i++) { | 955 for (var i = 0, domain; domain = domains[i]; i++) |
| 953 this.getGroupedVisitsDOM_(results, domain, visitsByDomain[domain]); | 956 this.getGroupedVisitsDOM_(results, domain, visitsByDomain[domain]); |
| 954 } | |
| 955 }; | 957 }; |
| 956 | 958 |
| 957 /** | 959 /** |
| 958 * Adds the results for a month. | 960 * Adds the results for a month. |
| 959 * @param {Array} visits Visits returned by the query. | 961 * @param {Array} visits Visits returned by the query. |
| 960 * @param {Element} parentElement Element to which to add the results to. | 962 * @param {Element} parentElement Element to which to add the results to. |
| 961 * @private | 963 * @private |
| 962 */ | 964 */ |
| 963 HistoryView.prototype.addMonthResults_ = function(visits, parentElement) { | 965 HistoryView.prototype.addMonthResults_ = function(visits, parentElement) { |
| 964 if (visits.length == 0) | 966 if (visits.length == 0) |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1545 historyView.reload(); | 1547 historyView.reload(); |
| 1546 } | 1548 } |
| 1547 | 1549 |
| 1548 // Add handlers to HTML elements. | 1550 // Add handlers to HTML elements. |
| 1549 document.addEventListener('DOMContentLoaded', load); | 1551 document.addEventListener('DOMContentLoaded', load); |
| 1550 | 1552 |
| 1551 // This event lets us enable and disable menu items before the menu is shown. | 1553 // This event lets us enable and disable menu items before the menu is shown. |
| 1552 document.addEventListener('canExecute', function(e) { | 1554 document.addEventListener('canExecute', function(e) { |
| 1553 e.canExecute = true; | 1555 e.canExecute = true; |
| 1554 }); | 1556 }); |
| OLD | NEW |