Skip to content

Commit f24bc0f

Browse files
committed
Widget: Deep extend options when creating a new plugin. Fixes #5830 - Widget: Using inheritance overwrites the base classes options.
1 parent 06f721b commit f24bc0f

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

tests/unit/widget/widget.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
<script type="text/javascript" src="../../jquery.simulate.js"></script>
1414
<script type="text/javascript" src="../testsuite.js"></script>
1515

16-
<script type="text/javascript" src="widget.js"></script>
16+
<script type="text/javascript" src="widget_core.js"></script>
17+
<script type="text/javascript" src="widget_tickets.js"></script>
1718
</head>
1819
<body>
1920

File renamed without changes.

tests/unit/widget/widget_tickets.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* widget unit tests
3+
*/
4+
(function($) {
5+
6+
module('widget: tickets');
7+
8+
test('#5830 - Widget: Using inheritance overwrites the base classes options', function() {
9+
$.widget( "ui.testWidgetBase", {
10+
options: {
11+
obj: {
12+
key1: "foo",
13+
key2: "bar"
14+
},
15+
arr: [ "testing" ]
16+
}
17+
});
18+
19+
$.widget( "ui.testWidgetExtension", $.ui.testWidgetBase, {
20+
options: {
21+
obj: {
22+
key1: "baz"
23+
},
24+
arr: [ "alpha", "beta" ]
25+
}
26+
});
27+
28+
same( $.ui.testWidgetBase.prototype.options.obj, {
29+
key1: "foo",
30+
key2: "bar"
31+
}, "base class option object not overridden");
32+
same( $.ui.testWidgetBase.prototype.options.arr, [ "testing" ],
33+
"base class option array not overridden");
34+
35+
same( $.ui.testWidgetExtension.prototype.options.obj, {
36+
key1: "baz",
37+
key2: "bar"
38+
}, "extension class option object extends base");
39+
same( $.ui.testWidgetExtension.prototype.options.arr, [ "alpha", "beta" ],
40+
"extension class option array overwrites base");
41+
42+
delete $.ui.testWidgetBase;
43+
delete $.ui.testWidgetExtension;
44+
});
45+
46+
})(jQuery);

ui/jquery.ui.widget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ $.widget = function( name, base, prototype ) {
5757
// basePrototype[ key ] = $.extend( {}, val );
5858
// }
5959
// });
60-
basePrototype.options = $.extend( {}, basePrototype.options );
60+
basePrototype.options = $.extend( true, {}, basePrototype.options );
6161
$[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
6262
namespace: namespace,
6363
widgetName: name,

0 commit comments

Comments
 (0)