X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=manifold%2Fstatic%2Fjs%2Fbuffer.js;fp=manifold%2Fstatic%2Fjs%2Fbuffer.js;h=46bac84aa8188997c18f1a4e3d410421b2f3f411;hb=174577cca1256f0b65b78837887d4ea9bac108a5;hp=0000000000000000000000000000000000000000;hpb=0feaf648c801631483b4889b7b00c1d6b01fb253;p=myslice.git diff --git a/manifold/static/js/buffer.js b/manifold/static/js/buffer.js new file mode 100644 index 00000000..46bac84a --- /dev/null +++ b/manifold/static/js/buffer.js @@ -0,0 +1,40 @@ +/* Buffered DOM updates */ +var Buffer = Class.extend({ + + init: function(callback, callback_this) { + this._callback = callback; + this._callback_this = callback_this; + this._timerid = null; + this._num_elements = 0; + this._elements = Array(); + + this._interval = 1000; + + return this; + }, + + add: function(element) + { + this._elements.push(element); + if (this._num_elements == 0) { + this._timerid = setInterval( + (function(self) { //Self-executing func which takes 'this' as self + return function() { //Return a function in the context of 'self' + console.log("running callback"); + clearInterval(self._timerid); + self._callback.apply(self._callback_this); + } + })(this), + this._interval); + } + this._num_elements++; + }, + + get: function() { + var elements = this._elements; + this._elements = Array(); + this._num_elements = 0; + return elements; + }, + +});