Skip to content

Commit 56e2129

Browse files
committed
Merge builds page polyfills and style-reduced.js into a new global script
1 parent 2a9c443 commit 56e2129

File tree

4 files changed

+115
-82
lines changed

4 files changed

+115
-82
lines changed

_includes/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
<link rel="stylesheet" href="/assets/css/style-print.css" media="print">
3030
<link rel="stylesheet" href="/assets/css/fonts.css">
3131
<!--<![endif]-->
32+
<script src="/assets/js/script.js"></script>
3233
<!--[if IE]>
33-
<script src="/assets/js/style-reduced.js"></script>
3434
<link rel="stylesheet" href="/assets/css/style-reduced.css" media="screen">
3535
<![endif]-->
3636
<!--[if gte IE 5]>

assets/js/script.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* This script is executed by all browsers, so keep it retro-friendly. */
2+
3+
/* Polyfills. */
4+
function addEvent(elem, evtName, func) {
5+
if (elem.addEventListener)
6+
return elem.addEventListener(evtName, func);
7+
evtName = 'on' + evtName;
8+
if (elem.attachEvent)
9+
return elem.attachEvent(evtName, func);
10+
var prevFunc = elem[evtName];
11+
if (prevFunc) {
12+
elem[evtName] = function(evt) {
13+
if (prevFunc(evt) == false)
14+
return false;
15+
return func(evt);
16+
};
17+
} else {
18+
elem[evtName] = func;
19+
}
20+
}
21+
if (!Array.prototype.indexOf) {
22+
Array.prototype.indexOf = function(elem, start) {
23+
for (var i = start || 0; i < this.length; i++) {
24+
if (this[i] == elem)
25+
return i;
26+
}
27+
return -1;
28+
};
29+
}
30+
if (!Array.prototype.push) {
31+
Array.prototype.push = function(elem) {
32+
this[this.length] = elem;
33+
};
34+
}
35+
if (!Array.prototype.unshift) {
36+
Array.prototype.unshift = function(elem) {
37+
for (var i = this.length; i; i--)
38+
this[i] = this[i - 1];
39+
this[0] = elem;
40+
};
41+
}
42+
var imgCache = {};
43+
function getNaturalWidth(img) { /* for the auto-sizing expression on the retro CSS */
44+
if (img.naturalWidth)
45+
return img.naturalWidth;
46+
47+
/* Cache images by src to avoid wasting memory. */
48+
var imgObj = imgCache[img.src];
49+
if (!imgObj) {
50+
imgObj = new Image();
51+
imgObj.src = img.src;
52+
imgCache[img.src] = imgObj;
53+
}
54+
return imgObj.width;
55+
}
56+
57+
/* Allow HTML5 elements to be styled on IE6. */
58+
if (navigator.userAgent.indexOf('MSIE') > -1) {
59+
document.createElement('nav');
60+
document.createElement('hero');
61+
document.createElement('main');
62+
document.createElement('footer');
63+
}
64+
65+
/* Make the logo transparent on IE6. Doing this on more
66+
images interferes with the auto-sizing CSS expression. */
67+
function fixPngs() {
68+
/* Check if the icon and logo are loaded, and try
69+
again after a while if they're not present yet. */
70+
if (!document.images || (document.images.length < 2))
71+
setTimeout(fixPngs, 500);
72+
73+
/* Fix icon and logo. */
74+
for (var i = 0; i < Math.min(2, document.images.length); i++) {
75+
var img = document.images[i];
76+
var oldpad = img.style.paddingRight; /* padding counts as space for AlphaImageLoader so swap it for margin */
77+
img.style.paddingRight = 0;
78+
var oldsrc = img.src;
79+
var oldw = img.clientWidth;
80+
var oldh = img.clientHeight;
81+
img.src = '/assets/images/blank.gif';
82+
img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + oldsrc + "', sizingMethod='scale')";
83+
img.style.width = oldw + 'px';
84+
img.style.height = oldh + 'px';
85+
img.style.marginRight = oldpad;
86+
}
87+
}
88+
if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent))
89+
fixPngs();
90+
91+
/* Merge horizontally-neighboring table cells with identical contents. */
92+
addEvent(window, 'load', function() {
93+
var tr = document.getElementsByTagName('tr');
94+
for (var i = 0; i < tr.length; i++) {
95+
var tdStart = tr[i].firstChild;
96+
while (tdStart && (tdStart.nodeType != 1))
97+
tdStart = tdStart.nextSibling;
98+
if (!tdStart)
99+
continue;
100+
var td = tdStart.nextSibling;
101+
while (td) {
102+
var tdNext = td.nextSibling;
103+
if (td.nodeType != 1) {
104+
/* Ignore non-elements. */
105+
} else if (td.innerHTML == tdStart.innerHTML) {
106+
td.parentNode.removeChild(td);
107+
tdStart.colSpan = (tdStart.colSpan || 1) + 1;
108+
} else {
109+
tdStart = td;
110+
}
111+
td = tdNext;
112+
}
113+
}
114+
});

assets/js/style-reduced.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

builds.md

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,6 @@ Most people should use the regular [**release builds**](https://github.com/86Box
1212
---
1313

1414
<script>
15-
/* Some polyfills because why not? */
16-
function addEvent(elem, evt, func) {
17-
if (elem.addEventListener)
18-
return elem.addEventListener(evt, func);
19-
evt = 'on' + evt;
20-
if (elem.attachEvent)
21-
return elem.attachEvent(evt, func);
22-
elem[evt] = func;
23-
}
24-
if (!Array.prototype.indexOf) {
25-
Array.prototype.indexOf = function(elem, start) {
26-
for (var i = start || 0; i < this.length; i++) {
27-
if (this[i] == elem)
28-
return i;
29-
}
30-
return -1;
31-
}
32-
}
33-
if (!Array.prototype.push) {
34-
Array.prototype.push = function(elem) {
35-
this[this.length] = elem;
36-
};
37-
}
38-
if (!Array.prototype.unshift) {
39-
Array.prototype.unshift = function(elem) {
40-
for (var i = this.length; i; i--)
41-
this[i] = this[i - 1];
42-
this[0] = elem;
43-
}
44-
}
45-
4615
addEvent(window, 'load', function() {
4716
/* Perform initial load. */
4817
window.firstBuildLoad = true;

0 commit comments

Comments
 (0)