Chris@0: /** Chris@0: * DO NOT EDIT THIS FILE. Chris@0: * See the following change record for more information, Chris@0: * https://www.drupal.org/node/2815083 Chris@0: * @preserve Chris@0: **/ Chris@0: Chris@0: (function ($, Drupal) { Chris@0: Drupal.theme.progressBar = function (id) { Chris@0: return '
' + '
 
' + '
' + '
' + '
 
' + '
'; Chris@0: }; Chris@0: Chris@0: Drupal.ProgressBar = function (id, updateCallback, method, errorCallback) { Chris@0: this.id = id; Chris@0: this.method = method || 'GET'; Chris@0: this.updateCallback = updateCallback; Chris@0: this.errorCallback = errorCallback; Chris@0: Chris@0: this.element = $(Drupal.theme('progressBar', id)); Chris@0: }; Chris@0: Chris@0: $.extend(Drupal.ProgressBar.prototype, { Chris@0: setProgress: function setProgress(percentage, message, label) { Chris@0: if (percentage >= 0 && percentage <= 100) { Chris@0: $(this.element).find('div.progress__bar').css('width', percentage + '%'); Chris@0: $(this.element).find('div.progress__percentage').html(percentage + '%'); Chris@0: } Chris@0: $('div.progress__description', this.element).html(message); Chris@0: $('div.progress__label', this.element).html(label); Chris@0: if (this.updateCallback) { Chris@0: this.updateCallback(percentage, message, this); Chris@0: } Chris@0: }, Chris@0: startMonitoring: function startMonitoring(uri, delay) { Chris@0: this.delay = delay; Chris@0: this.uri = uri; Chris@0: this.sendPing(); Chris@0: }, Chris@0: stopMonitoring: function stopMonitoring() { Chris@0: clearTimeout(this.timer); Chris@0: Chris@0: this.uri = null; Chris@0: }, Chris@0: sendPing: function sendPing() { Chris@0: if (this.timer) { Chris@0: clearTimeout(this.timer); Chris@0: } Chris@0: if (this.uri) { Chris@0: var pb = this; Chris@0: Chris@0: var uri = this.uri; Chris@0: if (uri.indexOf('?') === -1) { Chris@0: uri += '?'; Chris@0: } else { Chris@0: uri += '&'; Chris@0: } Chris@0: uri += '_format=json'; Chris@0: $.ajax({ Chris@0: type: this.method, Chris@0: url: uri, Chris@0: data: '', Chris@0: dataType: 'json', Chris@0: success: function success(progress) { Chris@0: if (progress.status === 0) { Chris@0: pb.displayError(progress.data); Chris@0: return; Chris@0: } Chris@0: Chris@0: pb.setProgress(progress.percentage, progress.message, progress.label); Chris@0: Chris@0: pb.timer = setTimeout(function () { Chris@0: pb.sendPing(); Chris@0: }, pb.delay); Chris@0: }, Chris@0: error: function error(xmlhttp) { Chris@0: var e = new Drupal.AjaxError(xmlhttp, pb.uri); Chris@0: pb.displayError('
' + e.message + '
'); Chris@0: } Chris@0: }); Chris@0: } Chris@0: }, Chris@0: displayError: function displayError(string) { Chris@0: var error = $('
').html(string); Chris@0: $(this.element).before(error).hide(); Chris@0: Chris@0: if (this.errorCallback) { Chris@0: this.errorCallback(this); Chris@0: } Chris@0: } Chris@0: }); Chris@0: })(jQuery, Drupal);