]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget factory: Support passing multiple option hashes on init. Fixes #4784.
authorScott González <scott.gonzalez@gmail.com>
Wed, 26 Aug 2009 02:06:19 +0000 (02:06 +0000)
committerScott González <scott.gonzalez@gmail.com>
Wed, 26 Aug 2009 02:06:19 +0000 (02:06 +0000)
tests/unit/core/core.js
ui/ui.core.js

index f26257053e793036440fd71047607460c2aff86b..232b9506120e2c57919f8321010fffa9c1ebbb7d 100644 (file)
@@ -57,4 +57,26 @@ test('zIndex', function() {
        equals($('#zIndexAutoNoParent').zIndex(), 0, 'zIndex never explicitly set in hierarchy');
 });
 
+test('widget factory, merge multiple option arguments', function() {
+       expect(1);
+       $.widget("ui.widgetTest", {
+               _init: function() {
+                       same(this.options, {
+                               disabled: false,
+                               option1: "value1",
+                               option2: "value2",
+                               option3: "value3"
+                       });
+               }
+       });
+       $("#main > :first").widgetTest({
+               option1: "valuex",
+               option2: "valuex",
+               option3: "value3"
+       }, {
+               option1: "value1",
+               option2: "value2"
+       });
+});
+
 })(jQuery);
index e166f0f067743a2cd852f6864900ceac75b6ba6b..37f1f09e9820fd69850b856bfab5148a9d842904 100644 (file)
@@ -253,6 +253,11 @@ $.widget = function(name, prototype) {
                        args = Array.prototype.slice.call(arguments, 1),
                        returnValue = this;
 
+               // allow multiple hashes to be passed on init
+               options = !isMethodCall && args.length
+                       ? $.extend.apply(null, arguments)
+                       : options;
+
                // prevent calls to internal methods
                if (isMethodCall && options.substring(0, 1) == '_') {
                        return returnValue;