Skip to content
Snippets Groups Projects
Select Git revision
  • e8c49d77f274c0b84d855aa377902dbf8a1492e9
  • 3.9 default
  • develop
  • 6.0
  • 5.0
  • 4.0
  • scrutinizer-patch-4
  • scrutinizer-patch-3
  • scrutinizer-patch-2
  • scrutinizer-patch-1
  • 3.7
  • 3.8
  • 3.6
  • 3.9_backported
  • 3.8_backported
  • 3.7_backported
  • 3.5
  • 3.6_backported
  • 3.5_backported
  • 3.4
  • 3.3_backported
  • 6.0.4
  • 6.0.3
  • 5.0.7
  • 6.0.2
  • 6.0.1
  • 5.0.6
  • 6.0.0
  • 5.0.5
  • 6.0.0-rc
  • 5.0.4
  • 6.0.0-beta
  • 5.0.3
  • 4.0.6
  • 5.0.2
  • 5.0.1
  • 4.0.5
  • 5.0.0
  • 4.0.4
  • 5.0.0-rc2
  • 5.0.0-rc1
41 results

functions.lib.php

Blame
  • progress.js 3.10 KiB
    // $Id: progress.js,v 1.27 2010/09/09 21:05:11 dries Exp $
    (function ($) {
    
    /**
     * A progressbar object. Initialized with the given id. Must be inserted into
     * the DOM afterwards through progressBar.element.
     *
     * method is the function which will perform the HTTP request to get the
     * progress bar state. Either "GET" or "POST".
     *
     * e.g. pb = new progressBar('myProgressBar');
     *      some_element.appendChild(pb.element);
     */
    Drupal.progressBar = function (id, updateCallback, method, errorCallback) {
      var pb = this;
      this.id = id;
      this.method = method || 'GET';
      this.updateCallback = updateCallback;
      this.errorCallback = errorCallback;
    
      // The WAI-ARIA setting aria-live="polite" will announce changes after users
      // have completed their current activity and not interrupt the screen reader.
      this.element = $('<div class="progress" aria-live="polite"></div>').attr('id', id);
      this.element.html('<div class="bar"><div class="filled"></div></div>' +
                        '<div class="percentage"></div>' +
                        '<div class="message">&nbsp;</div>');
    };
    
    /**
     * Set the percentage and status message for the progressbar.
     */
    Drupal.progressBar.prototype.setProgress = function (percentage, message) {
      if (percentage >= 0 && percentage <= 100) {
        $('div.filled', this.element).css('width', percentage + '%');
        $('div.percentage', this.element).html(percentage + '%');
      }
      $('div.message', this.element).html(message);
      if (this.updateCallback) {
        this.updateCallback(percentage, message, this);
      }
    };
    
    /**
     * Start monitoring progress via Ajax.
     */
    Drupal.progressBar.prototype.startMonitoring = function (uri, delay) {
      this.delay = delay;
      this.uri = uri;
      this.sendPing();
    };
    
    /**
     * Stop monitoring progress via Ajax.
     */
    Drupal.progressBar.prototype.stopMonitoring = function () {
      clearTimeout(this.timer);
      // This allows monitoring to be stopped from within the callback.
      this.uri = null;
    };
    
    /**
     * Request progress data from server.
     */
    Drupal.progressBar.prototype.sendPing = function () {
      if (this.timer) {
        clearTimeout(this.timer);
      }
      if (this.uri) {
        var pb = this;
        // When doing a post request, you need non-null data. Otherwise a