-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGallery.js
More file actions
64 lines (58 loc) · 1.84 KB
/
Copy pathGallery.js
File metadata and controls
64 lines (58 loc) · 1.84 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
/**
* Created by galmaor on 06/04/14.
*/
function addPic(parent, picUrl) {
var thePic = document.createElement("img");
thePic.setAttribute("src", picUrl);
thePic.onload = function () {
if (thePic.width >= thePic.height) {
thePic.setAttribute("class", "pic wide");
}
else {
thePic.setAttribute("class", "pic tall");
}
}
var container = document.createElement("div");
container.setAttribute("class", "piccontainer");
container.appendChild(thePic);
parent.appendChild(container);
}
function eventDispatcher(element, eventType) {
var dispatcher = {};
dispatcher.register = function (filterClass, f) {
if (f === undefined) {
f = filterClass;
filterClass = undefined;
}
var g = function (e) {
if (filterClass === undefined) {
f(e);
return;
}
if (!e.target.classList.contains(filterClass)) return;
f(e);
}
element.addEventListener(eventType, g);
return this;
}
return dispatcher;
}
function makeVisible(element) {
element.style.visibility = "visible";
}
function hide(element) {
element.style.visibility = "hidden";
}
var addDialog = document.getElementById("addPicDialogBox");
//makeVisible(addDialog);
var addButton = document.getElementById("addNewPhoto");
var urlCancelButton = document.getElementById("cancelUrlAdd");
eventDispatcher(addButton, "click").register(function () {
makeVisible(addDialog);
});
eventDispatcher(urlCancelButton, "click").register(function () {
hide(addDialog);
});
picsec = document.getElementById("picturesSection");
addPic(picsec, "http://www.fontplay.com/freephotos/seventeen/fpx041611-19.jpg");
addPic(picsec, "http://www.fontplay.com/freephotos/seventeen/fpx012211-01.jpg");