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

Unified Diff: chrome/browser/resources/md_history/searched_label.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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/md_history/searched_label.js
diff --git a/chrome/browser/resources/md_history/searched_label.js b/chrome/browser/resources/md_history/searched_label.js
new file mode 100644
index 0000000000000000000000000000000000000000..7bcefee1c863174216e798c5d3feb90a53aba055
--- /dev/null
+++ b/chrome/browser/resources/md_history/searched_label.js
@@ -0,0 +1,50 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+Polymer({
+ is: 'history-searched-label',
+
+ properties: {
+ // The text to show in this label.
+ title: String,
+
+ // The search term to bold within the title.
+ searchTerm: String,
+ },
+
+ observers: ['setSearchedTextToBold_(title, searchTerm)'],
+
+ /**
+ * Updates the page title. If the result was from a search, highlights any
tsergeant 2016/06/08 07:25:06 Nit: Update this comment.
calamity 2016/06/14 01:51:45 Done.
+ * occurrences of the search term in bold.
+ * @private
+ */
+ setSearchedTextToBold_: function() {
+ var i = 0;
+ var titleElem = this.$.container;
+ var titleText = this.title;
+
+ if (this.searchTerm == '' || this.searchTerm == null) {
+ titleElem.textContent = titleText;
+ return;
+ }
+
+ var re = new RegExp(quoteString(this.searchTerm), 'gim');
+ var match;
+ titleElem.textContent = '';
+ while (match = re.exec(titleText)) {
+ if (match.index > i)
+ titleElem.appendChild(document.createTextNode(
+ titleText.slice(i, match.index)));
+ i = re.lastIndex;
+ // Mark the highlighted text in bold.
+ var b = document.createElement('b');
+ b.textContent = titleText.substring(match.index, i);
+ titleElem.appendChild(b);
+ }
+ if (i < titleText.length)
+ titleElem.appendChild(
+ document.createTextNode(titleText.slice(i)));
+ },
+});

Powered by Google App Engine
This is Rietveld 408576698