mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Widget: Added _setOptions method for handling normalized options setting. Fixes #6114 - Widget: Add _setOptions() method.
This commit is contained in:
parent
0b6710aed7
commit
9d88b565d6
@ -209,7 +209,30 @@ test( ".option() - getter", function() {
|
|||||||
"modifying returned options hash does not modify plugin instance" );
|
"modifying returned options hash does not modify plugin instance" );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( ".option() - setter", function() {
|
test( ".option() - delegate to ._setOptions()", function() {
|
||||||
|
var calls = [];
|
||||||
|
$.widget( "ui.testWidget", {
|
||||||
|
_create: function() {},
|
||||||
|
_setOptions: function( options ) {
|
||||||
|
calls.push( options );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var div = $( "<div></div>" ).testWidget();
|
||||||
|
|
||||||
|
calls = [];
|
||||||
|
div.testWidget( "option", "foo", "bar" );
|
||||||
|
same( calls, [{ foo: "bar" }], "_setOptions called for single option" );
|
||||||
|
|
||||||
|
calls = [];
|
||||||
|
div.testWidget( "option", {
|
||||||
|
bar: "qux",
|
||||||
|
quux: "quuux"
|
||||||
|
});
|
||||||
|
same( calls, [{ bar: "qux", quux: "quuux" }],
|
||||||
|
"_setOptions called with multiple options" );
|
||||||
|
});
|
||||||
|
|
||||||
|
test( ".option() - delegate to ._setOption()", function() {
|
||||||
var calls = [];
|
var calls = [];
|
||||||
$.widget( "ui.testWidget", {
|
$.widget( "ui.testWidget", {
|
||||||
_create: function() {},
|
_create: function() {},
|
||||||
|
13
ui/jquery.ui.widget.js
vendored
13
ui/jquery.ui.widget.js
vendored
@ -176,12 +176,11 @@ $.Widget.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
option: function( key, value ) {
|
option: function( key, value ) {
|
||||||
var options = key,
|
var options = key;
|
||||||
self = this;
|
|
||||||
|
|
||||||
if ( arguments.length === 0 ) {
|
if ( arguments.length === 0 ) {
|
||||||
// don't return a reference to the internal hash
|
// don't return a reference to the internal hash
|
||||||
return $.extend( {}, self.options );
|
return $.extend( {}, this.options );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof key === "string" ) {
|
if (typeof key === "string" ) {
|
||||||
@ -192,11 +191,17 @@ $.Widget.prototype = {
|
|||||||
options[ key ] = value;
|
options[ key ] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._setOptions( options );
|
||||||
|
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
_setOptions: function( options ) {
|
||||||
|
var self = this;
|
||||||
$.each( options, function( key, value ) {
|
$.each( options, function( key, value ) {
|
||||||
self._setOption( key, value );
|
self._setOption( key, value );
|
||||||
});
|
});
|
||||||
|
|
||||||
return self;
|
return this;
|
||||||
},
|
},
|
||||||
_setOption: function( key, value ) {
|
_setOption: function( key, value ) {
|
||||||
this.options[ key ] = value;
|
this.options[ key ] = value;
|
||||||
|
Loading…
Reference in New Issue
Block a user