-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodal.js
66 lines (59 loc) · 2.19 KB
/
modal.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
let modal;
let modalImg;
let captionText;
let photoId;
let photoDir = "../upload_photos_normal/";
window.onload = function(){
modal = document.getElementById("modalarea");
modalImg = document .getElementById("modalimg");
captionText = document.getElementById("modalcaption");
// lisame kõigile thumbidele klikikuulaja
let allThumbs = document.getElementById("gallery").getElementsByTagName("img");
for(let i=0 ; i< allThumbs.length; i++){
allThumbs[i].addEventListener("click", openModal);
}
document.getElementById("modalclose").addEventListener("click", closeModal)
}
function openModal(e){
modalImg.src = photoDir + e.target.dataset.fn;
captionText.innerHTML = e.target.alt;
modal.style.display = "block";
photoId = e.target.dataset.id;
// nullib hinde osa
document.getElementById("avgRating").innerHTML = "";
for(let i = 1; i< 6; i++){
document.getElementById("rate" + i).checked = false;
}
document.getElementById("storeRating").addEventListener("click",storeRating);
modal.style.display = "block";
}
function closeModal(){
modal.style.display = "none";
modalImg.src = "../images/empty.png";
}
function storeRating(){
let rating = 0;
for(let i = 1; i < 6; i ++){
if(document.getElementById("rate" + i).checked) {
rating = i;
}
if(rating > 0){
//AJAX
let webRequest = new XMLHttpRequest();
webRequest.onreadystatechange = function(){
//kas õnnustus
if(this.readyState == 4 && this.status == 200){
//mida teeme, kui õnnestus
document.getElementById("avgRating").innerHTML = "Keskmine hinne: " + this.responseText;
rating = 0;
for(let i = 1; i < 6; i ++){
document.getElementById("rate" + i).checked = false;
}
}
};
webRequest.open("GET", "store_photorating.php?rating=" + rating + "&photoid=" + photoId, true);
webRequest.send();
//AJAX lõppeb
}
}
}