* _updateTitle * Updates the title of the tab (by setting `document.title`)
()
| 247 | * Updates the title of the tab (by setting `document.title`) |
| 248 | */ |
| 249 | _updateTitle() { |
| 250 | if (!this._started || this._paused) return; |
| 251 | if (!this.doUpdateTitle) return; |
| 252 | |
| 253 | const context = this.context; |
| 254 | const editor = context.systems.editor; |
| 255 | const graph = editor.staging.graph; |
| 256 | const l10n = context.systems.l10n; |
| 257 | const changeCount = editor.difference().summary().size; |
| 258 | |
| 259 | // Currently only support OSM ids |
| 260 | let selected; |
| 261 | const selectedIDs = context.selectedIDs().filter(id => graph.hasEntity(id)); |
| 262 | if (selectedIDs.length) { |
| 263 | const firstLabel = l10n.displayLabel(graph.entity(selectedIDs[0]), graph); |
| 264 | if (selectedIDs.length > 1) { |
| 265 | selected = l10n.t('title.labeled_and_more', { labeled: firstLabel, count: selectedIDs.length - 1 }); |
| 266 | } else { |
| 267 | selected = firstLabel; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | let format; |
| 272 | if (changeCount && selected) { |
| 273 | format = 'title.format.changes_context'; |
| 274 | } else if (changeCount && !selected) { |
| 275 | format = 'title.format.changes'; |
| 276 | } else if (!changeCount && selected) { |
| 277 | format = 'title.format.context'; |
| 278 | } |
| 279 | |
| 280 | let title; |
| 281 | if (format) { |
| 282 | title = l10n.t(format, { changes: changeCount, base: this.titleBase, context: selected }); |
| 283 | } else { |
| 284 | title = this.titleBase; |
| 285 | } |
| 286 | |
| 287 | if (document.title !== title) { |
| 288 | document.title = title; |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | |
| 293 | /** |
no test coverage detected