diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-03-24 09:21:53 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-03-24 09:21:53 -0400 |
commit | 6fc98deef03b91b0ea2ed51be2708bdd2c61d479 (patch) | |
tree | 95c28d5127688df58fd140e06a2cc45067d845ad /ui/jquery.ui.widget.js | |
parent | a2015497fc9ac32fb75e414a4bc644de05ed0c1c (diff) | |
download | jquery-ui-6fc98deef03b91b0ea2ed51be2708bdd2c61d479.tar.gz jquery-ui-6fc98deef03b91b0ea2ed51be2708bdd2c61d479.zip |
Widget: Allow setting individual properties of deep options. Fixes #7035 - Widget: Extend .option() to set partial nested options.
Diffstat (limited to 'ui/jquery.ui.widget.js')
-rw-r--r-- | ui/jquery.ui.widget.js | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 09c680ec3..27d08ccd2 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -208,19 +208,34 @@ $.Widget.prototype = { }, option: function( key, value ) { - var options = key; + var options = key, + parts, + curOption, + i; if ( arguments.length === 0 ) { // don't return a reference to the internal hash return $.extend( {}, this.options ); } - if (typeof key === "string" ) { + if ( typeof key === "string" ) { if ( value === undefined ) { return this.options[ key ]; } + // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } } options = {}; - options[ key ] = value; + parts = key.split( "." ); + key = parts.shift(); + if ( parts.length ) { + curOption = options[ key ] = $.extend( true, {}, this.options[ key ] ); + for ( i = 0; i < parts.length - 1; i++ ) { + curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {}; + curOption = curOption[ parts[ i ] ]; + } + curOption[ parts.pop() ] = value; + } else { + options[ key ] = value; + } } this._setOptions( options ); |