|
Register Event Class
XML Menu Builder
Build powerful, client-side DHTML menus using XML for data and CSS for style. No JavaScript data! No having to place list elements on every single page of your website! No plug-ins!
Class: CJL_RegisterEvent Summary: JavaScript Class that allows for generic setting and removing of event listeners. Submitted: 01/28/2003 Created by: CodeHouse.com Browser Compatibility for all Methods in this Module:
Demo The demo opens in a new window. To see the source code, use your browser's method of viewing the contents of the page, or save the page to your local machine and view it in an editor. Source Code The source code for this class is contained in the text area below. You can copy and paste it into your own source code. Before using the source code, make sure that you read and agree to the terms of the License Agreement, which will open in a separate window.
Class Index Constructor: CJL_RegisterEvent CJL_RegisterEvent(elem, type, listener, noAutoStart, useCapture) Description: Creates a new CJL_RegisterEvent class for attaching a listener method to an element, for a specific event type. Also allows for the programmatic starting and stopping of event listening. Example Usage: Attaches a mousedown listener, named myListener to the document element: new CJL_RegisterEvent(document, "mousedown", myListener); Parameters elem:
Element to attach the event listener method to
type:
Event type to set the event listener
method to listen to
listener:
Event listening method that
gets called to process events for elem
noAutoStart:
If this parameter is true,
listener is not automatically attached to elem.
If this parameter is false, listener is
automatically attached to elem.
In the example below, since the noAutoStart parameter was not supplied to the constructor, noAutoStart is implicitly false. Because noAutoStart is false, the constructor automatically attaches the listener — myListener to the element — document. new CJL_RegisterEvent(document, "mousedown", myListener); The example below does exactly the same thing as the example above. However, it does not attach myListener to document in the constructor. It tells the constructor not to automatically attach a listener by supplying a true value for the noAutoStart paramater. myListener is attached to document by calling the start() method. reg = new CJL_RegisterEvent(document, "mousedown",
myListener, false, true); useCapture:
This parameter allows event capturing only for
browsers which support DOM
Level 2 Event Capture. This parameter is ignored for browsers
which don't support the standard.
Methods start()
Starts listening for events for the target element — elem
specified in the constructor.
stop()
Stops listening for events for the target element — elem
specified in the constructor.
Support If you have any questions, find any bugs, or have suggestions, feel free to contact us. |