Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: chrome/browser/resources/md_history/history_item.js

Issue 1993613002: [MD History] Implement grouped history UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@privatize
Patch Set: address comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 Polymer({ 5 cr.define('md_history', function() {
6 is: 'history-item', 6 var HistoryItem = Polymer({
7 is: 'history-item',
7 8
8 properties: { 9 properties: {
9 // Underlying HistoryEntry data for this item. Contains read-only fields 10 // Underlying HistoryEntry data for this item. Contains read-only fields
10 // from the history backend, as well as fields computed by history-list. 11 // from the history backend, as well as fields computed by history-list.
11 item: { 12 item: {type: Object, observer: 'showIcon_'},
12 type: Object, 13
13 observer: 'showIcon_' 14 // True if the website is a bookmarked page.
15 starred: {type: Boolean, reflectToAttribute: true},
16
17 // Search term used to obtain this history-item.
18 searchTerm: {type: String},
19
20 selected: {type: Boolean, notify: true},
21
22 isCardStart: {type: Boolean, reflectToAttribute: true},
23
24 isCardEnd: {type: Boolean, reflectToAttribute: true},
25
26 hasTimeGap: {type: Boolean},
27
28 numberOfItems: {type: Number}
14 }, 29 },
15 30
16 // True if the website is a bookmarked page. 31 observers: ['setSearchedTextToBold_(item.title, searchTerm)'],
17 starred: { 32
18 type: Boolean, 33 /**
19 reflectToAttribute: true 34 * When a history-item is selected the toolbar is notified and increases
35 * or decreases its count of selected items accordingly.
36 * @private
37 */
38 onCheckboxSelected_: function() {
39 this.fire('history-checkbox-select', {
40 countAddition: this.$.checkbox.checked ? 1 : -1
41 });
20 }, 42 },
21 43
22 // Search term used to obtain this history-item. 44 /**
23 searchTerm: { 45 * Fires a custom event when the menu button is clicked. Sends the details
24 type: String 46 * of the history item and where the menu should appear.
47 */
48 onMenuButtonTap_: function(e) {
49 this.fire('toggle-menu', {
50 target: Polymer.dom(e).localTarget,
51 item: this.item,
52 });
53
54 // Stops the 'tap' event from closing the menu when it opens.
55 e.stopPropagation();
25 }, 56 },
26 57
27 selected: { 58 /**
28 type: Boolean, 59 * Set the favicon image, based on the URL of the history item.
29 notify: true 60 * @private
61 */
62 showIcon_: function() {
63 this.$.icon.style.backgroundImage =
64 cr.icon.getFaviconImageSet(this.item.url);
30 }, 65 },
31 66
32 isCardStart: { 67 /**
33 type: Boolean, 68 * Updates the page title. If the result was from a search, highlights any
34 reflectToAttribute: true 69 * occurrences of the search term in bold.
70 * @private
71 */
72 setSearchedTextToBold_: function() {
73 var i = 0;
74 var titleElem = this.$.title;
75 var titleText = this.item.title;
76
77 if (this.searchTerm == '' || this.searchTerm == null) {
78 titleElem.textContent = titleText;
79 return;
80 }
81
82 var re = new RegExp(quoteString(this.searchTerm), 'gim');
83 var match;
84 titleElem.textContent = '';
85 while (match = re.exec(titleText)) {
86 if (match.index > i)
87 titleElem.appendChild(document.createTextNode(
88 titleText.slice(i, match.index)));
89 i = re.lastIndex;
90 // Mark the highlighted text in bold.
91 var b = document.createElement('b');
92 b.textContent = titleText.substring(match.index, i);
93 titleElem.appendChild(b);
94 }
95 if (i < titleText.length)
96 titleElem.appendChild(
97 document.createTextNode(titleText.slice(i)));
35 }, 98 },
36 99
37 isCardEnd: { 100 selectionNotAllowed_: function() {
38 type: Boolean, 101 return !loadTimeData.getBoolean('allowDeletingHistory');
39 reflectToAttribute: true
40 }, 102 },
41 103
42 hasTimeGap: { 104 /**
43 type: Boolean 105 * Generates the title for this history card.
44 }, 106 * @param {number} numberOfItems The number of items in the card.
107 * @param {string} search The search term associated with these results.
108 * @private
109 */
110 cardTitle_: function(numberOfItems, historyDate, search) {
111 if (!search)
112 return this.item.dateRelativeDay;
45 113
46 numberOfItems: { 114 var resultId = numberOfItems == 1 ? 'searchResult' : 'searchResults';
47 type: Number 115 return loadTimeData.getStringF('foundSearchResults', numberOfItems,
116 loadTimeData.getString(resultId), search);
48 } 117 }
49 }, 118 });
50
51 observers: [
52 'setSearchedTextToBold_(item.title, searchTerm)'
53 ],
54 119
55 /** 120 /**
56 * When a history-item is selected the toolbar is notified and increases 121 * Check whether the time difference between the given history item and the
57 * or decreases its count of selected items accordingly. 122 * next one is large enough for a spacer to be required.
123 * @param {Array<HistoryEntry>} visits
124 * @param {number} currentIndex
125 * @param {string} searchedTerm
126 * @return {boolean} Whether or not time gap separator is required.
58 * @private 127 * @private
59 */ 128 */
60 onCheckboxSelected_: function() { 129 HistoryItem.needsTimeGap = function(visits, currentIndex, searchedTerm) {
61 this.fire('history-checkbox-select', { 130 if (currentIndex >= visits.length - 1 || visits.length == 0)
62 countAddition: this.$.checkbox.checked ? 1 : -1 131 return false;
63 });
64 },
65 132
66 /** 133 var currentItem = visits[currentIndex];
67 * Fires a custom event when the menu button is clicked. Sends the details of 134 var nextItem = visits[currentIndex + 1];
68 * the history item and where the menu should appear.
69 */
70 onMenuButtonTap_: function(e) {
71 this.fire('toggle-menu', {
72 target: Polymer.dom(e).localTarget,
73 item: this.item,
74 });
75 135
76 // Stops the 'tap' event from closing the menu when it opens. 136 if (searchedTerm)
77 e.stopPropagation(); 137 return currentItem.dateShort != nextItem.dateShort;
78 },
79 138
80 /** 139 return currentItem.time - nextItem.time > BROWSING_GAP_TIME &&
81 * Set the favicon image, based on the URL of the history item. 140 currentItem.dateRelativeDay == nextItem.dateRelativeDay;
82 * @private 141 };
83 */
84 showIcon_: function() {
85 this.$.icon.style.backgroundImage =
86 cr.icon.getFaviconImageSet(this.item.url);
87 },
88 142
89 /** 143 return { HistoryItem: HistoryItem };
90 * Updates the page title. If the result was from a search, highlights any
91 * occurrences of the search term in bold.
92 * @private
93 */
94 setSearchedTextToBold_: function() {
95 var i = 0;
96 var titleElem = this.$.title;
97 var titleText = this.item.title;
98
99 if (this.searchTerm == '' || this.searchTerm == null) {
100 titleElem.textContent = titleText;
101 return;
102 }
103
104 var re = new RegExp(quoteString(this.searchTerm), 'gim');
105 var match;
106 titleElem.textContent = '';
107 while (match = re.exec(titleText)) {
108 if (match.index > i)
109 titleElem.appendChild(document.createTextNode(
110 titleText.slice(i, match.index)));
111 i = re.lastIndex;
112 // Mark the highlighted text in bold.
113 var b = document.createElement('b');
114 b.textContent = titleText.substring(match.index, i);
115 titleElem.appendChild(b);
116 }
117 if (i < titleText.length)
118 titleElem.appendChild(
119 document.createTextNode(titleText.slice(i)));
120 },
121
122 selectionNotAllowed_: function() {
123 return !loadTimeData.getBoolean('allowDeletingHistory');
124 },
125
126 /**
127 * Generates the title for this history card.
128 * @param {number} numberOfItems The number of items in the card.
129 * @param {string} search The search term associated with these results.
130 * @private
131 */
132 cardTitle_: function(numberOfItems, historyDate, search) {
133 if (!search)
134 return this.item.dateRelativeDay;
135
136 var resultId = numberOfItems == 1 ? 'searchResult' : 'searchResults';
137 return loadTimeData.getStringF('foundSearchResults', numberOfItems,
138 loadTimeData.getString(resultId), search);
139 }
140 }); 144 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_history/history_item.html ('k') | chrome/browser/resources/md_history/history_list.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698