aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utilities
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2021-10-30 22:11:00 +0200
committerArmand Philippot <git@armandphilippot.com>2021-10-30 22:52:23 +0200
commit3a3baddad1c801d77dc398d2c6980f3c14f4a47c (patch)
tree9e06aef730504470111c010e53a1857f7b01ab83 /src/js/utilities
parentc3045b163e74b42c0a0e71c646740c76d3bb5ba1 (diff)
chore: move htdocs to repo root
Diffstat (limited to 'src/js/utilities')
-rw-r--r--src/js/utilities/animations.js45
-rw-r--r--src/js/utilities/helpers.js19
2 files changed, 64 insertions, 0 deletions
diff --git a/src/js/utilities/animations.js b/src/js/utilities/animations.js
new file mode 100644
index 0000000..9a30685
--- /dev/null
+++ b/src/js/utilities/animations.js
@@ -0,0 +1,45 @@
+/**
+ * Change the element classes to hide it with a slide out left animation.
+ * @param {HTMLElement} el - The HTMLElement to hide.
+ */
+function hideToLeft(el) {
+ el?.classList.remove('slide-in--left');
+ el?.classList.add('slide-out--left');
+ setTimeout(() => {
+ el?.classList.add('hide');
+ }, 800);
+}
+
+/**
+ * Change the element classes to show it with a slide in left animation.
+ * @param {HTMLElement} el - The HTMLElement to show.
+ */
+function showFromLeft(el) {
+ el?.classList.remove('slide-out--left');
+ el?.classList.remove('hide');
+ el?.classList.add('slide-in--left');
+}
+
+/**
+ * Change the element classes to hide it with a slide out bottom animation.
+ * @param {HTMLElement} el - The HTMLElement to hide.
+ */
+function hideToBottom(el) {
+ el?.classList.remove('slide-in--up');
+ el?.classList.add('slide-out--bottom');
+ setTimeout(() => {
+ el?.classList.add('hide');
+ }, 800);
+}
+
+/**
+ * Change the element classes to show it with a slide in up animation.
+ * @param {HTMLElement} el - The HTMLElement to show.
+ */
+function showFromBottom(el) {
+ el?.classList.remove('slide-out--bottom');
+ el?.classList.remove('hide');
+ el?.classList.add('slide-in--up');
+}
+
+export { hideToLeft, showFromLeft, hideToBottom, showFromBottom };
diff --git a/src/js/utilities/helpers.js b/src/js/utilities/helpers.js
new file mode 100644
index 0000000..470c49c
--- /dev/null
+++ b/src/js/utilities/helpers.js
@@ -0,0 +1,19 @@
+/**
+ * Check the size of the current viewport.
+ * @returns {Boolean} True if viewport lower than 1200px; false otherwise.
+ */
+function isSmallVw() {
+ return window.innerWidth < 1200;
+}
+
+/**
+ * Check if /assets/styles.js exists (Webpack dev mode).
+ * @returns {Boolean} True if style.js exists ; false otherwise.
+ */
+async function isStyleJsExists() {
+ const filePath = 'assets/js/style.js';
+ const response = await fetch(filePath);
+ return response.status === 200;
+}
+
+export { isSmallVw, isStyleJsExists };