]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget: option-method should work as getter only when argument length is 1. Fixes...
authorJyoti Deka <dekajp@gmail.com>
Tue, 15 Oct 2013 03:43:06 +0000 (23:43 -0400)
committerScott González <scott.gonzalez@gmail.com>
Tue, 26 Nov 2013 20:13:05 +0000 (15:13 -0500)
(cherry picked from commit ecde7cd41a59e9c3ff07f56baeeaec2147cca779)

tests/unit/widget/widget_core.js
ui/jquery.ui.widget.js

index 86b6ca5f96b2e47801761bf6fa8e5d42b035c591..7f9145c4455217779b6ed39763e0bbd1c48f8ec4 100644 (file)
@@ -535,7 +535,7 @@ test( ".option() - delegate to ._setOptions()", function() {
 });
 
 test( ".option() - delegate to ._setOption()", function() {
-       expect( 2 );
+       expect( 3 );
        var div,
                calls = [];
        $.widget( "ui.testWidget", {
@@ -554,6 +554,11 @@ test( ".option() - delegate to ._setOption()", function() {
        deepEqual( calls, [{ key: "foo", val: "bar" }],
                "_setOption called for single option" );
 
+       calls = [];
+       div.testWidget( "option", "foo", undefined );
+       deepEqual( calls, [{ key: "foo", val: undefined }],
+               "_setOption called for single option where value is undefined" );
+
        calls = [];
        div.testWidget( "option", {
                bar: "qux",
@@ -566,9 +571,9 @@ test( ".option() - delegate to ._setOption()", function() {
 });
 
 test( ".option() - deep option setter", function() {
-       expect( 6 );
+       expect( 9 );
        $.widget( "ui.testWidget", {} );
-       var div = $( "<div>" ).testWidget();
+       var result, div = $( "<div>" ).testWidget();
        function deepOption( from, to, msg ) {
                div.data( "ui-testWidget" ).options.foo = from;
                $.ui.testWidget.prototype._setOption = function( key, value ) {
@@ -580,6 +585,12 @@ test( ".option() - deep option setter", function() {
        deepOption( { bar: "baz" }, { bar: "qux" }, "one deep" );
        div.testWidget( "option", "foo.bar", "qux" );
 
+       deepOption( { bar: "baz" }, { bar: undefined }, "one deep - value = undefined" );
+
+       result = div.testWidget( "option", "foo.bar", undefined );
+
+       deepEqual ( result, div, "option should return widget on successful set operation" );
+
        deepOption( null, { bar: "baz" }, "null" );
        div.testWidget( "option", "foo.bar", "baz" );
 
index 050125fa9f1c3003bde203093cd3e4275373cdc7..427d3e3256f3f279028e08ba6699ff5f0392f889 100644 (file)
@@ -315,12 +315,12 @@ $.Widget.prototype = {
                                        curOption = curOption[ parts[ i ] ];
                                }
                                key = parts.pop();
-                               if ( value === undefined ) {
+                               if ( arguments.length === 1 ) {
                                        return curOption[ key ] === undefined ? null : curOption[ key ];
                                }
                                curOption[ key ] = value;
                        } else {
-                               if ( value === undefined ) {
+                               if ( arguments.length === 1 ) {
                                        return this.options[ key ] === undefined ? null : this.options[ key ];
                                }
                                options[ key ] = value;