[Pkg-javascript-commits] [leaflet] 159/301: Re-add ltr/rtl detection and make getMousePosition work correctly with rtl again when scrolled.

Jonas Smedegaard js at moszumanska.debian.org
Mon Jan 27 22:22:48 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository leaflet.

commit 80c48c5da74c68ff22ab0689c27fc2a4d89d65cc
Author: danzel <danzel at localhost.geek.nz>
Date:   Wed Oct 30 14:32:18 2013 +1300

    Re-add ltr/rtl detection and make getMousePosition work correctly with rtl again when scrolled.
---
 src/core/Browser.js | 2 ++
 src/dom/DomEvent.js | 8 ++++++--
 src/dom/DomUtil.js  | 8 ++++++++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/core/Browser.js b/src/core/Browser.js
index 02571c5..dda8a07 100644
--- a/src/core/Browser.js
+++ b/src/core/Browser.js
@@ -16,6 +16,7 @@
 	    phantomjs = ua.indexOf('phantom') !== -1,
 	    android = ua.indexOf('android') !== -1,
 	    android23 = ua.search('android [23]') !== -1,
+		gecko = ua.indexOf('gecko') !== -1,
 
 	    mobile = typeof orientation !== undefined + '',
 	    msPointer = window.navigator && window.navigator.msPointerEnabled &&
@@ -72,6 +73,7 @@
 		ie7: ie7,
 		ielt9: ielt9,
 		webkit: webkit,
+		gecko: gecko && !webkit && !window.opera && !ie,
 
 		android: android,
 		android23: android23,
diff --git a/src/dom/DomEvent.js b/src/dom/DomEvent.js
index 5ef5929..6a0a588 100644
--- a/src/dom/DomEvent.js
+++ b/src/dom/DomEvent.js
@@ -143,10 +143,14 @@ L.DomEvent = {
 	},
 
 	getMousePosition: function (e, container) {
-
 		var body = document.body,
 		    docEl = document.documentElement,
-		    x = e.pageX ? e.pageX - body.scrollLeft - docEl.scrollLeft: e.clientX,
+		    //gecko makes scrollLeft more negative as you scroll in rtl, other browsers don't
+			//ref: https://code.google.com/p/closure-library/source/browse/closure/goog/style/bidi.js
+			x = L.DomUtil.documentIsLtr() ?
+					(e.pageX ? e.pageX - body.scrollLeft - docEl.scrollLeft : e.clientX) :
+						(L.Browser.gecko ? e.pageX - body.scrollLeft - docEl.scrollLeft :
+						 e.pageX ? e.pageX - body.scrollLeft + docEl.scrollLeft : e.clientX),
 		    y = e.pageY ? e.pageY - body.scrollTop - docEl.scrollTop: e.clientY,
 		    pos = new L.Point(x, y);
 
diff --git a/src/dom/DomUtil.js b/src/dom/DomUtil.js
index d44e1ed..6874a6c 100644
--- a/src/dom/DomUtil.js
+++ b/src/dom/DomUtil.js
@@ -83,6 +83,14 @@ L.DomUtil = {
 		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) {
 
 		var el = document.createElement(tagName);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet.git



More information about the Pkg-javascript-commits mailing list