JSWindows (a JavaScript Inheritance Demo) Window Class

© 12 May, 2013, Martin Rinehart


A Window is a Rect that implements the Closable capability (with a window-closing ("X") button in the right-top corner).

With CSS3 border radii capabilities, a Window need not be rectangular. Circles and ovals are possible. We're partial to windows shaped like shields.

The Window Constructor

The arguments to the Window constructor are the same as the arguments to the Rect constructor. See the DEFAULTS.Window data to customize the window.

Internally, the constructor prepares the arguments for Rect.init method and the Btn_close constructor.

Window Closing

The default action on a closing button click is to call the window.onclose() method before deleting or closing anything. If the container's onclose() returns false the closing button's click handler immediately exits. If the onclose() doesn't exist, or if it exists and returns anything other than false the click handler recursively deletes all DOM elements.

If your window is, for example, a dialog box that you will want available for later use, its onclose() might just set display: 'none' and return false;.

Instance Methods

"Inherits" the Rect (and, by inheritance, Wobj methods).

Window Warning

Our favorite mistake is to use the name window for a reference to a Window instance. This, of course, causes havoc since window is the name of the global object. (More precisely, it is the name of one global object, since you have one global per frame, each of them named window.)

Feedback: MartinRinehart at gmail dot com

# # #