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

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

Issue 1643693003: MD History: Implement search functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch_to_be_uploaded
Patch Set: Update comments. Created 4 years, 10 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 Polymer({
6 is: 'history-item', 6 is: 'history-item',
7 7
8 properties: { 8 properties: {
9 timeAccessed_: { 9 timeAccessed_: {
10 type: String, 10 type: String,
11 value: '' 11 value: ''
12 }, 12 },
13 13
14 websiteTitle_: { 14 websiteTitle_: {
15 type: String, 15 type: String,
16 value: '' 16 value: '',
17 observer: 'setSearchedTextToBold_'
17 }, 18 },
18 19
19 // Domain is the website text shown on the history-item next to the title. 20 // Domain is the website text shown on the history-item next to the title.
20 // Gives the user some idea of which history items are different pages 21 // Gives the user some idea of which history items are different pages
21 // belonging to the same site, and can be used to look for more items 22 // belonging to the same site, and can be used to look for more items
22 // from the same site. 23 // from the same site.
23 websiteDomain_: { 24 websiteDomain_: {
24 type: String, 25 type: String,
25 value: '' 26 value: ''
26 }, 27 },
(...skipping 13 matching lines...) Expand all
40 value: false, 41 value: false,
41 reflectToAttribute: true 42 reflectToAttribute: true
42 }, 43 },
43 44
44 // The time in seconds of when the website was accessed. 45 // The time in seconds of when the website was accessed.
45 timestamp_: { 46 timestamp_: {
46 type: Number, 47 type: Number,
47 value: 0 48 value: 0
48 }, 49 },
49 50
51 // Search term used in the chrome.send to obtain this history-item.
52 searchTerm: {
53 type: String,
54 value: '',
55 observer: 'setSearchedTextToBold_'
56 },
57
50 selected: { 58 selected: {
51 type: Boolean, 59 type: Boolean,
52 value: false, 60 value: false,
53 notify: true 61 notify: true
54 } 62 }
55 }, 63 },
56 64
57 /** 65 /**
58 * When a history-item is selected the toolbar is notified and increases 66 * When a history-item is selected the toolbar is notified and increases
59 * or decreases its count of selected items accordingly. 67 * or decreases its count of selected items accordingly.
(...skipping 23 matching lines...) Expand all
83 var position = this.$['menu-button'].getBoundingClientRect(); 91 var position = this.$['menu-button'].getBoundingClientRect();
84 92
85 this.fire('toggle-menu', { 93 this.fire('toggle-menu', {
86 x: position.left, 94 x: position.left,
87 y: position.top, 95 y: position.top,
88 accessTime: this.timestamp_ 96 accessTime: this.timestamp_
89 }); 97 });
90 98
91 // Stops the 'tap' event from closing the menu when it opens. 99 // Stops the 'tap' event from closing the menu when it opens.
92 e.stopPropagation(); 100 e.stopPropagation();
101 },
102
103 /**
104 * If the results shown are search results set the search term to be bold
105 * where it is displayed in the history-item title.
106 * @private
107 */
108 setSearchedTextToBold_: function() {
109 var i = 0;
110 var title = this.$.title;
111
112 if (this.searchTerm == '' || this.searchTerm == null) {
113 title.textContent = this.websiteTitle_;
114 return;
115 }
116
117 var re = new RegExp(this.quoteString_(this.searchTerm), 'gim');
118 var match;
119 title.textContent = '';
120 while (match = re.exec(this.websiteTitle_)) {
121 if (match.index > i)
122 title.appendChild(document.createTextNode(
123 this.websiteTitle_.slice(i, match.index)));
124 i = re.lastIndex;
125 // Mark the highlighted text in bold.
126 var b = document.createElement('b');
127 b.textContent = this.websiteTitle_.substring(match.index, i);
128 title.appendChild(b);
129 }
130 if (i < this.websiteTitle_.length)
131 title.appendChild(document.createTextNode(this.websiteTitle_.slice(i)));
132 },
133
134 /**
135 * Quote a string so it can be used in a regular expression.
136 * @param {string} searchTerm The source string.
137 * @return {string} The escaped string.
138 * @private
139 */
140 quoteString_: function(searchTerm) {
141 return searchTerm.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g,
142 '\\$1');
93 } 143 }
94 }); 144 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698