mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Widget: Deep extend options when creating a new plugin. Fixes #5830 - Widget: Using inheritance overwrites the base classes options.
This commit is contained in:
parent
06f721b74f
commit
f24bc0fb1f
@ -13,7 +13,8 @@
|
|||||||
<script type="text/javascript" src="../../jquery.simulate.js"></script>
|
<script type="text/javascript" src="../../jquery.simulate.js"></script>
|
||||||
<script type="text/javascript" src="../testsuite.js"></script>
|
<script type="text/javascript" src="../testsuite.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" src="widget.js"></script>
|
<script type="text/javascript" src="widget_core.js"></script>
|
||||||
|
<script type="text/javascript" src="widget_tickets.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
46
tests/unit/widget/widget_tickets.js
Normal file
46
tests/unit/widget/widget_tickets.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* widget unit tests
|
||||||
|
*/
|
||||||
|
(function($) {
|
||||||
|
|
||||||
|
module('widget: tickets');
|
||||||
|
|
||||||
|
test('#5830 - Widget: Using inheritance overwrites the base classes options', function() {
|
||||||
|
$.widget( "ui.testWidgetBase", {
|
||||||
|
options: {
|
||||||
|
obj: {
|
||||||
|
key1: "foo",
|
||||||
|
key2: "bar"
|
||||||
|
},
|
||||||
|
arr: [ "testing" ]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$.widget( "ui.testWidgetExtension", $.ui.testWidgetBase, {
|
||||||
|
options: {
|
||||||
|
obj: {
|
||||||
|
key1: "baz"
|
||||||
|
},
|
||||||
|
arr: [ "alpha", "beta" ]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
same( $.ui.testWidgetBase.prototype.options.obj, {
|
||||||
|
key1: "foo",
|
||||||
|
key2: "bar"
|
||||||
|
}, "base class option object not overridden");
|
||||||
|
same( $.ui.testWidgetBase.prototype.options.arr, [ "testing" ],
|
||||||
|
"base class option array not overridden");
|
||||||
|
|
||||||
|
same( $.ui.testWidgetExtension.prototype.options.obj, {
|
||||||
|
key1: "baz",
|
||||||
|
key2: "bar"
|
||||||
|
}, "extension class option object extends base");
|
||||||
|
same( $.ui.testWidgetExtension.prototype.options.arr, [ "alpha", "beta" ],
|
||||||
|
"extension class option array overwrites base");
|
||||||
|
|
||||||
|
delete $.ui.testWidgetBase;
|
||||||
|
delete $.ui.testWidgetExtension;
|
||||||
|
});
|
||||||
|
|
||||||
|
})(jQuery);
|
2
ui/jquery.ui.widget.js
vendored
2
ui/jquery.ui.widget.js
vendored
@ -57,7 +57,7 @@ $.widget = function( name, base, prototype ) {
|
|||||||
// basePrototype[ key ] = $.extend( {}, val );
|
// basePrototype[ key ] = $.extend( {}, val );
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
basePrototype.options = $.extend( {}, basePrototype.options );
|
basePrototype.options = $.extend( true, {}, basePrototype.options );
|
||||||
$[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
|
$[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
|
||||||
namespace: namespace,
|
namespace: namespace,
|
||||||
widgetName: name,
|
widgetName: name,
|
||||||
|
Loading…
Reference in New Issue
Block a user