Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Several fixes for rendering in UIWebKit views.

Firstly, a bit more resilience against these views having weird UA
strings. This has been tested in the Facebook iOS apps, where Monocle
was breaking because it wasn't recognised as a WebKit browser.

Secondly, UIWebKit apparently doesn't recognised the "about:blank" URL,
so it was choking during the priming of frames. The little workaround is
to direct UIWebKit frames to "blank.html" instead, which should just
non-fatally 404 if there's nothing there. You could always put something
there in this case. Refs #51.
  • Loading branch information...
commit a07cea7026fa13ad9a269b30d98c888ad2b1a744 1 parent 650f2eb
@joseph joseph authored
View
11 src/compat/browser.js
@@ -5,7 +5,7 @@ Monocle.Browser = {}
Monocle.Browser.is = {
IE: !!(window.attachEvent && navigator.userAgent.indexOf('Opera') === -1),
Opera: navigator.userAgent.indexOf('Opera') > -1,
- WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
+ WebKit: navigator.userAgent.indexOf('AppleWebKit') > -1,
Gecko: navigator.userAgent.indexOf('Gecko') > -1 &&
navigator.userAgent.indexOf('KHTML') === -1,
MobileSafari: !!navigator.userAgent.match(/AppleWebKit.*Mobile/)
@@ -28,13 +28,16 @@ if (Monocle.Browser.is.IE) {
// Detect the client platform (typically device/operating system).
//
Monocle.Browser.on = {
- iPhone: navigator.userAgent.indexOf("iPhone") != -1,
- iPad: navigator.userAgent.indexOf("iPad") != -1,
+ iPhone: Monocle.Browser.is.MobileSafari && screen.width == 320,
+ iPad: Monocle.Browser.is.MobileSafari && screen.width == 768,
+ UIWebView: Monocle.Browser.is.MobileSafari &&
+ navigator.userAgent.indexOf("Safari") < 0 &&
+ !navigator.standalone,
BlackBerry: navigator.userAgent.indexOf("BlackBerry") != -1,
Android: navigator.userAgent.indexOf('Android') != -1,
MacOSX: navigator.userAgent.indexOf('Mac OS X') != -1 &&
!Monocle.Browser.is.MobileSafari,
- Kindle3: navigator.userAgent.match(/Kindle\/3/)
+ Kindle3: !!navigator.userAgent.match(/Kindle\/3/)
// TODO: Mac, Windows, etc
}
View
2  src/core/reader.js
@@ -203,7 +203,7 @@ Monocle.Reader = function (node, bookData, options, onLoadCallback) {
// Opens the frame to a particular URL (usually 'about:blank').
//
function primeFrames(url, callback) {
- url = url || "about:blank";
+ url = url || (Monocle.Browser.on.UIWebView ? "blank.html" : "about:blank");
var pageCount = 0;
View
63 test/compat/index.html
@@ -13,6 +13,7 @@
text-align: left;
}
td {
+ vertical-align: top;
font-family: Consolas, Andale Mono, Menlo, Monaco, monospace;
}
@@ -30,7 +31,7 @@
}
#compatibility.incompatible {
- background: green;
+ background: red;
}
</style>
@@ -40,65 +41,7 @@
<script type="text/javascript" src="../../src/compat/css.js"></script>
<script type="text/javascript" src="../../src/compat/stubs.js"></script>
<script type="text/javascript" src="../../src/compat/browser.js"></script>
-
- <script>
- Monocle.DEBUG = true;
-
- (function () {
- function readUA() {
- testResult("userAgent", navigator.userAgent);
- }
-
-
- function testResult(name, val) {
- var tbl = document.getElementById('results');
- var row = document.createElement('tr');
- var nCell = document.createElement('td');
- var vCell = document.createElement('td');
- var nCellText = document.createTextNode(name);
- var vCellText = document.createTextNode(val);
- nCell.appendChild(nCellText);
- vCell.appendChild(vCellText);
- vCell.style.color = colorForTestResult(name, val);
- row.appendChild(nCell);
- row.appendChild(vCell);
- tbl.appendChild(row);
- }
-
-
- function colorForTestResult(name, val) {
- var neutralNames = ["userAgent", "touch", "embedded"];
- try {
- if (neutralNames.indexOf(name) >= 0) {
- return "black";
- }
- } catch (e) {}
- if (name.match(/^supports/)) {
- return val ? "green" : "red";
- }
- return val ? "orange": "green";
- }
-
-
- function assertCompatibility(env) {
- var div = document.getElementById('compatibility');
- div.style.display = 'block';
- var x = env.isCompatible() ? "compatible" : "incompatible";
- div.innerHTML = "This browser is "+x+" with Monocle.";
- div.className = x;
- }
-
-
- function init() {
- readUA();
- env = new Monocle.Env();
- env.properties.resultCallback = testResult;
- env.survey(assertCompatibility);
- }
-
- window.onload = init;
- })();
- </script>
+ <script type="text/javascript" src="test.js"></script>
</head>
<body>
View
75 test/compat/test.js
@@ -0,0 +1,75 @@
+Monocle.DEBUG = true;
+
+(function () {
+ function readUA() {
+ testResult("userAgent", navigator.userAgent);
+ }
+
+
+ function readBrowser() {
+ var res = [];
+ for (var prop in Monocle.Browser.is) {
+ var val = Monocle.Browser.is[prop];
+ if (val) { res.push("is."+prop); }
+ }
+ for (var prop in Monocle.Browser.on) {
+ var val = Monocle.Browser.on[prop];
+ if (val) { res.push("on."+prop); }
+ }
+ testResult(
+ "Browser",
+ "engine: "+Monocle.Browser.engine+". "+res.join(", ")+"."
+ );
+ }
+
+
+ function testResult(name, val) {
+ var tbl = document.getElementById('results');
+ var row = document.createElement('tr');
+ var nCell = document.createElement('td');
+ var vCell = document.createElement('td');
+ var nCellText = document.createTextNode(name);
+ var vCellText = document.createTextNode(val);
+ nCell.appendChild(nCellText);
+ vCell.appendChild(vCellText);
+ vCell.style.color = colorForTestResult(name, val);
+ row.appendChild(nCell);
+ row.appendChild(vCell);
+ tbl.appendChild(row);
+ }
+
+
+ function colorForTestResult(name, val) {
+ var neutralNames = ["userAgent", "Browser", "touch", "embedded"];
+ try {
+ if (neutralNames.indexOf(name) >= 0) {
+ return "black";
+ }
+ } catch (e) {}
+ if (name.match(/^supports/)) {
+ return val ? "green" : "red";
+ }
+ return val ? "orange": "green";
+ }
+
+
+ function assertCompatibility(env) {
+ var div = document.getElementById('compatibility');
+ div.style.display = 'block';
+ var x = env.isCompatible() ? "compatible" : "incompatible";
+ div.innerHTML = "This browser is "+x+" with Monocle.";
+ div.className = x;
+ }
+
+
+ function init() {
+ readUA();
+ readBrowser();
+ env = new Monocle.Env();
+ env.properties.resultCallback = testResult;
+ env.survey(assertCompatibility);
+ }
+
+ window.onload = init;
+})();
+
Please sign in to comment.
Something went wrong with that request. Please try again.