⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.js

📁 javascript 很酷的类库
💻 JS
字号:
/*
 * Isomorphic SmartClient
 * Version 6.5 (2008-04-30)
 * Copyright(c) 1998-2007 Isomorphic Software, Inc. All rights reserved.
 * "SmartClient" is a trademark of Isomorphic Software, Inc.
 *
 * licensing@smartclient.com
 *
 * http://smartclient.com/license
 */
 //>	@class	Timer//// The Timer class provides a predictable cross-browser system for creating// timed events.//// @treeLocation Client Reference/System// @visibility external//<// create the Timer objectisc.ClassFactory.defineClass("Timer");// add class properties and constantsisc.Timer.addClassProperties({ 		_eventList : null,								//>	@classAttr	isc.Timer._eventList		(object : null : IRWA)															//		This is a single linked list of timerEvents that have been queued up for execution.															//		The attribute itself points to the first element in the list.															//															//		@group timer															//<																listEvent : {action: null,		 				//>	@classAttr	isc.Timer.listEvent		(object : {...} : IRWA)					 iterationInterval: null,		//			Properties for a timerEvent (a pseudoclass used in the isc.Timer class)					 iterationsRemaining: 0,		//								 _nextEvent: null,			//			             action: reference to function for this timerEvent					 _nextRunTime: null},			//			          condition: condition for continuing iteration, used by isc.Timer.setDoWhen() and isc.Timer.setDoUntil()															//			  iterationInterval: time between iterations of a timerEvent															//			iterationsRemaining: counter for remaining iterations of a timerEvent															//			               time: time when timerEvent should fire, used by Timer.seAlarm()															//			     _nextEvent: reference to next timerEvent in the eventList															//			       _nextRunTime: absolute time when this timerEvent should be run															//			           _execute: routine fired when timerEvent is executed.															//<																//>	@type	Units	//		Multiplier for an amount of time specified in milliseconds.	MSEC :       1,			//	@value	isc.Timer.MSEC		milliseconds	SEC :     1000,			//	@value	isc.Timer.SEC		seconds	MIN :    60000,			//	@value	isc.Timer.MIN		minutes	HOUR : 3600000,			//	@value	isc.Timer.HOUR		hours	//<		DEFAULT_TIMEOUT_LENGTH : 100,							//>	@classAttr isc.Timer.DEFAULT_TIMEOUT_LENGTH (number : 100 : R)															//		Default time to delay if an explicit delay is not specified.															//<				_clockHandle : null 									//>	@classAttr	isc.Timer.__clockHandle		(object : null : IRWA)															//		Reference to the setTimeout() instance that may be running at any given time.															//		Used to stop the timer, if necessary. If value is null, then the queue is not															// 	processing.															//															//		@see Timer._stopClock()															//<});// END isc.Timer.addClassProperties()// add a bunch of methods to the Timer objectisc.Timer.addClassMethods({//>	@classMethod	Timer.setTimeout()//    // Execute an action in a given amount of time.  This method wraps the native setTimeout() method,// correcting for browser-specific memory leaks.//// @see clear()////	// @param action (string expression or function)	//			     	 Function to be called when delay has elapsed. //				     Can also be a string representation of an expression.//	    			 Passing a string is preferred.//// @param delay (number) Time until action is executed (in milliseconds). If not specified, the//                       default is 100 milliseconds.// @return      (timerEvent) Reference to the timerEvent created. Note that this reference is provided// 							 only so that it can be used as an argument for Timer.clear().// @visibility external    //<// - avoid recreating the string to fire each delayed action_$fireTimeout:["isc.Timer._fireTimeout('", null, "')"],// - incrementing count to identify delayed actions uniquely_timeoutCount:0,// - map of native timer event IDs to delayed actions stored on the timer object_tmrIDMap:{},setTimeout : function (action, delay, units) {    if (action == null) return;    	// if an object is passed in the place of the action parameter, 	// then assign parameters from its values	if (action.action != null) {		delay = action.delay;		units = action.units;		action = action.action;	}	//defaults, loaded if not in parameters or in parameter object.	if (units == null) units = isc.Timer.MSEC;	if (delay == null) delay = isc.Timer.DEFAULT_TIMEOUT_LENGTH;	// get the actual length to delay according to the units passed in	delay = delay * units;        var ID = "_timeout" + this._timeoutCount++;    this._$fireTimeout[1] = ID;    this[ID] = action;        	// actually set the native timeout to fire at the appropriate time.        var actionString = this._$fireTimeout.join(isc.emptyString);    var tmrID = setTimeout(actionString, delay);    // Setting up a mapping between the native timer ID and the name of the temp slot we used    // to store the action allows us to clear both if a developer calls 'clear()'    this._tmrIDMap[tmrID] = ID;    return tmrID;},// method fired to actually execute a timeout_$TMR:"TMR",_fireTimeout : function (ID) {    var action = this[ID];            // Clear out the temp action slot, and the mapping to native timer ID    delete this[ID];    var tmrMap = this._tmrIDMap;    for (var i in tmrMap) {        if (tmrMap[i] = ID) {            delete tmrMap[i];            break;        }    }    if (action == null) return;    isc.EH._setThread(this._$TMR);            // fireCallback() will handle action specified as function, string to eval and    // object with 'target' and 'methodName' attributes.    // Since this is a new thread, pass in the param to catch errors - allows us to see JS    // errors in the arbitrary code    this.fireCallback(action, null, null, null, true);    isc.EH._clearThread();},//>	@classMethod	Timer.clear()//// Cancels the processing of a timerEvent if it has not already fired.//// @param	timerEvent	(object)		timerEvent object previously returned from Timer.setTimeout()//// @visibility external//<clear : function (timerEvent) {    if (isc.isAn.Array(timerEvent))        for (var i = 0; i < timerEvent.length; i++) this.clear(timerEvent[i]);    else {        // clear the temp action and the pointer to it        delete this[this._tmrIDMap[timerEvent]]        delete this._tmrIDMap[timerEvent]        // natively clear the timeout        clearTimeout(timerEvent);    }	return null;},clearTimeout : function (timerEvent) {    return this.clear(timerEvent);}});	// END isc.Timer.addClassMethods()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -