6 (function ($, Drupal) {
11 * Attaches the batch behavior to progress bars.
13 * @type {Drupal~behavior}
15 Drupal.behaviors.batch = {
16 attach: function (context, settings) {
17 var batch = settings.batch;
18 var $progress = $('[data-drupal-progress]').once('batch');
21 // Success: redirect to the summary.
22 function updateCallback(progress, status, pb) {
23 if (progress === '100') {
25 window.location = batch.uri + '&op=finished';
29 function errorCallback(pb) {
30 $progress.prepend($('<p class="error"></p>').html(batch.errorMessage));
34 if ($progress.length) {
35 progressBar = new Drupal.ProgressBar('updateprogress', updateCallback, 'POST', errorCallback);
36 progressBar.setProgress(-1, batch.initMessage);
37 progressBar.startMonitoring(batch.uri + '&op=do', 10);
38 // Remove HTML from no-js progress bar.
40 // Append the JS progressbar element.
41 $progress.append(progressBar.element);