refactor main.js into smaller pieces, and moved navbar.js to assets
This commit is contained in:
parent
fd8eeb3330
commit
177dffe553
19 changed files with 214 additions and 207 deletions
36
assets/scripts/core/device.js
Normal file
36
assets/scripts/core/device.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
let deviceState = {
|
||||
isMobile: false,
|
||||
isTablet: false,
|
||||
isLaptop: false,
|
||||
};
|
||||
|
||||
function detectDeviceState() {
|
||||
if (window.innerWidth <= 425) {
|
||||
deviceState = {
|
||||
isMobile: true,
|
||||
isTablet: false,
|
||||
isLaptop: false,
|
||||
};
|
||||
} else if (window.innerWidth <= 768) {
|
||||
deviceState = {
|
||||
isMobile: false,
|
||||
isTablet: true,
|
||||
isLaptop: false,
|
||||
};
|
||||
} else {
|
||||
deviceState = {
|
||||
isMobile: false,
|
||||
isTablet: false,
|
||||
isLaptop: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
detectDeviceState();
|
||||
window.addEventListener('resize', detectDeviceState);
|
||||
|
||||
// returns a copy of the device state
|
||||
// so other parts of code can't override this.
|
||||
export function getDeviceState() {
|
||||
return { ... deviceState };
|
||||
}
|
1
assets/scripts/core/index.js
Normal file
1
assets/scripts/core/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './device';
|
Loading…
Add table
Add a link
Reference in a new issue