-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from lachouettecoop/navigation-scannette
Navigation scannette
- Loading branch information
Showing
6 changed files
with
98 additions
and
10 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,44 @@ | ||
/* eslint-disable */ | ||
// Source: https://github.com/calvellido/focus-options-polyfill/blob/cc11aebb9141a36e7b5fd19e19a65201a63009ae/index.js | ||
// focus - focusOptions - preventScroll polyfill | ||
var supportsPreventScrollOption = false; | ||
try { | ||
var focusElem = window.createElement("div"); | ||
focusElem.addEventListener( | ||
"focus", | ||
function(event) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
}, | ||
true | ||
); | ||
// document.documentElement.focus( | ||
focusElem.focus( | ||
Object.defineProperty({}, "preventScroll", { | ||
get: function() { | ||
supportsPreventScrollOption = true; | ||
} | ||
}) | ||
); | ||
} catch (e) {} | ||
|
||
if ( | ||
HTMLElement.prototype.nativeFocus === undefined && | ||
!supportsPreventScrollOption | ||
) { | ||
HTMLElement.prototype.nativeFocus = HTMLElement.prototype.focus; | ||
|
||
var patchedFocus = function(args) { | ||
var actualPosition = window.scrollY; | ||
this.nativeFocus(); | ||
if (args && args.preventScroll) { | ||
// Hijacking the event loop order, since the focus() will trigger | ||
// internally an scroll that goes to the event loop | ||
setTimeout(function() { | ||
window.scroll(window.scrollX, actualPosition); | ||
}, 0); | ||
} | ||
}; | ||
|
||
HTMLElement.prototype.focus = patchedFocus; | ||
} |
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,33 @@ | ||
import { navigate } from "gatsby"; | ||
import React, { useEffect, useState } from "react"; | ||
import { FaHome } from "react-icons/fa"; | ||
import IconButton from "./IconButton"; | ||
|
||
const BackHome = ({ autoRedirect = false }) => { | ||
const [redirectInS, setRedirectInS] = useState( | ||
process.env.GATSBY_AUTOREDIRECT_DELAY_IN_S || 30 | ||
); | ||
|
||
useEffect(() => { | ||
if (!autoRedirect) { | ||
return; | ||
} | ||
if (redirectInS <= 0) { | ||
navigate("/"); | ||
return; | ||
} | ||
|
||
const timerID = setInterval(() => setRedirectInS(v => v - 1), 1000); | ||
return function cleanup() { | ||
clearInterval(timerID); | ||
}; | ||
}, [redirectInS, autoRedirect]); | ||
|
||
return ( | ||
<IconButton icon={FaHome} variant="secondary"> | ||
Retour à l’accueil {autoRedirect && `(${redirectInS})`} | ||
</IconButton> | ||
); | ||
}; | ||
|
||
export default BackHome; |
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