Check for rtl url parameter for testing (rather than regex)

This commit is contained in:
Bryan Housel
2016-10-08 12:45:01 -04:00
parent 17250a090d
commit 1c3e778baf
3 changed files with 18 additions and 12 deletions
+10 -8
View File
@@ -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 = '';
};
+3 -3
View File
@@ -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;
+5 -1
View File
@@ -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';