Raspsnir/public_html/browserquest/js/bubble.js

1 line
1.1 KiB
JavaScript

define(["jquery","timer"],function(e,t){var n=Class.extend({init:function(e,n,r){this.id=e,this.element=n,this.timer=new t(5e3,r)},isOver:function(e){return this.timer.isOver(e)?!0:!1},destroy:function(){e(this.element).remove()},reset:function(e){this.timer.lastTime=e}}),r=Class.extend({init:function(e){this.container=e,this.bubbles={}},getBubbleById:function(e){return e in this.bubbles?this.bubbles[e]:null},create:function(t,r,i){if(this.bubbles[t])this.bubbles[t].reset(i),e("#"+t+" p").html(r);else{var s=e('<div id="'+t+'" class="bubble"><p>'+r+'</p><div class="thingy"></div></div>');e(s).appendTo(this.container),this.bubbles[t]=new n(t,s,i)}},update:function(e){var t=this,n=[];_.each(this.bubbles,function(t){t.isOver(e)&&(t.destroy(),n.push(t.id))}),_.each(n,function(e){delete t.bubbles[e]})},clean:function(){var e=this,t=[];_.each(this.bubbles,function(e){e.destroy(),t.push(e.id)}),_.each(t,function(t){delete e.bubbles[t]}),this.bubbles={}},destroyBubble:function(e){var t=this.getBubbleById(e);t&&(t.destroy(),delete this.bubbles[e])},forEachBubble:function(e){_.each(this.bubbles,function(t){e(t)})}});return r});