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

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

Issue 2313823002: MD History: Remove shadow root from <history-searched-label> (Closed)
Patch Set: Fix tests Created 4 years, 3 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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-searched-label', 6 is: 'history-searched-label',
7 7
8 properties: { 8 properties: {
9 // The text to show in this label. 9 // The text to show in this label.
10 title: String, 10 title: String,
11 11
12 // The search term to bold within the title. 12 // The search term to bold within the title.
13 searchTerm: String, 13 searchTerm: String,
14 }, 14 },
15 15
16 observers: ['setSearchedTextToBold_(title, searchTerm)'], 16 observers: ['setSearchedTextToBold_(title, searchTerm)'],
17 17
18 /** 18 /**
19 * Updates the page title. If a search term is specified, highlights any 19 * Updates the page title. If a search term is specified, highlights any
20 * occurrences of the search term in bold. 20 * occurrences of the search term in bold.
21 * @private 21 * @private
22 */ 22 */
23 setSearchedTextToBold_: function() { 23 setSearchedTextToBold_: function() {
24 var i = 0; 24 var i = 0;
25 var titleElem = this.$.container;
26 var titleText = this.title; 25 var titleText = this.title;
27 26
28 if (this.searchTerm == '' || this.searchTerm == null) { 27 if (this.searchTerm == '' || this.searchTerm == null) {
29 titleElem.textContent = titleText; 28 this.textContent = titleText;
30 return; 29 return;
31 } 30 }
32 31
33 var re = new RegExp(quoteString(this.searchTerm), 'gim'); 32 var re = new RegExp(quoteString(this.searchTerm), 'gim');
34 var match; 33 var match;
35 titleElem.textContent = ''; 34 this.textContent = '';
36 while (match = re.exec(titleText)) { 35 while (match = re.exec(titleText)) {
37 if (match.index > i) 36 if (match.index > i)
Dan Beam 2016/09/06 15:54:32 nit: curlies
38 titleElem.appendChild(document.createTextNode( 37 this.appendChild(document.createTextNode(
39 titleText.slice(i, match.index))); 38 titleText.slice(i, match.index)));
40 i = re.lastIndex; 39 i = re.lastIndex;
41 // Mark the highlighted text in bold. 40 // Mark the highlighted text in bold.
42 var b = document.createElement('b'); 41 var b = document.createElement('b');
43 b.textContent = titleText.substring(match.index, i); 42 b.textContent = titleText.substring(match.index, i);
44 titleElem.appendChild(b); 43 this.appendChild(b);
45 } 44 }
46 if (i < titleText.length) 45 if (i < titleText.length)
47 titleElem.appendChild( 46 this.appendChild(
Dan Beam 2016/09/06 15:54:32 nit: curlies
48 document.createTextNode(titleText.slice(i))); 47 document.createTextNode(titleText.slice(i)));
49 }, 48 },
50 }); 49 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_history/searched_label.html ('k') | chrome/test/data/webui/md_history/history_list_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698