From 512825d358851f4b2b584f1b6463e9cd48f31752 Mon Sep 17 00:00:00 2001 From: Scott González Date: Wed, 6 Oct 2010 15:11:49 -0400 Subject: Widget: Added ability to define how to find options on init. Fixes #6158 - Widget: Ability to define new methods for gathering options on init. --- tests/unit/widget/widget_core.js | 26 ++++++++++++++++++++++++++ ui/jquery.ui.widget.js | 9 ++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 364838e3f..2673350f3 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -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" + }); + } + }); + $( "
" ).testWidget({ option2: "value2" }); +}); + test( "re-init", function() { var div = $( "
" ), actions = []; diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index bc6408125..f41f9637a 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -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() {}, -- cgit v1.2.3