2010-09-07 19:27:44 +08:00
|
|
|
/*
|
|
|
|
* L.DomUtil contains various utility functions for working with DOM
|
|
|
|
*/
|
|
|
|
|
|
|
|
L.DomUtil = {
|
2010-09-07 22:02:45 +08:00
|
|
|
get: function(id) {
|
|
|
|
return (typeof id == 'string' ? document.getElementById(id) : id);
|
|
|
|
},
|
2010-09-14 19:57:45 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
|
2010-09-07 19:27:44 +08:00
|
|
|
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);
|
|
|
|
},
|
2010-09-13 23:18:12 +08:00
|
|
|
|
|
|
|
setPosition: function(el, point) {
|
|
|
|
el._leaflet_pos = point;
|
|
|
|
if (L.Browser.webkit) {
|
|
|
|
el.style.webkitTransform = 'translate(' + point.x + 'px,' + point.y + 'px)';
|
|
|
|
} else {
|
2010-09-14 19:57:45 +08:00
|
|
|
el.style.left = point.x + 'px';
|
|
|
|
el.style.top = point.y + 'px';
|
2010-09-13 23:18:12 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
getPosition: function(el) {
|
|
|
|
return el._leaflet_pos;
|
|
|
|
},
|
2010-09-07 19:27:44 +08:00
|
|
|
|
|
|
|
// used for disabling text selection while dragging
|
|
|
|
disableTextSelection: function() {
|
|
|
|
if (document.selection && document.selection.empty) {
|
|
|
|
document.selection.empty();
|
|
|
|
}
|
|
|
|
if (!L.DomUtil._onselectstart) {
|
|
|
|
L.DomUtil._onselectstart = document.onselectstart;
|
|
|
|
document.onselectstart = function() { return false; };
|
|
|
|
}
|
|
|
|
},
|
|
|
|
enableTextSelection: function() {
|
|
|
|
document.onselectstart = L.DomUtil._onselectstart;
|
|
|
|
CM.DomEvent._onselectstart = null;
|
|
|
|
}
|
|
|
|
};
|