Skip to content

Instantly share code, notes, and snippets.

@tdreyno
Forked from anonymous/gist:1299007
Created October 19, 2011 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdreyno/1299055 to your computer and use it in GitHub Desktop.
Save tdreyno/1299055 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
$(document).ready(function() {
var dropdownW = $('ul.dropdown').prev('a.dropdown').innerWidth();
$('ul.dropdown').width(dropdownW);
$('a.dropdown').bind('click touchend', function(e) {
var dropdown = $(this).next('ul.dropdown')
if (!dropdown.is(':visible'))
{
dropdown.show();
var onClickDocument = function(e) {
if ( $('ul.dropdown').is(':visible') && !$(e.target).parents('ul.dropdown').length > 0 )
{
$('ul.dropdown').hide();
$(document).unbind('click touchend', onClickDocument);
e.preventDefault();
}
};
$(document).bind('click touchend', onClickDocument);
return false;
}
else
{
return true;
}
})
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment