-
Notifications
You must be signed in to change notification settings - Fork 0
/
atompm-scripts.js
122 lines (100 loc) · 3.92 KB
/
atompm-scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* --------------- Utilities --------------- */
// Get the value of a key in the query string from the URL
//function getQSValue(key) {
// key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&"); // escape RegEx meta chars
// var match = location.search.match(new RegExp("[?&]" + key + "=([^&]+)(&|$)"));
// return match && decodeURIComponent(match[1].replace(/\+/g, " "));
//}
// Convert a string to a version number: e.g., '1.5.2' -> 1.52
//function strToVersion(version) {
// v = 0;
// try {
// version = version.split('.');
// for (i = 0; i < version.length; i++) {
// v += parseInt(version[version.length - i - 1]) * Math.pow(10, i);
// }
// }
// catch (err) {
// return null;
// }
// return v;
//}
// Returns the name of the latest version of AToMPM
//function getAToMPMVersionName() {
// return $('meta[name=versionName]').attr('content'); // current version name in meta attributes
//}
function onreadystatechange(ev) {
if( req.readyState == 4 )
{
console.debug(method+' '+url+' >> '+req.status);
if( req.status == 0 )
WindowManagement.openDialog(__FATAL_ERROR,'lost connection to back-end');
else if( onresponse )
onresponse(req.status,req.responseText);
else if( ! utils.isHttpSuccessCode(req.status) )
WindowManagement.openDialog(_ERROR,req.responseText);
}
}
function setAToMPMVersionName() {
$(download_dev).text('Download AToMPM');
$(latest_version).text("here");
$(version_time).text("");
var httpReq = new XMLHttpRequest();
var isHttpSuccessCode = function(statusCode)
{
return Math.floor(statusCode/100.0) == 2;
};
var onreadystatechange = function(ev) {
if( httpReq.readyState == 4 )
{
if( isHttpSuccessCode(httpReq.status)){
var resp = JSON.parse(httpReq.responseText);
var curr_version = resp['tag_name'];
if (curr_version == undefined){
return;
}
console.log(typeof resp);
console.log(resp['tag_name']);
$(download_dev).text('Download AToMPM ' + curr_version);
$(latest_version).text(curr_version);
var time_at = resp['published_at'];
time_at = time_at.split("T")[0];
$(version_time).text(", released on " + time_at);
}
}
};
httpReq.open("GET", "https://api.github.com/repos/AToMPM/atompm/releases/latest");
httpReq.onreadystatechange = onreadystatechange;
httpReq.send(null);
}
// Tab behavior: load the appropriate page
function load(div) {
$('.entry').hide(); // hide all divs with CSS class "entry" (a dummy class)
$(div).fadeIn(); // show only the requested div
}
/* --------------- Onload --------------- */
// If a version number is present in the query string, check if it is the latest version and display the appropriate message
//$(document).ready(function () {
// version = strToVersion(getQSValue("version"));
// if (version != null) {
// msg = "";
// if (version < strToVersion($('meta[name=version]').attr('content'))) { // current version in meta attributes
// $(topbar).append('<a href="#dev" onclick="load('#dev');">You do not have the latest version of AToMPM. Click here to download the latest version.</a>');
// }
// else {
// $(topbar).text("You currently have the latest version " + getQSValue("version"));
// }
// $(topbar).fadeToggle(1500);
// }
//});
// Load the div specified in the URL after the hashtag
//$(document).ready(function () {
// var requestedDiv = window.location.hash;
// if (requestedDiv != '') {
// load(requestedDiv);
// }
//});
// Set the name of the latest AToMPM version in all fields dynamically
$(document).ready(function () {
setAToMPMVersionName();
});