DynAds
| Sample Testimonial
|
Thank you very much for your extremely helpful and detailed reply.
I adapted your sample script and was able to achieve exactly what I was looking for.
Once again I am amazed at both the flexibility of your product and your incredible technical support!
Best Regards.
B. Brooks, BetterWhoIs.com
More...
|
|
Global Event Handler (GEH) Class
Global Event Handler (GEH) class is designed to solve a practical problem in JavaScript.
If you want to assign more than one event handlers to a JavaScript event, there
is a problem of resource sharing. With the GEH class, multiple event handler codes can be
assigned to a single JavaScript event.
GEH: GEH Class.
GEH.NewHandler method: Add a new event handler code to the
event associated with this GEH object.
GEH.RemoveHandler Method: Removes a previously installed
event handler code to the event associated with this GEH object.
GEH.CallHandlers Method: Evaluates all of the installed
event handler codes, once.
GEH.tasks Property: Container array for the event handler codes
installed.
Pre-declared GEH Objects
API defines some pre-declared GEH objects that are associated to some JavaScript
object events for the users convenience.
gehMMove GEH Object: Associated with document.onmousemove event.
gehResize GEH Object: Associated with window.onresize event.
gehScroll GEH Object: Associated with window.onscroll event.
| GEH Class |
| Definition: |
Returns a new GEH object.
|
| Syntax: |
new GEH () ;
|
| Arguments: |
None
|
| Returns: |
A new GEH object.
|
| Remarks: |
GEH class is designed to handle multiple event handlers for a single event.
|
| Example: |
// Create a new GEH object
var gehMMove = new GEH() ;
// Access the CallHandlers method of gehMMove from this dummy global function
function gehMMoveHandler (ev) { gehMMove.CallHandlers(ev) ; }
// Assign the dummy function to the document.onmousemove event
document.onmousemove = gehMMoveHandler ;
// Add a new handler to call to whenever a mouse is moved
gehMMove.NewHandler ("mouseEventHandler (ev)") ;
|
| GEH.NewHandler Method |
| Definition: |
Add a new event handler code to the event associated with this GEH object.
|
| Syntax: |
function GEH.NewHandler(str) ;
|
| Arguments: |
str: String value containing a call to a function or any JavaScript code to be evaluated
whenever the associated event occurs.
|
| Returns: |
The index of the event handler. Use this index to remove the event handler later via
RemoveHandler method.
|
| Remarks: |
The code in 'str' can reference an event object named 'ev', though, the properties of the 'ev'
object depends on the browser used.
|
| Example: |
// Create a new GEH object
var gehMMove = new GEH() ;
// Access the CallHandlers method of gehMMove from this dummy global function
function gehMMoveHandler (ev) { gehMMove.CallHandlers(ev) ; }
// Assign the dummy function to the document.onmousemove event
document.onmousemove = gehMMoveHandler ;
// Add a new handler to call to whenever a mouse is moved
gehMMove.NewHandler ("mouseEventHandler (ev)") ;
|
| GEH.RemoveHandler Method |
| Definition: |
Removes a previously installed event handler code to the event associated with this GEH object.
|
| Syntax: |
function GEH.RemoveHandler(index) ;
|
| Arguments: |
index: Handler index as returned by GEH.NewHandler method.
|
| Returns: |
None.
|
| Remarks: |
None
|
| Example: |
// Create a new GEH object
var gehMMove = new GEH() ;
var handlerIndex = gehMMove.NewHandler ("mouseEventHandler (ev)") ;
...
gehMMove.RemoveHandler(handlerIndex) ;
|
| GEH.CallHandlers Method |
| Definition: |
Evaluates all of the installed event handler codes, once.
|
| Syntax: |
function GEH.CallHandlers(ev) ;
|
| Arguments: |
ev: Event object passed by some browsers as event handler argument.
|
| Returns: |
None |
| Remarks: |
This method makes an event object named 'ev' to be available for all handler codes. That is,
the installed (via GEH.NewHandler method) event handler codes can reference to this 'ev' object.
Note that, this 'ev' object is enhanced version of the argument 'ev' to cover more browsers,
though, the properties of the 'ev' object depends on the browser used.
In order to use this method as an event handler of an event, you need to create a
wrap-around function as shown in the example below, since only global functions can
be used as event handlers.
|
| Example: |
// window.onresize Global Event Handler
var gehResize = new GEH() ;
// This is the dummy wrap-around global function
function gehResizeHandler (ev) { gehResize.CallHandlers(ev) ; }
// Assing the dummy function as event handler
window.onresize = gehResizeHandler ;
|
| GEH.tasks Property |
| Definition: |
Container array for the event handler codes installed.
|
| Remarks: |
Normally, you do not access this array. Instead use GEH.NewHandler and GEH.RemoveHandler
methods.
|
| gehMMove GEH Object |
| Definition: |
Associated with document.onmousemove event.
|
| Syntax: |
var gehMMove = new GEH() ;
function gehMMoveHandler (ev) { gehMMove.CallHandlers(ev) ; }
document.onmousemove = gehMMoveHandler ;
gehMMove.NewHandler ("mouseEventHandler (ev)") ;
|
| Remarks: |
Add new handlers to document.onmousemove event by calling gehMMove.NewHandler() method.
|
| Example: |
// Show the position of mouse pointer in the status bar of the window.
gehMMove.NewHandler ("window.status = MouseX + \", \" + MouseY ;") ;
|
| gehResize GEH Object |
| Definition: |
Associated with window.onresize event.
|
| Syntax: |
var gehResize = new GEH() ;
function gehResizeHandler (ev) { gehResize.CallHandlers(ev) ; }
window.onresize = gehResizeHandler ;
|
| Remarks: |
Add new handlers to window.onresize event by calling gehResize.NewHandler() method.
|
| Example: |
// Show the client area width and height on the status bar of the window.
gehResize.NewHandler ("window.status = windWidth() + \", \" + windHeight() ;") ;
|
| gehScroll GEH Object |
| Definition: |
Associated with window.onscroll event
|
| Syntax: |
var gehScroll = new GEH() ;
function gehScrollHandler (ev) { gehScroll.CallHandlers(ev) ; }
window.onscroll = gehScrollHandler ;
|
| Remarks: |
Add new handlers to window.onscroll event by calling gehScroll.NewHandler() method.
|
| Example: |
// Show the document horizontal and vertical scroll offset
// on the status bar of the window.
gehScroll.NewHandler ("window.status = docXScroll() + \", \" + docYScroll() ;") ;
|
|
|