-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
253 lines (235 loc) · 8.38 KB
/
app.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
var lang_arr=[];
lang_arr['en']=[];
lang_arr['en']['expand']='Expand';
lang_arr['en']['collapse']='Collapse';
lang_arr['en']['prev_slide']='Previous slide';
lang_arr['en']['next_slide']='Next slide';
lang_arr['ru']=[];
lang_arr['ru']['expand']='Развернуть';
lang_arr['ru']['collapse']='Свернуть';
lang_arr['ru']['prev_slide']='Предыдущий слайд';
lang_arr['ru']['next_slide']='Следующий слайд';
function escape_html(text) {
var map = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
return text.replace(/[&<>"']/g,function(m){return map[m];});
}
function unescape_html(text) {
var map = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
''': "'"
};
return text.replace(/&(amp|quot|lt|gt|#039);/g,function(m){console.log('find',m);return map[m];});
}
function app_mouse(e){
if(!e)e=window.event;
var target=e.target || e.srcElement;
if($(target).hasClass('toggle-action')){
let toggle=$('.toggle-item.'+$(target).data('toggle'));
if('none'==toggle.css('display')){
toggle.css('display','block');
}
else{
toggle.css('display','none');
}
e.preventDefault();
}
if($(target).hasClass('close-presentation-action')){
if($('.presentation').hasClass('fullscreen')){
$('.presentation').removeClass('fullscreen');
$('.toggle-fullscreen-action').html(lang_arr[selected_lang]['expand']);
}
}
if($(target).hasClass('toggle-fullscreen-action')){
if($('.presentation').hasClass('fullscreen')){
$('.presentation').removeClass('fullscreen');
$(target).html(lang_arr[selected_lang]['expand']);
}
else{
$('.presentation').addClass('fullscreen');
$(target).html(lang_arr[selected_lang]['collapse']);
}
e.preventDefault();
}
if($(target).hasClass('next-action')){
let presentation=$(target).closest('.presentation');
let slide_count=presentation.find('.slide').length;
let current_slide=presentation.find('.slide.current');
let current_slide_num=current_slide.data('num');
let next_slide;
if(slide_count>=(1+current_slide_num)){
next_slide=presentation.find('.slide[data-num="'+(1+current_slide_num)+'"]');
next_slide.addClass('current');
current_slide.removeClass('current');
}
else{
next_slide=presentation.find('.slide[data-num="'+1+'"]');
next_slide.addClass('current');
current_slide.removeClass('current');
}
current_slide_num=next_slide.data('num');
presentation.find('.slide-counter').html(current_slide_num+' / '+slide_count);
let progress=Math.floor(100*current_slide_num/slide_count);
progress=Math.min(progress,100);
progress=Math.max(progress,0);
presentation.find('.progress .fill-level').css('width',progress+'%');
start_presentation_slider_time=0;
}
if($(target).hasClass('prev-action')){
let presentation=$(target).closest('.presentation');
let slide_count=presentation.find('.slide').length;
let current_slide=presentation.find('.slide.current');
let current_slide_num=current_slide.data('num');
let next_slide;
if(1<=(current_slide_num-1)){
next_slide=presentation.find('.slide[data-num="'+(current_slide_num-1)+'"]');
next_slide.addClass('current');
current_slide.removeClass('current');
}
else{
next_slide=presentation.find('.slide[data-num="'+slide_count+'"]');
next_slide.addClass('current');
current_slide.removeClass('current');
}
current_slide_num=next_slide.data('num');
presentation.find('.slide-counter').html(current_slide_num+' / '+slide_count);
let progress=Math.floor(100*current_slide_num/slide_count);
progress=Math.min(progress,100);
progress=Math.max(progress,0);
presentation.find('.progress .fill-level').css('width',progress+'%');
start_presentation_slider_time=0;
}
}
function app_keyboard(e){
if(!e)e=window.event;
var key=(e.charCode)?e.charCode:((e.keyCode)?e.keyCode:((e.which)?e.which:0));
if($(document.activeElement).closest('.presentation')){
if(key==37){//left arrow
e.preventDefault();
$('.presentation').find('.prev-action')[0].click();
}
if(key==39){//right arrow
e.preventDefault();
$('.presentation').find('.next-action')[0].click();
}
}
if(key==27){//esc
$('.presentation').removeClass('fullscreen');
$('.presentation .toggle-fullscreen-action').html(lang_arr[selected_lang]['expand']);
e.preventDefault();
}
}
var start_presentation_slider=false;
var presentation_timeout=5000;
var start_presentation_slider_timeout=10;
var start_presentation_slider_timer=0;
var start_presentation_slider_time=0;
function start_presentation_slider(){
if(!document.hasFocus()){
clearTimeout(start_presentation_slider_timer);
start_presentation_slider_timer=setTimeout(function(){start_presentation_slider()},start_presentation_slider_timeout*10);
return;
}
start_presentation_slider_time+=start_presentation_slider_timeout;
let presentation=$('.presentation');
let progress=Math.floor(1.1*1000*(start_presentation_slider_time)/presentation_timeout);//+10% end lag
progress=Math.min(progress,1100);
progress=Math.max(progress,0);
if(progress<=50.){
presentation.find('.slider .fill-level').css('display','none');
}
else{
presentation.find('.slider .fill-level').css('display','block');
}
presentation.find('.slider .fill-level').css('width',progress/10+'%');
console.log(progress);
if(progress==1100){
let slide_count=presentation.find('.slide').length;
let current_slide=presentation.find('.slide.current');
let end=false;
if(typeof current_slide.data('end') !== 'undefined'){
if(current_slide.data('end')){
end=true;
}
}
if(!end){
$('.presentation').find('.next-action')[0].click();
clearTimeout(start_presentation_slider_timer);
start_presentation_slider_timer=setTimeout(function(){start_presentation_slider()},start_presentation_slider_timeout);
}
else{
start_presentation_slider=false;
clearTimeout(start_presentation_slider_timer);
}
}
else{
clearTimeout(start_presentation_slider_timer);
start_presentation_slider_timer=setTimeout(function(){start_presentation_slider()},start_presentation_slider_timeout);
}
}
var hide_player_timeout=2000;
var hide_player_timer=0;
function hide_player(){
let presentation=$('.presentation');
presentation.find('.player').removeClass('hover');
if(start_presentation_slider){
clearTimeout(start_presentation_slider_timer);
start_presentation_slider_timer=setTimeout(function(){start_presentation_slider()},start_presentation_slider_timeout);
}
}
$(document).ready(function(){
document.addEventListener('click', app_mouse, false);
document.addEventListener('tap', app_mouse, false);
document.addEventListener('keyup',app_keyboard,false);
let presentation=$('.presentation');
presentation.find('.toggle-fullscreen-action').html(lang_arr[selected_lang]['expand']);
presentation.find('.next-action').prop('title',lang_arr[selected_lang]['next_slide']);
presentation.find('.prev-action').prop('title',lang_arr[selected_lang]['prev_slide']);
let slide_count=presentation.find('.slide').length;
let current_slide=presentation.find('.slide.current');
let current_slide_num=current_slide.data('num');
presentation.find('.slide-counter').html(current_slide_num+' / '+slide_count);
let progress=Math.floor(100*current_slide_num/slide_count);
progress=Math.min(progress,100);
progress=Math.max(progress,0);
presentation.find('.progress .fill-level').css('width',progress+'%');
presentation.on('mouseover',function(){
$(this).find('.player').addClass('hover');
clearTimeout(hide_player_timer);
hide_player_timer=setTimeout(function(){hide_player()},hide_player_timeout);
if(start_presentation_slider){
clearTimeout(start_presentation_slider_timer);
}
});
presentation.on('mouseout',function(){
clearTimeout(hide_player_timer);
$(this).find('.player').removeClass('hover');
if(start_presentation_slider){
clearTimeout(start_presentation_slider_timer);
start_presentation_slider_timer=setTimeout(function(){start_presentation_slider()},start_presentation_slider_timeout);
}
});
//presentation[0].dispatchEvent(new MouseEvent('mouseover',{'view': window,'bubbles': true,'cancelable':true}));
if(current_slide.data('start')){
start_presentation_slider=true;
if(typeof current_slide.data('timeout') !== 'undefined'){
if(!isNaN(current_slide.data('timeout'))){
presentation_timeout=parseInt(current_slide.data('timeout'));
}
}
start_presentation_slider_time=0;
start_presentation_slider();
}
$(window).on('scroll',function(){
});
$(window).on('resize',function(){
});
});