Created
August 3, 2012 14:03
-
-
Save rich97/3247949 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I need to use $progress into a callback like this: | |
callbacks.update = function(data) { | |
if (data.response !== null) { | |
if (data.response < 100) { | |
$progress.custom.update({ | |
completed: data.response | |
}); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
if (data.error !== null) { | |
$progress.custom.update({ | |
completed: 100, | |
status: 'error', | |
message: data.error.message | |
}); | |
} | |
// return false by default to prevent an infinate poll scenario | |
return false; | |
} | |
// I have a poll function which polls a script until the update callback is satified that it has the information it needs | |
function poll(s, d, c) { | |
if (typeof s === 'undefined' || typeof d === 'undefined' || typeof c === 'undefined') { | |
return false; | |
} | |
if (typeof c.start !== 'undefined') { | |
c.start(); | |
delete c.start; | |
} | |
$.get(s, d, function(result) { | |
var repost = false; | |
if (typeof c.update !== 'undefined') { | |
repost = c.update(result); | |
} | |
if (repost === true) { | |
setTimeout(function() { poll(s, d, c); }, 1000); | |
} else { | |
if (typeof c.end !== 'undefined') { | |
c.end(result); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment