From ad46474275276c917d06b8f896facb895ca68e6a Mon Sep 17 00:00:00 2001 From: mourner Date: Tue, 14 Sep 2010 14:57:45 +0300 Subject: [PATCH] added getStyle, fixed setPosition --- spec/runner.html | 17 +++++++++-------- spec/suites/dom/DomUtilSpec.js | 2 ++ src/dom/DomUtil.js | 18 +++++++++++++++--- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/spec/runner.html b/spec/runner.html index 6b219742..58660fdc 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -18,20 +18,21 @@ + + + + + + + + + - - - - - - - - diff --git a/spec/suites/dom/DomUtilSpec.js b/spec/suites/dom/DomUtilSpec.js index a604c7ff..60de22fe 100644 --- a/spec/suites/dom/DomUtilSpec.js +++ b/spec/suites/dom/DomUtilSpec.js @@ -24,4 +24,6 @@ describe('DomUtil', function() { }); describe('#setPosition', noSpecs); + + describe('#getStyle', noSpecs); }); \ No newline at end of file diff --git a/src/dom/DomUtil.js b/src/dom/DomUtil.js index 3be70310..500cc3b4 100644 --- a/src/dom/DomUtil.js +++ b/src/dom/DomUtil.js @@ -6,7 +6,19 @@ L.DomUtil = { get: function(id) { return (typeof id == 'string' ? document.getElementById(id) : id); }, - + + getStyle: function(el, style) { + var value = el.style[style]; + if ((typeof value == 'undefined') && el.currentStyle) { + value = el.currentStyle[style]; + } + if (typeof value == 'undefined') { + var css = document.defaultView.getComputedStyle(el, null); + value = css ? css[style] : null; + } + return (value == 'auto' ? null : value); + }, + getCumulativeOffset: function(el) { var top = 0, left = 0; @@ -23,8 +35,8 @@ L.DomUtil = { if (L.Browser.webkit) { el.style.webkitTransform = 'translate(' + point.x + 'px,' + point.y + 'px)'; } else { - el.style.left = point.x; - el.style.top = point.y; + el.style.left = point.x + 'px'; + el.style.top = point.y + 'px'; } }, getPosition: function(el) {