Leaflet/src/dom/DomUtil.js
2010-09-20 15:08:25 +03:00

55 lines
1.4 KiB
JavaScript

/*
* L.DomUtil contains various utility functions for working with DOM
*/
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;
do {
top += (el.offsetTop - el.scrollTop) || 0;
left += el.offsetLeft || 0;
el = el.offsetParent;
} while (el);
return new L.Point(left, top);
},
TRANSLATE_OPEN: 'translate' + (L.Browser.webkit3d ? '3d(' : '('),
TRANSLATE_CLOSE: L.Browser.webkit3d ? ',0)' : ')',
getTranslateString: function(point) {
return L.DomUtil.TRANSLATE_OPEN +
point.x + 'px,' + point.y + 'px' +
L.DomUtil.TRANSLATE_CLOSE;
},
setPosition: function(el, point) {
el._leaflet_pos = point;
if (L.Browser.webkit) {
el.style.webkitTransform = L.DomUtil.getTranslateString(point);
} else {
el.style.left = point.x + 'px';
el.style.top = point.y + 'px';
}
},
getPosition: function(el) {
return el._leaflet_pos;
}
};