From 94cc060914231b3369d5c36ab73711bea765c541 Mon Sep 17 00:00:00 2001
From: Wasabi Fan
{{ page.title | xml_escape }}
diff --git a/javascripts/api-cache.js b/javascripts/api-cache.js
index 119e4476d..7223465db 100644
--- a/javascripts/api-cache.js
+++ b/javascripts/api-cache.js
@@ -8,18 +8,20 @@ function supportsHtml5Storage() {
}
}
-function getApiValue(endpointUrl, cacheTime, callback) {
- try {
- var cacheData = supportsHtml5Storage() ? JSON.parse(localStorage[cacheKey]) : null;
- // This does an exact match for the URL given. Different spacing, duplicate slashes,
- // alternate caps, etc. will result in the cache being bypassed.
- if (cacheData && cacheData[endpointUrl] && Date.now() - cacheData[endpointUrl].dateRetrieved < cacheTime) {
- callback(cacheData[endpointUrl].requestResult);
- return;
+function getApiValue(endpointUrl, cacheTime, callback, clearCache) {
+ if(!clearCache) {
+ try {
+ var cacheData = supportsHtml5Storage() ? JSON.parse(localStorage[cacheKey]) : null;
+ // This does an exact match for the URL given. Different spacing, duplicate slashes,
+ // alternate caps, etc. will result in the cache being bypassed.
+ if (cacheData && cacheData[endpointUrl] && Date.now() - cacheData[endpointUrl].dateRetrieved < cacheTime) {
+ callback(cacheData[endpointUrl].requestResult);
+ return;
+ }
+ }
+ catch (e) {
+ // Ignore the error; if the saved JSON is invalid, we'll just request it from the server.
}
- }
- catch (e) {
- // Ignore the error; if the saved JSON is invalid, we'll just request it from the server.
}
console.log('No cached copy of API data for endpoint "' + endpointUrl + '" found. Downloading from remote server.');
diff --git a/javascripts/releases.js b/javascripts/releases.js
index fc58d256f..196078a81 100644
--- a/javascripts/releases.js
+++ b/javascripts/releases.js
@@ -2,54 +2,77 @@
var releaseCacheTimeMillis = 20 * 60 * 1000;
var releasePlatformRegexes = {
- ev3: "ev3dev-jessie-ev3-generic-[\\d-]+\\.zip",
- rpi: "ev3dev-jessie-rpi-generic-[\\d-]+\\.zip",
- rpi2: "ev3dev-jessie-rpi2-generic-[\\d-]+\\.zip",
- bone: "ev3dev-jessie-bone-generic-[\\d-]+\\.zip",
+ ev3: /ev3dev-jessie-ev3-generic-[\d-]+\.zip/,
+ rpi: /ev3dev-jessie-rpi-generic-[\d-]+\.zip/,
+ rpi2: /ev3dev-jessie-rpi2-generic-[\d-]+\.zip/,
+ bone: /ev3dev-jessie-bone-generic-[\d-]+\.zip/,
}
-function initDownloadLinks() {
- getApiValue('https://api.github.com/repos/ev3dev/ev3dev/releases', releaseCacheTimeMillis, function (releases, error) {
- if(error) {
- console.error("Download links not available! Falling back to static content.");
- $('.release-link-container').hide();
- $('.release-link-alt').show();
-
+function loadReleasesByPlatform(successCallback, errorCallback, clearCache) {
+ getApiValue('https://api.github.com/repos/ev3dev/ev3dev/releases', releaseCacheTimeMillis, function (releasesApiData, error) {
+ if (error) {
+ errorCallback(error);
return;
}
-
- releases.sort(function (a, b) {
- if (Date.parse(a['created_at']) < Date.parse(b['created_at']))
- return 1;
- if (Date.parse(a['created_at']) > Date.parse(b['created_at']))
- return -1;
-
- return 0;
+
+ var releaseMap = {};
+ releasesApiData.forEach(function (releaseApiData) {
+ releaseApiData['assets'].forEach(function (assetApiData) {
+ var assetPlatform = $.grep(Object.keys(releasePlatformRegexes), function (platId) {
+ return releasePlatformRegexes[platId].test(assetApiData['name']);
+ })[0];
+
+ if (!assetPlatform)
+ return true;
+
+ if (!Array.isArray(releaseMap[assetPlatform]))
+ releaseMap[assetPlatform] = [];
+
+ releaseMap[assetPlatform].push({
+ releaseName: releaseApiData['name'],
+ creationDate: Date.parse(releaseApiData['created_at']),
+ platform: assetPlatform,
+ size: assetApiData['size'],
+ downloadUrl: assetApiData['browser_download_url']
+ });
+ });
});
+ Object.keys(releaseMap).forEach(function (platformId) {
+ releaseMap[platformId].sort(function (a, b) {
+ return (b.creationDate > a.creationDate) - (b.creationDate < a.creationDate);
+ });
+ })
+
+ successCallback(releaseMap);
+ }, clearCache);
+}
+
+function initDownloadLinks(clearCache) {
+ loadReleasesByPlatform(function (releaseMap) {
+
$('a[data-release-link-platform]').each(function (i, element) {
var $linkElem = $(element);
var targetReleasePlatform = $linkElem.data('release-link-platform');
- if (!releasePlatformRegexes[targetReleasePlatform]) {
- console.error('"' + targetReleasePlatform + '" is an invalid release target.');
+ var targetRelease = (releaseMap[targetReleasePlatform] || [])[0];
+
+ if (!targetRelease) {
+ console.error('"' + targetReleasePlatform + '" is an invalid release target or no releases for the given platform exist.');
return true;
}
- var platformRegex = new RegExp(releasePlatformRegexes[targetReleasePlatform]);
-
- for (var releaseIndex in releases) {
- var releaseAssets = releases[releaseIndex].assets;
- for (var assetIndex in releaseAssets) {
- if (platformRegex.test(releaseAssets[assetIndex].name)) {
- $linkElem.attr('href', releaseAssets[assetIndex]['browser_download_url']);
- var fileSize = releaseAssets[assetIndex]['size'] >> 20;
- $('').text(' (' + fileSize + ' MiB)').appendTo($linkElem);
- return true;
- }
- }
- }
+ $linkElem.attr('href', targetRelease.downloadUrl);
+ $linkElem.children('small.download-size-label').remove();
+
+ var fileSize = targetRelease.size >> 20;
+ $('').addClass('download-size-label').text(' (' + fileSize + ' MiB)').appendTo($linkElem);
});
- });
+ },
+ function (error) {
+ console.error("Download links not available! Falling back to static content.");
+ $('.release-link-container').hide();
+ $('.release-link-alt').show();
+ }, clearCache);
}
$(document).ready(function () {
@@ -57,8 +80,12 @@ $(document).ready(function () {
// We do this as soon as the document loads so that the page flash is minimal.
$('.release-link-alt').hide();
$('.release-link-container').show();
-
+
if ($('a[data-release-link-platform]').length > 0) {
initDownloadLinks();
}
+
+ $('a.release-refresh-button').click(function() {
+ initDownloadLinks(true);
+ });
});
\ No newline at end of file
From 488f59314532baf958e6e701f2a143a9083a7696 Mon Sep 17 00:00:00 2001
From: Wasabi Fan
{{ page.title | xml_escape }}
diff --git a/javascripts/api-cache.js b/javascripts/api-cache.js
index 7223465db..6179a1ec9 100644
--- a/javascripts/api-cache.js
+++ b/javascripts/api-cache.js
@@ -9,7 +9,7 @@ function supportsHtml5Storage() {
}
function getApiValue(endpointUrl, cacheTime, callback, clearCache) {
- if(!clearCache) {
+ if(clearCache != true) {
try {
var cacheData = supportsHtml5Storage() ? JSON.parse(localStorage[cacheKey]) : null;
// This does an exact match for the URL given. Different spacing, duplicate slashes,
diff --git a/javascripts/releases.js b/javascripts/releases.js
index ba53e8a92..1de70b9dd 100644
--- a/javascripts/releases.js
+++ b/javascripts/releases.js
@@ -1,5 +1,5 @@
-// Cache will time out after 20 minutes
-var releaseCacheTimeMillis = 20 * 60 * 1000;
+// Cache will time out after five minutes
+var releaseCacheTimeMillis = 5 * 60 * 1000;
var releasePlatformRegexes = {
ev3: /ev3dev-jessie-ev3-generic-[\d-]+\.zip/,
@@ -8,7 +8,7 @@ var releasePlatformRegexes = {
bone: /ev3dev-jessie-bone-generic-[\d-]+\.zip/,
}
-function loadReleasesByPlatform(successCallback, errorCallback, clearCache) {
+function loadReleasesByPlatform(successCallback, errorCallback) {
getApiValue('https://api.github.com/repos/ev3dev/ev3dev/releases', releaseCacheTimeMillis, function (releasesApiData, error) {
if (error) {
errorCallback(error);
@@ -30,6 +30,7 @@ function loadReleasesByPlatform(successCallback, errorCallback, clearCache) {
releaseMap[assetPlatform].push({
releaseName: releaseApiData['name'],
+ assetName: assetApiData['name'],
creationDate: Date.parse(releaseApiData['created_at']),
platform: assetPlatform,
size: assetApiData['size'],
@@ -45,10 +46,10 @@ function loadReleasesByPlatform(successCallback, errorCallback, clearCache) {
})
successCallback(releaseMap);
- }, clearCache);
+ });
}
-function initDownloadLinks(clearCache) {
+function initDownloadLinks() {
loadReleasesByPlatform(function (releaseMap) {
$('a[data-release-link-platform]').each(function (i, element) {
@@ -63,22 +64,21 @@ function initDownloadLinks(clearCache) {
$linkElem.attr('href', targetRelease.downloadUrl);
- $linkElem.data('toggle', 'tooltip');
- $linkElem.data('placement', 'right');
- $linkElem.attr('title', targetRelease.releaseName);
-
- $linkElem.children('small.download-size-label').remove();
+ $linkElem.children('small.download-info-label').remove();
var fileSize = targetRelease.size >> 20;
- $('').addClass('download-size-label').text(' (' + fileSize + ' MiB)').appendTo($linkElem);
+ $('').addClass('download-info-label badge').text(fileSize + ' MiB').appendTo($linkElem);
+ $('').addClass('download-info-label').css({
+ 'display': 'block',
+ 'font-size': '65%'
+ }).text(targetRelease.assetName).appendTo($linkElem);
- $linkElem.tooltip();
});
},
function (error) {
console.error("Download links not available! Falling back to static content.");
$('.release-link-container').hide();
$('.release-link-alt').show();
- }, clearCache);
+ });
}
$(document).ready(function () {
@@ -90,8 +90,4 @@ $(document).ready(function () {
if ($('a[data-release-link-platform]').length > 0) {
initDownloadLinks();
}
-
- $('a.release-refresh-button').click(function() {
- initDownloadLinks(true);
- });
});
\ No newline at end of file
From 4a25eb060a129d27ff314288b01a7b07b21ec9bb Mon Sep 17 00:00:00 2001
From: Wasabi Fan
Other platforms
-Raspberry Pi 1
-Raspberry Pi 2
-BeagleBone
+Raspberry Pi 1
+Raspberry Pi 2
+BeagleBone
diff --git a/download.md b/download.md
index 458bc6ed0..9a821afe9 100644
--- a/download.md
+++ b/download.md
@@ -28,7 +28,7 @@ no-wrapper: true
the primary focus of development.
Other platforms
-Raspberry Pi 1
-Raspberry Pi 2
-BeagleBone
+Raspberry Pi Model Zero/1
+Raspberry Pi Model 2/3
+BeagleBone
diff --git a/download.md b/download.md
index 9a821afe9..916b1544e 100644
--- a/download.md
+++ b/download.md
@@ -28,9 +28,9 @@ no-wrapper: true
the primary focus of development.