[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

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


Generated: Thu Nov 21 01:00:03 2024 Cross-referenced by PHPXref 0.7.1