'use strict';

/**
 * Open and close button for aside-menu
 */
$('show-aside-button').addEvent('click', function (event) {
    // Get the aside current margin-left as integer
    var asideMargin = parseInt($('aside-menu').getStyle('margin-left'));

    /**
     * Change aside margin to show or hide it
     */
    $('aside-menu').setStyle(
        'margin-left',
        asideMargin === 0 ? '-18rem' : '0rem'
    );

    /**
     * Change content width do adjust to fit on the side of aside
     */
    $('content').setStyle(
        'width',
        asideMargin === 0 ? '100%' : 'calc(100% - 17rem)'
    );
});

@@ -8,16 +8,510 @@
 rict';%0A%0A
+%0A%0A/**%0A * Change aside margin to show it%0A * Change content width do adjust to fit on the side of aside%0A */%0Avar showAside = (function() %7B%0A    $('aside-menu').setStyle('margin-left', '0rem');%0A    $('content').setStyle('width', 'calc(100%25 - 17rem)');%0A%7D);%0A%0A%0A%0A/**%0A * Change aside margin to hide it%0A * Change content width do adjust to fit on the side of aside%0A */%0Avar hideAside = (function() %7B%0A    $('aside-menu').setStyle('margin-left', '-18rem');%0A    $('content').setStyle('width', '100%25');%0A%7D);%0A%0A%0A%0A
 /**%0A * O
@@ -744,281 +744,409 @@
     
-/**%0A     * Change
+if (0 ===
  aside
- m
+M
 argin
- to show or hide it%0A     */%0A    $('aside-menu').setStyle(%0A        'margin-left',
+) %7B%0A        hideAside();%0A%0A        return true;
 %0A    
+%7D%0A%0A
     
-asideMargin === 0 ? '-18rem' : '0rem'%0A    );%0A%0A    /**%0A     * Change content width do adjust to fit on the side of aside%0A     */%0A    $('content').s
+showAside();%0A%7D);%0A%0A%0A%0A/**%0A * Catch all clicks on the content element, then check if we should close the%0A * aside or not.%0A */%0A$('content').addEvent('click', function (event) %7B%0A    var asideButtonVisible = $('show-aside-button').getStyle('display') === 'inline-block';%0A    var asideVisible = parseInt($('aside-menu').g
 etStyle(
 %0A   
@@ -1145,90 +1145,216 @@
 yle(
-%0A        'width',%0A        asideMargin === 0 ? '100%25' : 'calc(100%25 - 17rem)'
+'margin-left')) === 0;%0A%0A    if (false === asideButtonVisible && false === asideVisible) %7B%0A        showAside();%0A    %7D%0A%0A    if (true === asideButtonVisible && true === asideVisible) %7B%0A        hideAside();
 %0A    
-);
+%7D
 %0A%7D);

Refactor and other ways to close the aside