Skip to content

Commit

Permalink
Remove special chars from links
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbarbosa committed Dec 23, 2023
1 parent a0d889b commit 1c639de
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
3 changes: 2 additions & 1 deletion js/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function setInfo(type, data) {
if (data) {
const { name } = data;

/** @type {any[]} */
const paths = [data];

let flag = '';
Expand Down Expand Up @@ -89,7 +90,7 @@ export function setInfo(type, data) {
`

document.title = `${paths.map(path => path.name.ja.join('')).join(' / ')} / 日本`;
document.location.hash = paths.reverse().map(path => path.name.en).join('/');
document.location.hash = paths.reverse().map(path => replaceSpecialCharactersWithAscii(path.name.en)).join('/');
} else {
info.classList.remove('active');
infoSelected.innerHTML = '';
Expand Down
14 changes: 8 additions & 6 deletions js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { regions } from '../data/regions.js';
import { drawLegendItems, setActiveMunicipalityType } from "./legend.js";
import { initFillMode } from './fillMode.js';
import { setActiveRegion, setActivePrefecture, setActiveCity } from './map/index.js';
import { extractCities, extractPrefectures, loadHTML, parseHash } from './utils.js';
import { extractCities, extractPrefectures, loadHTML, parseHash, replaceSpecialCharactersWithAscii } from './utils.js';
import { initLayers, setLayer } from './layers.js';
import { createInlineSVG, loadPatterns } from './svg.js';
import { initTokyo, setMunicipality } from './tokyo.js';
Expand Down Expand Up @@ -33,10 +33,10 @@ async function loadIncludes() {
function setActiveData() {
const { region, prefecture, city, municipality } = parseHash();

if (region === 'Tōkyō') {
if (region === 'Tokyo') {
setLayer('tokyo');
if (municipality) {
const municipalityData = tokyo.find(item => item.name.en === municipality);
const municipalityData = tokyo.find(item => replaceSpecialCharactersWithAscii(item.name.en) === municipality);
if (municipalityData) {
setActiveMunicipalityType(municipalityData.type);
setMunicipality(municipalityData);
Expand All @@ -47,15 +47,17 @@ function setActiveData() {
return;
}

const regionData = regions.find(record => record.name.en === region);
const prefectureData = extractPrefectures(regions, region).find(record => record.name.en === prefecture);
const cityData = extractCities(regions, region).find(record => record.name.en === city);
const regionData = regions.find(record => replaceSpecialCharactersWithAscii(record.name.en) === region);
const prefectureData = extractPrefectures(regions, regionData?.name.en).find(record => replaceSpecialCharactersWithAscii(record.name.en) === prefecture);
const cityData = extractCities(regions, regionData?.name.en).find(record => replaceSpecialCharactersWithAscii(record.name.en) === city);

setActiveRegion(regionData, () => {
setTimeout(() => {
if (cityData) {
setLayer('capitals');
setActiveCity(cityData);
} else {
setLayer('prefectures');
setActivePrefecture(prefectureData);
}
}, 100);
Expand Down
4 changes: 1 addition & 3 deletions js/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ export function setLayer(layer) {
clearRegion();
const items = document.querySelectorAll('#legend .item');
items.forEach(item => item.classList.remove('active'));
setTimeout(() => {
setActiveMunicipalityType(municipalityType.ku);
}, 100);
setActiveMunicipalityType(municipalityType.ku);
}

if (previousLayerItem?.dataset.layer === 'tokyo') {
Expand Down
8 changes: 7 additions & 1 deletion js/legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ export function setActiveMunicipalityType(type) {
item.classList.toggle('active', item.dataset.type === type.name.en);
});

setInfo('tokyo', tokyoData);
setTimeout(() => {
centerTokyo(type); // FIXME
}, 100);
}

function centerTokyo(type) {
const tokyo = document.getElementById('tokyo');
tokyo && (tokyo.className = type.name.en);

Expand All @@ -101,5 +108,4 @@ export function setActiveMunicipalityType(type) {
/** @type {NodeListOf<SVGTSpanElement>} */
const municipalities = document.querySelectorAll(`#Municipalities #Text #${type.name.en} tspan`);
centerPosition(municipalities, factor);
setInfo('tokyo', tokyoData);
}
4 changes: 2 additions & 2 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ export function parseHash() {
const hash = document.location.hash.replace('#', '');
const filters = decodeURI(hash).split('/');

if (filters[0] === 'Tōkyō') {
if (filters[0] === 'Tokyo') {
return {
region: 'Tōkyō',
region: 'Tokyo',
municipality: filters[1],
};
}
Expand Down

0 comments on commit 1c639de

Please sign in to comment.