| 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 <include src="history_focus_manager.js"> | 6 <include src="history_focus_manager.js"> |
| 7 | 7 |
| 8 /////////////////////////////////////////////////////////////////////////////// | 8 /////////////////////////////////////////////////////////////////////////////// |
| 9 // Globals: | 9 // Globals: |
| 10 /** @const */ var RESULTS_PER_PAGE = 150; | 10 /** @const */ var RESULTS_PER_PAGE = 150; |
| (...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1304 /** | 1304 /** |
| 1305 * Clear the results in the view. Since we add results piecemeal, we need | 1305 * Clear the results in the view. Since we add results piecemeal, we need |
| 1306 * to clear them out when we switch to a new page or reload. | 1306 * to clear them out when we switch to a new page or reload. |
| 1307 * @private | 1307 * @private |
| 1308 */ | 1308 */ |
| 1309 HistoryView.prototype.clear_ = function() { | 1309 HistoryView.prototype.clear_ = function() { |
| 1310 var alertOverlay = $('alertOverlay'); | 1310 var alertOverlay = $('alertOverlay'); |
| 1311 if (alertOverlay && alertOverlay.classList.contains('showing')) | 1311 if (alertOverlay && alertOverlay.classList.contains('showing')) |
| 1312 hideConfirmationOverlay(); | 1312 hideConfirmationOverlay(); |
| 1313 | 1313 |
| 1314 this.resultDiv_.textContent = ''; | 1314 // Remove everything but <h3 id="results-header"> (the first child). |
| 1315 while (this.resultDiv_.children.length > 1) { |
| 1316 this.resultDiv_.removeChild(this.resultDiv_.lastElementChild); |
| 1317 } |
| 1318 $('results-header').textContent = ''; |
| 1315 | 1319 |
| 1316 this.currentVisits_.forEach(function(visit) { | 1320 this.currentVisits_.forEach(function(visit) { |
| 1317 visit.isRendered = false; | 1321 visit.isRendered = false; |
| 1318 }); | 1322 }); |
| 1319 this.currentVisits_ = []; | 1323 this.currentVisits_ = []; |
| 1320 | 1324 |
| 1321 document.body.classList.remove('has-results'); | 1325 document.body.classList.remove('has-results'); |
| 1322 }; | 1326 }; |
| 1323 | 1327 |
| 1324 /** | 1328 /** |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1566 var results = this.model_.visits_; | 1570 var results = this.model_.visits_; |
| 1567 if (this.getRangeInDays() == HistoryModel.Range.ALL_TIME) { | 1571 if (this.getRangeInDays() == HistoryModel.Range.ALL_TIME) { |
| 1568 var rangeStart = this.pageIndex_ * RESULTS_PER_PAGE; | 1572 var rangeStart = this.pageIndex_ * RESULTS_PER_PAGE; |
| 1569 var rangeEnd = rangeStart + RESULTS_PER_PAGE; | 1573 var rangeEnd = rangeStart + RESULTS_PER_PAGE; |
| 1570 results = this.model_.getNumberedRange(rangeStart, rangeEnd); | 1574 results = this.model_.getNumberedRange(rangeStart, rangeEnd); |
| 1571 } | 1575 } |
| 1572 var searchText = this.model_.getSearchText(); | 1576 var searchText = this.model_.getSearchText(); |
| 1573 var groupByDomain = this.model_.getGroupByDomain(); | 1577 var groupByDomain = this.model_.getGroupByDomain(); |
| 1574 | 1578 |
| 1575 if (searchText) { | 1579 if (searchText) { |
| 1576 // Add a header for the search results, if there isn't already one. | 1580 var headerText; |
| 1577 if (!this.resultDiv_.querySelector('h3')) { | 1581 if (!doneLoading) { |
| 1578 var header = document.createElement('h3'); | 1582 headerText = loadTimeData.getStringF('searchResultsFor', searchText); |
| 1579 header.textContent = loadTimeData.getStringF('searchResultsFor', | 1583 } else if (results.length == 0) { |
| 1580 searchText); | 1584 headerText = loadTimeData.getString('noSearchResults'); |
| 1581 this.resultDiv_.appendChild(header); | 1585 } else { |
| 1586 var resultId = results.length == 1 ? 'searchResult' : 'searchResults'; |
| 1587 headerText = loadTimeData.getStringF('foundSearchResults', |
| 1588 results.length, |
| 1589 loadTimeData.getString(resultId), |
| 1590 searchText); |
| 1582 } | 1591 } |
| 1592 $('results-header').textContent = headerText; |
| 1583 | 1593 |
| 1584 this.addTimeframeInterval_(this.resultDiv_); | 1594 this.addTimeframeInterval_(this.resultDiv_); |
| 1585 | 1595 |
| 1586 var searchResults = createElementWithClassName('ol', 'search-results'); | 1596 var searchResults = createElementWithClassName('ol', 'search-results'); |
| 1587 | 1597 |
| 1588 // Don't add checkboxes if entries can not be edited. | 1598 // Don't add checkboxes if entries can not be edited. |
| 1589 if (!this.model_.editingEntriesAllowed) | 1599 if (!this.model_.editingEntriesAllowed) |
| 1590 searchResults.classList.add('no-checkboxes'); | 1600 searchResults.classList.add('no-checkboxes'); |
| 1591 | 1601 |
| 1592 if (results.length == 0 && doneLoading) { | 1602 if (doneLoading) { |
| 1593 var noSearchResults = searchResults.appendChild( | |
| 1594 createElementWithClassName('div', 'no-results-message')); | |
| 1595 noSearchResults.textContent = loadTimeData.getString('noSearchResults'); | |
| 1596 } else { | |
| 1597 for (var i = 0, visit; visit = results[i]; i++) { | 1603 for (var i = 0, visit; visit = results[i]; i++) { |
| 1598 if (!visit.isRendered) { | 1604 if (!visit.isRendered) { |
| 1599 searchResults.appendChild(visit.getResultDOM({ | 1605 searchResults.appendChild(visit.getResultDOM({ |
| 1600 isSearchResult: true, | 1606 isSearchResult: true, |
| 1601 addTitleFavicon: true | 1607 addTitleFavicon: true |
| 1602 })); | 1608 })); |
| 1603 this.setVisitRendered_(visit); | 1609 this.setVisitRendered_(visit); |
| 1604 } | 1610 } |
| 1605 } | 1611 } |
| 1606 } | 1612 } |
| 1607 this.resultDiv_.appendChild(searchResults); | 1613 this.resultDiv_.appendChild(searchResults); |
| 1608 } else { | 1614 } else { |
| 1609 var resultsFragment = document.createDocumentFragment(); | 1615 var resultsFragment = document.createDocumentFragment(); |
| 1610 | 1616 |
| 1611 this.addTimeframeInterval_(resultsFragment); | 1617 this.addTimeframeInterval_(resultsFragment); |
| 1612 | 1618 |
| 1613 if (results.length == 0 && doneLoading) { | 1619 var noResults = results.length == 0 && doneLoading; |
| 1614 var noResults = resultsFragment.appendChild( | 1620 $('results-header').textContent = noResults ? |
| 1615 createElementWithClassName('div', 'no-results-message')); | 1621 loadTimeData.getString('noResults') : ''; |
| 1616 noResults.textContent = loadTimeData.getString('noResults'); | 1622 |
| 1617 this.resultDiv_.appendChild(resultsFragment); | 1623 if (noResults) |
| 1618 return; | 1624 return; |
| 1619 } | |
| 1620 | 1625 |
| 1621 if (this.getRangeInDays() == HistoryModel.Range.MONTH && | 1626 if (this.getRangeInDays() == HistoryModel.Range.MONTH && |
| 1622 groupByDomain) { | 1627 groupByDomain) { |
| 1623 // Group everything together in the month view. | 1628 // Group everything together in the month view. |
| 1624 this.addMonthResults_(results, resultsFragment); | 1629 this.addMonthResults_(results, resultsFragment); |
| 1625 } else { | 1630 } else { |
| 1626 var dayStart = 0; | 1631 var dayStart = 0; |
| 1627 var dayEnd = 0; | 1632 var dayEnd = 0; |
| 1628 // Go through all of the visits and process them in chunks of one day. | 1633 // Go through all of the visits and process them in chunks of one day. |
| 1629 while (dayEnd < results.length) { | 1634 while (dayEnd < results.length) { |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2322 historyView.reload(); | 2327 historyView.reload(); |
| 2323 } | 2328 } |
| 2324 | 2329 |
| 2325 // Add handlers to HTML elements. | 2330 // Add handlers to HTML elements. |
| 2326 document.addEventListener('DOMContentLoaded', load); | 2331 document.addEventListener('DOMContentLoaded', load); |
| 2327 | 2332 |
| 2328 // This event lets us enable and disable menu items before the menu is shown. | 2333 // This event lets us enable and disable menu items before the menu is shown. |
| 2329 document.addEventListener('canExecute', function(e) { | 2334 document.addEventListener('canExecute', function(e) { |
| 2330 e.canExecute = true; | 2335 e.canExecute = true; |
| 2331 }); | 2336 }); |
| OLD | NEW |