Archive

Posts Tagged ‘GXT’

A fix to the missing ‘getBoxObjectFor’ javascript method

According to https://bugzilla.mozilla.org/show_bug.cgi?id=340571, the getBoxObjectFor method is now unavailable to firefox users.

Unfortunately, many javascript-based frameworks (like extJS) use this method, and some in-production sites may stop working until a new version is released.

I wrote this little javascript fix : just include this code at the top of your page :

<script>
//<![CDATA[
//temporary fix for getBoxObjectFor (https://bugzilla.mozilla.org/show_bug.cgi?id=340571)
if(!document.getBoxObjectFor){
	_getOffset = function(elt, offset){
		if(!elt){
			return;
			}
			offset.x += elt.offsetLeft;
			offset.y += elt.offsetTop;
			_getOffset(elt.offsetParent, offset);
		};

	document.getBoxObjectFor = function(elt){
		var rect = elt.getBoundingClientRect();
		var offset = {x:0,y:0};
		_getOffset(elt, offset);
		return {
			element:elt,
			height:rect.right-rect.left,
			parentBox:elt.offsetParent,
			screenX:offset.x,
			screenY:offset.y,
			width:rect.bottom-rect.top,
			x:rect.left,
			y:rect.top
		};
	};
}
//]]></script>
Publicités
Catégories :Uncategorized Étiquettes : , ,