From 33fcc249f4dbede985a2d3e7b56b4898b97d30ba Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 25 Jan 2014 02:07:21 +0400 Subject: [PATCH] added default close action to progress bar... Signed-off-by: Alex A. Naanou --- ui/ui.js | 23 ++++++++++++++++++++--- ui/workers.js | 8 +++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/ui/ui.js b/ui/ui.js index c4b855b5..5fe0fb8b 100755 --- a/ui/ui.js +++ b/ui/ui.js @@ -18,6 +18,8 @@ var CONTEXT_INDICATOR_UPDATERS = [] // - 'floating' // - 'panel' var PROGRESS_WIDGET_CONTAINER = 'floating' +// can be between 0 and 3000 +var PROGRESS_HIDE_TIMEOUT = 1500 @@ -468,16 +470,24 @@ function getProgressContainer(mode, parent){ // Make or get progress bar by name... // -function progressBar(name, container){ +function progressBar(name, container, close, hide_timeout){ container = container == null ? getProgressContainer() : container + close = close === undefined + ? function(){ + $(this).trigger('progressDone') } + : close + hide_timeout = hide_timeout == null ? PROGRESS_HIDE_TIMEOUT + : hide_timeout < 0 ? 0 + : hide_timeout > 3000 ? 3000 + : hide_timeout var widget = getProgressBar(name) // a progress bar already exists, reset it and return... // XXX should we re-bind the event handlers here??? - if(widget.length > 0){ + if(widget.length > 0 && widget.css('display') == 'none'){ return widget.trigger('progressReset') } @@ -513,7 +523,7 @@ function progressBar(name, container){ setTimeout(function(){ widget.hide() - }, 1500) + }, hide_timeout) }) .on('progressReset', function(){ widget @@ -527,6 +537,10 @@ function progressBar(name, container){ }) }) + if(close != null){ + widget.on('progressClose', close) + } + bar = $(bar[0]) state = $(state[0]) widget = $(widget[0]) @@ -540,6 +554,9 @@ function getProgressBar(name){ } + +/******************************************* Event trigger helpers ***/ + function resetProgressBar(name){ var widget = typeof(name) == typeof('str') ? getProgressBar(name) diff --git a/ui/workers.js b/ui/workers.js index 0729110a..e4daaf2e 100755 --- a/ui/workers.js +++ b/ui/workers.js @@ -29,10 +29,12 @@ function getWorkerProgressBar(name, worker, container){ var widget = getProgressBar(name) if(widget.length == 0){ - widget = progressBar(name, container) - .on('progressClose', function(){ + widget = progressBar( + name, + container, + function(){ WORKERS[name].dropQueue() - }) + }) worker .progress(function(done, total){