public
Last active

jQuery.sub() "module-specific jQuery extensions" usage example for jQuery 1.5

  • Download Gist
jquery15-sub-example.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
// Your module.
 
(function($uper){
var $ = $uper.sub();
 
// This method ONLY exists inside this IIFE.
$.fn.remove = function() {
if ( confirm( "Really remove " + this.length + " elements?" ) ) {
// Execute (and return the value of) the main jQuery .remove method.
return $uper.fn.remove.apply( this, arguments );
} else {
// Just return the collection of elements.
return this;
}
};
 
// This method exists everywhere, because it is defined on the "super" jQuery.
$uper.fn.alertLength = function() {
alert( "There are " + this.length + " selected elements!" );
return this;
};
 
$(function(){
// Annoying alert!
$("ul").alertLength();
 
// Requests confirmation before removing!
$("ul:first").remove();
});
})(jQuery);
 
// Some other guy's module.
 
(function($){
 
$(function(){
// Annoying alert!
$("ul").alertLength();
 
// Removes normally, no confirmation dialog.
$("ul:first").remove();
 
// Annoying alert!
$("ul").alertLength();
});
 
})(jQuery);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.