Skip to content

Commit

Permalink
Try to fix viewport issues
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousdannii committed May 24, 2024
1 parent a1df7cc commit 28b7d98
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
6 changes: 5 additions & 1 deletion arthur.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ <h1>Arthur</h1>
</div>
<div id="inner">
<div id="game">
<canvas id="canvas"></canvas>
<div id="arthurmodes">
<p class="arthurfull">Graphics</p><p class="arthurfull">Map</p><p class="arthurfull">Inventory</p><p class="arthurfull">Score</p><p class="arthurfull">Room</p><p class="arthurfull">Text only</p>
<p class="arthurshort">Graph</p><p class="arthurshort">Map</p><p class="arthurshort">Inv</p><p class="arthurshort">Score</p><p class="arthurshort">Room</p><p class="arthurshort">Text</p>
</div>
<canvas id="canvas" height="400"></canvas>
<textarea id="textinput" autocapitalize="off" rows="1"></textarea>
</div>
</div>
Expand Down
16 changes: 16 additions & 0 deletions interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
const canvas_elem = document.getElementById('canvas')
const textinput_elem = document.getElementById('textinput')

// Prevent iOS from zooming in when focusing input, but allow Android to still pinch zoom
// As they handle the maximum-scale viewport meta option differently, we will conditionally add it only in iOS
// Idea from https://stackoverflow.com/a/62750441/2854284
if (/iPhone OS/i.test(navigator.userAgent)) {
document.head.querySelector('meta[name="viewport"]').content = 'width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1'
}

visualViewport.addEventListener('resize', () => {
const height = visualViewport.height
document.documentElement.style.height = `${height}px`

// Safari might have scrolled weirdly, so try to put it right
window.scrollTo(0, 0)
setTimeout(() => window.scrollTo(0, 0), 500)
})

// Mobile input event handlers
canvas_elem.addEventListener('touchstart', ev => {
textinput_elem.focus()
Expand Down
7 changes: 0 additions & 7 deletions sfrotz.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ Module.arguments = ['/' + files[0], '/' + files[1]]
Module.canvas = document.getElementById('canvas')

Module.preRun = () => {
// Prevent iOS from zooming in when focusing input, but allow Android to still pinch zoom
// As they handle the maximum-scale viewport meta option differently, we will conditionally add it only in iOS
// Idea from https://stackoverflow.com/a/62750441/2854284
if (/iPhone OS/i.test(navigator.userAgent)) {
document.head.querySelector('meta[name="viewport"]').content = 'width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1'
}

// Load storyfile and blorb
FS.createPreloadedFile('/', files[0], files[0], true, false)
FS.createPreloadedFile('/', files[1], files[1], true, false)
Expand Down
34 changes: 32 additions & 2 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ html, body {
max-width: 640px;
}

#heading {
#heading, #arthurmodes {
display: flex;
flex-flow: row;
justify-content: space-between;
Expand All @@ -49,7 +49,7 @@ html, body {

#heading h1, #heading p {
font-size: 16px;
margin: 12px 0;
margin: 12px;
}

#inner {
Expand All @@ -59,6 +59,36 @@ html, body {
justify-content: center;
}

#arthurmodes {
justify-content: space-around;
}

#arthurmodes p {
border: 1px solid;
border-radius: 4px;
cursor: pointer;
margin: 6px 0;
padding: 6px;
}

/* Show shorter buttons on mobile */
#arthurshort {
display: none;
}

@media (max-width: 500px) {
#arthurfull {
display: none;
}
#arthurshort {
display: block;
}
}

canvas {
display: block;
}

#textinput {
position: absolute;
left: -10000px;
Expand Down

0 comments on commit 28b7d98

Please sign in to comment.