Last active
December 10, 2015 14:09
-
-
Save corydorning/4445666 to your computer and use it in GitHub Desktop.
Boilerplate for adding a reference to the original jQuery selector used to instantiate a widget, which can then be accessed inside of a patched/custom jQuery UI method.
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
/* Extend a jQuery Selector to the Widget Options | |
* =================================================== | |
* Use: Boilerplate for adding a reference to the | |
* original jQuery selector used to instantiate a | |
* widget, which can then be accessed inside of a | |
* patched/custom jQuery UI method. | |
* | |
* Replace WIDGET with the name of the jQuery UI widget | |
* Replace METHOD with the name of the jQuery UI widget | |
* method you are patching | |
* | |
*/ | |
;(function($) { | |
"use strict"; | |
// keep original reference to the WIDGET plugin and methods | |
var _WIDGET= { | |
// reference to widget plugin | |
fn: $.fn.WIDGET, | |
// original reference to the jQuery UI method | |
METHOD: $.ui.WIDGET.prototype.METHOD | |
}; | |
$.ui.WIDGET.prototype.METHOD = function(event){ | |
// reference original WIDGET selector | |
console.log(this.options.selector); | |
// run original close function | |
_WIDGET.METHOD.apply( this, arguments ); | |
}; | |
// extend the WIDGET options to include the original selector | |
$.fn.WIDGET = function(){ | |
$.extend($.ui.WIDGET.prototype.options, { selector: this.selector }); | |
// run original WIDGET function | |
_WIDGET.fn.apply( this, arguments ); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment