Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ once the version tag exists.
showed it for most of the rest.
- Tapping a document sets the cursor, so an edit can be typed. The keyboard
never came up before.
- A document opens at the top of its first page. On a wide screen it opened far
enough down to cut off the heading.

### Removed

Expand Down
24 changes: 21 additions & 3 deletions OpenDocumentReader/DocumentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,28 @@ class DocumentViewController: UIViewController, DocumentDelegate, UISearchBarDel
return;
}

var width = document.documentElement.scrollWidth;
if (width > window.innerWidth) {
meta.setAttribute('content', 'width=' + width + ',user-scalable=yes');
var served = meta.content;
var natural = document.documentElement.scrollWidth;

// The web view's own width, which the viewport named below does not
// change: the visual viewport is that many CSS pixels at that scale.
function available() {
var seen = window.visualViewport;

return seen ? Math.round(seen.width * seen.scale) : window.innerWidth;
}

function fit() {
meta.setAttribute(
'content',
natural > available() ? 'width=' + natural + ',user-scalable=yes' : served);
}

// On every resize, not just now: this first runs before the web view
// has the width it will keep, and a page held at a width it no
// longer needs is left scrolled off its own top.
fit();
window.addEventListener('resize', fit);
})();
"""
}
Expand Down