[jQuery] Deep Copy of UI Widget Options (1.6rc6)
I noticed that when creating a custom widget, the default options are
NOT deep copied to the options passed in during instantiation. For
example:
// Create the widget
$.widget('myWidget', {
init: function (){
/*
At this point, given the defaults and the instantiation
below,
I would expect the this.options to contain...
{
title: 'My Widget',
classes: {
'header': '.my-widget-header',
'content': '.my-widget-content',
'footer': '.custom-widget-footer'
}
}
Instead, this.options contains (because of no 'deep
copy')...
{
title: 'My Widget',
classes: {
'footer': '.custom-widget-footer'
}
}
*/
}
}
);
// Set the widget defaults
$.ui.myWidget.defaults = {
title: 'My Widget',
classes: {
'header': '.my-widget-header',
'content': '.my-widget-content',
'footer': '.my-widget-footer'
}
}
// Widgefy an element on the page with id='my-widget'
var testWidget = $('#my-widget').myWidget({
classes: {
'footer': '.custom-widget-footer'
}
});