Commit 5648fee9 authored by S Anand's avatar S Anand

BUG: do not re-run stop if already stopped

parent bfcfa5cf
......@@ -27,34 +27,36 @@ $.fn.doodle = function(options) {
// Turn off any other doodling on these paths
.off('stop.g.doodle start.g.doodle')
// And re-define the events
.on('stop.g.doodle', function(e, finish) {
if (finish) {
// Move to the end
start_pos = 1
tick()
.on('stop.g.doodle', function(e, position) {
if (!request_id)
return
// Cancel ticks as well as loop
request_id = global.cancelAnimationFrame(request_id)
if (timeout_id)
timeout_id = global.clearTimeout(timeout_id)
if (typeof position != 'undefined') {
// Move to specified position. 1 is the end, 0 is the start
start_pos = position
start_time = Date.now()
draw()
} else {
// Store the current pos as start_pos to allow resuming
start_pos = pos
}
// Cancel ticks as well as loop
if (request_id)
request_id = global.cancelAnimationFrame(request_id)
if (timeout_id)
timeout_id = global.clearTimeout(timeout_id)
})
.on('start.g.doodle', function(e, pos) {
.on('start.g.doodle', function(e, position) {
if (request_id)
return
if (typeof pos != 'undefined') {
if (typeof position != 'undefined') {
// When a specific position is set
start_pos = pos
start_pos = position
// Set or reset stroke-dashoffset. All paths after pos are set to the end, those before are set to 0
for (index=0; index < length; index++)
paths[index][PATH].attr('stroke-dashoffset', pos < paths[index][END_POS] ? paths[index][PATH_LENGTH] : 0)
paths[index][PATH].attr('stroke-dashoffset', position < paths[index][END_POS] ? paths[index][PATH_LENGTH] : 0)
// If options.fill, set or reset fill. All paths after pos are cleared, those before are filled
if (options.fill)
for (index=0; index < length; index++)
paths[index][PATH].css('fill', pos < paths[index][END_POS] ? 'none' : paths[index][FILL])
paths[index][PATH].css('fill', position < paths[index][END_POS] ? 'none' : paths[index][FILL])
}
// Reset the index and position. The first tick() will correct things
index = 0
......@@ -90,7 +92,7 @@ $.fn.doodle = function(options) {
// or defaults to a pre-defined number of seconds
duration = (options.duration || default_duration || 2) * 1000
function tick() {
function draw() {
pos = start_pos + easing((Date.now() - start_time) / duration)
// Find the current path that is being animated
if (index >= length || pos > paths[index][END_POS]) {
......@@ -111,6 +113,10 @@ $.fn.doodle = function(options) {
// Set its stroke offset
path[PATH].attr('stroke-dashoffset', path[PATH_LENGTH] * (end_pos - pos) / path[WIDTH])
}
function tick() {
draw()
request_id = global.requestAnimationFrame(tick)
}
if (typeof options.start === 'undefined' || options.start)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment