Created
January 31, 2011 21:04
-
-
Save cowboy/804811 to your computer and use it in GitHub Desktop.
jQuery.sub() "module-specific jQuery extensions" usage example for jQuery 1.5
This file contains hidden or 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
// 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