]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget: Added ability to define how to find options on init. Fixes #6158 - Widget...
authorScott González <scott.gonzalez@gmail.com>
Wed, 6 Oct 2010 19:11:49 +0000 (15:11 -0400)
committerScott González <scott.gonzalez@gmail.com>
Wed, 6 Oct 2010 19:11:49 +0000 (15:11 -0400)
tests/unit/widget/widget_core.js
ui/jquery.ui.widget.js

index 364838e3f208dded6b3e5946e9e5f1a1a9b597ce..2673350f3c8bf17fa7bcc312eff3e2dee6dd6fcd 100644 (file)
@@ -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 = [];
index bc6408125c7f523f44b7e8205df5b672803b14a0..f41f9637a165a30cf1c1f7416b471211d04a0cfc 100644 (file)
@@ -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() {},