Skip to content

Commit

Permalink
Make the download page work on IE7
Browse files Browse the repository at this point in the history
- List higher-order functions (map, filter, forEach) are not available on IE,
so implement them ourselves.

- Fix a bug in attachEvent. The event name must have the prefix 'on'.

- Use e.srcElement instead of e.target for IE.

- IE hates trailing commas, so remove them.
  • Loading branch information
sorawee authored Jun 15, 2020
1 parent 689cdc7 commit 05e9d79
Showing 1 changed file with 47 additions and 18 deletions.
65 changes: 47 additions & 18 deletions download/download-pages.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,33 @@
before installing other packages.}
@script/inline[type: 'text/javascript]{

// higher-order functions

function map(xs, f) {
var result = [];
for (var i = 0; i < xs.length; i++) {
result.push(f(xs[i], i));
}
return result;
}

function forEach(xs, f) {
for (var i = 0; i < xs.length; i++) {
f(xs[i], i);
}
}

function filter(xs, f) {
var result = [];
for (var i = 0; i < xs.length; i++) {
if (f(xs[i], i)) {
result.push(xs[i]);
}
}
return result;
}


// big-bang for HTML

// bigbang :: (HTMLElement, 'state, ('state -> Elem)) -> void
Expand Down Expand Up @@ -172,7 +199,7 @@ var elem = null;
if (tree.node.addEventListener) {
tree.node.addEventListener(key, closure, false);
} else {
tree.node.attachEvent(key, closure);
tree.node.attachEvent('on' + key, closure);
}
} else {
tree.node.setAttribute(key, value);
Expand All @@ -182,6 +209,7 @@ var elem = null;

function makeClosure(value) {
return function (e) {
e.target = e.target || e.srcElement; // IE uses srcElement
globalState = value(globalState, e);
rerender();
};
Expand All @@ -196,7 +224,8 @@ var elem = null;
var e = document.createElement(tree.type);
tree.node = e;
setAttribute(tree);
tree.children.forEach(function (child) {

forEach(tree.children, function (child) {
e.appendChild(render(child));
});
return e;
Expand All @@ -216,7 +245,7 @@ var elem = null;
if (newTree.node.removeEventListener) {
newTree.node.removeEventListener(key, closure, false);
} else {
newTree.node.detachEvent(key, closure);
newTree.node.detachEvent('on' + key, closure);
}
} else {
newTree.node.removeAttribute(key);
Expand Down Expand Up @@ -260,7 +289,7 @@ var elem = null;
};

elem = function (type, attrs, children) {
return new Elem(type, attrs, children.map(function (child) {
return new Elem(type, attrs, map(children, function (child) {
return (typeof child === 'string') ?
new Text(child) :
child;
Expand Down Expand Up @@ -484,37 +513,37 @@ var elem = null;
else return 0;
}
// sort the options, need to use a temporary array
var tmps = platforms.map(function (platform, i) {
var tmps = map(platforms, function (platform, i) {
return {
name: platform.platformName,
index: i,
platform: platform
};
});
tmps.sort(isBetter);
tmps.forEach(function (platformData, i) {
forEach(tmps, function (platformData, i) {
platforms[i] = platformData.platform;
});
}

allInstallers.forEach(function (dist) {
forEach(allInstallers, function (dist) {
orderPlatform(dist.installers);
});

function getAllPlatforms(allInstallers, currentDist) {
return allInstallers.filter(function (group) {
return filter(allInstallers, function (group) {
return group.dist === currentDist;
})[0].installers;
}

function getAllVariants(allPlatforms, currentPlatform) {
return allPlatforms.filter(function (group) {
return filter(allPlatforms, function (group) {
return group.platform === currentPlatform;
})[0].installers;
}

function getPackage(allVariants, currentVariant) {
return allVariants.filter(function (group) {
return filter(allVariants, function (group) {
return computeVariant(group) === currentVariant;
})[0];
}
Expand All @@ -541,7 +570,7 @@ var elem = null;
return {
dist: currentDist,
platform: currentPlatform,
variant: currentVariant,
variant: currentVariant
};
}

Expand All @@ -554,15 +583,15 @@ var elem = null;
return {
dist: currentDist,
platform: currentPlatform,
variant: currentVariant,
variant: currentVariant
};
}

function handleVariantChange(state, e) {
return {
dist: state.dist,
platform: state.platform,
variant: e.target.value,
variant: e.target.value
};
}

Expand All @@ -572,7 +601,7 @@ var elem = null;
elem('div', {}, [
'Distribution: ',
elem('select', {onchange: handleDistChange},
allInstallers.map(function (group) {
map(allInstallers, function (group) {
return elem('option',
group.dist === currentDist ?
{selected: 'selected', value: group.dist} :
Expand All @@ -583,22 +612,22 @@ var elem = null;
elem('div', {}, [
'Platform: ',
elem('select', {onchange: handlePlatformChange},
allPlatforms.map(function (group) {
map(allPlatforms, function (group) {
return elem('option',
group.platform === currentPlatform ?
{selected: 'selected', value: group.platform} :
{value: group.platform},
[group.platformName]);
}))
]),
])
];

if (allVariants.length !== 1) {
children.push(
elem('div', {}, [
'Variant: ',
elem('select', {onchange: handleVariantChange},
allVariants.map(function (group) {
map(allVariants, function (group) {
var theVariant = computeVariant(group);
return elem('option',
theVariant === currentVariant ?
Expand All @@ -620,7 +649,7 @@ var elem = null;
bigbang(document.getElementById('control'), {
dist: currentDist,
platform: currentPlatform,
variant: currentVariant,
variant: currentVariant
}, toDraw);
}

Expand Down

0 comments on commit 05e9d79

Please sign in to comment.