mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-10-05 01:44:18 +00:00
Progressbar: Added max option. Fixes #6681 - Progressbar: add max option.
This commit is contained in:
parent
d69f2ecb12
commit
d23fe49ae8
@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
var progressbar_defaults = {
|
var progressbar_defaults = {
|
||||||
disabled: false,
|
disabled: false,
|
||||||
value: 0
|
value: 0,
|
||||||
|
max: 100
|
||||||
};
|
};
|
||||||
|
|
||||||
commonWidgetTests('progressbar', { defaults: progressbar_defaults });
|
commonWidgetTests('progressbar', { defaults: progressbar_defaults });
|
||||||
|
@ -5,6 +5,19 @@
|
|||||||
|
|
||||||
module("progressbar: events");
|
module("progressbar: events");
|
||||||
|
|
||||||
|
test("create", function() {
|
||||||
|
expect(1);
|
||||||
|
$("#progressbar").progressbar({
|
||||||
|
value: 5,
|
||||||
|
create: function() {
|
||||||
|
same(5, $(this).progressbar("value") );
|
||||||
|
},
|
||||||
|
change: function() {
|
||||||
|
ok(false, 'create() has triggered change()');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
test("change", function() {
|
test("change", function() {
|
||||||
expect(1);
|
expect(1);
|
||||||
$("#progressbar").progressbar({
|
$("#progressbar").progressbar({
|
||||||
|
@ -31,4 +31,12 @@ test("{ value : 105 }", function() {
|
|||||||
same( 100, $("#progressbar").progressbar("value") );
|
same( 100, $("#progressbar").progressbar("value") );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("{ max : 5, value : 10 }", function() {
|
||||||
|
$("#progressbar").progressbar({
|
||||||
|
max: 5,
|
||||||
|
value: 10
|
||||||
|
});
|
||||||
|
same( 5, $("#progressbar").progressbar("value") );
|
||||||
|
});
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
27
ui/jquery.ui.progressbar.js
vendored
27
ui/jquery.ui.progressbar.js
vendored
@ -15,11 +15,11 @@
|
|||||||
|
|
||||||
$.widget( "ui.progressbar", {
|
$.widget( "ui.progressbar", {
|
||||||
options: {
|
options: {
|
||||||
value: 0
|
value: 0,
|
||||||
|
max: 100
|
||||||
},
|
},
|
||||||
|
|
||||||
min: 0,
|
min: 0,
|
||||||
max: 100,
|
|
||||||
|
|
||||||
_create: function() {
|
_create: function() {
|
||||||
this.element
|
this.element
|
||||||
@ -27,13 +27,14 @@ $.widget( "ui.progressbar", {
|
|||||||
.attr({
|
.attr({
|
||||||
role: "progressbar",
|
role: "progressbar",
|
||||||
"aria-valuemin": this.min,
|
"aria-valuemin": this.min,
|
||||||
"aria-valuemax": this.max,
|
"aria-valuemax": this.options.max,
|
||||||
"aria-valuenow": this._value()
|
"aria-valuenow": this._value()
|
||||||
});
|
});
|
||||||
|
|
||||||
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>" )
|
||||||
.appendTo( this.element );
|
.appendTo( this.element );
|
||||||
|
|
||||||
|
this.oldValue = this._value();
|
||||||
this._refreshValue();
|
this._refreshValue();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -63,8 +64,7 @@ $.widget( "ui.progressbar", {
|
|||||||
if ( key === "value" ) {
|
if ( key === "value" ) {
|
||||||
this.options.value = value;
|
this.options.value = value;
|
||||||
this._refreshValue();
|
this._refreshValue();
|
||||||
this._trigger( "change" );
|
if ( this._value() === this.options.max ) {
|
||||||
if ( this._value() === this.max ) {
|
|
||||||
this._trigger( "complete" );
|
this._trigger( "complete" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,14 +78,25 @@ $.widget( "ui.progressbar", {
|
|||||||
if ( typeof val !== "number" ) {
|
if ( typeof val !== "number" ) {
|
||||||
val = 0;
|
val = 0;
|
||||||
}
|
}
|
||||||
return Math.min( this.max, Math.max( this.min, val ) );
|
return Math.min( this.options.max, Math.max( this.min, val ) );
|
||||||
|
},
|
||||||
|
|
||||||
|
_percentage: function() {
|
||||||
|
return 100 * this._value() / this.options.max;
|
||||||
},
|
},
|
||||||
|
|
||||||
_refreshValue: function() {
|
_refreshValue: function() {
|
||||||
var value = this.value();
|
var value = this.value();
|
||||||
|
var percentage = this._percentage();
|
||||||
|
|
||||||
|
if ( this.oldValue !== value ) {
|
||||||
|
this.oldValue = value;
|
||||||
|
this._trigger( "change" );
|
||||||
|
}
|
||||||
|
|
||||||
this.valueDiv
|
this.valueDiv
|
||||||
.toggleClass( "ui-corner-right", value === this.max )
|
.toggleClass( "ui-corner-right", value === this.options.max )
|
||||||
.width( value + "%" );
|
.width( percentage.toFixed(0) + "%" );
|
||||||
this.element.attr( "aria-valuenow", value );
|
this.element.attr( "aria-valuenow", value );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user