rhammons' posterous.

« Back to blog

Control.Window : Windows, Modals, LightBoxes and Tooltips for Prototype

Class

ReturnNameDescription
Control.Windowopen([Element container [,Hash options]])Creates a window, opens it then returns it.
numberbaseZIndexDefaults to 9999.
arraywindowsReturns all windows, open or closed, in the order they were created.

Instance

ReturnNameDescription
Control.Windowinitialize([Element container [,Hash options]])See the tutorial for the different behaviors based on the lack of, or type of container passed.
nullbringToFront()
boolclose([Event])
nulldestroy()
nullensureInBounds()Redraws the window inside the viewport bounds if it is currently outside.
boolopen([Event])
nullposition([Event])Repositions the window.

Options

TypeNameDefaultDescription
mixedclassNamefalseClass name to apply to the container.
mixedcloseOnClickfalsefalse, string 'container', string 'overlay' or Element.
boolconstrainToViewportfalseIf draggable, the window will stay in bounds of the viewport. May not work with scrollable windows.
mixeddraggablefalseIf true, div.draggable_handle will be inserted into the container, which will become the draggable handle. If Element is passed, the element will become the handle.
boolfadefalse
numberfadeDuration0.75
mixedheightnullCan be null, number (in pixels), or function returning number.
mixedhoverfalseElement object to hover over, or if "true" only available for windows with sourceContainer (an anchor or any element already on the page with an href attribute).
booliframefalseIf the window has an href, this will display the href as an iframe instead of requesting the url as an an Ajax.Request.
booliframeshimtruePositions an iFrameShim underneath the window.
mixedindicatorfalsefalse or Element to show and hide when ajax requests, images and iframes are loading.
mixedinsertRemoteContentAtthis.containerElement to insert Ajax, IFrame or Lightbox content into. Can be string selector for this.container.down(), or an Element that must be a child of this.container.
mixedmaxHeightfalseFor resizable. Can be false or number in pixels.
mixedmaxWidthfalseFor resizable. Can be false or number in pixels.
mixedminHeightfalseFor resizable. Can be false or number in pixels.
mixedminWidthfalseFor resizable. Can be false or number in pixels.
mixedoffsetLeft0number x or function(){return x}
mixedoffsetTop0number y or function(){return y}
Hashparameters{}Will be passed to Ajax.Request if it is an Ajax window.
mixedposition'center'Can be string 'center', string 'relative' (to related element position), string 'mouse' (will follow the mouse), array [number x, number y] or array [function(){return x},function(){return y}]
mixedresizablefalseIf true, div.resizable_handle will be inserted into the container, which will become the resizable handle. If Element is passed, the element will become the handle.
mixedwidthnullCan be null, number (in pixels), or function returning number.

Events

NameDescription
afterClose()
afterDestroy()
afterInitialize()
afterOpen()
beforeClose()Throwing $break inside a callback will prevent the window from opening.
beforeOpen()Throwing $break inside a callback will prevent the window from opening.
bringToFront()
onComplete(object request)Ajax windows only.
onDrag()Draggable windows only.
onException(object request, object exception)Ajax windows only.
onFailure(object request)Ajax windows only.
onRemoteContentLoaded()Iframe, Ajax and LightBox windows will trigger this event.
onResize()Resizable windows only.
onSuccess(object request)Ajax windows only.

Control.Overlay Class

ReturnNameDescription
nullload()
nullhide()
nullshow()

Control.Overlay Events

NameDescription
afterHide()
afterShow()
beforeHide()Throwing $break will prevent the overlay from being hidden.
beforeShow()Throwing $break will prevent the overlay from being shown.

Control.Window Subclasses

All subclasses below inherit all of the methods, options and events from Control.Window.

Control.ToolTip Instance

ReturnNameDescription
Control.ToolTipinitialize(Element container [,mixed tooltip [,Hash options]])Tooltip can be a string, or an Element that is already on the page.

Control.Modal Class

ReturnNameDescription
nullclose()Closes current Modal if one is open.
Control.Modalopen([Element container [,Hash options]])
mixedcurrentFalse, or Control.Modal.

Control.Modal Instance

ReturnNameDescription
Control.Modalinitialize([Element container [,Hash options]])

Control.Modal Options

TypeNameDefaultDescription
numberoverlayOpacity0.5

Control.LightBox Instance

ReturnNameDescription
Control.LightBoxopen([Element container [,Hash options]])

Control.LightBox Options

TypeNameDefaultDescription
boolmodalfalseWill act as a Control.Modal instead of a Control.Window if true.

Interesting, possibly useful prototype based window control.