From 1fb3dd87e3bee37bb3525a8a3096b220031aab57 Mon Sep 17 00:00:00 2001 From: cTn Date: Wed, 16 Jul 2014 13:38:11 +0200 Subject: [PATCH] much cooler way of handling the options menu --- main.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 0423bb3f..aa2d752d 100644 --- a/main.js +++ b/main.js @@ -118,6 +118,7 @@ $(document).ready(function() { if (!el.hasClass('active')) { el.addClass('active'); el.after('
'); + $('div#options-window').load('./tabs/options.html', function() { googleAnalytics.sendAppView('Options'); @@ -147,13 +148,21 @@ $(document).ready(function() { googleAnalyticsConfig.setTrackingPermitted(result); }); + function close_and_cleanup(e) { + if (!$.contains($('div#options-window')[0], e.target)) { + $(document).unbind('click', close_and_cleanup); + + $('div#options-window').slideUp(function() { + el.removeClass('active'); + $(this).empty().remove(); + }); + } + } + + $(document).bind('click', close_and_cleanup); + $(this).slideDown(); }); - } else { - $('div#options-window').slideUp(function() { - el.removeClass('active'); - $(this).empty().remove(); - }); } });