Cross-Browser Functions in MR-lib

© 2012, Martin Rinehart

Prerequisite: Basic JavaScript.

center()

[left, top] = MRlib323.center( width, height );

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

fixup_mouse_event()

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
	y:
}

get_elements_by_class_name()

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

remove_children()

Cross-browser element emptier.

var empty_element = MRlib323.remove_children( element );

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

set_opacity()

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.

window_size()

{ 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

# # #