-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto fill/fit, less intrusive hints controller
- Loading branch information
1 parent
b06981f
commit 704aff0
Showing
4 changed files
with
29 additions
and
54 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,61 +1,35 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
|
||
// Connects to data-controller="hints" | ||
export default class extends Controller { | ||
connect() { | ||
const url = new URL(window.location.href); | ||
const sessionId = url.searchParams.get("i"); | ||
|
||
// Check if the sessionId is present and if the hint has not been shown yet | ||
if (sessionId && !sessionStorage.getItem(`hintShown-${sessionId}`)) { | ||
this.showResizeHint(); | ||
sessionStorage.setItem(`hintShown-${sessionId}`, "true"); | ||
} | ||
this.addHintMessage(); | ||
window.addEventListener("resize", this.updatePosition.bind(this)); | ||
} | ||
|
||
showResizeHint() { | ||
// Create overlay div | ||
const overlay = document.createElement("div"); | ||
overlay.style.position = "fixed"; | ||
overlay.style.top = "0"; | ||
overlay.style.left = "0"; | ||
overlay.style.width = "100%"; | ||
overlay.style.height = "100%"; | ||
overlay.style.backgroundColor = "rgba(0, 0, 0, 0.8)"; | ||
overlay.style.zIndex = "9999"; | ||
overlay.style.display = "flex"; | ||
overlay.style.justifyContent = "center"; | ||
overlay.style.alignItems = "center"; | ||
|
||
// Create text element | ||
const text = document.createElement("div"); | ||
text.innerText = | ||
"👋 EARTHLING. REMINDER! DRAG WINDOW CORNER ⇲ OR TURN PHONE TO RESIZE. CLICK TO SEE MORE. EOF. ENJOY ⇲ ⇲ ⇲ ⇲"; | ||
text.style.color = "magenta"; | ||
text.style.fontSize = "6em"; | ||
text.style.fontWeight = "1000"; // Heavy script | ||
text.style.fontFamily = "system-ui, sans-serif"; // Optional: for better font rendering | ||
text.style.animation = "flashing 1s infinite"; // Add animation | ||
|
||
// Append text to overlay | ||
overlay.appendChild(text); | ||
|
||
// Append overlay to body | ||
document.body.appendChild(overlay); | ||
disconnect() { | ||
window.removeEventListener("resize", this.updatePosition.bind(this)); | ||
} | ||
|
||
// Remove the overlay after 4.5 seconds | ||
setTimeout(() => { | ||
document.body.removeChild(overlay); | ||
}, 4500); | ||
addHintMessage() { | ||
this.hint = document.createElement("div"); | ||
this.hint.innerText = "drag corner to resize ⇲"; | ||
this.hint.style.position = "fixed"; | ||
this.hint.style.bottom = "10px"; | ||
this.hint.style.right = "10px"; | ||
this.hint.style.fontFamily = "monospace"; | ||
this.hint.style.mixBlendMode = "difference"; // For better visibility | ||
this.hint.style.backgroundColor = "rgba(255, 0, 255, 100)"; // Fuchsia with opacity | ||
this.hint.style.color = "white"; | ||
this.hint.style.padding = "5px"; | ||
this.hint.style.borderRadius = "5px"; | ||
this.hint.style.zIndex = "1000"; // Ensures it's on top of other elements if required | ||
|
||
document.body.appendChild(this.hint); | ||
} | ||
|
||
// CSS Styles for flashing animation | ||
const style = document.createElement("style"); | ||
style.innerHTML = ` | ||
@keyframes flashing { | ||
0%, 100% { opacity: 1; } | ||
50% { opacity: 0.1; } | ||
} | ||
`; | ||
document.head.appendChild(style); | ||
updatePosition() { | ||
if (this.hint) { | ||
this.hint.style.bottom = "10px"; | ||
this.hint.style.right = "10px"; | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -46,5 +46,6 @@ | |
> | ||
</div> | ||
<%= yield %> | ||
<div data-controller="hints"></div> | ||
</body> | ||
</html> |
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