-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgallery.js
More file actions
196 lines (156 loc) · 7.54 KB
/
gallery.js
File metadata and controls
196 lines (156 loc) · 7.54 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
'use strict';
let images = [
{src: "static\\img\\IMG_20191015_173524.jpg", alt: "Egerbakta", description: "A beautiful sunset from the hill"},
{src: "static\\img\\IMG_20191016_084110.jpg", alt: "Egerbakta", description: "The view of the village from the hill in the morning"},
{src: "static\\img\\IMG_20191016_095716.jpg", alt: "Eger", description: "The castle of Eger on the inside"},
{src: "static\\img\\IMG_20191016_141747.jpg", alt: "Szalajka-völgy", description: "The field which is the end station of the little engine from Szilvásvárad"},
{src: "static\\img\\IMG_20191016_142132.jpg", alt: "Szalajka-völgy", description: "A beautiful lake from which the water streams in the direction of the road back to Szilvásvárad"},
{src: "static\\img\\IMG_20191016_143841.jpg", alt: "Szalajka-völgy", description: "The so-called \"Fátyol-vízesés\"", needRotation: true},
{src: "static\\img\\IMG_20191016_144513.jpg", alt: "Szalajka-völgy", description: "The forest roads are beautiful in the autumn"},
{src: "static\\img\\IMG_20191016_145017.jpg", alt: "Szalajka-völgy", description: "The source of a stream", needRotation: true},
{src: "static\\img\\IMG_20191017_111420.jpg", alt: "Sirok", description: "The entrance of the Sirok castle", needRotation: true},
{src: "static\\img\\IMG_20191017_112516.jpg", alt: "Sirok", description: "The view on the village of Sirok from the castle"}
]
function addNewPicture (index, classToSet) {
let newPicture = document.createElement("img");
newPicture.setAttribute("src", images[index].src);
newPicture.setAttribute("class", classToSet);
newPicture.setAttribute("id", index);
if (images[index].needRotation === true) {
newPicture.setAttribute("style", "transform: rotate(90deg)");
}
return newPicture;
}
function showBigPicture (index) {
let currentPicture = document.getElementsByClassName("clicked")[0];
currentPicture.setAttribute("class", "notclicked");
let clickedPicture = document.getElementById(index);
clickedPicture.setAttribute("class", "clicked");
let pictureBox = document.getElementsByClassName("picture-box")[0];
if (pictureBox.getElementsByTagName("img")[0] !== undefined) {
pictureBox.removeChild(pictureBox.getElementsByTagName("img")[0]);
pictureBox.removeChild(pictureBox.getElementsByClassName("text-box")[0]);
}
pictureBox.appendChild(addNewPicture(index, "picture"));
let textBox = document.createElement("div");
textBox.setAttribute("class", "text-box");
let newHeader = document.createElement("h1");
newHeader.textContent = images[index].alt;
let newParagraph = document.createElement("p");
newParagraph.textContent = images[index].description;
textBox.appendChild(newHeader);
textBox.appendChild(newParagraph);
pictureBox.appendChild(textBox);
}
function pageLoad () {
// adding thumbnails with onlcick event
let thumbnailList = document.getElementById("picture-list").getElementsByTagName("ul")[0];
for (let i = 0; i < images.length; i++) {
let thumbnail;
if (i === 0) {
thumbnail = addNewPicture(i, "clicked");
} else {
thumbnail = addNewPicture(i, "notclicked");
}
let newLi = document.createElement("li");
newLi.appendChild(thumbnail);
thumbnailList.appendChild(newLi);
thumbnail.onclick = function () {
showBigPicture(i);
}
}
//adding the big picture
showBigPicture(0);
}
let leftArrow = document.getElementById("arrow-left");
leftArrow.onclick = function() {
let currentPicture = document.getElementsByClassName("clicked")[0];
if (parseInt(currentPicture.id) > 0) {
showBigPicture(parseInt(currentPicture.id) - 1);
}
}
let rightArrow = document.getElementById("arrow-right");
rightArrow.onclick = function() {
let currentPicture = document.getElementsByClassName("clicked")[0];
if (parseInt(currentPicture.id) < images.length - 1) {
showBigPicture(parseInt(currentPicture.id) + 1);
}
}
window.onload = function () {
pageLoad();
}
// let currentPicture = document.getElementsByClassName("picture-box")[0].getElementsByTagName("img")[0];
// let currentIndex = 0;
// function showPicture (x) {
// currentIndex = x;
// let pictureBox = document.getElementsByClassName("picture-box")[0];
// if (currentPicture !== undefined) {
// pictureBox.removeChild(pictureBox.getElementsByTagName("img")[0]);
// pictureBox.removeChild(pictureBox.getElementsByClassName("text-box")[0]);
// }
// let newPicture = document.createElement("img");
// newPicture.setAttribute("src", images[x].src);
// newPicture.setAttribute("alt", images[x].alt);
// newPicture.setAttribute("data-desc", images[x].description);
// newPicture.setAttribute("class", "picture");
// newPicture.setAttribute("data-index", x);
// if (images[x].needRotation === true) {
// newPicture.setAttribute("style", "transform: rotate(90deg)");
// }
// pictureBox.appendChild(newPicture);
// currentPicture = newPicture;
// let textBox = document.createElement("div");
// textBox.setAttribute("class", "text-box");
// let newHeader = document.createElement("h1");
// newHeader.textContent = images[x].alt;
// let newParagraph = document.createElement("p");
// newParagraph.textContent = images[x].description;
// textBox.appendChild(newHeader);
// textBox.appendChild(newParagraph);
// pictureBox.appendChild(textBox);
// }
// showPicture(currentIndex);
// let thumbnailList = document.getElementById("picture-list").getElementsByTagName("ul")[0];
// let clickedThumbnail;
// for (let i = 0; i < images.length; i++) {
// let thumbnail = document.createElement("img");
// thumbnail.setAttribute("src", images[i].src);
// thumbnail.setAttribute ("class", "notclicked");
// thumbnail.setAttribute ("id", i);
// if (images[i].needRotation === true) {
// thumbnail.setAttribute("style", "transform: rotate(90deg)");
// }
// if (i === 0) {
// clickedThumbnail = thumbnail;
// clickedThumbnail.setAttribute ("class", "clicked");
// }
// let newLi = document.createElement("li");
// newLi.appendChild(thumbnail);
// thumbnailList.appendChild(newLi);
// thumbnail.onclick = function() {
// clickedThumbnail.setAttribute ("class", "notclicked");
// clickedThumbnail = thumbnail;
// clickedThumbnail.setAttribute ("class", "clicked");
// showPicture(i);
// }
// }
// let leftArrow = document.getElementById("arrow-left");
// leftArrow.onclick = function() {
// if (currentPicture.dataset.index > 0) {
// let thumbnailIndex = parseInt(clickedThumbnail.id);
// clickedThumbnail.setAttribute ("class", "notclicked");
// clickedThumbnail = thumbnailList.getElementsByTagName("li")[thumbnailIndex - 1].getElementsByTagName("img")[0];
// clickedThumbnail.setAttribute ("class", "clicked");
// showPicture(currentIndex - 1);
// }
// }
// let rightArrow = document.getElementById("arrow-right");
// rightArrow.onclick = function() {
// if (currentPicture.dataset.index < images.length - 1) {
// let thumbnailIndex = parseInt(clickedThumbnail.id);
// clickedThumbnail.setAttribute ("class", "notclicked");
// clickedThumbnail = thumbnailList.getElementsByTagName("li")[thumbnailIndex + 1].getElementsByTagName("img")[0];
// clickedThumbnail.setAttribute ("class", "clicked");
// showPicture(currentIndex + 1);
// }
// }