Merge pull request #1100 from danzel/rtl

RTL Fixes round 2
This commit is contained in:
Vladimir Agafonkin 2012-10-28 16:15:59 -07:00
commit ae7561ec6b
2 changed files with 26 additions and 9 deletions

View File

@ -1,7 +1,9 @@
(function () { (function () {
var ie = !!window.ActiveXObject, var ie = !!window.ActiveXObject,
// http://tanalin.com/en/articles/ie-version-js/
ie6 = ie && !window.XMLHttpRequest, ie6 = ie && !window.XMLHttpRequest,
ie7 = ie && !document.querySelector,
// terrible browser detection to work around Safari / iOS / Android browser bugs // terrible browser detection to work around Safari / iOS / Android browser bugs
// see TileLayer._addTile and debug/hacks/jitter.html // see TileLayer._addTile and debug/hacks/jitter.html
@ -56,6 +58,7 @@
L.Browser = { L.Browser = {
ie6: ie6, ie6: ie6,
ie7: ie7,
webkit: webkit, webkit: webkit,
android: android, android: android,

View File

@ -15,7 +15,7 @@ L.DomUtil = {
value = el.currentStyle[style]; value = el.currentStyle[style];
} }
if (!value || value === 'auto') { if ((!value || value === 'auto') && document.defaultView) {
var css = document.defaultView.getComputedStyle(el, null); var css = document.defaultView.getComputedStyle(el, null);
value = css ? css[style] : null; value = css ? css[style] : null;
} }
@ -29,7 +29,8 @@ L.DomUtil = {
left = 0, left = 0,
el = element, el = element,
docBody = document.body, docBody = document.body,
pos; pos,
ie7 = L.Browser.ie7;
do { do {
top += el.offsetTop || 0; top += el.offsetTop || 0;
@ -52,14 +53,19 @@ L.DomUtil = {
do { do {
if (el === docBody) { break; } if (el === docBody) { break; }
top -= el.scrollTop || 0; top -= el.scrollTop || 0;
left -= el.scrollLeft || 0;
//See https://developer.mozilla.org/en-US/docs/DOM/element.scrollLeft //Webkit (and ie <= 7) handles RTL scrollLeft different to everyone else
// http://www.nczonline.net/blog/2010/08/03/working-with-bidirectional-bidi-text-and-rtl-languages-on-the-web/ // https://code.google.com/p/closure-library/source/browse/trunk/closure/goog/style/bidi.js
if (L.DomUtil.getStyle(el, 'direction') == "ltr") { if (!L.DomUtil.documentIsLtr() && (L.Browser.webkit || ie7)) {
left -= el.scrollLeft || 0; left += el.scrollWidth - el.clientWidth;
} else {
left -= (el.scrollLeft || 0) - el.scrollWidth + el.clientWidth; //ie7 shows the scrollbar by default and provides clientWidth counting it, so we need to add it back in if it is visible
// Scrollbar is on the left as we are RTL
if (ie7 && L.DomUtil.getStyle(el, 'overflow-y') !== 'hidden' && L.DomUtil.getStyle(el, 'overflow') !== 'hidden') {
left += 17;
}
} }
el = el.parentNode; el = el.parentNode;
@ -68,6 +74,14 @@ L.DomUtil = {
return new L.Point(left, top); return new L.Point(left, top);
}, },
documentIsLtr: function () {
if (!L.DomUtil._docIsLtrCached) {
L.DomUtil._docIsLtrCached = true;
L.DomUtil._docIsLtr = L.DomUtil.getStyle(document.body, 'direction') === "ltr";
}
return L.DomUtil._docIsLtr;
},
create: function (tagName, className, container) { create: function (tagName, className, container) {
var el = document.createElement(tagName); var el = document.createElement(tagName);