-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
122 lines (114 loc) · 3.32 KB
/
main.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
var prideSocket = new WebSocket('wss://' + window.location.host + '/ws/humans/');
var searchQueries = [];
prideSocket.onmessage = function (e) {
var data = JSON.parse(e.data);
var queries = data['message'];
if (searchQueries.length < 50) {
searchQueries.push.apply(searchQueries, queries);
}
};
prideSocket.onclose = function (e) {
console.error('Chat socket closed unexpectedly');
};
function ready(fn) {
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
var delay = (function () {
var timer = 0;
return function (callback, ms) {
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
})();
function checkForEntry() {
var isCacheEmpty = searchQueries.length === 0;
if (isCacheEmpty) {
delay(function () {
checkForEntry()
}, 500)
} else {
var home_quote = document.getElementById('home_quote');
home_quote.classList.remove('fadeInDown');
['fadeInDown', 'slow'].map(item => home_quote.classList.remove(item)
)
;
home_quote.classList.add('fadeOutDown');
document.getElementById('header_div').classList.remove('hidden');
document.getElementById('head_1').classList.add('rotateInDownLeft');
document.getElementById('head_2').classList.add('rotateInDownRight');
fromCacheToHtml();
var ball = document.getElementById('ball');
ball.parentNode.removeChild(ball);
showElements();
}
}
ready(function () {
anime({
targets: '#ev_s',
color: [
{value: '#2196f3'},
{value: '#FFF'}
],
loop: true,
easing: 'linear',
direction: 'alternate',
duration: 5000,
});
delay(function () {
checkForEntry()
}, 4000);
});
function fromCacheToHtml() {
var elementsToShow = searchQueries.splice(0, 10);
var insert = '';
for (var i = 0; i < elementsToShow.length; i++) {
var item = elementsToShow[i];
insert += '<div class="wrapper"><div class="item">' +
'<a class="link" target="_blank" href="https://www.yandex.ru/search/?text=' + item + '">' +
elementsToShow[i] +
'</div></div>';
}
document.getElementById('search-items').innerHTML = insert;
}
function showElements() {
var els = document.querySelectorAll('.item');
var callback = anime({
targets: els,
translateX: [-200, "0%"],
easing: 'easeInOutBack',
elasticity: 100,
duration: function (el, i, l) {
return 200 + (i * 200);
},
delay: function (el, i, l) {
return i * 30;
},
});
callback.complete = function () {
delay(function () {
moveRight(els);
}, 4000);
};
}
function moveRight(els) {
var callback = anime({
targets: els,
translateX: ["0%", "100vw"],
easing: 'easeInOutBack',
duration: function (el, i, l) {
return 150 + (i * 150);
},
delay: function (el, i, l) {
return i * 10;
},
});
callback.complete = function () {
// start new loop
fromCacheToHtml();
showElements();
}
}