-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16.js
More file actions
2669 lines (2351 loc) · 93.1 KB
/
Copy path16.js
File metadata and controls
2669 lines (2351 loc) · 93.1 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
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* video.js v0.4.3 - 18/06/07
* JavaScript Videoplayer - by Arne Westphal
* eLearning Buero MIN-Fakultaet - Universitaet Hamburg
*/
var eLearnVideoJS = eLearnVideoJS || {};
eLearnVideoJS.localization = {
"de": {
"play": "Abspielen",
"pause": "Pausieren",
"mute": "Stummschalten",
"time": "Zeit",
"timeleft": "Verbleibende Zeit",
"duration": "Dauer",
"fullscreen": "Vollbild",
"annotations": "Annotationen",
"usernotes": "Notizen",
"notehint": "Notiz anzeigen",
"notesave": "Notiz speichern",
"notecancel": "Abbrechen",
"noteadd": "Notiz hinzufügen",
"displayall": "Alle einblenden",
"error": "Ein Fehler ist aufgetreten.<br>Das Video kann nicht abgespielt werden.<br>Klicken zum neu laden!",
"alert.notenotext": "Text eingeben, um Notiz speichern zu können.",
"alert.noteinvalidstart": "Die Startzeit ist keine gültige Eingabe.\r\nFormat: HH:MM:SS",
"alert.noteinvalidend": "Die Endzeit ist keine gültige Eingabe.\r\nFormat: HH:MM:SS",
"alert.importreset": "Aktuelle Notizen können vor dem Import gelöscht und somit durch neue Notizen ersetzt werden.\r\n'OK' zum Ersetzen, 'Abbrechen' zum Hinzufügen.",
"alert.importsuccess": "Notizen erfolgreich importiert.",
"alert.importerror": "Die Datei scheint nicht zum import geeignet zu sein.",
"alert.nonotes": "Keine Notizen vorhanden.",
"alert.localstorageerror": "Die letzte Notizänderung konnte nicht gespeichert werden, da der lokale Speicher voll ist.",
"alert.remove": "Soll diese Notiz wirklich dauerhaft gelöscht werden?",
"alert.removeall": "Sollen wirklich alle Notizen dieses Videos dauerhaft gelöscht werden?",
"dropdown.import": "Notizen importieren",
"dropdown.export": "Notizen exportieren als JSON",
"dropdown.exportcsv": "Notizen exportieren als CSV",
"dropdown.removeall": "Alle Notizen löschen",
"dropdown.edit": "Bearbeiten",
"dropdown.remove": "Löschen",
"dropdown.moveup": "Nach oben bewegen",
"dropdown.movedown": "Nach unten bewegen",
"placeholder.start": "Start",
"placeholder.end": "Ende",
"placeholder.writenote": "Schreibe eine Notiz... (diese sind lokal gespeichert und nicht öffentlich)",
},
"en": {
"play": "Play",
"pause": "Pause",
"mute": "Mute",
"time": "Time",
"timeleft": "Time left",
"duration": "Duration",
"fullscreen": "Fullscreen",
"annotations": "Annotations",
"usernotes": "Notes",
"notehint": "Display Note",
"notesave": "Save Note",
"notecancel": "Cancel",
"noteadd": "Add Note",
"displayall": "Display all",
"error": "An error occurred.<br>The video cannot be played.<br>Click to reload!",
"alert.notenotext": "Insert a text before saving a note.",
"alert.noteinvalidstart": "Start time is not valid.\r\nFormat: HH:MM:SS",
"alert.noteinvalidend": "End time is not valid.\r\nFormat: HH:MM:SS",
"alert.importreset": "You can delete current notes before importing others to replace them.\r\n'OK' to replace, 'Cancel' to keep both.",
"alert.importsuccess": "Notes imported successfully",
"alert.importerror": "The file seems to be invalid and cannot be imported.",
"alert.nonotes": "No notes existing.",
"alert.localstorageerror": "The last notes change could not be saved. The LocalStorage seems to be full.",
"alert.remove": "Really remove this note permanently?",
"alert.removeall": "Really remove all notes for this video permanently?",
"dropdown.import": "Import Notes",
"dropdown.export": "Export Notes as JSON",
"dropdown.exportcsv": "Export Notes as CSV",
"dropdown.removeall": "Remove all Notes",
"dropdown.edit": "Edit",
"dropdown.remove": "Remove",
"dropdown.moveup": "Move Up",
"dropdown.movedown": "Move Down",
"placeholder.start": "Start",
"placeholder.end": "End",
"placeholder.writenote": "Write a note... (notes are saved locally and are not public)",
},
};
eLearnVideoJS.selectedLocale = eLearnVideoJS.selectedLocale || "de";
/**
* Initialisiert die Videoplayer
*/
$(document).ready(function() {
eLearnVideoJS.initiateTouchDetection();
eLearnVideoJS.initiateVideoPlayers();
eLearnVideoJS.setLanguage(eLearnVideoJS.selectedLocale);
});
// ----------------------------------------------------------------------------
// ------------------------- VIDEO PLAYER -------------------------------------
// ----------------------------------------------------------------------------
eLearnVideoJS.video_hover_timers = {};
eLearnVideoJS.video_volumes = {};
eLearnVideoJS.video_timetypes = {
TIMELEFT: 0,
DURATION: 1
};
eLearnVideoJS.FILETYPE_JSON = 'json';
eLearnVideoJS.FILETYPE_CSV = 'csv';
eLearnVideoJS.video_timestyle = 0;
eLearnVideoJS.touchend_block = false;
eLearnVideoJS.touchend_timer = null;
eLearnVideoJS.user_notes = {};
/**
* Initiates all videoplayers, by adding wrapper around <video> elements.
* Also initiates all listeners and everything necessary, so that the players
* work correctly.
*/
eLearnVideoJS.initiateVideoPlayers = function() {
eLearnVideoJS.loadLocalVideoNotesStorage();
$('video').not('.ignore_elearnvideo').each(function(i, e) {
this.controls = false;
$(this).wrap('<div class="video-container">');
$(this).wrap("<div class='elearnjs-video hovered' tabindex='-1'>");
var div = $(this).parent();
div.append("<div class='mobile-overlay'><div class='icon playpause paused'></div></div>");
div.append("<div class='loading-overlay'><div class='loading-con'>"
+ "<div class='loading-animation'>"
+ "<div class='background'></div>"
+ "<div class='inner'><div class='light'></div></div>"
+ "<div class='inner skip'><div class='light'></div></div>"
+ "</div>"
+ "</div></div>");
if(this.autoplay) {
this.play();
}
else {
div.append("<div class='play-overlay'><div class='icon play'></div></div>");
}
div.append("<div class='controls'>"
+ "<div class='bottom-row'>"
+ "<div class='icon playpause playing'></div>"
+ "<div class='volume'>"
+ "<div class='icon high' lang-code-title='mute'></div>"
+ "<div class='volume-con'>"
+ "<div class='volume-wrap'>"
+ "<div class='volume-bar'></div>"
+ "<div class='volume-control'></div>"
+ "</div>"
+ "</div>"
+ "</div>"
+ "<div class='text playtime' lang-code-title='time'></div>"
+ "<div class='video-progress-con'>"
+ "<div class='video-progress'><div class='video-progress-loaded'></div><div class='video-progress-bar'></div></div>"
+ "<div class='video-progress-pointer'></div>"
+ "</div>"
+ "<div class='text timeleft'></div>"
+ "<div class='icon fullscreen' lang-code-title='fullscreen'></div>"
+ "</div>"
+ "</div>");
eLearnVideoJS.addVideoPlayerListener(div);
eLearnVideoJS.videoCheckForBrowserSpecifics(div);
eLearnVideoJS.updateVideoVolume(div);
});
eLearnVideoJS.addGenerelVideoPlayerListener();
// only fallback values, should work without this resizes,
// based on IntersectionObserver support
document.addEventListener("ejssectionchange", eLearnVideoJS.resizeAllVideoPlayers);
window.addEventListener("ejswindowresize", eLearnVideoJS.resizeAllVideoPlayers);
$(window).resize(eLearnVideoJS.resizeAllVideoPlayers);
// Used to explicitly set video-note width to equal video width
window.addEventListener("ejsvideotouchmousechange", eLearnVideoJS.switchTouchMouse);
eLearnVideoJS.initiateVideoNotes();
};
eLearnVideoJS.initListeners = function() {
$('.elearnjs-video').each(function(i, e) {
const el = $(e);
try {
var options = {
root: document.body,
rootMargin: '0px',
threshold: 1.0
}
var observer = new IntersectionObserver(function(entries, observer) {
for(var i = 0; i < entries.length; i++) {
var entry = entries[i];
eLearnVideoJS.resizeVideoPlayer($(entry.target));
}
}, options);
observer.observe(el.get(0));
} catch(e) {
// ignore
};
// resizesensor as visibility listener this will only work with Chrome engine browsers
try {
new ResizeSensor(el, function(dim) {
eLearnVideoJS.resizeVideoPlayer(el);
});
} catch(e) {
// ignore
};
});
};
/**
* Add general video player listeners. These are listeners which are not on the
* player itself but on the document.
*/
eLearnVideoJS.addGenerelVideoPlayerListener = function() {
// Fullscreenchange
$(document).bind('webkitfullscreenchange mozfullscreenchange fullscreenchange',
eLearnVideoJS.checkVideoFullscreen);
$(document).on('mouseup touchend', eLearnVideoJS.onMouseUp);
};
/**
* Adds all video player specific listeners. So every listener which is appended
* on a single video element or the wrapper of it.
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.addVideoPlayerListener = function(div) {
eLearnVideoJS.videoAddButtonListeners(div);
eLearnVideoJS.videoAddUserInteractionListeners(div);
eLearnVideoJS.videoAddProgressBarListeners(div);
eLearnVideoJS.videoAddVolumeListeners(div);
eLearnVideoJS.videoAddEventListeners(div);
// fullscreen listeners
div.on('webkitfullscreenchange mozfullscreenchange fullscreenchange', function(event) {
eLearnVideoJS.checkVideoFullscreen();
});
div.find('video').on('webkitfullscreenchange mozfullscreenchange fullscreenchange', function(event) {
eLearnVideoJS.checkVideoFullscreen();
});
// stop propagation at div in fullscreen, event not triggert in any parent
div.on('blur change click contextmenu copy cut dblclick error foxus focusin focusout '
+ 'keydown keypress keyup load mousedown mouseenter mouseleave mousemove '
+ 'mouseout mouseover mouseup mousewheel paste reset resize scroll '
+ 'select submit textinput unload wheel '
+ 'orientationchange pointerdown pointermove pointerup '
+ 'touchstart touchmove touchend ', function(e) {
if(div.is('.full')) {
e.stopPropagation();
}
});
};
/**
* Adds listeners to buttons within the video player.
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoAddButtonListeners = function(div) {
// buttons
div.find('.playpause').click(function(event) {
event.preventDefault();
event.stopPropagation();
eLearnVideoJS.videoTogglePlay(div);
eLearnVideoJS.videoHover(div);
});
div.find('.volume').find('.icon').on('mouseup touchend', function(event) {
eLearnVideoJS.videoVolumeClick(div, event);
});
div.find('.volume').on('mouseenter', function(event) {
eLearnVideoJS.videoVolumeHover(div, event);
});
div.find('.volume').on('mouseleave', function(event) {
eLearnVideoJS.videoVolumeHover(div, event);
});
div.find('.timeleft').click(function(event) {
event.preventDefault();
event.stopPropagation();
eLearnVideoJS.videoToggleTimeleftDuration();
});
div.find('.fullscreen').click(function(event) {
event.preventDefault();
event.stopPropagation();
eLearnVideoJS.videoToggleFullscreen(div);
});
};
/**
* Adds listeners to other player interaction. E.g. clicks on the video
* or touch events which are not targeted at a button.
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoAddUserInteractionListeners = function(div) {
div.on('touchstart touchend touchcancel', function(event) {
eLearnVideoJS.videoRefreshHover(div, event);
});
// overlay
div.find('.play-overlay').on('click', function(event) {
event.preventDefault();
event.stopPropagation();
eLearnVideoJS.videoTogglePlay(div);
eLearnVideoJS.videoHover(div);
div.find('.play-overlay').remove();
});
// general player
div.on('mousemove', function(event) {
if(!div.is('.mobile')) {
eLearnVideoJS.videoHover(div);
}
});
div.on('mouseup touchend', eLearnVideoJS.onMouseUp);
div.on('mouseup touchend', function(event) {
if(event.type === "touchend" || event.button == 0) {
// other listeneres take care of these
if(eLearnVideoJS.videoProgressMouseDown || eLearnVideoJS.videoVolumeMouseDown
|| $(event.target).is('.bottom-row') || $(event.target).is('.bottom-row *')
|| $(event.target).is('.play-overlay') || $(event.target).is('.play-overlay *')
|| $(event.target).is('.mobile-overlay .playpause')
|| $(event.target).is('.error-con') || $(event.target).is('.error-con *')) {
return true;
}
// touch
if(event.type === "touchend") {
// keine clicks durch 2. mouse event auf eingeblendete Elemente
setTimeout(function() { eLearnVideoJS.videoToggleHover(div) }, 50);
eLearnVideoJS.touchend_block = true;
clearTimeout(eLearnVideoJS.touchend_timer);
eLearnVideoJS.touchend_timer = setTimeout(function() { eLearnVideoJS.touchend_block = false; }, 100);
}
// no touch
else if(!eLearnVideoJS.touchend_block) {
eLearnVideoJS.videoOnClick(div);
}
}
});
div.on('mouseleave', function(event) {
if(!div.is('.mobile')) {
eLearnVideoJS.videoHoverEnd(div);
}
});
div.bind('keydown', function(event) {
eLearnVideoJS.videoKeyDown(div, event);
});
};
/**
* Adds listeners to the progress bar. E.g. for time skipping and hover events.
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoAddProgressBarListeners = function(div) {
// progressbar
div.find('.video-progress-con').on('mouseenter', function(event) {
event.preventDefault();
event.stopPropagation();
eLearnVideoJS.videoProgressMouseEnter(div, event);
});
div.find('.video-progress-con').on('mouseleave', function(event) {
event.preventDefault();
event.stopPropagation();
eLearnVideoJS.videoProgressMouseLeave(div, event);
});
div.on('mousemove touchmove', function(event) {
eLearnVideoJS.videoProgressMouseMove(div, event);
});
div.find('.video-progress-con').on('mousedown touchstart', function(event) {
event.preventDefault();
event.stopPropagation();
eLearnVideoJS.setVideoMouseDown(div, true);
eLearnVideoJS.videoProgressMouseMove(div, event);
if(event.type === "touchstart") div.append('<div class="progress-hover-time"></div>');
});
};
/**
* Adds listeners to the volume bar. For volume changes.
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoAddVolumeListeners = function(div) {
// listener for video volume control
div.on('mousemove touchmove', function(event) {
if(eLearnVideoJS.videoVolumeMouseDown && eLearnVideoJS.videoVolumeMouseDownTarget != null) {
event.preventDefault();
event.stopPropagation();
eLearnVideoJS.videoProgressVolumeMouseMove(div, event);
}
});
div.find('.volume-con').on('mousedown touchstart', function(event) {
eLearnVideoJS.setVideoVolumeMouseDown(div, true, event);
});
};
/**
* Adds all events based on the exact video element. E.g. timeupdate/playpause
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoAddEventListeners = function(div) {
var video = div.find('video');
// listener to video progress
video.on('ended', function(event) {
eLearnVideoJS.videoHover(div);
});
video.on('timeupdate progress', function(event) {
eLearnVideoJS.updateVideoTime(div);
eLearnVideoJS.updateVideoUserNoteTime(div);
});
video.on('play', function(event) {
eLearnVideoJS.videoUpdatePlayPauseButton(div);
});
video.on('pause', function(event) {
eLearnVideoJS.videoUpdatePlayPauseButton(div);
});
video.on('volumechange', function(event) {
eLearnVideoJS.updateVideoVolume(div);
});
video.on('error abort', function(event) {
eLearnVideoJS.videoOnError(div, event);
});
video.on('canplay', function(event) {
eLearnVideoJS.videoRemoveError(div, event);
eLearnVideoJS.videoRemoveBuffering(div);
});
video.on('waiting', function(event) {
eLearnVideoJS.videoOnBuffering(div, event);
});
video.on('resize', function(event) {
eLearnVideoJS.resizeVideoPlayer(div);
});
eLearnVideoJS.videoCheckDelayedError(div);
};
eLearnVideoJS.onMouseUp = function(event) {
if(eLearnVideoJS.videoVolumeMouseDownTarget != null) {
event.preventDefault();
event.stopImmediatePropagation();
eLearnVideoJS.setVideoVolumeMouseDown(eLearnVideoJS.videoVolumeMouseDownTarget, false, event);
return false;
}
else if((event.type === "touchend" || event.button == 0) && eLearnVideoJS.videoProgressMouseDown) {
if(eLearnVideoJS.videoProgressMouseDownTarget != null) {
event.preventDefault();
event.stopImmediatePropagation();
if(!eLearnVideoJS.videoOverProgress) eLearnVideoJS.videoProgressMouseDownTarget.find('.progress-hover-time').remove();
eLearnVideoJS.setVideoMouseDown(eLearnVideoJS.videoProgressMouseDownTarget, false);
}
return false;
}
else {
return true;
}
};
/**
* Sets the language for all elements.
*/
eLearnVideoJS.setLanguage = function(langCode) {
langCode = langCode.toLowerCase();
if(eLearnVideoJS.localization[langCode] !== undefined) {
eLearnVideoJS.selectedLocale = langCode;
$('[lang-code],[lang-code-title],[lang-code-tab],[lang-code-placeholder]').each(function(i, e) {
eLearnVideoJS.localizeElement($(e));
});
// additional updates
eLearnVideoJS.resizeAllVideoPlayers();
eLearnVideoJS.videoUpdateTimeleftDuration();
$('.elearnjs-video').each(function(i, e) {
eLearnVideoJS.videoUpdatePlayPauseButton($(e));
eLearnVideoJS.updateVideoUserNoteTime($(e));
})
}
else {
throw "Unsupported language selected. Supported language codes are: " + Object.keys(eLearnVideoJS.localization).toString();
}
};
eLearnVideoJS.selectLanguage = eLearnVideoJS.setLanguage;
/**
* Localizes one specific element to match the selected language.
* The selected language is the eLearnVideoJS.selectedLocale if not specific
* `lang` attribute is present in the HTML element
*/
eLearnVideoJS.localizeElement = function(el, force) {
if($(el).attr('localized') === "false" && !force) return;
var loc = eLearnVideoJS.selectedLocale;
if(el.closest('[lang]').length) {
var lang = el.closest('[lang]').attr('lang').toLowerCase();
if(eLearnVideoJS.localization[lang]) loc = lang;
}
if(el.attr("lang-code")) {
var text = eLearnVideoJS.localization[loc][el.attr("lang-code")];
if(text) {
if($(el).attr('localized') === "html") el.html(text);
else el.text(text);
}
}
if(el.attr("lang-code-title")) {
var text = eLearnVideoJS.localization[loc][el.attr("lang-code-title")];
if(text) {
el.attr('title', text);
}
}
if(el.attr("lang-code-tab")) {
var text = eLearnVideoJS.localization[loc][el.attr("lang-code-tab")];
if(text) {
var index = el.parent().children().index(el);
var tabs = el.closest('.tabbed-container').children('.tabs').children('.tab-select');
tabs.eq(index).text(text);
}
}
if(el.attr("lang-code-placeholder")) {
var text = eLearnVideoJS.localization[loc][el.attr("lang-code-placeholder")];
if(text) {
el.attr('placeholder', text);
}
}
};
/**
* Localizes all children of an element.
* Will not localize the element itself.
*/
eLearnVideoJS.localizeChildren = function(el, force) {
el.find('[lang-code],[lang-code-title],[lang-code-tab]').each(function(i, e) {
eLearnVideoJS.localizeElement($(e), force);
});
};
eLearnVideoJS.getLocalizationFor = function(code) {
var loc = eLearnVideoJS.selectedLocale;
if($('html').attr('lang')
&& eLearnVideoJS.localization[$('html').attr('lang').toLowerCase()] !== undefined) {
loc = $('html').attr('lang').toLowerCase();
}
return eLearnVideoJS.localization[loc][code];
}
/**
* Checks for browser specific adjustments to the video player.
* E.G. mobile safari does not allow volume changes. These elements are hidden.
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoCheckForBrowserSpecifics = function(div) {
var device = "";
var ua = navigator.userAgent.toLowerCase();
if(/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
device = "ios";
}
if(device === "ios") {
// hide volume, because it doesn't work on iOs
div.find('.volume').hide()
}
};
// HOVER ---------------------------------------------------
/**
* Toggles the hover overlay of one specific video wrapper.
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoToggleHover = function(div) {
if(div.is('.hovered')) {
eLearnVideoJS.videoHoverEnd(div);
}
else {
eLearnVideoJS.videoHover(div);
}
};
/**
* Checks if the eLearnVideoJS.videoHover should be refreshed based on the given events target.
* Refreshes the hover if so.
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoRefreshHover = function(div, event) {
var trgt = $(event.target);
if(trgt.is('.mobile-overlay *') || trgt.is('.controls *')) {
eLearnVideoJS.videoHover(div);
}
};
/**
* Sets a video player hovered. Will show the controls overlay.
* Initiates a timeout for automatic hiding of the overlay after a hard coded
* time.
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoHover = function(div) {
if(!div.is(".hovered")) {
div.addClass("hovered");
}
var vid = div.find('video')[0];
var idx = $('.elearnjs-video').index(div);
if(eLearnVideoJS.video_hover_timers[idx] != undefined) clearTimeout(eLearnVideoJS.video_hover_timers[idx]);
if(!(vid.paused && div.is('.mobile'))) {
eLearnVideoJS.video_hover_timers[idx] = setTimeout(function() {
if(eLearnVideoJS.videoProgressMouseDown || eLearnVideoJS.videoVolumeMouseDown) {
eLearnVideoJS.videoHover(div);
}
else {
eLearnVideoJS.videoHoverEnd(div);
}
}, 2500);
}
};
/**
* Removes the hover overlay for a specific video player.
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoHoverEnd = function(div) {
var vid = div.find('video')[0];
if(!vid.ended) {
div.removeClass("hovered");
}
};
// FULLSCREEN -----------------------------------------------
/**
* Checks if the browser is in fullscreen mode. If not all video players are
* reset to normal display mode.
*/
eLearnVideoJS.checkVideoFullscreen = function() {
var isFullScreen = document.fullScreen ||
document.mozFullScreen ||
document.webkitIsFullScreen;
if(!isFullScreen) {
$('.elearnjs-video').removeClass("full");
}
};
// BUTTONS --------------------------------------------------
eLearnVideoJS.videoFullscreenPending = {};
/**
* Called when clicked on a video.
* This will pause or check for double click and set the video to fullscreen/back
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoOnClick = function(div) {
var dblclick_time = 250;
var idx = $('.elearnjs-video').index(div);
if(eLearnVideoJS.videoFullscreenPending[idx] == undefined
|| eLearnVideoJS.videoFullscreenPending[idx] === false) {
eLearnVideoJS.videoFullscreenPending[idx] = true;
// reset double click wait
setTimeout(function() {
// if still pending
if(eLearnVideoJS.videoFullscreenPending[idx] === true) {
eLearnVideoJS.videoTogglePlay(div);
eLearnVideoJS.videoFullscreenPending[idx] = false;
}
}, dblclick_time);
}
else if(eLearnVideoJS.videoFullscreenPending[idx] === true) {
// reset
eLearnVideoJS.videoFullscreenPending[idx] = false;
eLearnVideoJS.videoToggleFullscreen(div);
}
};
/**
* Toggles play for a video player. Updates the playpause button
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoTogglePlay = function(div) {
var vid = div.find('video')[0];
var btn = div.find('.playpause')[0];
if(vid.playbackRate === 0) {
vid.playbackRate = 1;
}
// paused now -> play
if(vid.paused || vid.ended) {
vid.play();
}
// pause
else {
vid.pause();
}
eLearnVideoJS.videoUpdatePlayPauseButton(div);
};
/**
* Updates the play/pause button based on the video play-status.
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoUpdatePlayPauseButton = function(div) {
var vid = div.find('video')[0];
// paused now -> play
if(vid.paused || vid.ended) {
div.find('.playpause').attr("title", eLearnVideoJS.getLocalizationFor("play"));
div.find('.playpause').removeClass("playing");
div.find('.playpause').addClass("paused");
}
// pause
else {
div.find('.playpause').attr("title", eLearnVideoJS.getLocalizationFor("pause"));
div.find('.playpause').addClass("playing");
div.find('.playpause').removeClass("paused");
}
};
/**
* Toggles between the display of timeleft (e.g. -0:12) and the videos duration
* (e.g. 0:28, static)
*/
eLearnVideoJS.videoToggleTimeleftDuration = function() {
eLearnVideoJS.video_timestyle = (eLearnVideoJS.video_timestyle + 1) % 2;
eLearnVideoJS.videoUpdateTimeleftDuration();
};
/**
* Toggles between the display of timeleft (e.g. -0:12) and the videos duration
* (e.g. 0:28, static)
*/
eLearnVideoJS.videoUpdateTimeleftDuration = function() {
var timeleft_field = $('.timeleft');
var title = "";
switch(eLearnVideoJS.video_timestyle) {
case eLearnVideoJS.video_timetypes.DURATION:
title = eLearnVideoJS.getLocalizationFor("duration"); break;
case eLearnVideoJS.video_timetypes.TIMELEFT:
title = eLearnVideoJS.getLocalizationFor("timeleft"); break;
}
timeleft_field.attr("title", title);
$('.elearnjs-video').each(function(i, e) {
eLearnVideoJS.updateVideoTime($(e));
});
};
/**
* Toggles fullscreen for a video player.
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoToggleFullscreen = function(div) {
// to fullscreen
if(!div.is(".full")) {
var elem = div[0];
if(elem.requestFullscreen) {
elem.requestFullscreen();
} else if(elem.msRequestFullscreen) {
elem.msRequestFullscreen();
} else if(elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if(elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
} else if(elem.webkitEnterFullscreen) {
elem.webkitEnterFullscreen();
} else {
elem = div.find('video')[0];
if(elem.requestFullscreen) {
elem.requestFullscreen();
} else if(elem.msRequestFullscreen) {
elem.msRequestFullscreen();
} else if(elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if(elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
} else if(elem.webkitEnterFullscreen) {
elem.webkitEnterFullscreen();
} else {
alert('No Fullscreen Support.')
return;
}
return;
}
div.addClass("full");
}
else {
if(document.exitFullscreen) {
document.exitFullscreen();
} else if(document.msExitFullscreen) {
document.msExitFullscreen();
} else if(document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if(document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
div.removeClass("full");
}
};
// VOLUME --------------------------------------------------
eLearnVideoJS.withinVolumeControl = false;
eLearnVideoJS.videoVolumePending = {};
eLearnVideoJS.videoVolumeMouseDown = false;
eLearnVideoJS.videoVolumeMouseDownTarget = null;
/**
* Called when clicked on the volume icon
* should open volume control on touch devices and mute/unmute otherwise
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoVolumeClick = function(div, e) {
var vid = div.find('video')[0];
var idx = $('.elearnjs-video').index(div);
if(e.type === "touchend") {
eLearnVideoJS.touchend_block = true;
clearTimeout(eLearnVideoJS.touchend_timer);
eLearnVideoJS.touchend_timer = setTimeout(function() { eLearnVideoJS.touchend_block = false; }, 100);
}
if(e.type === "touchend" || !eLearnVideoJS.touchend_block) {
if(div.is('.mobile')) {
eLearnVideoJS.videoSetVolumeControlOpen(div, !div.find('.volume').is('.controlopen'));
}
else if($(e.target).is('.icon') && !eLearnVideoJS.videoVolumeMouseDown) {
if(vid.volume > 0) {
eLearnVideoJS.video_volumes[idx] = vid.volume;
vid.volume = 0;
}
else if(eLearnVideoJS.video_volumes[idx] != undefined && eLearnVideoJS.video_volumes[idx] > 0) {
vid.volume = eLearnVideoJS.video_volumes[idx];
}
// should never happen
else {
vid.volume = 0.5;
}
}
}
};
/**
* Called when hovering over the volume icon
* shouldn't do anything on touch devices, because they have no hover
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoVolumeHover = function(div, event) {
if(!div.is('.mobile')) {
if(event.type === "mouseenter") {
eLearnVideoJS.withinVolumeControl = true;
eLearnVideoJS.videoSetVolumeControlOpen(div, true);
}
else if(event.type === "mouseleave") {
eLearnVideoJS.withinVolumeControl = false;
if(!eLearnVideoJS.videoVolumeMouseDown) {
eLearnVideoJS.videoSetVolumeControlOpen(div, false);
}
}
}
};
/**
* Opens or closes the Volume Control
* is called by eLearnVideoJS.videoVolumeHover, eLearnVideoJS.videoVolumeClick and eLearnVideoJS.setVideoVolumeMouseDown
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoSetVolumeControlOpen = function(div, bool) {
var idx = $('.elearnjs-video').index(div);
if(bool) {
var controls = div.find('.controls');
var volume = controls.find('.volume');
if(!volume.is('.controlopen')) {
clearTimeout(eLearnVideoJS.videoVolumePending[idx]);
volume.addClass('hovered');
volume[0].offsetHeight; // to force css change
volume.addClass('controlopen');
}
}
else {
var controls = div.find('.controls');
var volume = controls.find('.volume');
if(volume.is('.controlopen')) {
volume.removeClass('controlopen');
eLearnVideoJS.videoVolumePending[idx] = setTimeout(function() {
volume.removeClass('hovered');
}, 115); /* based on transition time, calculated by sizes */
}
}
};
/**
* Called when moving the mouse over any .elearnjs-video (@param: div)
* Used to apply volume changes
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.videoProgressVolumeMouseMove = function(div, e) {
if(eLearnVideoJS.videoVolumeMouseDown) {
e.preventDefault();
e.stopPropagation();
eLearnVideoJS.videoHover(div);
var vid = div.find('video')[0];
var volume = div.find('.volume');
var pos = 0;
if(e.type.toLowerCase() === "mousemove"
|| e.type.toLowerCase() === "mousedown") {
pos = e.originalEvent.pageY - volume.find('.volume-wrap').offset().top;
}
else if(e.type.toLowerCase() === "touchmove"
|| e.type.toLowerCase() === "touchstart") {
pos = e.originalEvent.touches[0].pageY - volume.find('.volume-wrap').offset().top;
}
var perc = pos / volume.find('.volume-wrap').height();
if(perc < 0) perc = 0;
if(perc > 1) perc = 1;
vid.volume = 1 - perc;
}
};
/**
* Used to set volume change active or not.
* @param div: the .elearnjs-video Wrapper of the video element.
* @param e: the event occured initiating this. (mousedown/touchstart...)
*/
eLearnVideoJS.setVideoVolumeMouseDown = function(div, bool, e) {
eLearnVideoJS.videoVolumeMouseDown = bool;
if(bool) {
eLearnVideoJS.videoVolumeMouseDownTarget = div;
// instant position calculation
eLearnVideoJS.videoProgressVolumeMouseMove(div, e);
}
else {
if(!eLearnVideoJS.withinVolumeControl && !div.is('.mobile')) {
eLearnVideoJS.videoSetVolumeControlOpen(div, false);
}
// add volume to last volume
var vid = div.find('video')[0];
if(vid.volume > 0) {
var idx = $('.elearnjs-video').index(div);
eLearnVideoJS.video_volumes[idx] = vid.volume;
}
eLearnVideoJS.videoVolumeMouseDownTarget = null;
}
};
/**
* Called when the video within the div has a volume change
* @param div: the .elearnjs-video Wrapper of the video element.
*/
eLearnVideoJS.updateVideoVolume = function(div) {
var vid = div.find('video')[0];
var btn = div.find('.volume').find('.icon');
var volume = div.find('.volume');
volume.find('.volume-control').css('top', (1 - vid.volume) * 100 + "%");
btn.removeClass("mute");
btn.removeClass("low");
btn.removeClass("medium");
btn.removeClass("high");
if(vid.volume == 0) {
btn.addClass("mute");
}
else if(vid.volume < 0.33) {
btn.addClass("low");
}
else if(vid.volume < 0.66) {
btn.addClass("medium");
}
else {
btn.addClass("high");
}
};
// VIDEO KEYBOARD EVENTS ------------------------------------
/**
* Processes a keydown event on a video player. The player needs to be target
* of the event so this is triggered. (e.g. Space to toggle play/pause)
* @param div: the .elearnjs-video Wrapper of the video element.
*/