Skip to content

@cowboy /jquery15-sub-example.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
jQuery.sub() "module-specific jQuery extensions" usage example for jQuery 1.5
// 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.