-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgod-skin-themes.js
85 lines (80 loc) · 2.48 KB
/
god-skin-themes.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
// Fix for IE11
if (typeof NodeList.prototype.forEach !== "function" ) {
NodeList.prototype.forEach = Array.prototype.forEach;
}
// Fix for IE
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes#Polyfill
if (!String.prototype.includes) {
Object.defineProperty(String.prototype, 'includes', {
value: function(search, start) {
if (typeof start !== 'number') {
start = 0
}
if (start + search.length > this.length) {
return false
} else {
return this.indexOf(search, start) !== -1
}
}
})
}
document.dataHandler = {
init: function(){
document.imageLoader.init()
detailsExpandStateSaver.init()
},
}
document.imageLoader = {
observer: null,
init: function(){
var images = document.querySelectorAll('img.skincard')
if ('IntersectionObserver' in window){
observer = new IntersectionObserver(this.onItem.bind(this));
images.forEach(this.observe);
} else {
images.forEach(this.loadImage);
}
},
observe: function(img){
this.observer.observe(img)
},
onItem: function(items, observer) {
items.forEach(this.onItemIndiv.bind(this));
},
onItemIndiv: function(item) {
if (item.isIntersecting){
let img = item.target
this.loadImage(img);
observer.unobserve(img);
}
},
loadImage: function(img){
img.src = img.dataset.src
},
}
detailsExpandStateSaver = {
init: function() {
if (window.localStorage === undefined) {
return
}
var els = document.querySelectorAll('details[id] summary')
for (var i = 0; i < els.length; ++i) {
var el = els[i]
var details = el.parentElement
if (!details.id) {
continue
}
el.addEventListener('click', this.onClick)
var isOpen = window.localStorage.getItem('details-expand-state.' + details.id) === 'true'
details.open = isOpen
}
},
onClick: function(ev) {
var details = this.parentElement;
if (!details.id) {
return
}
window.localStorage.setItem('details-expand-state.' + details.id, !details.open)
},
}
document.dataHandler.init()