-
+
diff --git a/js/detector/bubblr.js b/js/detector/bubblr.js
index 3405345..52c38e3 100644
--- a/js/detector/bubblr.js
+++ b/js/detector/bubblr.js
@@ -38,6 +38,8 @@
return;
}
+ if (this.timerId) this.remove();
+
$canvas = $(this.element);
this.width = $canvas.width();
@@ -63,11 +65,16 @@
}, this.options.animationSpeed);
-
- // this.clear();
+ $(window).on('resize',this.onResize.bind(this));
};
+ Bubblr.prototype.onResize= function(){
+ this.clear();
+ this.width = Math.max($canvas.width(),this.element.width);
+ this.height = Math.max($canvas.height(),this.element.height);
+ };
+
Bubblr.prototype.start = function(timespan) {
var self = this;
if (!this.on){
@@ -78,17 +85,22 @@
this.on=true;
} else {
clearInterval(this.nextOffID);
- this.nextOff = setTimeout(self.stop.bind(self),timespan);
+ this.nextOffID = setTimeout(self.stop.bind(self),timespan);
}
};
Bubblr.prototype.stop = function() {
- // this.clear();
- // clearInterval(this.timerId);
this.on=false;
- this.timerId=undefined;
+ this.nextOffID=null;
};
+ /** remove animation loop **/
+ Bubblr.prototype.remove = function (arguments) {
+ clearInterval(this.timerId);
+ this.timerId=null;
+ detector.bubblr.clear()
+ }
+
Bubblr.prototype.animationLoop = function() {
this.clear();
diff --git a/js/detector/detector.js b/js/detector/detector.js
index 7b5deb4..5543640 100644
--- a/js/detector/detector.js
+++ b/js/detector/detector.js
@@ -24,14 +24,7 @@ var detector =
lastRender: 0,
- animate: function(time)
- {
- // var duration = typeof time !== 'undefined' ? time - detector.lastRender : 16;
- // detector.lastRender = time;
- //
- // requestAnimFrame(detector.animate);
- // detector.draw(duration);
- },
+ bubblr: undefined,
init: function(baseSize)
{
@@ -86,8 +79,17 @@ var detector =
detector.events.ctx.scale(ratio, ratio);
}
+
+ detector.initBubbles();
+ // TODO refactor flame animation and put it here
+ // this.flame = $('#detector-flame').flame();
+
+ detector.animate();
+ },
+
+ initBubbles: function(){
// init the test tube animation
- var bubblrElem = $('detector-core').bubblr({
+ var bubblrElem = $('#detector-core').bubblr({
backgroundColor: '#e8e8e8',
bubbleColor: "#bfbfbf",
bubbleMinSize: 3,
@@ -101,35 +103,34 @@ var detector =
// top edge bubbles will disappear
bubbleYpopLimit: 10
});
- this.bubblr = bubblrElem.data('plugin_bubblr');
-
- // TODO refactor flame animation and put it here
- // this.flame = $('#detector-flame').flame();
-
- // detector.coreDraw();
- detector.animate();
+ detector.bubblr = bubblrElem.data('plugin_bubblr');
},
- /** draw a static core on background **/
- // coreDraw: function()
- // {
- //
- // },
+ animate: function(time)
+ {
+ // var duration = typeof time !== 'undefined' ? time - detector.lastRender : 16;
+ // detector.lastRender = time;
+ //
+ // requestAnimFrame(detector.animate);
+ // detector.draw(duration);
+ },
+ /** When a user clicks the detector **/
addEvent: function()
{
-
+ detector.bubblr.start(500); // bubble for 500ms, TODO make one bubble
},
+ /** When a worker clicks the detector **/
addEventExternal: function(numWorkers)
{
-
+ // detector.bubblr.start(500*numWorkers);
},
/** Draw current events **/
draw: function(duration)
{
-
+ detector.bubblr.start(duration);
}
};