Skip to content

Instantly share code, notes, and snippets.

@karlbright
Created October 27, 2011 00:03
Show Gist options
  • Save karlbright/1318395 to your computer and use it in GitHub Desktop.
Save karlbright/1318395 to your computer and use it in GitHub Desktop.
Fixing some of Jesse's code. Example of using jquery extend functionality.
$.fn.modalize = function(){
$(this).each(function(i,v){ // Iterate over each of the elements
var el = $(v), popup = el.prev('.popup');
el.bind('input', function(){ // When the user types within input...
if(popup.is(':hidden')) el.prev('.popup').fadeIn(100); // Grab previous sibling with class of 'popup'
});
el.bind('focusout', function(){ // When focus leaves this element...
$('.popup').fadeOut(300); // Fade all popups out
});
})
return this; // Return elements so you can chain methods - example: $('input').modalize().show();
};
$(function(){
$("input").modalize();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment