Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save togakangaroo/3995833 to your computer and use it in GitHub Desktop.
Save togakangaroo/3995833 to your computer and use it in GitHub Desktop.
Shim to revert updated jQuery Ui Widget Bridge to older behavior
var slice = Array.prototype.slice;
var _originalBridge = $.widget.bridge;
$.widget.bridge = function (name, object) {
var fullName = object.prototype.widgetFullName;
$.fn[name] = function (options) {
var isMethodCall = typeof options === "string",
args = slice.call(arguments, 1),
returnValue = this;
// allow multiple hashes to be passed on init
options = !isMethodCall && args.length ?
$.widget.extend.apply(null, [options].concat(args)) :
options;
if (isMethodCall) {
this.each(function () {
var methodValue,
instance = $.data(this, fullName);
if (!instance) {
return; // Revert to older functionality where methods on uninitialized widgets don't do anything
// return $.error("cannot call methods on " + name + " prior to initialization; " +
// "attempted to call method '" + options + "'");
}
if (!instance[options] || options.charAt(0) === "_") {
return $.error("no such method '" + options + "' for " + name + " widget instance");
} else if(!$.isFunction(instance[options])) {
return instance[options]; // Revert to older functionality where non-functions can be returned
}
methodValue = instance[options].apply(instance, args);
if (methodValue !== instance && methodValue !== undefined) {
returnValue = methodValue && methodValue.jquery ?
returnValue.pushStack(methodValue.get()) :
methodValue;
return false;
}
});
} else {
this.each(function () {
var instance = $.data(this, fullName);
if (instance) {
instance.option(options || {})._init();
} else {
new object(options, this);
}
});
}
return returnValue;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment