2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, Drupal) {
9 Drupal.theme.progressBar = function (id) {
10 return '<div id="' + id + '" class="progress" aria-live="polite">' + '<div class="progress__label"> </div>' + '<div class="progress__track"><div class="progress__bar"></div></div>' + '<div class="progress__percentage"></div>' + '<div class="progress__description"> </div>' + '</div>';
13 Drupal.ProgressBar = function (id, updateCallback, method, errorCallback) {
15 this.method = method || 'GET';
16 this.updateCallback = updateCallback;
17 this.errorCallback = errorCallback;
19 this.element = $(Drupal.theme('progressBar', id));
22 $.extend(Drupal.ProgressBar.prototype, {
23 setProgress: function setProgress(percentage, message, label) {
24 if (percentage >= 0 && percentage <= 100) {
25 $(this.element).find('div.progress__bar').css('width', percentage + '%');
26 $(this.element).find('div.progress__percentage').html(percentage + '%');
28 $('div.progress__description', this.element).html(message);
29 $('div.progress__label', this.element).html(label);
30 if (this.updateCallback) {
31 this.updateCallback(percentage, message, this);
34 startMonitoring: function startMonitoring(uri, delay) {
39 stopMonitoring: function stopMonitoring() {
40 clearTimeout(this.timer);
44 sendPing: function sendPing() {
46 clearTimeout(this.timer);
52 if (uri.indexOf('?') === -1) {
57 uri += '_format=json';
63 success: function success(progress) {
64 if (progress.status === 0) {
65 pb.displayError(progress.data);
69 pb.setProgress(progress.percentage, progress.message, progress.label);
71 pb.timer = setTimeout(function () {
75 error: function error(xmlhttp) {
76 var e = new Drupal.AjaxError(xmlhttp, pb.uri);
77 pb.displayError('<pre>' + e.message + '</pre>');
82 displayError: function displayError(string) {
83 var error = $('<div class="messages messages--error"></div>').html(string);
84 $(this.element).before(error).hide();
86 if (this.errorCallback) {
87 this.errorCallback(this);