From 8eef9f3514548fb173371245bfe40498cd69a068 Mon Sep 17 00:00:00 2001 From: Olimpia Magliulo <olimpiam@intern-ikts-MacBook-Air.local> Date: Wed, 13 Dec 2017 11:40:02 +0100 Subject: [PATCH] Separate javascript relative to side-menu from general script to a specific one. --- templates/base.twig | 1 + www/assets/js/src/script.js | 54 ++-------------------------------- www/assets/js/src/side_menu.js | 48 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 52 deletions(-) create mode 100644 www/assets/js/src/side_menu.js diff --git a/templates/base.twig b/templates/base.twig index 499ecee94..b895f0ce1 100644 --- a/templates/base.twig +++ b/templates/base.twig @@ -52,6 +52,7 @@ <script type="text/javascript" src="/{{ baseurlpath }}assets/js/lib/clipboard.min.js"></script> <script type="text/javascript" src="/{{ baseurlpath }}assets/js/lib/selectize.min.js"></script> <script type="text/javascript" src="/{{ baseurlpath }}assets/js/src/language.js"></script> + <script type="text/javascript" src="/{{ baseurlpath }}assets/js/src/side_menu.js"></script> <script type="text/javascript" src="/{{ baseurlpath }}assets/js/src/script.js"></script> {% block postload %}{% endblock %} </body></html> diff --git a/www/assets/js/src/script.js b/www/assets/js/src/script.js index 0ae37d351..83ec1128d 100644 --- a/www/assets/js/src/script.js +++ b/www/assets/js/src/script.js @@ -39,6 +39,7 @@ function SimpleSAML_hide(id) { element.style.display = 'none'; } + // Attach the `fileselect` event to all file inputs on the page $(document).on('change', ':file', function() { var input = $(this), @@ -52,7 +53,7 @@ $(document).ready(function() { $('#organization').selectize(); new Clipboard('.clipboard-btn'); - // Watch for custom `fileselect` event +// Watch for custom `fileselect` event $(':file').on('fileselect', function(event, numFiles, label) { var input = $(this).parents('.pure-button-group').find(':text'), @@ -69,54 +70,3 @@ $(document).ready(function() { }); - -/*************/ - -(function (window, document) { - - var layout = document.getElementById('layout'), - menu = document.getElementById('menu'), - menuLink = document.getElementById('menuLink'), - content = document.getElementById('content'); - footer = document.getElementById('foot'); - - function toggleClass(element, className) { - var classes = element.className.split(/\s+/), - length = classes.length, - i = 0; - - for(; i < length; i++) { - if (classes[i] === className) { - classes.splice(i, 1); - break; - } - } - // The className is not found - if (length === classes.length) { - classes.push(className); - } - - element.className = classes.join(' '); - } - - function toggleAll(e) { - var active = 'active'; - - e.preventDefault(); - toggleClass(layout, active); - toggleClass(menu, active); - toggleClass(menuLink, active); - toggleClass(footer, active); - } - - menuLink.onclick = function (e) { - toggleAll(e); - }; - - content.onclick = function(e) { - if (menu.className.indexOf('active') !== -1) { - toggleAll(e); - } - }; - -}(this, this.document)); diff --git a/www/assets/js/src/side_menu.js b/www/assets/js/src/side_menu.js new file mode 100644 index 000000000..4ba1b214b --- /dev/null +++ b/www/assets/js/src/side_menu.js @@ -0,0 +1,48 @@ +(function (window, document) { + + var layout = document.getElementById('layout'), + menu = document.getElementById('menu'), + menuLink = document.getElementById('menuLink'), + content = document.getElementById('content'); + footer = document.getElementById('foot'); + + function toggleClass(element, className) { + var classes = element.className.split(/\s+/), + length = classes.length, + i = 0; + + for(; i < length; i++) { + if (classes[i] === className) { + classes.splice(i, 1); + break; + } + } + // The className is not found + if (length === classes.length) { + classes.push(className); + } + + element.className = classes.join(' '); + } + + function toggleAll(e) { + var active = 'active'; + + e.preventDefault(); + toggleClass(layout, active); + toggleClass(menu, active); + toggleClass(menuLink, active); + toggleClass(footer, active); + } + + menuLink.onclick = function (e) { + toggleAll(e); + }; + + content.onclick = function(e) { + if (menu.className.indexOf('active') !== -1) { + toggleAll(e); + } + }; + +}(this, this.document)); -- GitLab