-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
148 lines (115 loc) · 3.85 KB
/
main.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
var slide_index = 0;
var slides = document.getElementsByClassName("slide");
function displaySlides(src) {
var i;
var texte ="";
var src = src.split("/"); //enlever le chemin
var nom = src[src.length-1];
for (i = 0; i < slides.length; i++) {
var im = slides[i].firstElementChild;
var ref= im.getAttribute("src"); //enlever le chemin là aussi
ref = ref.split("/");
ref = ref[ref.length-1];
if ( slides[i].lastElementChild.tagName == "figcaption")
{texte = slides[i].lastElementChild.textContent;
}
if (nom == ref)
{
//afficher grandes-images/ref dans une popup avec flèches, overlay...
slide_index = i;
ImagePopup(nom, texte);
break;
}
}
}
function ImagePopup(ref, texte) {
var overlay = document.createElement('div');
overlay.className = 'overlay';
var croix = document.createElement('span');
croix.innerText ='X';
croix.className = 'close';
croix.addEventListener('click', function() {this.parentNode.remove();})
overlay.appendChild(croix);
var popup = document.createElement('div');
popup.className = 'popup';
popupContent(ref, popup, texte);
var nextlink = document.createElement('span');
nextlink.className ='next';
nextlink.innerText = '>';
nextlink.addEventListener('click',goToNext);
var prevlink = document.createElement('span');
prevlink.className ='prev';
prevlink.innerText = '<';
prevlink.addEventListener('click',goToPrev);
overlay.appendChild(prevlink);
overlay.appendChild(popup); //la popup est bien à l'intérieur de l'overlay
overlay.appendChild(nextlink);
overlay.addEventListener('click',
function (e) {
if (this == e.target) //sur l'overlay mais pas popup
{
this.remove();
}
}
);
document.body.appendChild(overlay);
}
function popupContent(ref, box, texte) {
var img = document.createElement('img');
var source = document.getElementById('param').value;
img.src = source+ref;
img.alt = "photo " +ref;
img.maxWidth = "100%";
img.marginTop = 0;
box.appendChild(img);
if (texte.length)
{
var fig = document.createElement('fig');
var txt = document.createTextNode(texte);
fig.appendChild(txt);
box.appendChild(fig);
}
}
function goToNext(e) {
e.preventDefault();
var nextIndex = slide_index + 1;
if (slides.length <= nextIndex) {
nextIndex = 0;
}
goTo(nextIndex);
}
function goTo(index)
{
var texte ="";
var overlay = document.querySelector('.overlay');
if (overlay) {overlay.remove();}
var src = slides[index].firstElementChild.getAttribute("src");
if ( slides[index].lastElementChild.tagName == "FIGCAPTION")
{texte = slides[index].lastElementChild.textContent;
}
ref = src.split("/");
ref = ref[ref.length-1];
ImagePopup(ref,texte);
slide_index = Number(index);
}
function goToPrev(e) {
e.preventDefault();
var nextIndex = slide_index - 1;
if (0 > nextIndex) {
nextIndex = slides.length -1;
}
goTo(nextIndex);
}
function infobulle()
{
var bulle = document.createElement('span');
var txt = document.createTextNode('Cliquez sur une image pour avoir des détails et le diaporama');
bulle.appendChild(txt);
bulle.setAttribute("id","infobulle");
document.body.appendChild(bulle);
}
function closebulle()
{
var bulle = document.getElementsById("infobulle");
body.removeChild(bulle);
}