Merge pull request #465 from danvk/callback-this
authorRobert Konigsberg <konigsberg@gmail.com>
Sun, 16 Nov 2014 00:29:32 +0000 (19:29 -0500)
committerRobert Konigsberg <konigsberg@gmail.com>
Sun, 16 Nov 2014 00:29:32 +0000 (19:29 -0500)
Set "this" to the Dygraph object in all callbacks

1  2 
dygraph.js

diff --combined dygraph.js
@@@ -43,9 -43,6 +43,9 @@@
  
   */
  
 +// For "production" code, this gets set to false by uglifyjs.
 +if (typeof(DEBUG) === 'undefined') DEBUG=true;
 +
  /*jshint globalstrict: true */
  /*global DygraphLayout:false, DygraphCanvasRenderer:false, DygraphOptions:false, G_vmlCanvasManager:false,ActiveXObject:false */
  "use strict";
@@@ -668,16 -665,16 +668,16 @@@ Dygraph.prototype.toString = function(
   * @return { ... } The value of the option.
   */
  Dygraph.prototype.attr_ = function(name, seriesName) {
 -// <REMOVE_FOR_COMBINED>
 -  if (typeof(Dygraph.OPTIONS_REFERENCE) === 'undefined') {
 -    console.error('Must include options reference JS for testing');
 -  } else if (!Dygraph.OPTIONS_REFERENCE.hasOwnProperty(name)) {
 -    console.error('Dygraphs is using property ' + name + ', which has no ' +
 -                  'entry in the Dygraphs.OPTIONS_REFERENCE listing.');
 -    // Only log this error once.
 -    Dygraph.OPTIONS_REFERENCE[name] = true;
 +  if (DEBUG) {
 +    if (typeof(Dygraph.OPTIONS_REFERENCE) === 'undefined') {
 +      console.error('Must include options reference JS for testing');
 +    } else if (!Dygraph.OPTIONS_REFERENCE.hasOwnProperty(name)) {
 +      console.error('Dygraphs is using property ' + name + ', which has no ' +
 +                    'entry in the Dygraphs.OPTIONS_REFERENCE listing.');
 +      // Only log this error once.
 +      Dygraph.OPTIONS_REFERENCE[name] = true;
 +    }
    }
 -// </REMOVE_FOR_COMBINED>
    return seriesName ? this.attributes_.getForSeries(name, seriesName) : this.attributes_.get(name);
  };
  
@@@ -1624,7 -1621,7 +1624,7 @@@ Dygraph.prototype.doZoomXDates_ = funct
    var that = this;
    this.doAnimatedZoom(old_window, new_window, null, null, function() {
      if (that.getFunctionOption("zoomCallback")) {
-       that.getFunctionOption("zoomCallback")(
+       that.getFunctionOption("zoomCallback").call(that,
            minDate, maxDate, that.yAxisRanges());
      }
    });
@@@ -1657,7 -1654,7 +1657,7 @@@ Dygraph.prototype.doZoomY_ = function(l
    this.doAnimatedZoom(null, null, oldValueRanges, newValueRanges, function() {
      if (that.getFunctionOption("zoomCallback")) {
        var xRange = that.xAxisRange();
-       that.getFunctionOption("zoomCallback")(
+       that.getFunctionOption("zoomCallback").call(that,
            xRange[0], xRange[1], that.yAxisRanges());
      }
    });
@@@ -1712,7 -1709,7 +1712,7 @@@ Dygraph.prototype.resetZoom = function(
        }
        this.drawGraph_();
        if (this.getFunctionOption("zoomCallback")) {
-         this.getFunctionOption("zoomCallback")(
+         this.getFunctionOption("zoomCallback").call(this,
              minDate, maxDate, this.yAxisRanges());
        }
        return;
              }
            }
            if (that.getFunctionOption("zoomCallback")) {
-             that.getFunctionOption("zoomCallback")(
+             that.getFunctionOption("zoomCallback").call(that,
                  minDate, maxDate, that.yAxisRanges());
            }
          });
@@@ -1992,7 -1989,7 +1992,7 @@@ Dygraph.prototype.mouseMove_ = function
  
    var callback = this.getFunctionOption("highlightCallback");
    if (callback && selectionChanged) {
-     callback(event,
+     callback.call(this, event,
          this.lastx_,
          this.selPoints_,
          this.lastRow_,
@@@ -2122,7 -2119,7 +2122,7 @@@ Dygraph.prototype.updateSelection_ = fu
        ctx.lineWidth = this.getNumericOption('strokeWidth', pt.name);
        ctx.strokeStyle = color;
        ctx.fillStyle = color;
-       callback(this, pt.name, ctx, canvasx, pt.canvasy,
+       callback.call(this, this, pt.name, ctx, canvasx, pt.canvasy,
            color, circleSize, pt.idx);
      }
      ctx.restore();
@@@ -2205,10 -2202,10 +2205,10 @@@ Dygraph.prototype.setSelection = functi
   */
  Dygraph.prototype.mouseOut_ = function(event) {
    if (this.getFunctionOption("unhighlightCallback")) {
-     this.getFunctionOption("unhighlightCallback")(event);
+     this.getFunctionOption("unhighlightCallback").call(this, event);
    }
  
-   if (this.getFunctionOption("hideOverlayOnMouseOut") && !this.lockedSet_) {
+   if (this.getBooleanOption("hideOverlayOnMouseOut") && !this.lockedSet_) {
      this.clearSelection();
    }
  };
@@@ -2694,7 -2691,7 +2694,7 @@@ Dygraph.prototype.renderGraph_ = functi
    if (this.getFunctionOption('underlayCallback')) {
      // NOTE: we pass the dygraph object to this callback twice to avoid breaking
      // users who expect a deprecated form of this callback.
-     this.getFunctionOption('underlayCallback')(
+     this.getFunctionOption('underlayCallback').call(this,
          this.hidden_ctx_, this.layout_.getPlotArea(), this, this);
    }
  
@@@ -3722,7 -3719,7 +3722,7 @@@ Dygraph.prototype.ready = function(call
    if (this.is_initial_draw_) {
      this.readyFns_.push(callback);
    } else {
-     callback(this);
+     callback.call(this, this);
    }
  };