-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathall.js
216 lines (175 loc) · 6.41 KB
/
all.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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
'use strict';
window.onload = function(){
childManager()
childIndex();
modalizer();
mixPattern(50);
}
document.getElementById('pattern').onclick = function(){
mixPattern(50)
}
function mixPattern(num) {
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var pattern = document.getElementById('pattern');
pattern.innerHTML = '';
for (var i = 0; i < num; i++) {
var item = document.createElement('span');
item.classList.add('ball');
pattern.appendChild(item)
}
var pItems = pattern.children;
for (var i = 0; i < pItems.length; i++ ) {
position(pItems[i])
}
function position(el){
var py = getRandomInt(1, 100);
var px = getRandomInt(1, 100);
var size = getRandomInt(1, 100);
var blur = getRandomInt(1,5);
el.style.width = size + 'px';
el.style.height = size + 'px';
el.style.top = py + '%';
el.style.left = px + '%';
el.style.webkitFilter = 'blur('+blur + 'px)';
el.style.filter = 'blur('+blur + 'px)';
}
}
// Generate li incrementer
function childManager(){
var families = document.querySelectorAll('.doc ul');
var controlTpl = `<button class="add-item btn btn-blue w-icon">add child <svg><use xlink:href="#icon-add"></use></svg></button> <button class="remove-item btn btn-blue w-icon">remove child <svg><use xlink:href="#icon-remove"></use></svg></button>`;
var orderTpl = `<button class="btn btn-blue w-icon" data-state-a="current direction\: forward" data-state-b="current direction\: backward" data-state></button>`;
for ( var i = 0; i < families.length; i++) {
addControls(families[i], i);
}
function addControls(set, num) {
var controls = document.createElement('div');
var controlsId = "controls-" + num;
if(set.getAttribute('data-controls') == 'order') {
controls.id = 'order-' + controlsId;
controls.innerHTML = orderTpl;
set.parentNode.children[0].appendChild(controls)
} else {
controls.id = controlsId;
controls.innerHTML = controlTpl;
set.parentNode.children[0].appendChild(controls)
}
performControls(controlsId, num)
}
function performControls(id, num) {
if(document.querySelector('[id="controls-'+i+'"]')) {
var add = document.querySelector('#'+id+' .add-item') || false;
var remove = document.querySelector('#'+id+' .remove-item') || false;
add.addEventListener('click', function(){
var familyClass = this.parentNode.parentNode.parentNode.children[2].className;
var item = document.createElement('li');
document.querySelector('.'+familyClass).appendChild(item)
childNum(familyClass);
})
remove.addEventListener('click', function(){
var familyClass = this.parentNode.parentNode.parentNode.children[2].className;
var familyList = document.querySelector('.'+familyClass);
var lastItem = familyList.lastElementChild;
familyList.removeChild(lastItem)
childNum(familyClass);
})
}
}
function childNum(listId) {
var lists = document.querySelectorAll('div > ul.'+listId);
for (var i = 0; i < lists.length; i++) {
giveIds(lists[i])
}
function giveIds(list) {
var childsLength = list.children.length;
list.lastElementChild.textContent = childsLength
}
}
addState()
}
// Controls for the child-index property demo
function childIndex(){
var item = document.querySelector('ul.child-index');
var button = item.parentNode.children[0].children[2].children[0];
button.addEventListener('click', function(){
var v = this.textContent;
if ( v == 'current direction: forward') {
indexem(item, 'forward')
} else {
indexem(item, 'backward')
}
function indexem(parent, direction) {
var children = parent.children;
var styleHolder = document.querySelector('#style-child-index');
styleHolder.innerHTML = 'ul.child-index li{ z-index: 0}';
for ( var i = 0; i < children.length; i++) {
applyIndex(children[i], direction, i)
}
function applyIndex(el, dir, id) {
var z = window.getComputedStyle(el,null).getPropertyValue('z-index');
var id = parseInt(id) + 1;
if( dir == 'forward' ) {
document.querySelector('#demo-index').innerHTML = 'forward'
styleHolder.innerHTML += `
ul.child-index li:nth-child(${id}){ z-index: ${id} !important;}`;
} else {
document.querySelector('#demo-index').innerHTML = 'backward'
styleHolder.innerHTML += `
ul.child-index li:nth-last-child(${id}){ z-index: ${id} !important;}`;
}
}
}
})
}
// Used for the "Child-Index()" demo
// To indicate which direction is defined
function addState() {
var hasState = document.querySelectorAll('[data-state]');
for ( var i = 0; i < hasState.length; i++ ) {
writeState(hasState[i])
}
function writeState(el) {
var stateA = el.getAttribute('data-state-a');
var stateB = el.getAttribute('data-state-b');
el.innerHTML = stateA + '<svg><use xlink:href="#icon-arrow-right"></use></svg>';
el.addEventListener('click', function(){
var str = el.textContent;
if ( str == stateA ) {
el.innerHTML = stateB + '<svg><use xlink:href="#icon-arrow-left"></use></svg>'
} else {
el.innerHTML = stateA + '<svg><use xlink:href="#icon-arrow-right"></use></svg>'
}
})
}
};
// Simple modal toggler
function modalizer() {
var trigger = document.querySelector('[data-toggle-modal]');
var modal = document.querySelector('#about');
var backdropModal = document.querySelector('.modal-backdrop');
var closeModal = document.getElementById('close');
trigger.addEventListener('click', function(){
modal.classList.toggle('display');
backdropModal.classList.toggle('display');
});
closeModal.addEventListener('click', function(){
modal.classList.remove('display');
backdropModal.classList.remove('display');
})
}
window.addEventListener('DOMContentLoaded',function(){
var search = document.querySelector('.searchbox input'),
projectNames = document.querySelectorAll('.mixin h3'),
projectDescriptions = document.querySelectorAll('.mixin'),
clearButton = document.querySelector('.searchbox #clear');
clearButton.addEventListener('click', function(){
clearSearch()
})
function clearSearch() {
for (var i = 0; i < projectNames.length; i++) {
projectNames[i].parentNode.parentNode.classList.remove('hidden');
}
}
});