Created
November 1, 2012 19:20
-
-
Save togakangaroo/3995833 to your computer and use it in GitHub Desktop.
Shim to revert updated jQuery Ui Widget Bridge to older behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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