diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-10-24 18:54:24 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-10-24 18:54:24 +0200 |
| commit | 2afa7afed65d3a14c5f65c92d4f1a2345ca0ec1d (patch) | |
| tree | 331cbd92a7ac12d248f355f65e2d8c81437f6dd7 /htdocs/src | |
| parent | 10b3d9a17e42df812ec766e49ef8f870dbbf9ca5 (diff) | |
chore: load styles on development mode
Diffstat (limited to 'htdocs/src')
| -rw-r--r-- | htdocs/src/js/app.js | 22 | ||||
| -rw-r--r-- | htdocs/src/js/utilities/helpers.js | 19 |
2 files changed, 41 insertions, 0 deletions
diff --git a/htdocs/src/js/app.js b/htdocs/src/js/app.js new file mode 100644 index 0000000..1b7bbc6 --- /dev/null +++ b/htdocs/src/js/app.js @@ -0,0 +1,22 @@ +import { isStyleJsExists } from './utilities/helpers'; + +/** + * Add style.js script for development purposes. + */ +function loadWebpackStyles() { + if (isStyleJsExists()) { + const head = document.querySelector('head'); + const script = document.createElement('script'); + script.src = 'assets/js/style.js'; + head.appendChild(script); + } +} + +/** + * Initialize the website with the projects list. + */ +function init() { + loadWebpackStyles(); +} + +init(); diff --git a/htdocs/src/js/utilities/helpers.js b/htdocs/src/js/utilities/helpers.js new file mode 100644 index 0000000..470c49c --- /dev/null +++ b/htdocs/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 }; |
