| 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 // The date of these history items. | 9 // The date of these history items. |
| 10 historyDate: { | 10 historyDate: { |
| 11 type: String, | 11 type: String, |
| 12 value: '' | 12 value: '' |
| 13 }, | 13 }, |
| 14 | 14 |
| 15 timeAccessed: { | 15 visibleTimestamp: { |
| 16 type: String, | 16 type: String, |
| 17 value: '' | 17 value: '' |
| 18 }, | 18 }, |
| 19 | 19 |
| 20 websiteTitle: { | 20 websiteTitle: { |
| 21 type: String, | 21 type: String, |
| 22 value: '' | 22 value: '', |
| 23 observer: 'setSearchedTextToBold_' |
| 23 }, | 24 }, |
| 24 | 25 |
| 25 // Domain is the website text shown on the history-item next to the title. | 26 // Domain is the website text shown on the history-item next to the title. |
| 26 // Gives the user some idea of which history items are different pages | 27 // Gives the user some idea of which history items are different pages |
| 27 // belonging to the same site, and can be used to look for more items | 28 // belonging to the same site, and can be used to look for more items |
| 28 // from the same site. | 29 // from the same site. |
| 29 websiteDomain: { | 30 websiteDomain: { |
| 30 type: String, | 31 type: String, |
| 31 value: '' | 32 value: '' |
| 32 }, | 33 }, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 46 value: false, | 47 value: false, |
| 47 reflectToAttribute: true | 48 reflectToAttribute: true |
| 48 }, | 49 }, |
| 49 | 50 |
| 50 // The time in seconds of when the website was accessed. | 51 // The time in seconds of when the website was accessed. |
| 51 timestamp: { | 52 timestamp: { |
| 52 type: Number, | 53 type: Number, |
| 53 value: 0 | 54 value: 0 |
| 54 }, | 55 }, |
| 55 | 56 |
| 57 // Search term used in the chrome.send to obtain this history-item. |
| 58 searchTerm: { |
| 59 type: String, |
| 60 value: '', |
| 61 observer: 'setSearchedTextToBold_' |
| 62 }, |
| 63 |
| 56 selected: { | 64 selected: { |
| 57 type: Boolean, | 65 type: Boolean, |
| 58 value: false, | 66 value: false, |
| 59 notify: true | 67 notify: true |
| 60 }, | 68 }, |
| 61 | 69 |
| 62 isCardStart: { | 70 isCardStart: { |
| 63 type: Boolean, | 71 type: Boolean, |
| 64 value: false, | 72 value: false, |
| 65 reflectToAttribute: true | 73 reflectToAttribute: true |
| 66 }, | 74 }, |
| 67 | 75 |
| 68 isCardEnd: { | 76 isCardEnd: { |
| 69 type: Boolean, | 77 type: Boolean, |
| 70 value: false, | 78 value: false, |
| 71 reflectToAttribute: true | 79 reflectToAttribute: true |
| 72 }, | 80 }, |
| 73 | 81 |
| 74 hasTimeGap: { | 82 hasTimeGap: { |
| 75 type: Boolean, | 83 type: Boolean, |
| 76 value: false | 84 value: false |
| 85 }, |
| 86 |
| 87 numberOfItems: { |
| 88 type: Number, |
| 89 value: 0 |
| 77 } | 90 } |
| 78 }, | 91 }, |
| 79 | 92 |
| 80 /** | 93 /** |
| 81 * When a history-item is selected the toolbar is notified and increases | 94 * When a history-item is selected the toolbar is notified and increases |
| 82 * or decreases its count of selected items accordingly. | 95 * or decreases its count of selected items accordingly. |
| 83 * @private | 96 * @private |
| 84 */ | 97 */ |
| 85 onCheckboxSelected_: function() { | 98 onCheckboxSelected_: function() { |
| 86 this.fire('history-checkbox-select', { | 99 this.fire('history-checkbox-select', { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 108 this.fire('toggle-menu', { | 121 this.fire('toggle-menu', { |
| 109 x: position.left, | 122 x: position.left, |
| 110 y: position.top, | 123 y: position.top, |
| 111 accessTime: this.timestamp | 124 accessTime: this.timestamp |
| 112 }); | 125 }); |
| 113 | 126 |
| 114 // Stops the 'tap' event from closing the menu when it opens. | 127 // Stops the 'tap' event from closing the menu when it opens. |
| 115 e.stopPropagation(); | 128 e.stopPropagation(); |
| 116 }, | 129 }, |
| 117 | 130 |
| 131 /** |
| 132 * If the results shown are search results set the search term to be bold |
| 133 * where it is displayed in the history-item title. |
| 134 * @private |
| 135 */ |
| 136 setSearchedTextToBold_: function() { |
| 137 var i = 0; |
| 138 var title = this.$.title; |
| 139 |
| 140 if (this.searchTerm == '' || this.searchTerm == null) { |
| 141 title.textContent = this.websiteTitle; |
| 142 return; |
| 143 } |
| 144 |
| 145 var re = new RegExp(this.quoteString_(this.searchTerm), 'gim'); |
| 146 var match; |
| 147 title.textContent = ''; |
| 148 while (match = re.exec(this.websiteTitle)) { |
| 149 if (match.index > i) |
| 150 title.appendChild(document.createTextNode( |
| 151 this.websiteTitle.slice(i, match.index))); |
| 152 i = re.lastIndex; |
| 153 // Mark the highlighted text in bold. |
| 154 var b = document.createElement('b'); |
| 155 b.textContent = this.websiteTitle.substring(match.index, i); |
| 156 title.appendChild(b); |
| 157 } |
| 158 if (i < this.websiteTitle.length) |
| 159 title.appendChild(document.createTextNode(this.websiteTitle.slice(i))); |
| 160 }, |
| 161 |
| 162 /** |
| 163 * Quote a string so it can be used in a regular expression. |
| 164 * @param {string} searchTerm The source string. |
| 165 * @return {string} The escaped string. |
| 166 * @private |
| 167 */ |
| 168 quoteString_: function(searchTerm) { |
| 169 return searchTerm.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, |
| 170 '\\$1'); |
| 171 }, |
| 172 |
| 118 selectionNotAllowed_: function() { | 173 selectionNotAllowed_: function() { |
| 119 return !loadTimeData.getBoolean('allowDeletingHistory'); | 174 return !loadTimeData.getBoolean('allowDeletingHistory'); |
| 175 }, |
| 176 |
| 177 /** |
| 178 * Generates the title for this history card. |
| 179 * @param {number} numberOfItems The number of items in the card. |
| 180 * @param {string} search The search term associated with these results. |
| 181 * @private |
| 182 */ |
| 183 listTitle_: function(numberOfItems, historyDate, search) { |
| 184 var resultId = numberOfItems == 1 ? 'searchResult' : 'searchResults'; |
| 185 |
| 186 if (search) |
| 187 return loadTimeData.getStringF('foundSearchResults', numberOfItems, |
| 188 loadTimeData.getString(resultId), search); |
| 189 else |
| 190 return historyDate; |
| 120 } | 191 } |
| 121 }); | 192 }); |
| OLD | NEW |