Browse files

Progressbar: Add ability to set value: false for an indeterminate pro…

…gressbar. Fixes #7624 - Progressbar: Support value: false for indeterminate progressbar
  • Loading branch information...
1 parent d771048 commit 0e1ed574300626e9978115e7abb87a3b859725a5 @kborchers kborchers committed with kborchers Mar 26, 2012
View
9 demos/progressbar/animated.html
@@ -9,14 +9,11 @@
<script src="../../ui/jquery.ui.widget.js"></script>
<script src="../../ui/jquery.ui.progressbar.js"></script>
<link rel="stylesheet" href="../demos.css">
- <style>
- .ui-progressbar .ui-progressbar-value { background-image: url(images/pbar-ani.gif); }
- </style>
<script>
$(function() {
$( "#progressbar" ).progressbar({
value: 59
- });
+ }).find( ".ui-progressbar-value div" ).addClass( "ui-progressbar-overlay" );
});
</script>
</head>
@@ -27,10 +24,10 @@
<div class="demo-description">
<p>
This progressbar has an animated fill by setting the
-<code>background-image</code>
+<code>ui-progressbar-overlay</code> class
on the
<code>.ui-progressbar-value</code>
-element, using css.
+element's overlay div.
</p>
</div>
</body>
View
53 demos/progressbar/indeterminate.html
@@ -0,0 +1,53 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Progressbar - Indeterminate Value</title>
+ <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
+ <script src="../../jquery-1.8.2.js"></script>
+ <script src="../../ui/jquery.ui.core.js"></script>
+ <script src="../../ui/jquery.ui.widget.js"></script>
+ <script src="../../ui/jquery.ui.progressbar.js"></script>
+ <link rel="stylesheet" href="../demos.css">
+ <script>
+ $(function() {
+ $( "#progressbar" ).progressbar({
+ value: false
+ });
+ $( "button" ).on( "click", function( event ) {
+ var target = $( event.target ),
+ pbar = $( "#progressbar" ),
+ pbarValue = pbar.find( ".ui-progressbar-value" );
+
+ if ( target.is( "#numButton" ) ) {
+ pbar.progressbar( "option", {
+ value: Math.floor( Math.random() * 100 )
+ });
+ } else if ( target.is( "#colorButton" ) ) {
+ pbarValue.css({
+ "background": '#' + Math.floor( Math.random() * 16777215 ).toString( 16 )
+ });
+ } else if ( target.is( "#falseButton" ) ) {
+ pbar.progressbar( "option", "value", false );
+ }
+ });
+ });
+ </script>
+ <style>
+ #progressbar .ui-progressbar-value {
+ background-color: #CCCCCC;
+ }
+ </style>
+</head>
+<body>
+
+<div id="progressbar"></div>
+<button id="numButton">Random Value - Determinate</button>
+<button id="falseButton">Indeterminate</button>
+<button id="colorButton">Random Color</button>
+
+<div class="demo-description">
+<p>Indeterminate progress bar and switching between determinate and indeterminate styles.</p>
+</div>
+</body>
+</html>
View
1 demos/progressbar/index.html
@@ -10,6 +10,7 @@
<li><a href="default.html">Default functionality</a></li>
<li><a href="animated.html">Animated</a></li>
<li><a href="resize.html">Resizable progressbar</a></li>
+ <li><a href="indeterminate.html">Indeterminate</a></li>
</ul>
</body>
View
BIN themes/base/images/animated-overlay.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
11 themes/base/jquery.ui.progressbar.css
@@ -9,4 +9,13 @@
* http://docs.jquery.com/UI/Progressbar#theming
*/
.ui-progressbar { height:2em; text-align: left; overflow: hidden; }
-.ui-progressbar .ui-progressbar-value {margin: -1px; height:100%; }
+.ui-progressbar .ui-progressbar-value { margin: -1px; height:100%; }
+.ui-progressbar .ui-progressbar-value .ui-progressbar-overlay {
+ background: url("images/animated-overlay.gif");
+ height: 100%;
+ filter: alpha(opacity=25);
+ opacity: 0.25;
+}
+.ui-progressbar .ui-progressbar-indeterminate {
+ background-image: none;
+}
View
30 ui/jquery.ui.progressbar.js
@@ -29,11 +29,10 @@ $.widget( "ui.progressbar", {
.attr({
role: "progressbar",
"aria-valuemin": this.min,
- "aria-valuemax": this.options.max,
- "aria-valuenow": this._value()
+ "aria-valuemax": this.options.max
});
- this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
+ this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'><div></div></div>" )
.appendTo( this.element );
this.oldValue = this._value();
@@ -62,7 +61,7 @@ $.widget( "ui.progressbar", {
_setOption: function( key, value ) {
if ( key === "value" ) {
- this.options.value = value;
+ this.options[ key ] = value;
this._refreshValue();
if ( this._value() === this.options.max ) {
this._trigger( "complete" );
@@ -74,31 +73,42 @@ $.widget( "ui.progressbar", {
_value: function() {
var val = this.options.value;
+ this.indeterminate = val === false;
+
// normalize invalid value
- if ( typeof val !== "number" ) {
+ if ( typeof val !== "number" && val !== false ) {
val = 0;
}
- return Math.min( this.options.max, Math.max( this.min, val ) );
+ return this.indeterminate ? false : Math.min( this.options.max, Math.max( this.min, val ) );
},
_percentage: function() {
- return 100 * this._value() / this.options.max;
+ var val = this._value();
+ return this.indeterminate ? 100 : 100 * val / this.options.max;
},
_refreshValue: function() {
var value = this.value(),
- percentage = this._percentage();
+ percentage = this._percentage(),
+ overlay = this.valueDiv.children().eq( 0 );
+
+ overlay.toggleClass( "ui-progressbar-overlay", this.indeterminate );
+ this.valueDiv.toggleClass( "ui-progressbar-indeterminate", this.indeterminate );
if ( this.oldValue !== value ) {
this.oldValue = value;
this._trigger( "change" );
}
this.valueDiv
- .toggle( value > this.min )
+ .toggle( this.indeterminate || value > this.min )
.toggleClass( "ui-corner-right", value === this.options.max )
.width( percentage.toFixed(0) + "%" );
- this.element.attr( "aria-valuenow", value );
+ if ( this.indeterminate ) {
+ this.element.removeAttr( "aria-valuenow" );
+ } else {
+ this.element.attr( "aria-valuenow", value );
+ }
}
});

0 comments on commit 0e1ed57

Please sign in to comment.