integration/back-office/lib/jquery-ui/ui/jquery.ui.progressbar.js
author Anthony Ly <anthonyly.com@gmail.com>
Tue, 14 May 2013 18:17:07 +0200
changeset 1 b95aebb070b5
permissions -rw-r--r--
first commit back office front metadatacomposer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     1
/*!
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     2
 * jQuery UI Progressbar 1.10.3
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     3
 * http://jqueryui.com
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     4
 *
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     5
 * Copyright 2013 jQuery Foundation and other contributors
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     6
 * Released under the MIT license.
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     7
 * http://jquery.org/license
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     8
 *
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     9
 * http://api.jqueryui.com/progressbar/
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    10
 *
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    11
 * Depends:
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    12
 *   jquery.ui.core.js
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    13
 *   jquery.ui.widget.js
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    14
 */
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    15
(function( $, undefined ) {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    16
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    17
$.widget( "ui.progressbar", {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    18
	version: "1.10.3",
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    19
	options: {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    20
		max: 100,
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    21
		value: 0,
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    22
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    23
		change: null,
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    24
		complete: null
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    25
	},
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    26
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    27
	min: 0,
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    28
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    29
	_create: function() {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    30
		// Constrain initial value
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    31
		this.oldValue = this.options.value = this._constrainedValue();
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    32
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    33
		this.element
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    34
			.addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    35
			.attr({
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    36
				// Only set static values, aria-valuenow and aria-valuemax are
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    37
				// set inside _refreshValue()
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    38
				role: "progressbar",
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    39
				"aria-valuemin": this.min
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    40
			});
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    41
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    42
		this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    43
			.appendTo( this.element );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    44
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    45
		this._refreshValue();
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    46
	},
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    47
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    48
	_destroy: function() {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    49
		this.element
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    50
			.removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    51
			.removeAttr( "role" )
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    52
			.removeAttr( "aria-valuemin" )
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    53
			.removeAttr( "aria-valuemax" )
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    54
			.removeAttr( "aria-valuenow" );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    55
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    56
		this.valueDiv.remove();
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    57
	},
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    58
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    59
	value: function( newValue ) {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    60
		if ( newValue === undefined ) {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    61
			return this.options.value;
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    62
		}
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    63
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    64
		this.options.value = this._constrainedValue( newValue );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    65
		this._refreshValue();
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    66
	},
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    67
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    68
	_constrainedValue: function( newValue ) {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    69
		if ( newValue === undefined ) {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    70
			newValue = this.options.value;
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    71
		}
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    72
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    73
		this.indeterminate = newValue === false;
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    74
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    75
		// sanitize value
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    76
		if ( typeof newValue !== "number" ) {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    77
			newValue = 0;
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    78
		}
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    79
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    80
		return this.indeterminate ? false :
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    81
			Math.min( this.options.max, Math.max( this.min, newValue ) );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    82
	},
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    83
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    84
	_setOptions: function( options ) {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    85
		// Ensure "value" option is set after other values (like max)
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    86
		var value = options.value;
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    87
		delete options.value;
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    88
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    89
		this._super( options );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    90
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    91
		this.options.value = this._constrainedValue( value );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    92
		this._refreshValue();
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    93
	},
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    94
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    95
	_setOption: function( key, value ) {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    96
		if ( key === "max" ) {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    97
			// Don't allow a max less than min
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    98
			value = Math.max( this.min, value );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    99
		}
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   100
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   101
		this._super( key, value );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   102
	},
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   103
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   104
	_percentage: function() {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   105
		return this.indeterminate ? 100 : 100 * ( this.options.value - this.min ) / ( this.options.max - this.min );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   106
	},
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   107
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   108
	_refreshValue: function() {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   109
		var value = this.options.value,
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   110
			percentage = this._percentage();
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   111
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   112
		this.valueDiv
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   113
			.toggle( this.indeterminate || value > this.min )
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   114
			.toggleClass( "ui-corner-right", value === this.options.max )
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   115
			.width( percentage.toFixed(0) + "%" );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   116
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   117
		this.element.toggleClass( "ui-progressbar-indeterminate", this.indeterminate );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   118
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   119
		if ( this.indeterminate ) {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   120
			this.element.removeAttr( "aria-valuenow" );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   121
			if ( !this.overlayDiv ) {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   122
				this.overlayDiv = $( "<div class='ui-progressbar-overlay'></div>" ).appendTo( this.valueDiv );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   123
			}
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   124
		} else {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   125
			this.element.attr({
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   126
				"aria-valuemax": this.options.max,
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   127
				"aria-valuenow": value
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   128
			});
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   129
			if ( this.overlayDiv ) {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   130
				this.overlayDiv.remove();
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   131
				this.overlayDiv = null;
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   132
			}
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   133
		}
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   134
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   135
		if ( this.oldValue !== value ) {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   136
			this.oldValue = value;
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   137
			this._trigger( "change" );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   138
		}
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   139
		if ( value === this.options.max ) {
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   140
			this._trigger( "complete" );
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   141
		}
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   142
	}
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   143
});
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   144
b95aebb070b5 first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   145
})( jQuery );