Page MenuHomePhabricator
Authored By
matmarex
Jun 17 2019, 7:06 PM
Size
1 KB
Referenced Files
None
Subscribers
None

T216446.html

<meta id="m" name="viewport" content="width=device-width">
<!-- <textarea id="a" style="width: 100%; height: 50%;">foo bar</textarea> -->
<div contenteditable id="a" style="font-size: 12px; width: 100%; height: 50%;">foo bar</div>
<p id="zoom"></p>
<p id="log" style="white-space: pre"></p>
<script>
function log(text) {
document.getElementById('log').textContent += '\n' + text;
}
// Note that this doesn't actually prevent e.g. pinch-zoom on Safari, but it does prevent
// automatic zoom upon focussing an input with small font.
function preventZoom() {
document.getElementById('m').setAttribute('content', "width=device-width, maximum-scale=1.0");
document.getElementById('zoom').textContent = '❌';
}
function allowZoom() {
document.getElementById('m').setAttribute('content', "width=device-width");
document.getElementById('zoom').textContent = '✔';
}
allowZoom();
var wasMoved = false;
document.getElementById('a').addEventListener('touchstart', function (e) {
log('touchstart' + e.touches.length);
if ( e.touches.length === 1 ) {
wasMoved = false;
}
allowZoom();
}, false);
document.getElementById('a').addEventListener('touchmove', function (e) {
wasMoved = true;
}, false);
document.getElementById('a').addEventListener('touchend', function (e) {
log('touchend' + e.touches.length);
if ( e.touches.length === 0 && !wasMoved ) {
// There was a single touch point, that hasn't moved, and now it's gone.
// Looks like we're going to focus the input, so prevent automatic zoom.
preventZoom();
} else {
// Otherwise, allow zoom, so that the user can pinch-zoom
allowZoom();
}
}, false);
document.getElementById('a').addEventListener('focus', function (e) {
log('focus');
allowZoom();
}, false);
</script>

File Metadata

Mime Type
text/html
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
7648785
Default Alt Text
T216446.html (1 KB)

Event Timeline