Skip to content

Commit

Permalink
References to effects in prototype adapter are kept until they are fi…
Browse files Browse the repository at this point in the history
…nished or canceled. Closes highcharts#291
  • Loading branch information
Erik Olsson committed Aug 9, 2011
1 parent 682fe43 commit fc5a59e
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions js/adapters/prototype-adapter.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ return {
opts;

this.element = element;

this.key = attr;
from = element.attr(attr);

// special treatment for paths
Expand All @@ -67,7 +67,14 @@ return {
},
setup: function () {
HighchartsAdapter._extend(this.element);
this.element._highchart_animation = this;
// If this is the first animation on this object, create the _highcharts_animation helper that
// contain pointers to the animation objects.
if (!this.element._highchart_animation) {
this.element._highchart_animation = {};
}

// Store a reference to this animation instance.
this.element._highchart_animation[this.key] = this;
},
update: function (position) {
var paths = this.paths;
Expand All @@ -79,7 +86,9 @@ return {
this.element.attr(this.options.attribute, position);
},
finish: function () {
this.element._highchart_animation = null;
// Delete the property that holds this animation now that it is finished.
// Both canceled animations and complete ones gets a 'finish' call.
delete this.element._highchart_animation[this.key];
}
});
}
Expand Down Expand Up @@ -121,6 +130,8 @@ return {
// animate wrappers and DOM elements
if (hasEffect) {
for (key in params) {
// The fx variable is seemingly thrown away here, but the Effect.setup will add itself to the _highcharts_animation object
// on the element itself so its not really lost.
fx = new Effect.HighchartsTransition($(el), key, params[key], options);
}
} else {
Expand All @@ -136,8 +147,13 @@ return {

// this only occurs in higcharts 2.0+
stop: function (el) {
var key;
if (el._highcharts_extended && el._highchart_animation) {
el._highchart_animation.cancel();
for (key in el._highchart_animation) {
// Cancel the animation
// The 'finish' function in the Effect object will remove the reference
el._highchart_animation[key].cancel();
}
}
},

Expand Down

0 comments on commit fc5a59e

Please sign in to comment.