Search and Top Navigation
Ticket #4411: auto-getters.patch
File auto-getters.patch, 2.7 KB (added by scottgonzalez, March 30, 2009 01:56AM UTC)
Index: /Users/sgonzale/Documents/workspace/jQuery UI/ui/ui.core.js
===================================================================
--- /Users/sgonzale/Documents/workspace/jQuery UI/ui/ui.core.js (revision 2394)
+++ /Users/sgonzale/Documents/workspace/jQuery UI/ui/ui.core.js (working copy)
@@ -203,19 +203,6 @@
// $.widget is a factory to create jQuery plugins
// taking some boilerplate code out of the plugin code
-function getter(namespace, plugin, method, args) {
- function getMethods(type) {
- var methods = $[namespace][plugin][type] || [];
- return (typeof methods == 'string' ? methods.split(/,?\s+/) : methods);
- }
-
- var methods = getMethods('getter');
- if (args.length == 1 && typeof args[0] == 'string') {
- methods = methods.concat(getMethods('getterSetter'));
- }
- return ($.inArray(method, methods) != -1);
-}
-
$.widget = function(name, prototype) {
var namespace = name.split(".")[0],
fullName;
@@ -230,32 +217,31 @@
// create plugin method
$.fn[name] = function(options) {
var isMethodCall = (typeof options == 'string'),
- args = Array.prototype.slice.call(arguments, 1);
+ args = Array.prototype.slice.call(arguments, 1),
+ returnValue = this;
// prevent calls to internal methods
if (isMethodCall && options.substring(0, 1) == '_') {
- return this;
+ return returnValue;
}
- // handle getter methods
- if (isMethodCall && getter(namespace, name, options, args)) {
- var instance = $.data(this[0], name);
- return (instance ? instance[options].apply(instance, args)
- : undefined);
- }
-
- // handle initialization and non-getter methods
- return this.each(function() {
- var instance = $.data(this, name);
-
- // constructor
- (!instance && !isMethodCall &&
- $.data(this, name, new $[namespace][name](this, options))._init());
+ (isMethodCall
+ ? this.each(function() {
+ var instance = $.data(this, name),
+ methodValue = (instance && $.isFunction(instance[options])
+ ? instance[options].apply(instance, args)
+ : instance);
+ if (methodValue !== instance) {
+ returnValue = methodValue;
+ return false;
+ }
+ })
+ : this.each(function() {
+ ($.data(this, name) ||
+ $.data(this, name, new $[namespace][name](this, options))._init());
+ }));
- // method call
- (instance && isMethodCall && $.isFunction(instance[options]) &&
- instance[options].apply(instance, args));
- });
+ return returnValue;
};
// create widget constructor
@@ -292,10 +278,6 @@
// add widget prototype
$[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);
-
- // TODO: merge getter and getterSetter properties from widget prototype
- // and plugin prototype
- $[namespace][name].getterSetter = 'option';
};
$.widget.prototype = {
Download in other formats:
Original Format
File auto-getters.patch, 2.7 KB (added by scottgonzalez, March 30, 2009 01:56AM UTC)
Index: /Users/sgonzale/Documents/workspace/jQuery UI/ui/ui.core.js
===================================================================
--- /Users/sgonzale/Documents/workspace/jQuery UI/ui/ui.core.js (revision 2394)
+++ /Users/sgonzale/Documents/workspace/jQuery UI/ui/ui.core.js (working copy)
@@ -203,19 +203,6 @@
// $.widget is a factory to create jQuery plugins
// taking some boilerplate code out of the plugin code
-function getter(namespace, plugin, method, args) {
- function getMethods(type) {
- var methods = $[namespace][plugin][type] || [];
- return (typeof methods == 'string' ? methods.split(/,?\s+/) : methods);
- }
-
- var methods = getMethods('getter');
- if (args.length == 1 && typeof args[0] == 'string') {
- methods = methods.concat(getMethods('getterSetter'));
- }
- return ($.inArray(method, methods) != -1);
-}
-
$.widget = function(name, prototype) {
var namespace = name.split(".")[0],
fullName;
@@ -230,32 +217,31 @@
// create plugin method
$.fn[name] = function(options) {
var isMethodCall = (typeof options == 'string'),
- args = Array.prototype.slice.call(arguments, 1);
+ args = Array.prototype.slice.call(arguments, 1),
+ returnValue = this;
// prevent calls to internal methods
if (isMethodCall && options.substring(0, 1) == '_') {
- return this;
+ return returnValue;
}
- // handle getter methods
- if (isMethodCall && getter(namespace, name, options, args)) {
- var instance = $.data(this[0], name);
- return (instance ? instance[options].apply(instance, args)
- : undefined);
- }
-
- // handle initialization and non-getter methods
- return this.each(function() {
- var instance = $.data(this, name);
-
- // constructor
- (!instance && !isMethodCall &&
- $.data(this, name, new $[namespace][name](this, options))._init());
+ (isMethodCall
+ ? this.each(function() {
+ var instance = $.data(this, name),
+ methodValue = (instance && $.isFunction(instance[options])
+ ? instance[options].apply(instance, args)
+ : instance);
+ if (methodValue !== instance) {
+ returnValue = methodValue;
+ return false;
+ }
+ })
+ : this.each(function() {
+ ($.data(this, name) ||
+ $.data(this, name, new $[namespace][name](this, options))._init());
+ }));
- // method call
- (instance && isMethodCall && $.isFunction(instance[options]) &&
- instance[options].apply(instance, args));
- });
+ return returnValue;
};
// create widget constructor
@@ -292,10 +278,6 @@
// add widget prototype
$[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);
-
- // TODO: merge getter and getterSetter properties from widget prototype
- // and plugin prototype
- $[namespace][name].getterSetter = 'option';
};
$.widget.prototype = {