|
| 1 | +function closeEdemSidebar() { |
| 2 | + $('.JS-openSidebar').removeClass('-active'); |
| 3 | + $('body').removeClass('-sidebaropen'); |
| 4 | +} |
| 5 | + |
| 6 | +function openEdemSidebar(option) { |
| 7 | + var contentSelector = '.JS-' + option + 'Content'; |
| 8 | + var linkSelector = '.JS-openSidebar[data-sidebar-content="' + option + '"]'; |
| 9 | + |
| 10 | + $('body').addClass('-sidebaropen'); |
| 11 | + $('.JS-sidebarContent').removeClass('-show'); |
| 12 | + $('.JS-openSidebar').removeClass('-active'); |
| 13 | + $(linkSelector).addClass('-active'); |
| 14 | + $(contentSelector).addClass('-show'); |
| 15 | + resizeRecaptcha(); |
| 16 | +} |
| 17 | + |
1 | 18 | function resizeRecaptcha() { |
2 | 19 | if (!$('.JS-signupContent').hasClass('JS-signupFinished')){ // Only run if signup is not completed |
3 | 20 | var accessWidth = $('.JS-signUpForm')[0].getBoundingClientRect().width; // Get value with decimals |
@@ -38,49 +55,31 @@ function showSuccessSignupMessage() { |
38 | 55 |
|
39 | 56 | // Resize reCAPTCHA on window resize |
40 | 57 | $(window).resize(function(){ |
41 | | - resizeRecaptcha(); |
| 58 | + if ($('body').hasClass('-sidebaropen')) { |
| 59 | + resizeRecaptcha(); |
| 60 | + } |
42 | 61 | }); |
43 | 62 |
|
44 | | -// eDemocracia open sidebar and its contents |
| 63 | +// Create and append to body an overlay div for when the sidebar is opened |
| 64 | +$('<div/>', {class: 'edem-overlay'}).appendTo('body'); |
| 65 | + |
| 66 | +// Open sidebar via the topbar |
45 | 67 | $('.JS-openSidebar').click(function() { |
46 | 68 | if ($(this).hasClass('-active')) { |
47 | | - $(this).removeClass('-active'); |
48 | | - $('body').removeClass('-sidebaropen'); |
49 | | - |
| 69 | + closeEdemSidebar(); |
50 | 70 | } else { |
51 | | - $('body').addClass('-sidebaropen') |
52 | | - $('.JS-sidebarContent').removeClass('-show'); |
53 | | - $('.JS-openSidebar').removeClass('-active'); |
54 | | - $(this).addClass('-active'); |
55 | | - |
56 | | - if ($(this).hasClass('JS-showSignin')) { |
57 | | - $('.JS-signinContent').addClass('-show'); |
58 | | - |
59 | | - } else if ($(this).hasClass('JS-showSignup')) { |
60 | | - $('.JS-signupContent').addClass('-show'); |
61 | | - resizeRecaptcha(); |
62 | | - |
63 | | - } else if ($(this).hasClass('JS-showProfile')) { |
64 | | - $('.JS-profileContent').addClass('-show'); |
65 | | - } |
| 71 | + openEdemSidebar($(this).data('sidebarContent')); |
66 | 72 | } |
67 | 73 | }); |
68 | 74 |
|
69 | 75 | // eDemocracia sidebar close button |
70 | 76 | $('.JS-closeSidebar').click(function(){ |
71 | | - $('.JS-openSidebar').removeClass('-active'); |
72 | | - $('body').removeClass('-sidebaropen'); |
| 77 | + closeEdemSidebar(); |
73 | 78 | }); |
74 | 79 |
|
75 | | -// Close sidebar if click is outside of sidebar or topbar |
76 | | -document.addEventListener('click', function(e) { |
77 | | - var onEdemCore = $(e.target).closest('.edem-topbar, .edem-sidebar').length; |
78 | | - var sidebarOpen = $('body').hasClass('-sidebaropen'); |
79 | | - |
80 | | - if (!onEdemCore && sidebarOpen ) { |
81 | | - $('.JS-openSidebar').removeClass('-active'); |
82 | | - $('body').removeClass('-sidebaropen'); |
83 | | - } |
| 80 | +// Close sidebar if click on the overlay |
| 81 | +$('.edem-overlay').click(function(){ |
| 82 | + closeEdemSidebar(); |
84 | 83 | }); |
85 | 84 |
|
86 | 85 | // Detect when input is filled |
@@ -195,3 +194,11 @@ $('.JS-signUpForm').submit(function(event) { |
195 | 194 | }); |
196 | 195 | } |
197 | 196 | }); |
| 197 | + |
| 198 | +// XXX This should be exclusively on Audiencias Plugin whenever is possible |
| 199 | +if (location.href.match(/audiencias/)) { |
| 200 | + $(document).on('click', 'a[href^="/home/?next="]', function(e){ |
| 201 | + e.preventDefault(); |
| 202 | + openEdemSidebar('signin'); |
| 203 | + }); |
| 204 | +} |
0 commit comments