From 88e99536d793408ed28e2be62d5d6d0c6b4ea6d6 Mon Sep 17 00:00:00 2001
From: Tim van Dijen <tvdijen@gmail.com>
Date: Mon, 21 Mar 2022 17:03:31 +0100
Subject: [PATCH] Reorder entire PR

---
 modules/admin/templates/federation.twig     |  5 ---
 modules/core/www/assets/js/loginuserpass.js |  3 +-
 src/js/bundle.js                            | 45 ---------------------
 src/js/bundle/clipboard.js                  | 11 +++++
 src/js/bundle/expander.js                   | 15 +++++++
 src/js/bundle/highlight.js                  | 16 ++++++++
 src/js/{main.js => bundle/language.js}      | 36 -----------------
 src/js/bundle/main.js                       | 10 +++++
 src/js/bundle/ready.js                      | 15 +++++++
 src/js/logout/logout.js                     |  2 +-
 src/js/logout/main.js                       |  2 +-
 templates/auth_status.twig                  |  8 ----
 templates/base.twig                         |  4 +-
 webpack.config.js                           |  2 +-
 14 files changed, 73 insertions(+), 101 deletions(-)
 delete mode 100644 src/js/bundle.js
 create mode 100644 src/js/bundle/clipboard.js
 create mode 100644 src/js/bundle/expander.js
 create mode 100644 src/js/bundle/highlight.js
 rename src/js/{main.js => bundle/language.js} (53%)
 create mode 100644 src/js/bundle/main.js
 create mode 100644 src/js/bundle/ready.js

diff --git a/modules/admin/templates/federation.twig b/modules/admin/templates/federation.twig
index bcf5c6fba..367acbe68 100644
--- a/modules/admin/templates/federation.twig
+++ b/modules/admin/templates/federation.twig
@@ -4,7 +4,6 @@
 
 {% block preload %}
 <link rel="stylesheet" href="{{ asset('css/admin.css', 'admin') }}">
-<link rel="preload" href="{{ asset('js/bundle.js') }}" as="script">
 {% endblock %}
 
 {% block content %}
@@ -147,7 +146,3 @@
       </fieldset>
     </form>
 {% endblock %}
-{% block postload %}
-    <script src="{{ asset('js/bundle.js') }}"></script>
-{% endblock %}
-
diff --git a/modules/core/www/assets/js/loginuserpass.js b/modules/core/www/assets/js/loginuserpass.js
index 46d50fc4c..8667593a7 100644
--- a/modules/core/www/assets/js/loginuserpass.js
+++ b/modules/core/www/assets/js/loginuserpass.js
@@ -1,5 +1,3 @@
-"use strict";
-
 ready(function () {
     var button = document.getElementById("submit_button");
     button.onclick = function () {
@@ -11,3 +9,4 @@ ready(function () {
         return true;
     };
 });
+
diff --git a/src/js/bundle.js b/src/js/bundle.js
deleted file mode 100644
index 055168c37..000000000
--- a/src/js/bundle.js
+++ /dev/null
@@ -1,45 +0,0 @@
-"use strict";
-
-import ClipboardJS from "clipboard/dist/clipboard";
-import hljs from  "highlight.js/lib/core";
-import xml from "highlight.js/lib/languages/xml";
-import php from "highlight.js/lib/languages/php";
-import json from "highlight.js/lib/languages/json";
-
-// Expander boxes
-var expandable = document.querySelectorAll('.expandable > .expander');
-expandable.forEach(function (currentValue, index, arr) {
-    currentValue.onclick = function (e) {
-        e.preventDefault();
-
-        var parent = e.currentTarget.parentNode;
-        if (parent.className.match(/(?:^|\s)expanded(?!\S)/)) {
-            parent.className = parent.className.replace(/(?:^|\s)expanded(?!\S)/g , '');
-        } else {
-            parent.className += " expanded";
-        }
-
-        e.currentTarget.blur();
-    }
-});
-
-ready(function () {
-    // Syntax highlight
-    hljs.registerLanguage('xml', xml);
-    hljs.registerLanguage('php', php);
-    hljs.registerLanguage('json', json);
-
-    var codeBoxes = document.querySelectorAll('.code-box-content.xml, .code-box-content.php, .code-box-content.json');
-    codeBoxes.forEach(function (currentValue, index, arr) {
-        hljs.highlightElement(currentValue);
-    });
-
-
-    // Clipboard
-    var clipboard = new ClipboardJS('.copy');
-    clipboard.on('success', function (e) {
-        setTimeout(function () {
-            e.clearSelection();
-        }, 150);
-    });
-});
diff --git a/src/js/bundle/clipboard.js b/src/js/bundle/clipboard.js
new file mode 100644
index 000000000..f3dfbeb81
--- /dev/null
+++ b/src/js/bundle/clipboard.js
@@ -0,0 +1,11 @@
+import ClipboardJS from "clipboard/dist/clipboard";
+
+ready(function () {
+    // Clipboard
+    var clipboard = new ClipboardJS('.copy');
+    clipboard.on('success', function (e) {
+        setTimeout(function () {
+            e.clearSelection();
+        }, 150);
+    });
+});
diff --git a/src/js/bundle/expander.js b/src/js/bundle/expander.js
new file mode 100644
index 000000000..42bb2e57d
--- /dev/null
+++ b/src/js/bundle/expander.js
@@ -0,0 +1,15 @@
+ready(function () {
+    // Expander boxes
+    var expandable = document.querySelectorAll('.expandable > .expander');
+    for (var i = 0; i < expandable.length; i++) {
+        expandable[i].currentValue.onclick = function (e) {
+            var parent = e.currentTarget.parentNode;
+            if (parent.className.match(/(?:^|\s)expanded(?!\S)/)) {
+                parent.className = parent.className.replace(/(?:^|\s)expanded(?!\S)/g , '');
+            } else {
+                parent.className += " expanded";
+            }
+            e.currentTarget.blur();
+        };
+    }
+});
diff --git a/src/js/bundle/highlight.js b/src/js/bundle/highlight.js
new file mode 100644
index 000000000..ce7b0728a
--- /dev/null
+++ b/src/js/bundle/highlight.js
@@ -0,0 +1,16 @@
+import hljs from  "highlight.js/lib/core";
+import xml from "highlight.js/lib/languages/xml";
+import php from "highlight.js/lib/languages/php";
+import json from "highlight.js/lib/languages/json";
+
+ready(function () {
+    // Syntax highlight
+    hljs.registerLanguage('xml', xml);
+    hljs.registerLanguage('php', php);
+    hljs.registerLanguage('json', json);
+
+    var codeBoxes = document.querySelectorAll('.code-box-content.xml, .code-box-content.php, .code-box-content.json');
+    codeBoxes.forEach(function (currentValue, index, arr) {
+        hljs.highlightElement(currentValue);
+    });
+});
diff --git a/src/js/main.js b/src/js/bundle/language.js
similarity index 53%
rename from src/js/main.js
rename to src/js/bundle/language.js
index 47b5079be..5734632b4 100644
--- a/src/js/main.js
+++ b/src/js/bundle/language.js
@@ -1,24 +1,3 @@
-"use strict";
-
-import "es5-shim";
-import "es6-shim";
-
-window.readyHandlers = [];
-window.ready = function ready(handler) {
-    window.readyHandlers.push(handler);
-    handleState();
-};
-
-window.handleState = function handleState () {
-    if (document.readyState === 'interactive' || document.readyState === "complete") {
-        while(window.readyHandlers.length > 0) {
-            (window.readyHandlers.shift())();
-        }
-    }
-};
-
-document.onreadystatechange = window.handleState;
-
 ready(function () {
     // Language selector
     var languageSelector = document.getElementById("language-selector");
@@ -54,19 +33,4 @@ ready(function () {
             menuLink.className += " active";
         }
     };
-
-
-    // Expander boxes
-    var expandable = document.querySelectorAll('.expandable > .expander');
-    for (var i = 0; i < expandable.length; i++) {
-        expandable[i].currentValue.onclick = function (e) {
-            var parent = e.currentTarget.parentNode;
-            if (parent.className.match(/(?:^|\s)expanded(?!\S)/)) {
-                parent.className = parent.className.replace(/(?:^|\s)expanded(?!\S)/g , '');
-            } else {
-                parent.className += " expanded";
-            }
-            e.currentTarget.blur();
-        };
-    }
 });
diff --git a/src/js/bundle/main.js b/src/js/bundle/main.js
new file mode 100644
index 000000000..dba686359
--- /dev/null
+++ b/src/js/bundle/main.js
@@ -0,0 +1,10 @@
+'use strict';
+
+import "es5-shim";
+import "es6-shim";
+import * as ready from './ready';
+import * as language from './language';
+import * as expander from './expander';
+import * as clipboard from './clipboard';
+import * as highlight from './highlight';
+
diff --git a/src/js/bundle/ready.js b/src/js/bundle/ready.js
new file mode 100644
index 000000000..8e6c27a09
--- /dev/null
+++ b/src/js/bundle/ready.js
@@ -0,0 +1,15 @@
+window.readyHandlers = [];
+window.ready = function ready(handler) {
+    window.readyHandlers.push(handler);
+    handleState();
+};
+
+window.handleState = function handleState () {
+    if (document.readyState === 'interactive' || document.readyState === "complete") {
+        while(window.readyHandlers.length > 0) {
+            (window.readyHandlers.shift())();
+        }
+    }
+};
+
+document.onreadystatechange = window.handleState;
diff --git a/src/js/logout/logout.js b/src/js/logout/logout.js
index f4f68966e..58598ae7e 100644
--- a/src/js/logout/logout.js
+++ b/src/js/logout/logout.js
@@ -1,4 +1,4 @@
-"use strict";
+'use strict';
 
 /**
  * This class is used for the logout page.
diff --git a/src/js/logout/main.js b/src/js/logout/main.js
index 929c535be..3e9eebad9 100644
--- a/src/js/logout/main.js
+++ b/src/js/logout/main.js
@@ -1,4 +1,4 @@
-"use strict";
+'use strict';
 
 import SimpleSAMLLogout from './logout.js';
 
diff --git a/templates/auth_status.twig b/templates/auth_status.twig
index f276f26b9..731ef1f87 100644
--- a/templates/auth_status.twig
+++ b/templates/auth_status.twig
@@ -1,10 +1,6 @@
 {% set pagetitle = 'Authentication status'|trans %}
 {% extends 'base.twig' %}
 
-{% block preload %}
-    <link rel="preload" href="{{ asset('js/main.js') }}" as="script">
-{% endblock %}
-
 {% block content %}
 <h2>{{ pagetitle }}</h2>
 
@@ -120,7 +116,3 @@
     </div>
 {% endif %}
 {% endblock %}
-{% block postload %}
-    <script src="{{ asset('js/bundle.js') }}"></script>
-{% endblock %}
-
diff --git a/templates/base.twig b/templates/base.twig
index 34641fb8b..8579598f8 100644
--- a/templates/base.twig
+++ b/templates/base.twig
@@ -12,7 +12,7 @@
     <link rel="stylesheet" href="{{ asset("assets/css/src/default-rtl.css") }}">
     {% endif %}
     <meta name="robots" content="noindex, nofollow">
-    <link rel="preload" href="{{ asset('js/main.js') }}" as="script">
+    <link rel="preload" href="{{ asset('js/bundle.js') }}" as="script">
     {% block preload %}{% endblock %}
   </head>
   <body id="{{ templateId }}">
@@ -30,7 +30,7 @@
     <div id="foot">
       {% block footer %}{% include "_footer.twig" %}{% endblock %}
     </div>
-    <script src="{{ asset('js/main.js') }}"></script>
+    <script src="{{ asset('js/bundle.js') }}"></script>
     {% block postload %}{% endblock %}
   </body>
 </html>
diff --git a/webpack.config.js b/webpack.config.js
index 12a13b08a..d9c5434cb 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -17,7 +17,7 @@ module.exports = environment => {
     const secondaryBackground = env.hasOwnProperty('secondaryBackground') ? env.secondaryBackground : '#e8410c';
     return {
         entry: {
-            bundle: './src/js/bundle',
+            bundle: './src/js/bundle/main',
             logout: './src/js/logout/main',
             stylesheet: './src/js/style'
         },
-- 
GitLab