Chromium Code Reviews| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 // Whether this is the continuation of a previous day. | 65 // Whether this is the continuation of a previous day. |
| 66 this.continued = continued; | 66 this.continued = continued; |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Visit, public: ------------------------------------------------------------- | 69 // Visit, public: ------------------------------------------------------------- |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * Returns a dom structure for a browse page result or a search page result. | 72 * Returns a dom structure for a browse page result or a search page result. |
| 73 * @param {Object} propertyBag A bag of configuration properties, false by | 73 * @param {Object} propertyBag A bag of configuration properties, false by |
| 74 * default: | 74 * default: |
| 75 * <ul> | 75 * - isSearchResult: Whether or not the result is a search result. |
| 76 * <li>isSearchResult: Whether or not the result is a search result.</li> | 76 * - addTitleFavicon: Whether or not the favicon should be added. |
| 77 * <li>addTitleFavicon: Whether or not the favicon should be added.</li> | |
| 78 * </ul> | |
| 79 * @return {Node} A DOM node to represent the history entry or search result. | 77 * @return {Node} A DOM node to represent the history entry or search result. |
| 80 */ | 78 */ |
| 81 Visit.prototype.getResultDOM = function(propertyBag) { | 79 Visit.prototype.getResultDOM = function(propertyBag) { |
| 82 var isSearchResult = propertyBag.isSearchResult || false; | 80 var isSearchResult = propertyBag.isSearchResult || false; |
| 83 var addTitleFavicon = propertyBag.addTitleFavicon || false; | 81 var addTitleFavicon = propertyBag.addTitleFavicon || false; |
| 84 var node = createElementWithClassName('li', 'entry'); | 82 var node = createElementWithClassName('li', 'entry'); |
| 85 var time = createElementWithClassName('div', 'time'); | 83 var time = createElementWithClassName('div', 'time'); |
| 86 var entryBox = createElementWithClassName('label', 'entry-box'); | 84 var entryBox = createElementWithClassName('label', 'entry-box'); |
| 87 var domain = createElementWithClassName('div', 'domain'); | 85 var domain = createElementWithClassName('div', 'domain'); |
| 88 | 86 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 // Visit, private: ------------------------------------------------------------ | 152 // Visit, private: ------------------------------------------------------------ |
| 155 | 153 |
| 156 /** | 154 /** |
| 157 * Extracts and returns the domain (and subdomains) from a URL. | 155 * Extracts and returns the domain (and subdomains) from a URL. |
| 158 * @param {string} url The url. | 156 * @param {string} url The url. |
| 159 * @return {string} The domain. An empty string is returned if no domain can | 157 * @return {string} The domain. An empty string is returned if no domain can |
| 160 * be found. | 158 * be found. |
| 161 * @private | 159 * @private |
| 162 */ | 160 */ |
| 163 Visit.prototype.getDomainFromURL_ = function(url) { | 161 Visit.prototype.getDomainFromURL_ = function(url) { |
| 164 var domain = url.replace(/^.+:\/\//, '').match(/[^/]+/); | 162 var domain = url.replace(/^.+?:\/\//, '').match(/[^/]+/); |
|
Patrick Dubroy
2013/01/30 19:23:04
And...this is why doing this is with a regex is a
Sergiu
2013/01/30 21:12:43
I'll put in a TODO.
Sergiu
2013/02/05 18:21:23
Put the TODO in.
| |
| 165 return domain ? domain[0] : ''; | 163 return domain ? domain[0] : ''; |
| 166 }; | 164 }; |
| 167 | 165 |
| 168 /** | 166 /** |
| 169 * Add child text nodes to a node such that occurrences of the specified text is | 167 * Add child text nodes to a node such that occurrences of the specified text is |
| 170 * highlighted. | 168 * highlighted. |
| 171 * @param {Node} node The node under which new text nodes will be made as | 169 * @param {Node} node The node under which new text nodes will be made as |
| 172 * children. | 170 * children. |
| 173 * @param {string} content Text to be added beneath |node| as one or more | 171 * @param {string} content Text to be added beneath |node| as one or more |
| 174 * text nodes. | 172 * text nodes. |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 * Receiver for history query. | 370 * Receiver for history query. |
| 373 * @param {Object} info An object containing information about the query. | 371 * @param {Object} info An object containing information about the query. |
| 374 * @param {Array} results A list of results. | 372 * @param {Array} results A list of results. |
| 375 */ | 373 */ |
| 376 HistoryModel.prototype.addResults = function(info, results) { | 374 HistoryModel.prototype.addResults = function(info, results) { |
| 377 $('loading-spinner').hidden = true; | 375 $('loading-spinner').hidden = true; |
| 378 this.inFlight_ = false; | 376 this.inFlight_ = false; |
| 379 this.isQueryFinished_ = info.finished; | 377 this.isQueryFinished_ = info.finished; |
| 380 this.queryCursor_ = info.cursor; | 378 this.queryCursor_ = info.cursor; |
| 381 | 379 |
| 382 // If the results are not for the current search term there's nothing more | 380 // If the results are not for the current search term then there is nothing |
| 383 // to do. | 381 // more to do. |
| 384 if (info.term != this.searchText_) | 382 if (info.term != this.searchText_) |
| 385 return; | 383 return; |
| 386 | 384 |
| 387 // If necessary, sort the results from newest to oldest. | 385 // If necessary, sort the results from newest to oldest. |
| 388 if (!results.sorted) | 386 if (!results.sorted) |
| 389 results.sort(function(a, b) { return b.time - a.time; }); | 387 results.sort(function(a, b) { return b.time - a.time; }); |
| 390 | 388 |
| 391 var lastVisit = this.visits_.slice(-1)[0]; | 389 var lastVisit = this.visits_.slice(-1)[0]; |
| 392 var lastDay = lastVisit ? lastVisit.dateRelativeDay : null; | 390 var lastDay = lastVisit ? lastVisit.dateRelativeDay : null; |
| 393 | 391 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 691 * Record that the given visit has been rendered. | 689 * Record that the given visit has been rendered. |
| 692 * @param {Visit} visit The visit that was rendered. | 690 * @param {Visit} visit The visit that was rendered. |
| 693 * @private | 691 * @private |
| 694 */ | 692 */ |
| 695 HistoryView.prototype.setVisitRendered_ = function(visit) { | 693 HistoryView.prototype.setVisitRendered_ = function(visit) { |
| 696 visit.isRendered = true; | 694 visit.isRendered = true; |
| 697 this.currentVisits_.push(visit); | 695 this.currentVisits_.push(visit); |
| 698 }; | 696 }; |
| 699 | 697 |
| 700 /** | 698 /** |
| 701 * This function generates and adds the grouped visits DOM for a certain | 699 * Generates and adds the grouped visits DOM for a certain domain. This |
| 702 * domain. This includes the clickable arrow and domain name and the visit | 700 * includes the clickable arrow and domain name and the visit entries for |
| 703 * entries for that domain. | 701 * that domain. |
| 704 * @param {Element} results DOM object to which to add the elements. | 702 * @param {Element} results DOM object to which to add the elements. |
| 705 * @param {string} domain Current domain name. | 703 * @param {string} domain Current domain name. |
| 706 * @param {Array} domainVisits Array of visits for this domain. | 704 * @param {Array} domainVisits Array of visits for this domain. |
| 707 * @private | 705 * @private |
| 708 */ | 706 */ |
| 709 HistoryView.prototype.getGroupedVisitsDOM_ = function( | 707 HistoryView.prototype.getGroupedVisitsDOM_ = function( |
| 710 results, domain, domainVisits) { | 708 results, domain, domainVisits) { |
| 711 // Add a new domain entry. | 709 // Add a new domain entry. |
| 712 var siteResults = results.appendChild( | 710 var siteResults = results.appendChild( |
| 713 createElementWithClassName('li', 'site-entry')); | 711 createElementWithClassName('li', 'site-entry')); |
| 714 // Make a wrapper that will contain the arrow, the favicon and the domain. | 712 // Make a wrapper that will contain the arrow, the favicon and the domain. |
| 715 var siteDomainWrapper = siteResults.appendChild( | 713 var siteDomainWrapper = siteResults.appendChild( |
| 716 createElementWithClassName('div', 'site-domain-wrapper')); | 714 createElementWithClassName('div', 'site-domain-wrapper')); |
| 717 var siteArrow = siteDomainWrapper.appendChild( | 715 var siteArrow = siteDomainWrapper.appendChild( |
| 718 createElementWithClassName('div', 'site-domain-arrow collapse')); | 716 createElementWithClassName('div', 'site-domain-arrow collapse')); |
| 719 siteArrow.textContent = '►'; | 717 siteArrow.textContent = '►'; |
| 720 var siteDomain = siteDomainWrapper.appendChild( | 718 var siteDomain = siteDomainWrapper.appendChild( |
| 721 createElementWithClassName('div', 'site-domain')); | 719 createElementWithClassName('div', 'site-domain')); |
| 722 var numberOfVisits = createElementWithClassName('span', 'number-visits'); | 720 var numberOfVisits = createElementWithClassName('span', 'number-visits'); |
| 723 numberOfVisits.textContent = loadTimeData.getStringF('numbervisits', | 721 numberOfVisits.textContent = loadTimeData.getStringF('numbervisits', |
| 724 domainVisits.length); | 722 domainVisits.length); |
| 725 siteDomain.textContent = domain; | 723 var domainElement = document.createElement('span'); |
| 724 domainElement.textContent = domain; | |
| 725 siteDomain.appendChild(domainElement); | |
| 726 siteDomain.appendChild(numberOfVisits); | 726 siteDomain.appendChild(numberOfVisits); |
| 727 siteResults.appendChild(siteDomainWrapper); | 727 siteResults.appendChild(siteDomainWrapper); |
| 728 var resultsList = siteResults.appendChild( | 728 var resultsList = siteResults.appendChild( |
| 729 createElementWithClassName('ol', 'site-results')); | 729 createElementWithClassName('ol', 'site-results')); |
| 730 | 730 |
| 731 domainVisits[0].addFaviconToElement_(siteDomain); | 731 domainVisits[0].addFaviconToElement_(siteDomain); |
| 732 | 732 |
| 733 siteDomainWrapper.addEventListener('click', toggleHandler); | 733 siteDomainWrapper.addEventListener('click', toggleHandler); |
| 734 // Collapse until it gets toggled. | 734 // Collapse until it gets toggled. |
| 735 resultsList.style.height = 0; | 735 resultsList.style.height = 0; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 758 visitsByDomain[domain] = []; | 758 visitsByDomain[domain] = []; |
| 759 domains.push(domain); | 759 domains.push(domain); |
| 760 } | 760 } |
| 761 visitsByDomain[domain].push(visit); | 761 visitsByDomain[domain].push(visit); |
| 762 } | 762 } |
| 763 var sortByVisits = function(a, b) { | 763 var sortByVisits = function(a, b) { |
| 764 return visitsByDomain[b].length - visitsByDomain[a].length; | 764 return visitsByDomain[b].length - visitsByDomain[a].length; |
| 765 }; | 765 }; |
| 766 domains.sort(sortByVisits); | 766 domains.sort(sortByVisits); |
| 767 | 767 |
| 768 for (var i = 0, domain; domain = domains[i]; i++) { | 768 for (var i = 0, domain; domain = domains[i]; i++) |
| 769 this.getGroupedVisitsDOM_(results, domain, visitsByDomain[domain]); | 769 this.getGroupedVisitsDOM_(results, domain, visitsByDomain[domain]); |
| 770 } | |
| 771 }; | 770 }; |
| 772 | 771 |
| 773 /** | 772 /** |
| 774 * Adds the results grouped by days, grouping them if needed. | 773 * Adds the results grouped by days, grouping them if needed. |
| 775 * @param {Array} visits Visits returned by the query. | 774 * @param {Array} visits Visits returned by the query. |
| 776 * @param {Element} parentElement Element to which to add the results to. | 775 * @param {Element} parentElement Element to which to add the results to. |
| 777 * @private | 776 * @private |
| 778 */ | 777 */ |
| 779 HistoryView.prototype.addDayResults_ = function(visits, parentElement) { | 778 HistoryView.prototype.addDayResults_ = function(visits, parentElement) { |
| 780 if (visits.length == 0) | 779 if (visits.length == 0) |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 962 * Set the hash to a specified state, this will create an entry in the | 961 * Set the hash to a specified state, this will create an entry in the |
| 963 * session history so the back button cycles through hash states, which | 962 * session history so the back button cycles through hash states, which |
| 964 * are then picked up by our listener. | 963 * are then picked up by our listener. |
| 965 * @param {string} term The current search string. | 964 * @param {string} term The current search string. |
| 966 * @param {number} page The page currently being viewed. | 965 * @param {number} page The page currently being viewed. |
| 967 * @param {boolean} grouped Whether the results are grouped or not. | 966 * @param {boolean} grouped Whether the results are grouped or not. |
| 968 */ | 967 */ |
| 969 PageState.prototype.setUIState = function(term, page, grouped) { | 968 PageState.prototype.setUIState = function(term, page, grouped) { |
| 970 // Make sure the form looks pretty. | 969 // Make sure the form looks pretty. |
| 971 $('search-field').value = term; | 970 $('search-field').value = term; |
| 972 if (grouped) { | 971 if (grouped) |
|
Patrick Dubroy
2013/01/30 19:23:04
I'd change this to:
$('display-filter-sites')
Sergiu
2013/02/05 18:21:23
Done.
| |
| 973 $('display-filter-sites').checked = true; | 972 $('display-filter-sites').checked = true; |
| 974 } else { | 973 else |
| 975 $('display-filter-sites').checked = false; | 974 $('display-filter-sites').checked = false; |
| 976 } | |
| 977 var hash = this.getHashData(); | 975 var hash = this.getHashData(); |
| 978 if (hash.q != term || hash.p != page || hash.g != grouped) { | 976 if (hash.q != term || hash.p != page || hash.g != grouped) { |
| 979 window.location.hash = PageState.getHashString( | 977 window.location.hash = PageState.getHashString( |
| 980 term, page, grouped); | 978 term, page, grouped); |
| 981 } | 979 } |
| 982 }; | 980 }; |
| 983 | 981 |
| 984 /** | 982 /** |
| 985 * Static method to get the hash string for a specified state | 983 * Static method to get the hash string for a specified state |
| 986 * @param {string} term The current search string. | 984 * @param {string} term The current search string. |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1306 historyView.reload(); | 1304 historyView.reload(); |
| 1307 } | 1305 } |
| 1308 | 1306 |
| 1309 // Add handlers to HTML elements. | 1307 // Add handlers to HTML elements. |
| 1310 document.addEventListener('DOMContentLoaded', load); | 1308 document.addEventListener('DOMContentLoaded', load); |
| 1311 | 1309 |
| 1312 // This event lets us enable and disable menu items before the menu is shown. | 1310 // This event lets us enable and disable menu items before the menu is shown. |
| 1313 document.addEventListener('canExecute', function(e) { | 1311 document.addEventListener('canExecute', function(e) { |
| 1314 e.canExecute = true; | 1312 e.canExecute = true; |
| 1315 }); | 1313 }); |
| OLD | NEW |