Cross-Browser Functions in MR-lib

© 2012, Martin Rinehart

Prerequisite: Basic JavaScript.


[left, top] = width, height );

Returns array [left, top] that will position an element of dimensions width, height in the center of the browser's client area.


event = MRlib323.fixup_mouse_event( event );

Returns a new event object from an event-handling method (the parameter or, for MSIE, window.event).

var event = {
    event: // the host object
	target: // the originating element
	button: // 1, 2 or 4
	x: // client coords


Gets elements by class name. (Adds getElementsByClassname() to MSIE.)


Cross-browser element emptier.

var empty_element = MRlib323.remove_children( element );

Makes element.innerHTML = ''; work in MSIE, too.


style.opacity = 0.25;
style.opacity = '25%';

Cross-browser opacity setter generates 0.25 from '25%' (if required) and sets opacity even in that weird MSIE filter manner.


{ width: w, height: h } = MRlib323.window_size();

Guesses the browser window's size (client area). Not reliable! (But we don't know one that is any better.) Returns window.innerWidth or document.documentElement.clientWidth or document.body.clientWidth (in that order of preference). Ditto for height.

Feedback: MartinRinehart at gmail dot com

# # #