-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
75 lines (62 loc) · 2 KB
/
script.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
;(function(){
if (window.jQuery) {
// jQuery version
$(document).ready(function(){
// Add a 'js' class to the html tag
// If you're using modernizr or similar, you
// won't need to do this
$('html').addClass('js');
// Fade in videos
var $fade_in_videos = $('.video-bg video');
$fade_in_videos.each(function(){
if( $(this)[0].currentTime > 0 ) {
// It's already started playing
$(this).addClass('is-playing');
} else {
// It hasn't started yet, wait for the playing event
$(this).on('playing', function(){
$(this).addClass('is-playing');
});
}
});
// Scrap videos on iOS because it won't autoplay,
// it adds it's own play icon and opens the
// media player when clicked
var iOS = /iPad|iPhone|iPod/.test(navigator.platform) || /iPad|iPhone|iPod/.test(navigator.userAgent);
if( iOS ) {
$('.video-bg video').remove();
}
});
} else {
// Vanilla JS version
// Add a 'js' class to the html tag
// If you're using modernizr or similar, you
// won't need to do this
document.documentElement.className += " js";
// Fade in videos
var fade_in_videos = document.querySelectorAll('.video-bg video');
for( i=0; i<fade_in_videos.length; i++ ) {
if( fade_in_videos[i].currentTime > 0 ) {
// It's already started playing
fade_in_videos[i].className += ' is-playing';
} else {
// It hasn't started yet, wait for the playing event
fade_in_videos[i].addEventListener("playing", function(){
if(this.className.indexOf('is-playing') < 0) {
this.className += ' is-playing';
}
});
}
}
// Scrap videos on iOS because it won't autoplay,
// it adds it's own play icon and opens the
// media player when clicked
var iOS = /iPad|iPhone|iPod/.test(navigator.platform);
if( iOS ) {
var background_videos = document.querySelectorAll('.video-bg video');
for( i=0; i<background_videos.length; i++ ) {
background_videos[i].parentNode.removeChild(background_videos[i]);
}
}
}
})();