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

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

Issue 2046303002: [MD History] Add history-searched-label to embolden the synced device search. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@disable_grouped
Patch Set: Created 4 years, 6 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 cr.define('md_history', function() { 5 cr.define('md_history', function() {
6 var HistoryItem = Polymer({ 6 var HistoryItem = Polymer({
7 is: 'history-item', 7 is: 'history-item',
8 8
9 properties: { 9 properties: {
10 // Underlying HistoryEntry data for this item. Contains read-only fields 10 // Underlying HistoryEntry data for this item. Contains read-only fields
(...skipping 10 matching lines...) Expand all
21 21
22 isCardStart: {type: Boolean, reflectToAttribute: true}, 22 isCardStart: {type: Boolean, reflectToAttribute: true},
23 23
24 isCardEnd: {type: Boolean, reflectToAttribute: true}, 24 isCardEnd: {type: Boolean, reflectToAttribute: true},
25 25
26 hasTimeGap: {type: Boolean}, 26 hasTimeGap: {type: Boolean},
27 27
28 numberOfItems: {type: Number} 28 numberOfItems: {type: Number}
29 }, 29 },
30 30
31 observers: ['setSearchedTextToBold_(item.title, searchTerm)'],
32
33 /** 31 /**
34 * When a history-item is selected the toolbar is notified and increases 32 * When a history-item is selected the toolbar is notified and increases
35 * or decreases its count of selected items accordingly. 33 * or decreases its count of selected items accordingly.
36 * @private 34 * @private
37 */ 35 */
38 onCheckboxSelected_: function() { 36 onCheckboxSelected_: function() {
39 this.fire('history-checkbox-select', { 37 this.fire('history-checkbox-select', {
40 countAddition: this.$.checkbox.checked ? 1 : -1 38 countAddition: this.$.checkbox.checked ? 1 : -1
41 }); 39 });
42 }, 40 },
(...skipping 14 matching lines...) Expand all
57 55
58 /** 56 /**
59 * Set the favicon image, based on the URL of the history item. 57 * Set the favicon image, based on the URL of the history item.
60 * @private 58 * @private
61 */ 59 */
62 showIcon_: function() { 60 showIcon_: function() {
63 this.$.icon.style.backgroundImage = 61 this.$.icon.style.backgroundImage =
64 cr.icon.getFaviconImageSet(this.item.url); 62 cr.icon.getFaviconImageSet(this.item.url);
65 }, 63 },
66 64
67 /**
68 * Updates the page title. If the result was from a search, highlights any
69 * occurrences of the search term in bold.
70 * @private
71 */
72 // TODO(calamity): Pull this bolding behavior into a separate element for
73 // synced device search.
74 setSearchedTextToBold_: function() {
75 var i = 0;
76 var titleElem = this.$.title;
77 var titleText = this.item.title;
78
79 if (this.searchTerm == '' || this.searchTerm == null) {
80 titleElem.textContent = titleText;
81 return;
82 }
83
84 var re = new RegExp(quoteString(this.searchTerm), 'gim');
85 var match;
86 titleElem.textContent = '';
87 while (match = re.exec(titleText)) {
88 if (match.index > i)
89 titleElem.appendChild(document.createTextNode(
90 titleText.slice(i, match.index)));
91 i = re.lastIndex;
92 // Mark the highlighted text in bold.
93 var b = document.createElement('b');
94 b.textContent = titleText.substring(match.index, i);
95 titleElem.appendChild(b);
96 }
97 if (i < titleText.length)
98 titleElem.appendChild(
99 document.createTextNode(titleText.slice(i)));
100 },
101
102 selectionNotAllowed_: function() { 65 selectionNotAllowed_: function() {
103 return !loadTimeData.getBoolean('allowDeletingHistory'); 66 return !loadTimeData.getBoolean('allowDeletingHistory');
104 }, 67 },
105 68
106 /** 69 /**
107 * Generates the title for this history card. 70 * Generates the title for this history card.
108 * @param {number} numberOfItems The number of items in the card. 71 * @param {number} numberOfItems The number of items in the card.
109 * @param {string} search The search term associated with these results. 72 * @param {string} search The search term associated with these results.
110 * @private 73 * @private
111 */ 74 */
(...skipping 25 matching lines...) Expand all
137 100
138 if (searchedTerm) 101 if (searchedTerm)
139 return currentItem.dateShort != nextItem.dateShort; 102 return currentItem.dateShort != nextItem.dateShort;
140 103
141 return currentItem.time - nextItem.time > BROWSING_GAP_TIME && 104 return currentItem.time - nextItem.time > BROWSING_GAP_TIME &&
142 currentItem.dateRelativeDay == nextItem.dateRelativeDay; 105 currentItem.dateRelativeDay == nextItem.dateRelativeDay;
143 }; 106 };
144 107
145 return { HistoryItem: HistoryItem }; 108 return { HistoryItem: HistoryItem };
146 }); 109 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698