mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-07-08 09:24:25 +03:00
42321428f8
* Перенесены либы из фреймворка
41 lines
960 B
JavaScript
41 lines
960 B
JavaScript
/**
|
|
* Таймер
|
|
*
|
|
* @module timer
|
|
*
|
|
* @license GNU General Public License, version 2
|
|
* @copyright 2013 OOO "ЛС-СОФТ" {@link http://livestreetcms.com}
|
|
* @author Denis Shakhov <denis.shakhov@gmail.com>
|
|
*/
|
|
|
|
var ls = ls || {};
|
|
|
|
ls.timer = (function ($) {
|
|
"use strict";
|
|
|
|
var _aTimers = {};
|
|
|
|
/**
|
|
* Запуск метода через определенный период, поддерживает пролонгацию
|
|
*/
|
|
this.run = function(oContext, fMethod, sUniqKey, aParams, iTime) {
|
|
iTime = iTime || 1500;
|
|
aParams = aParams || [];
|
|
sUniqKey = sUniqKey || Math.random();
|
|
|
|
if (_aTimers[sUniqKey]) {
|
|
clearTimeout(_aTimers[sUniqKey]);
|
|
_aTimers[sUniqKey] = null;
|
|
}
|
|
|
|
var timeout = setTimeout(function(){
|
|
clearTimeout(_aTimers[sUniqKey]);
|
|
_aTimers[sUniqKey] = null;
|
|
fMethod.apply(oContext, aParams);
|
|
}.bind(this), iTime);
|
|
|
|
_aTimers[sUniqKey] = timeout;
|
|
};
|
|
|
|
return this;
|
|
}).call(ls.timer || {},jQuery); |