Skip to content
This repository was archived by the owner on Dec 14, 2021. It is now read-only.

Commit ff53299

Browse files
URL: Workaround for Opera Mini. Resolves #138
1 parent 6d99e61 commit ff53299

File tree

5 files changed

+95
-65
lines changed

5 files changed

+95
-65
lines changed

polyfill.js

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5586,29 +5586,39 @@ function __cons(t, a) {
55865586
if (base) {
55875587
url = (function () {
55885588
if (nativeURL) return new origURL(url, base).href;
5589+
var iframe;
5590+
try {
5591+
var doc;
5592+
// Use another document/base tag/anchor for relative URL resolution, if possible
5593+
if (navigator.userAgent.match(/Opera Mini/)) {
5594+
iframe = document.createElement('iframe');
5595+
iframe.style.display = 'none';
5596+
document.documentElement.appendChild(iframe);
5597+
doc = iframe.contentWindow.document;
5598+
} else if (document.implementation && document.implementation.createHTMLDocument) {
5599+
doc = document.implementation.createHTMLDocument('');
5600+
} else if (document.implementation && document.implementation.createDocument) {
5601+
doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
5602+
doc.documentElement.appendChild(doc.createElement('head'));
5603+
doc.documentElement.appendChild(doc.createElement('body'));
5604+
} else if (window.ActiveXObject) {
5605+
doc = new window.ActiveXObject('htmlfile');
5606+
doc.write('<head><\/head><body><\/body>');
5607+
doc.close();
5608+
}
55895609

5590-
var doc;
5591-
// Use another document/base tag/anchor for relative URL resolution, if possible
5592-
if (document.implementation && document.implementation.createHTMLDocument) {
5593-
doc = document.implementation.createHTMLDocument('');
5594-
} else if (document.implementation && document.implementation.createDocument) {
5595-
doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
5596-
doc.documentElement.appendChild(doc.createElement('head'));
5597-
doc.documentElement.appendChild(doc.createElement('body'));
5598-
} else if (window.ActiveXObject) {
5599-
doc = new window.ActiveXObject('htmlfile');
5600-
doc.write('<head><\/head><body><\/body>');
5601-
doc.close();
5610+
if (!doc) throw Error('base not supported');
5611+
5612+
var baseTag = doc.createElement('base');
5613+
baseTag.href = base;
5614+
doc.getElementsByTagName('head')[0].appendChild(baseTag);
5615+
var anchor = doc.createElement('a');
5616+
anchor.href = url;
5617+
return anchor.href;
5618+
} finally {
5619+
if (iframe)
5620+
iframe.parentNode.removeChild(iframe);
56025621
}
5603-
5604-
if (!doc) throw Error('base not supported');
5605-
5606-
var baseTag = doc.createElement('base');
5607-
baseTag.href = base;
5608-
doc.getElementsByTagName('head')[0].appendChild(baseTag);
5609-
var anchor = doc.createElement('a');
5610-
anchor.href = url;
5611-
return anchor.href;
56125622
}());
56135623
}
56145624

polyfill.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

url.js

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -276,29 +276,39 @@
276276
if (base) {
277277
url = (function () {
278278
if (nativeURL) return new origURL(url, base).href;
279+
var iframe;
280+
try {
281+
var doc;
282+
// Use another document/base tag/anchor for relative URL resolution, if possible
283+
if (navigator.userAgent.match(/Opera Mini/)) {
284+
iframe = document.createElement('iframe');
285+
iframe.style.display = 'none';
286+
document.documentElement.appendChild(iframe);
287+
doc = iframe.contentWindow.document;
288+
} else if (document.implementation && document.implementation.createHTMLDocument) {
289+
doc = document.implementation.createHTMLDocument('');
290+
} else if (document.implementation && document.implementation.createDocument) {
291+
doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
292+
doc.documentElement.appendChild(doc.createElement('head'));
293+
doc.documentElement.appendChild(doc.createElement('body'));
294+
} else if (window.ActiveXObject) {
295+
doc = new window.ActiveXObject('htmlfile');
296+
doc.write('<head><\/head><body><\/body>');
297+
doc.close();
298+
}
279299

280-
var doc;
281-
// Use another document/base tag/anchor for relative URL resolution, if possible
282-
if (document.implementation && document.implementation.createHTMLDocument) {
283-
doc = document.implementation.createHTMLDocument('');
284-
} else if (document.implementation && document.implementation.createDocument) {
285-
doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
286-
doc.documentElement.appendChild(doc.createElement('head'));
287-
doc.documentElement.appendChild(doc.createElement('body'));
288-
} else if (window.ActiveXObject) {
289-
doc = new window.ActiveXObject('htmlfile');
290-
doc.write('<head><\/head><body><\/body>');
291-
doc.close();
300+
if (!doc) throw Error('base not supported');
301+
302+
var baseTag = doc.createElement('base');
303+
baseTag.href = base;
304+
doc.getElementsByTagName('head')[0].appendChild(baseTag);
305+
var anchor = doc.createElement('a');
306+
anchor.href = url;
307+
return anchor.href;
308+
} finally {
309+
if (iframe)
310+
iframe.parentNode.removeChild(iframe);
292311
}
293-
294-
if (!doc) throw Error('base not supported');
295-
296-
var baseTag = doc.createElement('base');
297-
baseTag.href = base;
298-
doc.getElementsByTagName('head')[0].appendChild(baseTag);
299-
var anchor = doc.createElement('a');
300-
anchor.href = url;
301-
return anchor.href;
302312
}());
303313
}
304314

web.js

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,29 +1185,39 @@
11851185
if (base) {
11861186
url = (function () {
11871187
if (nativeURL) return new origURL(url, base).href;
1188+
var iframe;
1189+
try {
1190+
var doc;
1191+
// Use another document/base tag/anchor for relative URL resolution, if possible
1192+
if (navigator.userAgent.match(/Opera Mini/)) {
1193+
iframe = document.createElement('iframe');
1194+
iframe.style.display = 'none';
1195+
document.documentElement.appendChild(iframe);
1196+
doc = iframe.contentWindow.document;
1197+
} else if (document.implementation && document.implementation.createHTMLDocument) {
1198+
doc = document.implementation.createHTMLDocument('');
1199+
} else if (document.implementation && document.implementation.createDocument) {
1200+
doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
1201+
doc.documentElement.appendChild(doc.createElement('head'));
1202+
doc.documentElement.appendChild(doc.createElement('body'));
1203+
} else if (window.ActiveXObject) {
1204+
doc = new window.ActiveXObject('htmlfile');
1205+
doc.write('<head><\/head><body><\/body>');
1206+
doc.close();
1207+
}
11881208

1189-
var doc;
1190-
// Use another document/base tag/anchor for relative URL resolution, if possible
1191-
if (document.implementation && document.implementation.createHTMLDocument) {
1192-
doc = document.implementation.createHTMLDocument('');
1193-
} else if (document.implementation && document.implementation.createDocument) {
1194-
doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
1195-
doc.documentElement.appendChild(doc.createElement('head'));
1196-
doc.documentElement.appendChild(doc.createElement('body'));
1197-
} else if (window.ActiveXObject) {
1198-
doc = new window.ActiveXObject('htmlfile');
1199-
doc.write('<head><\/head><body><\/body>');
1200-
doc.close();
1209+
if (!doc) throw Error('base not supported');
1210+
1211+
var baseTag = doc.createElement('base');
1212+
baseTag.href = base;
1213+
doc.getElementsByTagName('head')[0].appendChild(baseTag);
1214+
var anchor = doc.createElement('a');
1215+
anchor.href = url;
1216+
return anchor.href;
1217+
} finally {
1218+
if (iframe)
1219+
iframe.parentNode.removeChild(iframe);
12011220
}
1202-
1203-
if (!doc) throw Error('base not supported');
1204-
1205-
var baseTag = doc.createElement('base');
1206-
baseTag.href = base;
1207-
doc.getElementsByTagName('head')[0].appendChild(baseTag);
1208-
var anchor = doc.createElement('a');
1209-
anchor.href = url;
1210-
return anchor.href;
12111221
}());
12121222
}
12131223

web.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)