From 1c3e778bafe2da07e6c120b1c89a5013f6a4e590 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Sat, 8 Oct 2016 12:45:01 -0400 Subject: [PATCH] Check for `rtl` url parameter for testing (rather than regex) --- modules/behavior/hash.js | 18 ++++++++++-------- modules/renderer/background.js | 6 +++--- modules/util/detect.js | 6 +++++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/modules/behavior/hash.js b/modules/behavior/hash.js index 43d4b5270..1cdeb9b15 100644 --- a/modules/behavior/hash.js +++ b/modules/behavior/hash.js @@ -4,7 +4,7 @@ import { utilQsString, utilStringQs } from '../util/index'; export function behaviorHash(context) { - var s0 = null, // cached location.hash + var s0 = null, // cached window.location.hash lat = 90 - 1e-8; // allowable latitude range @@ -25,7 +25,7 @@ export function behaviorHash(context) { center = map.center(), zoom = map.zoom(), precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)), - q = _.omit(utilStringQs(location.hash.substring(1)), 'comment'), + q = _.omit(utilStringQs(window.location.hash.substring(1)), 'comment'), newParams = {}; if (mode && mode.id === 'browse') { @@ -50,7 +50,9 @@ export function behaviorHash(context) { function update() { if (context.inIntro()) return; var s1 = formatter(context.map()); - if (s0 !== s1) location.replace(s0 = s1); // don't recenter the map! + if (s0 !== s1) { + window.location.replace(s0 = s1); // don't recenter the map! + } } @@ -58,8 +60,8 @@ export function behaviorHash(context) { function hashchange() { - if (location.hash === s0) return; // ignore spurious hashchange events - if (parser(context.map(), (s0 = location.hash).substring(1))) { + if (window.location.hash === s0) return; // ignore spurious hashchange events + if (parser(context.map(), (s0 = window.location.hash).substring(1))) { update(); // replace bogus hash } } @@ -75,8 +77,8 @@ export function behaviorHash(context) { d3.select(window) .on('hashchange.hash', hashchange); - if (location.hash) { - var q = utilStringQs(location.hash.substring(1)); + if (window.location.hash) { + var q = utilStringQs(window.location.hash.substring(1)); if (q.id) context.zoomToEntity(q.id.split(',')[0], !q.map); if (q.comment) context.storage('comment', q.comment); hashchange(); @@ -97,7 +99,7 @@ export function behaviorHash(context) { d3.select(window) .on('hashchange.hash', null); - location.hash = ''; + window.location.hash = ''; }; diff --git a/modules/renderer/background.js b/modules/renderer/background.js index 497e5e0d8..49a94321e 100644 --- a/modules/renderer/background.js +++ b/modules/renderer/background.js @@ -52,7 +52,7 @@ export function rendererBackground(context) { epsilon = 0.01, x = +meters[0].toFixed(2), y = +meters[1].toFixed(2), - q = utilStringQs(location.hash.substring(1)); + q = utilStringQs(window.location.hash.substring(1)); var id = b.id; if (id === 'custom') { @@ -77,7 +77,7 @@ export function rendererBackground(context) { delete q.offset; } - location.replace('#' + utilQsString(q, true)); + window.location.replace('#' + utilQsString(q, true)); var imageryUsed = [b.imageryUsed()]; @@ -199,7 +199,7 @@ export function rendererBackground(context) { return geoExtent([args[1], args[2]]); } - var q = utilStringQs(location.hash.substring(1)), + var q = utilStringQs(window.location.hash.substring(1)), chosen = q.background || q.layer, extent = parseMap(q.map), best; diff --git a/modules/util/detect.js b/modules/util/detect.js index a208cf1b9..54c7a1d06 100644 --- a/modules/util/detect.js +++ b/modules/util/detect.js @@ -1,4 +1,6 @@ import { currentLocale, setTextDirection } from './locale'; +import { utilStringQs } from './index'; + export function utilDetect() { var detected = {}; @@ -64,7 +66,9 @@ export function utilDetect() { detected.locale = loadedLocale; } - if (['ar', 'fa', 'iw', 'dv'].indexOf(detected.locale.split('-')[0]) > -1 || window.location.href.indexOf('rtl-test-rtl') > -1) { + // detect text direction + var q = utilStringQs(window.location.hash.substring(1)); + if (['ar', 'fa', 'iw', 'dv'].indexOf(detected.locale.split('-')[0]) > -1 || q.hasOwnProperty('rtl')) { detected.textDirection = 'rtl'; } else { detected.textDirection = 'ltr';