mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
66 lines
1.9 KiB
JavaScript
66 lines
1.9 KiB
JavaScript
/** @module utils */
|
|
__PluginManager__.register('utils', function(module, exports, require){
|
|
var StackExecutionLimiter = (function () {
|
|
var stack = function (context, callback, timeout = 1000) {
|
|
this.counter = 0;
|
|
this.timerId = 0;
|
|
this.timeout = 0;
|
|
this.arguments = null;
|
|
this.context = null;
|
|
this.setContext(context);
|
|
this.setCallback(callback);
|
|
this.setTimeout(timeout);
|
|
};
|
|
stack.prototype.setCallback = function(callback){
|
|
this.callback = callback;
|
|
};
|
|
stack.prototype.setContext = function(context){
|
|
this.context = context || window;
|
|
};
|
|
stack.prototype.setTimeout = function(timeout){
|
|
this.timeout = timeout;
|
|
};
|
|
stack.prototype.exec = function() {
|
|
this.arguments = arguments;
|
|
this.counter++;
|
|
|
|
if(this.timerId === 0) {
|
|
this.__exec(this.counter);
|
|
}
|
|
};
|
|
stack.prototype.__exec = function (counter) {
|
|
this.timerId = setTimeout((function(){
|
|
if(this.counter > counter) {
|
|
this.__exec(this.counter);
|
|
return null;
|
|
}
|
|
this.timerId = 0;
|
|
}).bind(this), this.timeout);
|
|
this.callback.apply(this.context, this.arguments);
|
|
};
|
|
stack.prototype.reset = function () {
|
|
clearTimeout(this.timerId);
|
|
this.timerId = 0;
|
|
};
|
|
return stack;
|
|
})();
|
|
var str = {
|
|
ucFirst: function (str) {
|
|
if (!str) return str;
|
|
return str[0].toUpperCase() + str.slice(1);
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* @memberof kitCore
|
|
* @instance
|
|
*/
|
|
var utils = {
|
|
StackExecutionLimiter: StackExecutionLimiter,
|
|
str: str,
|
|
};
|
|
|
|
return module.exports = utils;
|
|
});
|