File tree Expand file tree Collapse file tree 2 files changed +33
-5
lines changed Expand file tree Collapse file tree 2 files changed +33
-5
lines changed Original file line number Diff line number Diff line change @@ -209,7 +209,30 @@ test( ".option() - getter", function() {
209
209
"modifying returned options hash does not modify plugin instance" ) ;
210
210
} ) ;
211
211
212
- test ( ".option() - setter" , function ( ) {
212
+ test ( ".option() - delegate to ._setOptions()" , function ( ) {
213
+ var calls = [ ] ;
214
+ $ . widget ( "ui.testWidget" , {
215
+ _create : function ( ) { } ,
216
+ _setOptions : function ( options ) {
217
+ calls . push ( options ) ;
218
+ }
219
+ } ) ;
220
+ var div = $ ( "<div></div>" ) . testWidget ( ) ;
221
+
222
+ calls = [ ] ;
223
+ div . testWidget ( "option" , "foo" , "bar" ) ;
224
+ same ( calls , [ { foo : "bar" } ] , "_setOptions called for single option" ) ;
225
+
226
+ calls = [ ] ;
227
+ div . testWidget ( "option" , {
228
+ bar : "qux" ,
229
+ quux : "quuux"
230
+ } ) ;
231
+ same ( calls , [ { bar : "qux" , quux : "quuux" } ] ,
232
+ "_setOptions called with multiple options" ) ;
233
+ } ) ;
234
+
235
+ test ( ".option() - delegate to ._setOption()" , function ( ) {
213
236
var calls = [ ] ;
214
237
$ . widget ( "ui.testWidget" , {
215
238
_create : function ( ) { } ,
Original file line number Diff line number Diff line change @@ -176,12 +176,11 @@ $.Widget.prototype = {
176
176
} ,
177
177
178
178
option : function ( key , value ) {
179
- var options = key ,
180
- self = this ;
179
+ var options = key ;
181
180
182
181
if ( arguments . length === 0 ) {
183
182
// don't return a reference to the internal hash
184
- return $ . extend ( { } , self . options ) ;
183
+ return $ . extend ( { } , this . options ) ;
185
184
}
186
185
187
186
if ( typeof key === "string" ) {
@@ -192,11 +191,17 @@ $.Widget.prototype = {
192
191
options [ key ] = value ;
193
192
}
194
193
194
+ this . _setOptions ( options ) ;
195
+
196
+ return this ;
197
+ } ,
198
+ _setOptions : function ( options ) {
199
+ var self = this ;
195
200
$ . each ( options , function ( key , value ) {
196
201
self . _setOption ( key , value ) ;
197
202
} ) ;
198
203
199
- return self ;
204
+ return this ;
200
205
} ,
201
206
_setOption : function ( key , value ) {
202
207
this . options [ key ] = value ;
You can’t perform that action at this time.
0 commit comments