X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph.js;h=6c1569807d70aad9c18a9e66f048729aeebb3017;hb=c02097ab8767f4977d97964a092923baddc7ca08;hp=528fc4b70b5f16bb23dd48856be3bcdbc19bdae1;hpb=28aa77ac7282494f66ccc0901c39f54a847919e3;p=dygraphs.git diff --git a/dygraph.js b/dygraph.js index 528fc4b..6c15698 100644 --- a/dygraph.js +++ b/dygraph.js @@ -407,6 +407,8 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { this.setIndexByName_ = {}; this.datasetIndex_ = []; + this.registeredEvents_ = []; + // Create the containing DIV and other interactive elements this.createInterface_(); @@ -950,12 +952,12 @@ Dygraph.prototype.createInterface_ = function() { this.mouseMoveHandler = function(e) { dygraph.mouseMove_(e); }; - Dygraph.addEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler); + this.addEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler); this.mouseOutHandler = function(e) { dygraph.mouseOut_(e); }; - Dygraph.addEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler); + this.addEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler); this.createDragInterface_(); @@ -965,7 +967,7 @@ Dygraph.prototype.createInterface_ = function() { // Update when the window is resized. // TODO(danvk): drop frames depending on complexity of the chart. - Dygraph.addEvent(window, 'resize', this.resizeHandler); + this.addEvent(window, 'resize', this.resizeHandler); }; /** @@ -980,11 +982,17 @@ Dygraph.prototype.destroy = function() { node.removeChild(node.firstChild); } }; - - // remove mouse event handlers - Dygraph.removeEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler); - Dygraph.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler); - Dygraph.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseUpHandler_); + + for (var idx = 0; idx < this.registeredEvents_.length; idx++) { + var reg = this.registeredEvents_[idx]; + this.removeEvent(reg.elem, reg.type, reg.fn); + } + this.registeredEvents_ = []; + + // remove mouse event handlers (This may not be necessary anymore) + this.removeEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler); + this.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler); + this.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseUpHandler_); removeRecursive(this.maindiv_); var nullOut = function(obj) { @@ -995,7 +1003,7 @@ Dygraph.prototype.destroy = function() { } }; // remove event handlers - Dygraph.removeEvent(window,'resize',this.resizeHandler); + this.removeEvent(window,'resize',this.resizeHandler); this.resizeHandler = null; // These may not all be necessary, but it can't hurt... nullOut(this.layout_); @@ -1214,7 +1222,8 @@ Dygraph.prototype.createDragInterface_ = function() { boundedDates: null, // [minDate, maxDate] boundedValues: null, // [[minValue, maxValue] ...] - initializeMouseDown: function(event, g, context) { + // contextB is the same thing as this context object but renamed. + initializeMouseDown: function(event, g, contextB) { // prevents mouse drags from selecting page text. if (event.preventDefault) { event.preventDefault(); // Firefox, Chrome, etc. @@ -1223,11 +1232,11 @@ Dygraph.prototype.createDragInterface_ = function() { event.cancelBubble = true; } - context.px = Dygraph.findPosX(g.canvas_); - context.py = Dygraph.findPosY(g.canvas_); - context.dragStartX = g.dragGetX_(event, context); - context.dragStartY = g.dragGetY_(event, context); - context.cancelNextDblclick = false; + contextB.px = Dygraph.findPosX(g.canvas_); + contextB.py = Dygraph.findPosY(g.canvas_); + contextB.dragStartX = g.dragGetX_(event, contextB); + contextB.dragStartY = g.dragGetY_(event, contextB); + contextB.cancelNextDblclick = false; } }; @@ -1245,7 +1254,7 @@ Dygraph.prototype.createDragInterface_ = function() { for (var eventName in interactionModel) { if (!interactionModel.hasOwnProperty(eventName)) continue; - Dygraph.addEvent(this.mouseEventElement_, eventName, + this.addEvent(this.mouseEventElement_, eventName, bindHandler(interactionModel[eventName])); } @@ -1269,7 +1278,7 @@ Dygraph.prototype.createDragInterface_ = function() { } }; - Dygraph.addEvent(document, 'mouseup', this.mouseUpHandler_); + this.addEvent(document, 'mouseup', this.mouseUpHandler_); }; /**