Changeset 636

Show
Ignore:
Timestamp:
08/26/08 19:44:12 (19 months ago)
Author:
scott.gonzalez
Message:

Core: Fixed #3257: Added option method to widget factory.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ui/ui.core.js

    r616 r636  
    5353// taking some boilerplate code out of the plugin code 
    5454// created by Scott González and Jörn Zaefferer 
    55 function getter(namespace, plugin, method) { 
    56         var methods = $[namespace][plugin].getter || []; 
    57         methods = (typeof methods == "string" ? methods.split(/,?\s+/) : methods); 
     55function getter(namespace, plugin, method, args) { 
     56        function getMethods(type) { 
     57                var methods = $[namespace][plugin][type] || []; 
     58                return (typeof methods == 'string' ? methods.split(/,?\s+/) : methods); 
     59        } 
     60         
     61        var methods = getMethods('getter'); 
     62        if (args.length == 1 && typeof args[0] == 'string') { 
     63                methods = methods.concat(getMethods('getterSetter')); 
     64        } 
    5865        return ($.inArray(method, methods) != -1); 
    5966} 
     
    7481                 
    7582                // handle getter methods 
    76                 if (isMethodCall && getter(namespace, name, options)) { 
     83                if (isMethodCall && getter(namespace, name, options, args)) { 
    7784                        var instance = $.data(this[0], name); 
    7885                        return (instance ? instance[options].apply(instance, args) 
     
    121128        // add widget prototype 
    122129        $[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype); 
     130         
     131        // TODO: merge getter and getterSetter properties from widget prototype 
     132        // and plugin prototype 
     133        $[namespace][name].getterSetter = 'option'; 
    123134}; 
    124135 
     
    129140        }, 
    130141         
     142        option: function(key, value) { 
     143                var options = key, 
     144                        self = this; 
     145                 
     146                if (typeof key == "string") { 
     147                        if (value === undefined) { 
     148                                return this._getData(key); 
     149                        } 
     150                        options = {}; 
     151                        options[key] = value; 
     152                } 
     153                 
     154                $.each(options, function(key, value) { 
     155                        self._setData(key, value); 
     156                }); 
     157        }, 
    131158        _getData: function(key) { 
    132159                return this.options[key];