]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget: Added _setOptions method for handling normalized options setting. Fixes ...
authorScott González <scott.gonzalez@gmail.com>
Mon, 27 Sep 2010 15:21:09 +0000 (11:21 -0400)
committerScott González <scott.gonzalez@gmail.com>
Mon, 27 Sep 2010 15:21:09 +0000 (11:21 -0400)
tests/unit/widget/widget_core.js
ui/jquery.ui.widget.js

index 6042221064c4160d6af80870c661c12ce410dbd4..76d6543c249e90eb2dab496b3692f1892171ad48 100644 (file)
@@ -209,7 +209,30 @@ test( ".option() - getter", function() {
                "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 = [];
        $.widget( "ui.testWidget", {
                _create: function() {},
index aef9b8378c7cc05717e1b5b75fa8c66e6976e0df..866f7441e5cb230f88099b4dead9aefb17648218 100644 (file)
@@ -176,12 +176,11 @@ $.Widget.prototype = {
        },
 
        option: function( key, value ) {
-               var options = key,
-                       self = this;
+               var options = key;
 
                if ( arguments.length === 0 ) {
                        // don't return a reference to the internal hash
-                       return $.extend( {}, self.options );
+                       return $.extend( {}, this.options );
                }
 
                if  (typeof key === "string" ) {
@@ -192,11 +191,17 @@ $.Widget.prototype = {
                        options[ key ] = value;
                }
 
+               this._setOptions( options );
+
+               return this;
+       },
+       _setOptions: function( options ) {
+               var self = this;
                $.each( options, function( key, value ) {
                        self._setOption( key, value );
                });
 
-               return self;
+               return this;
        },
        _setOption: function( key, value ) {
                this.options[ key ] = value;