-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hide mouse class to the container if inactive (#153)
* Add hide mouse class to the container if inactive * Update class name * Properly attach an event * Remove mousemove event listener after exiting full mode Co-authored-by: Vadim Makeev <[email protected]>
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export default (shower) => { | ||
const { mouseHiddenClass, mouseInactivityTimeout } = shower.options; | ||
|
||
let hideMouseTimeoutId = null; | ||
|
||
const cleanUp = () => { | ||
shower.container.classList.remove(mouseHiddenClass); | ||
clearTimeout(hideMouseTimeoutId); | ||
hideMouseTimeoutId = null; | ||
}; | ||
|
||
const hideMouseIfInactive = () => { | ||
if (hideMouseTimeoutId !== null) { | ||
cleanUp(); | ||
} | ||
|
||
hideMouseTimeoutId = setTimeout(() => { | ||
shower.container.classList.add(mouseHiddenClass); | ||
}, mouseInactivityTimeout); | ||
}; | ||
|
||
const initHideMouseIfInactiveModule = () => { | ||
shower.container.addEventListener('mousemove', hideMouseIfInactive); | ||
}; | ||
|
||
const destroyHideMouseIfInactiveModule = () => { | ||
shower.container.removeEventListener('mousemove', hideMouseIfInactive); | ||
cleanUp(); | ||
}; | ||
|
||
const handleModeChange = () => { | ||
if (shower.isFullMode) { | ||
initHideMouseIfInactiveModule(); | ||
} else { | ||
destroyHideMouseIfInactiveModule(); | ||
} | ||
}; | ||
|
||
shower.addEventListener('start', handleModeChange); | ||
shower.addEventListener('modechange', handleModeChange); | ||
}; |