Skip to content

Commit

Permalink
show message in element if present
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Jun 13, 2017
1 parent 0a52a23 commit 7eca458
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions js/wq/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,31 @@ progress.init = function(conf) {

// wq/app.js plugin
progress.run = function($page) {
var $progress = $page.find('progress');
var $progress = $page.find('progress'),
$status;
if (!$progress.length) {
return;
}

progress.start($progress);
if ($progress.data('wq-status')) {
$status = $page.find('#' + $progress.data('wq-status'));
}
progress.start($progress, $status);
$page.on('pagehide', function() {
progress.stop($progress);
});
};

// progress.start accepts a jQuery-wrapped progress element and looks for a
// data-wq-url attribute to poll (and an optional data-interval attribute)
progress.start = function($progress) {
progress.start = function($progress, $status) {
var url = $progress.data('wq-url');
var interval = $progress.data('wq-interval') || progress.config.interval;
if (!url || _timers[url]) {
return;
}
_timers[url] = setInterval(
progress.timer($progress, url),
progress.timer($progress, url, $status),
interval * 1000
);
};
Expand Down Expand Up @@ -77,7 +81,7 @@ progress.fail = function($progress, data) {

// progress.timer generates a function suitable for setInterval
// (with $progress and url bound to scope).
progress.timer = function($progress, url) {
progress.timer = function($progress, url, $status) {
return function() {
json.get(url).then(function(data) {
var done = false;
Expand Down Expand Up @@ -114,6 +118,9 @@ progress.timer = function($progress, url) {
} else if (!done && progress.config.onProgress) {
progress.config.onProgress($progress, data);
}
if ((data.error || data.message) && $status) {
$status.text(data.error || data.message);
}
if (data.location && progress.app) {
progress.app.nav(data.location.substring(1));
}
Expand Down

0 comments on commit 7eca458

Please sign in to comment.