[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/jquery/ui/ -> progressbar.js (source)

   1  /*!
   2   * jQuery UI Progressbar 1.14.2
   3   * https://jqueryui.com
   4   *
   5   * Copyright OpenJS Foundation and other contributors
   6   * Released under the MIT license.
   7   * https://jquery.org/license
   8   */
   9  
  10  //>>label: Progressbar
  11  //>>group: Widgets
  12  //>>description: Displays a status indicator for loading state, standard percentage, and other progress indicators.
  13  //>>docs: https://api.jqueryui.com/progressbar/
  14  //>>demos: https://jqueryui.com/progressbar/
  15  //>>css.structure: ../../themes/base/core.css
  16  //>>css.structure: ../../themes/base/progressbar.css
  17  //>>css.theme: ../../themes/base/theme.css
  18  
  19  ( function( factory ) {
  20      "use strict";
  21  
  22      if ( typeof define === "function" && define.amd ) {
  23  
  24          // AMD. Register as an anonymous module.
  25          define( [
  26              "jquery",
  27              "../version",
  28              "../widget"
  29          ], factory );
  30      } else {
  31  
  32          // Browser globals
  33          factory( jQuery );
  34      }
  35  } )( function( $ ) {
  36  "use strict";
  37  
  38  return $.widget( "ui.progressbar", {
  39      version: "1.14.2",
  40      options: {
  41          classes: {
  42              "ui-progressbar": "ui-corner-all",
  43              "ui-progressbar-value": "ui-corner-left",
  44              "ui-progressbar-complete": "ui-corner-right"
  45          },
  46          max: 100,
  47          value: 0,
  48  
  49          change: null,
  50          complete: null
  51      },
  52  
  53      min: 0,
  54  
  55      _create: function() {
  56  
  57          // Constrain initial value
  58          this.oldValue = this.options.value = this._constrainedValue();
  59  
  60          this.element.attr( {
  61  
  62              // Only set static values; aria-valuenow and aria-valuemax are
  63              // set inside _refreshValue()
  64              role: "progressbar",
  65              "aria-valuemin": this.min
  66          } );
  67          this._addClass( "ui-progressbar", "ui-widget ui-widget-content" );
  68  
  69          this.valueDiv = $( "<div>" ).appendTo( this.element );
  70          this._addClass( this.valueDiv, "ui-progressbar-value", "ui-widget-header" );
  71          this._refreshValue();
  72      },
  73  
  74      _destroy: function() {
  75          this.element.removeAttr( "role aria-valuemin aria-valuemax aria-valuenow" );
  76  
  77          this.valueDiv.remove();
  78      },
  79  
  80      value: function( newValue ) {
  81          if ( newValue === undefined ) {
  82              return this.options.value;
  83          }
  84  
  85          this.options.value = this._constrainedValue( newValue );
  86          this._refreshValue();
  87      },
  88  
  89      _constrainedValue: function( newValue ) {
  90          if ( newValue === undefined ) {
  91              newValue = this.options.value;
  92          }
  93  
  94          this.indeterminate = newValue === false;
  95  
  96          // Sanitize value
  97          if ( typeof newValue !== "number" ) {
  98              newValue = 0;
  99          }
 100  
 101          return this.indeterminate ? false :
 102              Math.min( this.options.max, Math.max( this.min, newValue ) );
 103      },
 104  
 105      _setOptions: function( options ) {
 106  
 107          // Ensure "value" option is set after other values (like max)
 108          var value = options.value;
 109          delete options.value;
 110  
 111          this._super( options );
 112  
 113          this.options.value = this._constrainedValue( value );
 114          this._refreshValue();
 115      },
 116  
 117      _setOption: function( key, value ) {
 118          if ( key === "max" ) {
 119  
 120              // Don't allow a max less than min
 121              value = Math.max( this.min, value );
 122          }
 123          this._super( key, value );
 124      },
 125  
 126      _setOptionDisabled: function( value ) {
 127          this._super( value );
 128  
 129          this.element.attr( "aria-disabled", value );
 130          this._toggleClass( null, "ui-state-disabled", !!value );
 131      },
 132  
 133      _percentage: function() {
 134          return this.indeterminate ?
 135              100 :
 136              100 * ( this.options.value - this.min ) / ( this.options.max - this.min );
 137      },
 138  
 139      _refreshValue: function() {
 140          var value = this.options.value,
 141              percentage = this._percentage();
 142  
 143          this.valueDiv
 144              .toggle( this.indeterminate || value > this.min )
 145              .width( percentage.toFixed( 0 ) + "%" );
 146  
 147          this
 148              ._toggleClass( this.valueDiv, "ui-progressbar-complete", null,
 149                  value === this.options.max )
 150              ._toggleClass( "ui-progressbar-indeterminate", null, this.indeterminate );
 151  
 152          if ( this.indeterminate ) {
 153              this.element.removeAttr( "aria-valuenow" );
 154              if ( !this.overlayDiv ) {
 155                  this.overlayDiv = $( "<div>" ).appendTo( this.valueDiv );
 156                  this._addClass( this.overlayDiv, "ui-progressbar-overlay" );
 157              }
 158          } else {
 159              this.element.attr( {
 160                  "aria-valuemax": this.options.max,
 161                  "aria-valuenow": value
 162              } );
 163              if ( this.overlayDiv ) {
 164                  this.overlayDiv.remove();
 165                  this.overlayDiv = null;
 166              }
 167          }
 168  
 169          if ( this.oldValue !== value ) {
 170              this.oldValue = value;
 171              this._trigger( "change" );
 172          }
 173          if ( value === this.options.max ) {
 174              this._trigger( "complete" );
 175          }
 176      }
 177  } );
 178  
 179  } );


Generated : Mon Jul 27 08:20:18 2026 Cross-referenced by PHPXref