forked from zombieFox/nightTab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshade.js
More file actions
68 lines (63 loc) · 1.8 KB
/
Copy pathshade.js
File metadata and controls
68 lines (63 loc) · 1.8 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
var shade = (function() {
var previousShade = null;
var destroy = function() {
var allShade = helper.eA(".shade");
if (allShade[0]) {
for (var i = 0; i < allShade.length; i++) {
allShade[i].destroy();
};
};
};
var render = function(override) {
var options = {
action: null
};
if (override) {
options = helper.applyOptions(options, override);
};
var _destroyPreviousShade = function() {
if (previousShade != null) {
destroy();
};
};
var _makeShade = function() {
var body = helper.e("body");
var shade = document.createElement("div");
shade.setAttribute("class", "shade");
shade.destroy = function() {
if (shade.classList.contains("is-opaque")) {
helper.removeClass(shade, "is-opaque");
helper.addClass(shade, "is-transparent");
} else {
shade.remove();
};
};
shade.addEventListener("transitionend", function(event, elapsed) {
if (event.propertyName === "opacity" && getComputedStyle(this).opacity == 0) {
this.parentElement.removeChild(this);
};
if (event.propertyName === "opacity" && getComputedStyle(this).opacity == 1) {
helper.addClass(this, "is-transition-end");
};
}.bind(shade), false);
shade.addEventListener("click", function() {
this.destroy();
if (options.action) {
options.action();
};
}, false);
previousShade = shade;
body.appendChild(shade);
getComputedStyle(shade).opacity;
helper.removeClass(shade, "is-transparent");
helper.addClass(shade, "is-opaque");
};
_destroyPreviousShade();
_makeShade();
};
// exposed methods
return {
destroy: destroy,
render: render
};
})();