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