summaryrefslogtreecommitdiff
path: root/misc/batch.js
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2007-07-01 15:37:10 +0000
committerDries Buytaert <dries@buytaert.net>2007-07-01 15:37:10 +0000
commitc11cb4ec24479e801076c094f043f2084b344d0c (patch)
tree5248d25917032a394ec350b65ebde88259168ffe /misc/batch.js
parenta3d75e547f62174fe9fa2b5c3f9684b620612b00 (diff)
downloadbrdo-c11cb4ec24479e801076c094f043f2084b344d0c.tar.gz
brdo-c11cb4ec24479e801076c094f043f2084b344d0c.tar.bz2
- Patch #120360 by nedjo: enable AJAX by making all behaviours reattachable.
Diffstat (limited to 'misc/batch.js')
-rw-r--r--misc/batch.js61
1 files changed, 34 insertions, 27 deletions
diff --git a/misc/batch.js b/misc/batch.js
index 8cf1f910f..51b1e8b59 100644
--- a/misc/batch.js
+++ b/misc/batch.js
@@ -1,31 +1,38 @@
-if (Drupal.jsEnabled) {
- $(document).ready(function() {
- $('#progress').each(function () {
- var holder = this;
- var uri = Drupal.settings.batch.uri;
- var initMessage = Drupal.settings.batch.initMessage;
- var errorMessage = Drupal.settings.batch.errorMessage;
+// $Id$
- // Success: redirect to the summary.
- var updateCallback = function (progress, status, pb) {
- if (progress == 100) {
- pb.stopMonitoring();
- window.location = uri+'&op=finished';
- }
- };
+/**
+ * Attaches the batch behaviour to progress bars.
+ */
+Drupal.behaviors.batch = function (context) {
+ // This behavior attaches by ID, so is only valid once on a page.
+ if ($('#progress.batch-processed').size()) {
+ return;
+ }
+ $('#progress', context).addClass('batch-processed').each(function () {
+ var holder = this;
+ var uri = Drupal.settings.batch.uri;
+ var initMessage = Drupal.settings.batch.initMessage;
+ var errorMessage = Drupal.settings.batch.errorMessage;
- var errorCallback = function (pb) {
- var div = document.createElement('p');
- div.className = 'error';
- $(div).html(errorMessage);
- $(holder).prepend(div);
- $('#wait').hide();
- };
+ // Success: redirect to the summary.
+ var updateCallback = function (progress, status, pb) {
+ if (progress == 100) {
+ pb.stopMonitoring();
+ window.location = uri+'&op=finished';
+ }
+ };
- var progress = new Drupal.progressBar('updateprogress', updateCallback, "POST", errorCallback);
- progress.setProgress(-1, initMessage);
- $(holder).append(progress.element);
- progress.startMonitoring(uri+'&op=do', 10);
- });
+ var errorCallback = function (pb) {
+ var div = document.createElement('p');
+ div.className = 'error';
+ $(div).html(errorMessage);
+ $(holder).prepend(div);
+ $('#wait').hide();
+ };
+
+ var progress = new Drupal.progressBar('updateprogress', updateCallback, "POST", errorCallback);
+ progress.setProgress(-1, initMessage);
+ $(holder).append(progress.element);
+ progress.startMonitoring(uri+'&op=do', 10);
});
-}
+};