Skip to content

Commit

Permalink
auto fill/fit, less intrusive hints controller
Browse files Browse the repository at this point in the history
  • Loading branch information
progapandist committed Jun 9, 2024
1 parent b06981f commit 704aff0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 54 deletions.
2 changes: 1 addition & 1 deletion app/assets/builds/application.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 26 additions & 52 deletions app/javascript/controllers/hints_controller.js
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";
}
}
}
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
>
</div>
<%= yield %>
<div data-controller="hints"></div>
</body>
</html>
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def go_seed
slug_name,
width: 3840,
height: 2160,
resizing_type: :fit,
resizing_type: :auto,
gravity: :sm,
format: :avif
))
Expand Down

0 comments on commit 704aff0

Please sign in to comment.