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

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: Hide cards that haven't been rerendered from previous chrome.send(). 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 properties: { 7 properties: {
8 timeAccessed: { 8 timeAccessed: {
9 type: String, 9 type: String,
10 value: '' 10 value: ''
11 }, 11 },
12 12
13 websiteTitle: { 13 websiteTitle: {
14 type: String, 14 type: String,
15 value: '' 15 value: '',
16 observer: 'setSearchedTextToBold_'
16 }, 17 },
17 18
18 // Domain is the website text shown on the history-item next to the title. 19 // Domain is the website text shown on the history-item next to the title.
19 // Gives the user some idea of which history items are different pages 20 // Gives the user some idea of which history items are different pages
20 // belonging to the same site, and can be used to look for more items 21 // belonging to the same site, and can be used to look for more items
21 // from the same site. 22 // from the same site.
22 websiteDomain: { 23 websiteDomain: {
23 type: String, 24 type: String,
24 value: '' 25 value: ''
25 }, 26 },
(...skipping 13 matching lines...) Expand all
39 value: false, 40 value: false,
40 reflectToAttribute: true 41 reflectToAttribute: true
41 }, 42 },
42 43
43 // The time in seconds of when the website was accessed. 44 // The time in seconds of when the website was accessed.
44 timestamp: { 45 timestamp: {
45 type: Number, 46 type: Number,
46 value: 0 47 value: 0
47 }, 48 },
48 49
50 // Search term used in the chrome.send to obtain this history-item.
51 searchTerm: {
52 type: String,
53 value: '',
54 observer: 'setSearchedTextToBold_'
55 },
56
49 selected: { 57 selected: {
50 type: Boolean, 58 type: Boolean,
51 value: false, 59 value: false,
52 notify: true 60 notify: true
53 } 61 }
54 }, 62 },
55 63
56 /** 64 /**
57 * When a history-item is selected the toolbar is notified and increases 65 * When a history-item is selected the toolbar is notified and increases
58 * or decreases its count of selected items accordingly. 66 * or decreases its count of selected items accordingly.
(...skipping 23 matching lines...) Expand all
82 openMenu: function(e) { 90 openMenu: function(e) {
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 // Stops the 'tap' event from closing the menu when it opens. 98 // Stops the 'tap' event from closing the menu when it opens.
91 e.stopPropagation(); 99 e.stopPropagation();
100 },
101
102 /**
103 * If the results shown are search results set the search term to be bold
104 * where it is displayed in the history-item title.
105 * @private
106 */
107 setSearchedTextToBold_: function() {
tsergeant 2016/02/02 02:57:36 This is generally good. The thing that's a little
hsampson 2016/02/03 02:37:59 Done.
108 var i = 0;
109 if ((this.searchTerm != '') && (this.searchTerm != null)) {
110 var searchText = new RegExp(this.quoteString_(this.searchTerm), 'gim');
111 var match;
112 this.$['title'].textContent = '';
tsergeant 2016/02/02 02:57:36 Just use this.$.title
hsampson 2016/02/03 02:37:59 Done.
113 while (match = searchText.exec(this.websiteTitle)) {
114 if (match.index > i)
115 this.$['title'].appendChild(document.createTextNode(
116 this.websiteTitle.slice(i, match.index)));
117 i = searchText.lastIndex;
118 // Mark the highlighted text in bold.
119 var b = document.createElement('b');
120 b.textContent = this.websiteTitle.substring(match.index, i);
121 this.$['title'].appendChild(b);
122 }
123 if (i < this.websiteTitle.length)
124 this.$['title'].appendChild(document.createTextNode(
125 this.websiteTitle.slice(i)));
126 } else {
127 this.$['title'].textContent = this.websiteTitle;
128 }
129 },
130
131 /**
132 * Quote a string so it can be used in a regular expression.
133 * @param {string} str The source string.
134 * @return {string} The escaped string.
135 * @private
136 */
137 quoteString_: function(searchTerm) {
138 return searchTerm.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g,
139 '\\$1');
92 } 140 }
93 }); 141 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698