Widget factory: Fixed #3275: Prevent multiple instantiations of the same plugin on a single element.

This commit is contained in:
Scott González 2008-09-02 23:34:42 +00:00
parent b95772ef09
commit ccdb99e313

View File

@ -89,11 +89,14 @@ $.widget = function(name, prototype) {
// handle initialization and non-getter methods // handle initialization and non-getter methods
return this.each(function() { return this.each(function() {
var instance = $.data(this, name); var instance = $.data(this, name);
if (isMethodCall && instance && $.isFunction(instance[options])) {
instance[options].apply(instance, args); // constructor
} else if (!isMethodCall) { (!instance && !isMethodCall &&
$.data(this, name, new $[namespace][name](this, options)); $.data(this, name, new $[namespace][name](this, options)));
}
// method call
(instance && isMethodCall &&
instance[options].apply(instance, args));
}); });
}; };