Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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; | |
|
calamity
2016/02/05 02:30:10
Pull this.$.title into a local var here.
tsergeant
2016/02/08 22:59:01
Bump on the comments in this file.
hsampson
2016/02/09 02:17:51
Done.
| |
| 110 if ((this.searchTerm != '') && (this.searchTerm != null)) { | |
|
calamity
2016/02/05 02:30:10
nit: less parens.
hsampson
2016/02/09 02:17:51
Done.
| |
| 111 var searchText = new RegExp(this.quoteString_(this.searchTerm), 'gim'); | |
|
calamity
2016/02/05 02:30:10
nit: TBH, I kinda like just calling this re. searc
hsampson
2016/02/09 02:17:51
Done.
| |
| 112 var match; | |
| 113 this.$.title.textContent = ''; | |
| 114 while (match = searchText.exec(this.websiteTitle_)) { | |
| 115 if (match.index > i) | |
|
calamity
2016/02/05 02:30:10
nit: This one needs braces since the content is 2
hsampson
2016/02/09 02:17:51
NA now.
| |
| 116 this.$.title.appendChild(document.createTextNode( | |
| 117 this.websiteTitle_.slice(i, match.index))); | |
| 118 i = searchText.lastIndex; | |
| 119 // Mark the highlighted text in bold. | |
| 120 var b = document.createElement('b'); | |
| 121 b.textContent = this.websiteTitle_.substring(match.index, i); | |
| 122 this.$.title.appendChild(b); | |
| 123 } | |
| 124 if (i < this.websiteTitle_.length) | |
| 125 this.$.title.appendChild(document.createTextNode( | |
| 126 this.websiteTitle_.slice(i))); | |
| 127 } else { | |
| 128 this.$.title.textContent = this.websiteTitle_; | |
|
calamity
2016/02/05 02:30:10
Invert the condition above and early return in thi
hsampson
2016/02/09 02:17:51
No idea what that is :P but done I think.
| |
| 129 } | |
| 130 }, | |
| 131 | |
| 132 /** | |
| 133 * Quote a string so it can be used in a regular expression. | |
| 134 * @param {string} searchTerm The source string. | |
| 135 * @return {string} The escaped string. | |
| 136 * @private | |
| 137 */ | |
| 138 quoteString_: function(searchTerm) { | |
| 139 return searchTerm.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, | |
| 140 '\\$1'); | |
| 93 } | 141 } |
| 94 }); | 142 }); |
| OLD | NEW |