[ Mini Kiebo ]
Server: Windows NT DESKTOP-5B8S0D4 6.2 build 9200 (Windows 8 Professional Edition) i586
Path:
D:
/
Backup
/
05122024
/
htdocs
/
simpeg
/
zapatec
/
zpform
/
utils
/
jsdocs
/
[
Home
]
File: overview-summary-zpeventdriven.js.html
<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"> <html> <head> <title> Zapatec Utils Overview </title> <link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style"> <script> function asd() { parent.document.title="zpeventdriven.js Overview"; } </script> </head> <body bgcolor="white" onload="asd();"> <!-- ========== START OF NAVBAR ========== --> <a name="navbar_top"><!-- --></a> <table border="0" width="100%" cellpadding="1" cellspacing="0"> <tr> <td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1"> <a name="navbar_top_firstrow"><!-- --></a> <table border="0" cellpadding="0" cellspacing="3"> <tr align="center" valign="top"> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a> </td> <td bgcolor="#FFFFFF" class="NavBarCell1Rev"> <font class="NavBarFont1Rev"><b>File</b></font> </td> <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a> </td> </tr> </table> </td> <td bgcolor="#EEEEFF" align="right" valign="top"> <em> <b>Zapatec Utils</b></em> </td> </tr> <tr> <td bgcolor="white" class="NavBarCell2"><font size="-2"> PREV NEXT</font></td> <td bgcolor="white" class="NavBarCell2"><font size="-2"> <a href="index.html" target="_top"><b>FRAMES</b></a> <a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a> <script> <!-- if(window==top) { document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>'); } //--> </script> <noscript> <a href="allclasses-noframe.html" target=""><b>All Classes</b></a> </noscript> </font></td> </tr> </table> <!-- =========== END OF NAVBAR =========== --> <hr> <center> <h2>zpeventdriven.js</h2> </center> <h4>Summary</h4> <p> Zapatec EventDriven library. Base EventDriven class. Contains functions to handle events and basic methods for event-driven class. <pre> Copyright (c) 2004-2007 by Zapatec, Inc. http://www.zapatec.com 1700 MLK Way, Berkeley, California, 94709, U.S.A. All rights reserved. </pre><BR/><BR/> </p> <hr> <table border="1" cellpadding="3" cellspacing="0" width="100%"> <tr bgcolor="#CCCCFF" class="TableHeadingColor"> <td colspan=2><font size="+2"> <b>Class Summary</b> </font></td> </tr> <tr bgcolor="white" class="TableRowColor"> <td width="15%"><b><a href="Zapatec/EventDriven.html">Zapatec.EventDriven</a></b></td> <td> </td> </tr> </table> <hr/> <!-- ========== METHOD SUMMARY =========== --> <!-- ========== END METHOD SUMMARY =========== --> <pre class="sourceview"><span class="comment">/** * <span class="attrib">@fileoverview</span> Zapatec EventDriven library. Base EventDriven class. Contains * functions to handle events and basic methods for event-driven class. * * <pre> * Copyright (c) 2004-2007 by Zapatec, Inc. * http://www.zapatec.com * 1700 MLK Way, Berkeley, California, * 94709, U.S.A. * All rights reserved. * </pre> */</span> <span class="comment">/* $Id: zpeventdriven.js 7323 2007-06-01 21:05:51Z alex $ */</span> <span class="reserved">if</span> (typeof Zapatec == <span class="literal">'undefined'</span>) { <span class="comment">/** * <span class="attrib">@ignore</span> Namespace definition. */</span> Zapatec = <span class="reserved">function</span>() {}; } <span class="comment">/** * Base event-driven class. * <span class="attrib">@constructor</span> */</span> Zapatec.EventDriven = <span class="reserved">function</span>() {}; <span class="comment">/** * Initializes object. * <span class="attrib">@private</span> */</span> Zapatec.EventDriven.<span class="reserved">prototype</span>.init = <span class="reserved">function</span>() { <span class="comment">// Holds events of this object</span> <span class="reserved">this</span>.events = {}; }; <span class="comment">/** * Adds event listener to the end of list. * * <pre> * If multiple identical event listeners are registered on the same event, the * duplicate instances are discarded. They do not cause the event listener to be * called twice, and since the duplicates are discarded, they do not need to be * removed manually with the removeEventListener method. * * Synopsis: * * oEventDriven.addEventListener('eventName', fEventListener); * * There is also static method doing the same with global events: * * Zapatec.EventDriven.addEventListener('globalEventName', fEventListener); * </pre> * * <span class="attrib">@param</span> {string} sEv Event name * <span class="attrib">@param</span> {function} fLsnr Event listener */</span> Zapatec.EventDriven.<span class="reserved">prototype</span>.addEventListener = <span class="reserved">function</span>(sEv, fLsnr) { <span class="reserved">if</span> (typeof fLsnr != <span class="literal">"function"</span>) { <span class="reserved">return</span> false; } var oE = <span class="reserved">this</span>.events; <span class="reserved">if</span> (!oE[sEv]) { oE[sEv] = { listeners: [] }; } <span class="reserved">else</span> { <span class="reserved">this</span>.removeEventListener(sEv, fLsnr); } oE[sEv].listeners.push(fLsnr); }; <span class="comment">/** * Adds event listener to the beginning of list. Note that there is no guarantee * that it will be always first in the list. It will become second once this * method is called again. Never rely on that! * * <pre> * If multiple identical event listeners are registered on the same event, the * duplicate instances are discarded. They do not cause the event listener to be * called twice, and since the duplicates are discarded, they do not need to be * removed manually with the removeEventListener method. * * Synopsis: * * oEventDriven.unshiftEventListener('eventName', fEventListener); * * There is also static method doing the same with global events: * * Zapatec.EventDriven.unshiftEventListener('globalEventName', fEventListener); * </pre> * * <span class="attrib">@param</span> {string} sEv Event name * <span class="attrib">@param</span> {function} fLsnr Event listener */</span> Zapatec.EventDriven.<span class="reserved">prototype</span>.unshiftEventListener = <span class="reserved">function</span>(sEv, fLsnr) { <span class="reserved">if</span> (typeof fLsnr != <span class="literal">"function"</span>) { <span class="reserved">return</span> false; } var oE = <span class="reserved">this</span>.events; <span class="reserved">if</span> (!oE[sEv]) { oE[sEv] = { listeners: [] }; } <span class="reserved">else</span> { <span class="reserved">this</span>.removeEventListener(sEv, fLsnr); } oE[sEv].listeners.unshift(fLsnr); }; <span class="comment">/** * Removes event listener. * * <pre> * Synopsis: * * oEventDriven.removeEventListener('eventName', fEventListener); * * There is also static method doing the same with global events: * * Zapatec.EventDriven.removeEventListener('globalEventName', fEventListener); * </pre> * * <span class="attrib">@param</span> {string} sEv Event name * <span class="attrib">@param</span> {function} fLsnr Event listener * <span class="attrib">@return</span> Number of listeners removed * <span class="attrib">@type</span> number */</span> Zapatec.EventDriven.<span class="reserved">prototype</span>.removeEventListener = <span class="reserved">function</span>(sEv, fLsnr) { var oE = <span class="reserved">this</span>.events; <span class="reserved">if</span> (!oE[sEv]) { <span class="reserved">return</span> 0; } var aL = oE[sEv].listeners; var iRemoved = 0; <span class="reserved">for</span> (var iL = aL.length - 1; iL >= 0; iL--) { <span class="reserved">if</span> (aL[iL] == fLsnr) { aL.splice(iL, 1); iRemoved++; } } <span class="reserved">return</span> iRemoved; }; <span class="comment">/** * Returns array of listeners for the specified event. * * <pre> * Synopsis: * * oEventDriven.getEventListeners('eventName'); * * There is also static method doing the same with global events: * * Zapatec.EventDriven.getEventListeners('globalEventName'); * </pre> * * <span class="attrib">@param</span> {string} sEv Event name * <span class="attrib">@return</span> Array of function references * <span class="attrib">@type</span> object */</span> Zapatec.EventDriven.<span class="reserved">prototype</span>.getEventListeners = <span class="reserved">function</span>(sEv) { var oE = <span class="reserved">this</span>.events; <span class="reserved">if</span> (!oE[sEv]) { <span class="reserved">return</span> []; } <span class="reserved">return</span> oE[sEv].listeners; }; <span class="comment">/** * Checks if the event listener is attached to the event. * * <pre> * Synopsis: * * oEventDriven.isEventListener('eventName', fEventListener); * * There is also static method doing the same with global events: * * Zapatec.EventDriven.isEventListener('globalEventName', fEventListener); * </pre> * * <span class="attrib">@param</span> {string} sEv Event name * <span class="attrib">@param</span> {function} fLsnr Event listener * <span class="attrib">@return</span> True if event listener is attached to the event * <span class="attrib">@type</span> boolean */</span> Zapatec.EventDriven.<span class="reserved">prototype</span>.isEventListener = <span class="reserved">function</span>(sEv, fLsnr) { var oE = <span class="reserved">this</span>.events; <span class="reserved">if</span> (!oE[sEv]) { <span class="reserved">return</span> false; } var aL = oE[sEv].listeners; <span class="reserved">for</span> (var iL = aL.length - 1; iL >= 0; iL--) { <span class="reserved">if</span> (aL[iL] == fLsnr) { <span class="reserved">return</span> true; } } <span class="reserved">return</span> false; }; <span class="comment">/** * Checks if the event exists. * * <pre> * Synopsis: * * oEventDriven.isEvent('eventName'); * * There is also static method doing the same with global events: * * Zapatec.EventDriven.isEvent('globalEventName'); * </pre> * * <span class="attrib">@param</span> {string} sEv Event name * <span class="attrib">@return</span> Exists * <span class="attrib">@type</span> boolean */</span> Zapatec.EventDriven.<span class="reserved">prototype</span>.isEvent = <span class="reserved">function</span>(sEv) { <span class="reserved">if</span> (<span class="reserved">this</span>.events[sEv]) { <span class="reserved">return</span> true; } <span class="reserved">return</span> false; }; <span class="comment">/** * Removes all listeners for the event. * * <pre> * Synopsis: * * oEventDriven.removeEvent('eventName'); * * There is also static method doing the same with global events: * * Zapatec.EventDriven.removeEvent('globalEventName'); * </pre> * * <span class="attrib">@param</span> {string} sEv Event name */</span> Zapatec.EventDriven.<span class="reserved">prototype</span>.removeEvent = <span class="reserved">function</span>(sEv) { var oE = <span class="reserved">this</span>.events; <span class="reserved">if</span> (oE[sEv]) { var undef; oE[sEv] = undef; } }; <span class="comment">/** * Fires event. Takes in one mandatory argument sEv and optionally any number of * other arguments that should be passed to the listeners. * * <pre> * Synopsis: * * oEventDriven.fireEvent('eventName'); * * There is also static method doing the same with global events: * * Zapatec.EventDriven.fireEvent('globalEventName'); * </pre> * * <span class="attrib">@param</span> {string} sEv Event name */</span> Zapatec.EventDriven.<span class="reserved">prototype</span>.fireEvent = <span class="reserved">function</span>(sEv) { var oE = <span class="reserved">this</span>.events; <span class="reserved">if</span> (!oE[sEv]) { <span class="reserved">return</span>; } <span class="comment">// Duplicate array because it may be modified from within the listeners</span> var aL = oE[sEv].listeners.slice(); var iLs = aL.length; var aArgs; <span class="reserved">for</span> (var iL = 0; iLs--; iL++) { <span class="comment">// Remove first argument</span> aArgs = [].slice.call(arguments, 1); <span class="comment">// Call in scope of this object</span> aL[iL].apply(<span class="reserved">this</span>, aArgs); } }; <span class="comment">/** * Holds global events. * <span class="attrib">@private</span> */</span> Zapatec.EventDriven.events = {}; <span class="comment">/** * Adds event listener to global event to the end of list. * * <pre> * If multiple identical event listeners are registered on the same event, the * duplicate instances are discarded. They do not cause the event listener to be * called twice, and since the duplicates are discarded, they do not need to be * removed manually with the removeEventListener method. * </pre> * * <span class="attrib">@param</span> {string} sEv Event name * <span class="attrib">@param</span> {function} fLsnr Event listener */</span> Zapatec.EventDriven.addEventListener = <span class="reserved">function</span>(sEv, fLsnr) { <span class="reserved">if</span> (typeof fLsnr != <span class="literal">"function"</span>) { <span class="reserved">return</span> false; } var oED = Zapatec.EventDriven; var oE = oED.events; <span class="reserved">if</span> (!oE[sEv]) { oE[sEv] = { listeners: [] }; } <span class="reserved">else</span> { oED.removeEventListener(sEv, fLsnr); } oE[sEv].listeners.push(fLsnr); }; <span class="comment">/** * Adds event listener to global event to the beginning of list. Note that there * is no guarantee that it will be always first in the list. It will become * second once this method is called again. Never rely on that! * * <pre> * If multiple identical event listeners are registered on the same event, the * duplicate instances are discarded. They do not cause the event listener to be * called twice, and since the duplicates are discarded, they do not need to be * removed manually with the removeEventListener method. * </pre> * * <span class="attrib">@param</span> {string} sEv Event name * <span class="attrib">@param</span> {function} fLsnr Event listener */</span> Zapatec.EventDriven.unshiftEventListener = <span class="reserved">function</span>(sEv, fLsnr) { <span class="reserved">if</span> (typeof fLsnr != <span class="literal">"function"</span>) { <span class="reserved">return</span> false; } var oED = Zapatec.EventDriven; var oE = oED.events; <span class="reserved">if</span> (!oE[sEv]) { oE[sEv] = { listeners: [] }; } <span class="reserved">else</span> { oED.removeEventListener(sEv, fLsnr); } oE[sEv].listeners.unshift(fLsnr); }; <span class="comment">/** * Removes event listener from global event. * * <span class="attrib">@param</span> {string} sEv Event name * <span class="attrib">@param</span> {function} fLsnr Event listener * <span class="attrib">@return</span> number of listeners removed * <span class="attrib">@type</span> number */</span> Zapatec.EventDriven.removeEventListener = <span class="reserved">function</span>(sEv, fLsnr) { var oE = Zapatec.EventDriven.events; <span class="reserved">if</span> (!oE[sEv]) { <span class="reserved">return</span> 0; } var aL = oE[sEv].listeners; var iRemoved = 0; <span class="reserved">for</span> (var iL = aL.length - 1; iL >= 0; iL--) { <span class="reserved">if</span> (aL[iL] == fLsnr) { aL.splice(iL, 1); iRemoved++; } } <span class="reserved">return</span> iRemoved; }; <span class="comment">/** * Returns array of listeners for the specified global event. * * <span class="attrib">@param</span> {string} sEv Event name * <span class="attrib">@return</span> Array of function references * <span class="attrib">@type</span> object */</span> Zapatec.EventDriven.getEventListeners = <span class="reserved">function</span>(sEv) { var oE = Zapatec.EventDriven.events; <span class="reserved">if</span> (!oE[sEv]) { <span class="reserved">return</span> []; } <span class="reserved">return</span> oE[sEv].listeners; }; <span class="comment">/** * Checks if the event listener is attached to the global event. * * <span class="attrib">@param</span> {string} sEv Event name * <span class="attrib">@param</span> {function} fLsnr Event listener * <span class="attrib">@return</span> True if event listener is attached to the event * <span class="attrib">@type</span> boolean */</span> Zapatec.EventDriven.isEventListener = <span class="reserved">function</span>(sEv, fLsnr) { var oE = Zapatec.EventDriven.events; <span class="reserved">if</span> (!oE[sEv]) { <span class="reserved">return</span> false; } var aL = oE[sEv].listeners; <span class="reserved">for</span> (var iL = aL.length - 1; iL >= 0; iL--) { <span class="reserved">if</span> (aL[iL] == fLsnr) { <span class="reserved">return</span> true; } } <span class="reserved">return</span> false; }; <span class="comment">/** * Checks if the global event exists. * * <span class="attrib">@param</span> {string} sEv Event name * <span class="attrib">@return</span> Exists * <span class="attrib">@type</span> boolean */</span> Zapatec.EventDriven.isEvent = <span class="reserved">function</span>(sEv) { <span class="reserved">if</span> (Zapatec.EventDriven.events[sEv]) { <span class="reserved">return</span> true; } <span class="reserved">return</span> false; }; <span class="comment">/** * Removes all listeners for the global event. * * <span class="attrib">@param</span> {string} sEv Event name */</span> Zapatec.EventDriven.removeEvent = <span class="reserved">function</span>(sEv) { var oE = Zapatec.EventDriven.events; <span class="reserved">if</span> (oE[sEv]) { var undef; oE[sEv] = undef; } }; <span class="comment">/** * Fires global event. Takes in one mandatory argument sEv and optionally any * number of other arguments that should be passed to the listeners. * * <span class="attrib">@param</span> {string} sEv Event name */</span> Zapatec.EventDriven.fireEvent = <span class="reserved">function</span>(sEv) { var oE = Zapatec.EventDriven.events; <span class="reserved">if</span> (!oE[sEv]) { <span class="reserved">return</span>; } <span class="comment">// Duplicate array because it may be modified from within the listeners</span> var aL = oE[sEv].listeners.slice(); var iLs = aL.length; var aArgs; <span class="reserved">for</span> (var iL = 0; iLs--; iL++) { <span class="comment">// Remove first argument</span> aArgs = [].slice.call(arguments, 1); <span class="comment">// Call listener</span> aL[iL].apply(aL[iL], aArgs); } }; </pre> <hr> <!-- ========== START OF NAVBAR ========== --> <a name="navbar_top"><!-- --></a> <table border="0" width="100%" cellpadding="1" cellspacing="0"> <tr> <td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1"> <a name="navbar_top_firstrow"><!-- --></a> <table border="0" cellpadding="0" cellspacing="3"> <tr align="center" valign="top"> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a> </td> <td bgcolor="#FFFFFF" class="NavBarCell1Rev"> <font class="NavBarFont1Rev"><b>File</b></font> </td> <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a> </td> </tr> </table> </td> <td bgcolor="#EEEEFF" align="right" valign="top"><em> <b>Zapatec Utils</b></em> </td> </tr> <tr> <td bgcolor="white" class="NavBarCell2"><font size="-2"> PREV NEXT</font></td> <td bgcolor="white" class="NavBarCell2"><font size="-2"> <a href="index.html" target="_top"><b>FRAMES</b></a> <a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a> <script> <!-- if(window==top) { document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>'); } //--> </script> <noscript> <a href="allclasses-noframe.html" target=""><b>All Classes</b></a> </noscript> </font></td> </tr> </table> <!-- =========== END OF NAVBAR =========== --> <hr> <font size="-1"> </font> <div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Thu Aug 16 12:18:39 2007</div> </body> </html>