Use the Fetch API instead of PrototypeJS

This commit is contained in:
nemunaire 2019-09-01 17:13:03 +02:00
parent b08ad493a9
commit d5fd91902f
3 changed files with 21 additions and 7606 deletions

View File

@ -4,8 +4,6 @@
<title>YouP0m</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" media="all" href="/css/style.css">
<script type="text/javascript" src="/js/prototype.js"></script>
<script type="text/javascript" src="/js/youp0m.js"></script>
</head>
<body>
<h1>Welcome on YouP0m!</h1>
@ -18,5 +16,6 @@
<script type="text/javascript">
document.write("<h2>We are loading a cute picture just for you, please wait&hellip;</h2>");
</script>
<script type="text/javascript" src="/js/youp0m.js"></script>
</body>
</html>

7588
static/js/prototype.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -3,12 +3,16 @@ var api_url = "/api/images";
var img_url = "/images/";
function get_picts(then, then_value) {
new Ajax.Request(api_url, {
method: 'get',
onSuccess: function(transport) {
picts = transport.responseText.evalJSON();
fetch(api_url)
.then(function(response) {
return response.json();
})
.then(function(my_picts) {
picts = my_picts;
if (then) then(then_value);
},
})
.catch(function(error) {
display_error(error);
});
}
@ -69,16 +73,16 @@ function show_picture(id) {
function get_picture(id) {
if (id == null) id = "last";
new Ajax.Request(api_url + "/" + id, {
method: 'get',
onSuccess: function(transport) {
var response = transport.responseText.evalJSON();
display_picture(response);
},
onFailure: function(transport) {
var response = transport.responseText.evalJSON();
display_error(response["errmsg"]);
}
fetch(api_url + "/" + id)
.then(function(response) {
return response.json();
})
.then(function(my_pict) {
display_picture(my_pict);
})
.catch(function(error) {
display_error(error);
});
}