Skip to content

Commit d23fe49

Browse files
fxscottgonzalez
authored andcommitted
Progressbar: Added max option. Fixes #6681 - Progressbar: add max option.
1 parent d69f2ec commit d23fe49

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

tests/unit/progressbar/progressbar_defaults.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
var progressbar_defaults = {
66
disabled: false,
7-
value: 0
7+
value: 0,
8+
max: 100
89
};
910

1011
commonWidgetTests('progressbar', { defaults: progressbar_defaults });

tests/unit/progressbar/progressbar_events.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55

66
module("progressbar: events");
77

8+
test("create", function() {
9+
expect(1);
10+
$("#progressbar").progressbar({
11+
value: 5,
12+
create: function() {
13+
same(5, $(this).progressbar("value") );
14+
},
15+
change: function() {
16+
ok(false, 'create() has triggered change()');
17+
}
18+
})
19+
});
20+
821
test("change", function() {
922
expect(1);
1023
$("#progressbar").progressbar({

tests/unit/progressbar/progressbar_options.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,12 @@ test("{ value : 105 }", function() {
3131
same( 100, $("#progressbar").progressbar("value") );
3232
});
3333

34+
test("{ max : 5, value : 10 }", function() {
35+
$("#progressbar").progressbar({
36+
max: 5,
37+
value: 10
38+
});
39+
same( 5, $("#progressbar").progressbar("value") );
40+
});
41+
3442
})(jQuery);

ui/jquery.ui.progressbar.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,26 @@
1515

1616
$.widget( "ui.progressbar", {
1717
options: {
18-
value: 0
18+
value: 0,
19+
max: 100
1920
},
2021

2122
min: 0,
22-
max: 100,
2323

2424
_create: function() {
2525
this.element
2626
.addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
2727
.attr({
2828
role: "progressbar",
2929
"aria-valuemin": this.min,
30-
"aria-valuemax": this.max,
30+
"aria-valuemax": this.options.max,
3131
"aria-valuenow": this._value()
3232
});
3333

3434
this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
3535
.appendTo( this.element );
3636

37+
this.oldValue = this._value();
3738
this._refreshValue();
3839
},
3940

@@ -63,8 +64,7 @@ $.widget( "ui.progressbar", {
6364
if ( key === "value" ) {
6465
this.options.value = value;
6566
this._refreshValue();
66-
this._trigger( "change" );
67-
if ( this._value() === this.max ) {
67+
if ( this._value() === this.options.max ) {
6868
this._trigger( "complete" );
6969
}
7070
}
@@ -78,14 +78,25 @@ $.widget( "ui.progressbar", {
7878
if ( typeof val !== "number" ) {
7979
val = 0;
8080
}
81-
return Math.min( this.max, Math.max( this.min, val ) );
81+
return Math.min( this.options.max, Math.max( this.min, val ) );
82+
},
83+
84+
_percentage: function() {
85+
return 100 * this._value() / this.options.max;
8286
},
8387

8488
_refreshValue: function() {
8589
var value = this.value();
90+
var percentage = this._percentage();
91+
92+
if ( this.oldValue !== value ) {
93+
this.oldValue = value;
94+
this._trigger( "change" );
95+
}
96+
8697
this.valueDiv
87-
.toggleClass( "ui-corner-right", value === this.max )
88-
.width( value + "%" );
98+
.toggleClass( "ui-corner-right", value === this.options.max )
99+
.width( percentage.toFixed(0) + "%" );
89100
this.element.attr( "aria-valuenow", value );
90101
}
91102
});

0 commit comments

Comments
 (0)