mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-10-05 01:44:18 +00:00
Widget: Added ability to define how to find options on init. Fixes #6158 - Widget: Ability to define new methods for gathering options on init.
This commit is contained in:
parent
c3b282fceb
commit
512825d358
@ -156,6 +156,32 @@ test("merge multiple option arguments", function() {
|
||||
});
|
||||
});
|
||||
|
||||
test( "_getCreateOptions()", function() {
|
||||
expect( 1 );
|
||||
$.widget( "ui.testWidget", {
|
||||
options: {
|
||||
option1: "valuex",
|
||||
option2: "valuex",
|
||||
option3: "value3",
|
||||
},
|
||||
_getCreateOptions: function() {
|
||||
return {
|
||||
option1: "override1",
|
||||
option2: "overideX",
|
||||
};
|
||||
},
|
||||
_create: function() {
|
||||
same( this.options, {
|
||||
disabled: false,
|
||||
option1: "override1",
|
||||
option2: "value2",
|
||||
option3: "value3"
|
||||
});
|
||||
}
|
||||
});
|
||||
$( "<div>" ).testWidget({ option2: "value2" });
|
||||
});
|
||||
|
||||
test( "re-init", function() {
|
||||
var div = $( "<div></div>" ),
|
||||
actions = [];
|
||||
|
9
ui/jquery.ui.widget.js
vendored
9
ui/jquery.ui.widget.js
vendored
@ -145,7 +145,7 @@ $.Widget.prototype = {
|
||||
this.element = $( element );
|
||||
this.options = $.extend( true, {},
|
||||
this.options,
|
||||
$.metadata && $.metadata.get( element )[ this.widgetName ],
|
||||
this._getCreateOptions(),
|
||||
options );
|
||||
|
||||
var self = this;
|
||||
@ -157,6 +157,13 @@ $.Widget.prototype = {
|
||||
this._trigger( "create" );
|
||||
this._init();
|
||||
},
|
||||
_getCreateOptions: function() {
|
||||
var options = {};
|
||||
if ( $.metadata ) {
|
||||
options = $.metadata.get( element )[ this.widgetName ];
|
||||
}
|
||||
return options;
|
||||
},
|
||||
_create: function() {},
|
||||
_init: function() {},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user