From 7cb82d68ebf6aaad388343fcf337a944c1e1ccfd Mon Sep 17 00:00:00 2001 From: Tommy Chen Date: Wed, 6 Jun 2012 16:50:53 +0800 Subject: hide navigation when click outside --- source/javascripts/slash.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source/javascripts') diff --git a/source/javascripts/slash.js b/source/javascripts/slash.js index c33635a..5288572 100644 --- a/source/javascripts/slash.js +++ b/source/javascripts/slash.js @@ -34,6 +34,13 @@ appendCaption(); // Delete or comment this line to disable caption var mobilenav = $('#mobile-nav'); + + $('html').click(function(){ + mobilenav.find('.on').each(function(){ + $(this).removeClass('on').next().hide(); + }); + }); + mobilenav.on('click', '.menu .button', function(){ if (!$(this).hasClass('on')){ var width = $(this).width() + 42; @@ -44,9 +51,12 @@ }).on('click', '.search .button', function(){ if (!$(this).hasClass('on')){ var width = mobilenav.width() - 51; + mobilenav.children('.menu').children().eq(0).removeClass('on').next().hide(); $(this).addClass('on').next().show().css({width: width}).children().children().eq(0).focus(); } else { $(this).removeClass('on').next().hide().children().children().eq(0).val(''); } + }).click(function(e){ + e.stopPropagation(); }); })(jQuery); \ No newline at end of file -- cgit v1.2.3