| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- jQuery.timer = function (interval, callback) {
- var interval = interval || 100;
- if (!callback)
- return false;
- _timer = function (interval, callback) {
- this.stop = function () {
- clearInterval(self.id);
- };
-
- this.internalCallback = function () {
- callback(self);
- };
-
- this.reset = function (val) {
- if (self.id)
- clearInterval(self.id);
-
- var val = val || 100;
- this.id = setInterval(this.internalCallback, val);
- };
-
- this.interval = interval;
- this.id = setInterval(this.internalCallback, this.interval);
-
- var self = this;
- };
- return new _timer(interval, callback);
- };
- // see: http://stackoverflow.com/questions/210717/using-jquery-to-center-a-div-on-the-screen
- jQuery.fn.center = function () {
- this.css("position","absolute");
- this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
- this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
- return this;
- }
- function log(str) {
- //firebug running
- if('object' == typeof console) {
- console.log(str);
- }
- }
- function simple_moving_averager(period) {
- var nums = [];
- return function(num) {
- nums.push(num);
- if (nums.length > period)
- nums.splice(0,1); // remove the first element of the array
- var sum = 0;
- for (var i in nums)
- sum += nums[i];
- var n = period;
- if (nums.length < period)
- n = nums.length;
- return(sum/n);
- }
- }
|