Commit 06adf95b4bd08f4355b452781fe7ffbbe5735cfd

Authored by Leonardo Merlin
1 parent 8e5c6908

add handler of loginPanel (press ESC or click out to hide)

Showing 1 changed file with 27 additions and 1 deletions   Show diff stats
js/main.js
... ... @@ -783,7 +783,8 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun
783 783  
784 784 // create login panel on header
785 785 (function (){
786   - var $loginPanel = $('#login-panel');
  786 + var loginPanelId = '#login-panel';
  787 + var $loginPanel = $(loginPanelId);
787 788 $loginPanel.hide();
788 789 $loginPanel.removeClass('hide');
789 790 $loginPanel.append(loginTemplate());
... ... @@ -803,6 +804,31 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun
803 804 $loginPanel.toggle();
804 805 });
805 806  
  807 + // handle click on elsewhere (out of loginPanel)
  808 + $(document).click(function(e){
  809 + var $target = $(e.target);
  810 + // console.log('e.target', e.target);
  811 +
  812 + var isLoginButton = ($target.attr('id') === 'login-button');
  813 + // console.log('isLoginButton', isLoginButton);
  814 +
  815 + var isChildOfPanel = ($target.closest(loginPanelId).length !== 0);
  816 + // console.log('isChildOfPanel', isChildOfPanel);
  817 +
  818 + if( !isLoginButton && !isChildOfPanel ){
  819 + $loginPanel.hide();
  820 + }
  821 + });
  822 +
  823 + // handle esc
  824 + $(document).keyup(function(e) {
  825 +
  826 + // escape key maps to keycode `27`
  827 + if (e.keyCode == 27) { // ESC
  828 + $loginPanel.hide();
  829 + }
  830 + });
  831 +
806 832 $('.participar').removeClass('hide');
807 833 })();
808 834  
... ...