update document title

This commit is contained in:
Katarzyna Król
2020-01-14 18:47:19 +01:00
parent 57d70ac04b
commit 91b67277bd
2 changed files with 53 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ import _throttle from 'lodash-es/throttle';
import { select as d3_select } from 'd3-selection';
import { utilDisplayLabel } from '../util';
import { geoSphericalDistance } from '../geo';
import { modeBrowse } from '../modes/browse';
import { utilObjectOmit, utilQsString, utilStringQs } from '../util';
@@ -29,7 +30,6 @@ export function behaviorHash(context) {
if (mode && mode.id.match(/^draw/) !== null && dist > maxdist) {
context.enter(modeBrowse(context));
}
map.centerZoom([args[2], Math.min(lat, Math.max(-lat, args[1]))], args[0]);
}
};
@@ -51,6 +51,7 @@ export function behaviorHash(context) {
if (selected.length) {
newParams.id = selected.join(',');
}
updateTitle(selected);
newParams.map = zoom.toFixed(2) +
'/' + center[1].toFixed(precision) +
@@ -59,6 +60,33 @@ export function behaviorHash(context) {
return '#' + utilQsString(Object.assign(q, newParams), true);
};
function updateTitle(selected){
var oldTitle = document.title;
var endIndex = oldTitle.indexOf("-");
var oldIDStr = oldTitle.substring(endIndex+2);
if (selected.length === 1) {
if (endIndex === -1) {
oldTitle += " - " + utilDisplayLabel(context.entity(selected[0]), context);
}
else {
var newIDStr = utilDisplayLabel(context.entity(selected[0]), context);
oldTitle = oldTitle.replace(oldIDStr, newIDStr);
}
}
else if (selected.length > 1 ) {
var newIDStr = utilDisplayLabel(context.entity(selected[0]), context) + " and " + (selected.length-1).toString() + " more";
oldTitle = oldTitle.replace(oldIDStr, newIDStr);
}
else{
if(endIndex !== -1){
var oldIDStr = oldTitle.substring(endIndex);
oldTitle = oldTitle.replace(oldIDStr, "");
}
}
document.title = oldTitle;
}
function update() {
if (context.inIntro()) return;
@@ -94,8 +122,11 @@ export function behaviorHash(context) {
var q = utilStringQs(window.location.hash.substring(1));
if (q.id) {
context.zoomToEntity(q.id.split(',')[0], !q.map);
}
if (!context.history().hasRestorableChanges()) {
// targeting specific features: download, select, and zoom to them
context.zoomToEntities(q.id.split(','));
}
}
// Store these here instead of updating local storage since local
// storage could be flushed if the user discards pending changes

View File

@@ -51,10 +51,29 @@ export function uiToolSave(context) {
}
}
function updateTitle(val) {
var oldTitle = document.title;
var endIndex = oldTitle.indexOf(")");
var oldIDStr = oldTitle.substring(0, endIndex+1);
var newIDStr = "iD (" + val.toString() + ")";
if(val === 0) {
oldTitle = oldTitle.replace(oldIDStr, "iD");
}
else if(_numChanges !== 0){
oldTitle = oldTitle.replace(oldIDStr, newIDStr);
}
else {
oldTitle = oldTitle.replace("iD", newIDStr);
}
document.title = oldTitle;
}
function updateCount() {
var val = history.difference().summary().length;
if (val === _numChanges) return;
updateTitle(val);
_numChanges = val;
if (tooltipBehavior) {