Skip to content

Instantly share code, notes, and snippets.

Created October 19, 2011 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/1299007 to your computer and use it in GitHub Desktop.
Save anonymous/1299007 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) {
var ul = $(e.target).closest('ul.dropdown')
if ( ul.length < 0 || ul.get(0) != dropdown.get(0) )
{
$('ul.dropdown').hide();
$(document).unbind('click touchend', onClickDocument);
}
};
$(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