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> <title>YouP0m</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" media="all" href="/css/style.css"> <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> </head>
<body> <body>
<h1>Welcome on YouP0m!</h1> <h1>Welcome on YouP0m!</h1>
@ -18,5 +16,6 @@
<script type="text/javascript"> <script type="text/javascript">
document.write("<h2>We are loading a cute picture just for you, please wait&hellip;</h2>"); document.write("<h2>We are loading a cute picture just for you, please wait&hellip;</h2>");
</script> </script>
<script type="text/javascript" src="/js/youp0m.js"></script>
</body> </body>
</html> </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/"; var img_url = "/images/";
function get_picts(then, then_value) { function get_picts(then, then_value) {
new Ajax.Request(api_url, { fetch(api_url)
method: 'get', .then(function(response) {
onSuccess: function(transport) { return response.json();
picts = transport.responseText.evalJSON(); })
if (then) then(then_value); .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) { function get_picture(id) {
if (id == null) id = "last"; if (id == null) id = "last";
new Ajax.Request(api_url + "/" + id, {
method: 'get', fetch(api_url + "/" + id)
onSuccess: function(transport) { .then(function(response) {
var response = transport.responseText.evalJSON(); return response.json();
display_picture(response); })
}, .then(function(my_pict) {
onFailure: function(transport) { display_picture(my_pict);
var response = transport.responseText.evalJSON(); })
display_error(response["errmsg"]); .catch(function(error) {
} display_error(error);
}); });
} }