add a new 'playing' property to the Tween class so that a call to stop doesn't do anything if animation is already finished, r=ahocevar,crschmidt (Closes #1392)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@6387 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
pgiraud
2008-02-27 13:57:13 +00:00
parent 0fc0112e07
commit ffecbe0594
3 changed files with 27 additions and 2 deletions

View File

@@ -318,6 +318,12 @@ OpenLayers.Map = OpenLayers.Class({
* Default is to fall through.
*/
fallThrough: true,
/**
* Property: panTween
* {OpenLayers.Tween} Animated panning tween object, see panTo()
*/
panTween: null,
/**
* Constructor: OpenLayers.Map

View File

@@ -58,6 +58,12 @@ OpenLayers.Tween = OpenLayers.Class({
*/
interval: null,
/**
* Property: playing
* {Boolean} Tells if the easing is currently playing
*/
playing: false,
/**
* Constructor: OpenLayers.Tween
* Creates a Tween.
@@ -80,6 +86,7 @@ OpenLayers.Tween = OpenLayers.Class({
* options - {Object} hash of options (for example callbacks (start, eachStep, done))
*/
start: function(begin, finish, duration, options) {
this.playing = true;
this.begin = begin;
this.finish = finish;
this.duration = duration;
@@ -98,14 +105,20 @@ OpenLayers.Tween = OpenLayers.Class({
/**
* APIMethod: stop
* Stops the Tween, and calls the finish callback
* Stops the Tween, and calls the done callback
* Doesn't do anything if animation is already finished
*/
stop: function() {
if (!this.playing) {
return
}
if (this.callbacks && this.callbacks.done) {
this.callbacks.done.call(this, this.finish);
}
window.clearInterval(this.interval);
this.interval = null;
this.playing = false;
},
/**

View File

@@ -46,12 +46,18 @@
}
function test_Tween_stop(t) {
t.plan(1);
t.plan(2);
var tween = new OpenLayers.Tween();
tween.interval = window.setInterval(function() {}, 10);
tween.playing = true;
tween.stop();
t.eq(tween.interval, null, "tween correctly stopped");
tween.interval = window.setInterval(function() {}, 10);
tween.playing = false;
tween.stop();
t.ok(tween.interval != null, "stop method doesn't do anything if tween isn't running");
}
</script>