PageSourceSearch

https://hsgct.org/wp-content/themes/hsg/js/jquery-background-video…/jquery.background-video.js?ver=1.0.19

js hsgct.org collected 2026-10-02 10:34:58 UTC 7,581 bytes, 270 lines download raw bytes

vendor: 7,581 bytes, lines 1-270
1// The MIT License (MIT)
2
3// Copyright (c) 2015 BG Stock - html5backgroundvideos.com
4
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23(function($) {
24
25	// Add js class to html
26	$('html').addClass('js');
27
28	// Add IE8 shim for Date.now()
29	if (!Date.now) {
30		Date.now = function() { return new Date().getTime(); }
31	}
32
33	// Return current time in seconds
34	function currentTime() {
35		return Math.floor(Date.now() / 1000);
36	}
37
38	// The plugin
39	$.fn.bgVideo = function( options ) {
40
41		// @bool iOS
42		function iOSversion() {
43			if (/iP(hone|od|ad)/.test(navigator.platform)) {
44				var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
45				return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
46			}
47		}
48
49		var iOSVersion = iOSversion();
50		var old_iOS = false;
51
52		if (iOSVersion && (iOSVersion[0] < 10)){
53			old_iOS = true;
54		}
55
56		// Settings
57		var settings = $.extend({}, $.fn.bgVideo.defaults, options );
58
59		// Do the things
60		return this.each(function() {
61
62			// Set some handy variables
63			var $video = $(this); // jQuery Object
64			var video = $video[0]; // DOM node
65			var poster = $video.attr('poster') || '';
66			var $container = $video.parent();
67			var $pauseplay = $('<button class="jquery-background-video-pauseplay pause"><span>Pause</span></button>');
68			var start_time; // We'll set this when it starts playing
69
70
71			// Check for any data attributes that will override the settings for this particular element
72			var el_settings = $.extend({}, settings);
73			var data_attrs = $video.data();
74			$.each( data_attrs, function( data_name, data_val ) {
75				if( data_name.indexOf('bgvideo') === 0 ) {
76					// It's a match! Strip the bgvideo prefix and lowercase the first letter
77					data_name = data_name.replace('bgvideo', '');
78					data_name = data_name.charAt(0).toLowerCase() + data_name.slice(1);
79					// Then set the setting
80					el_settings[data_name] = data_val;
81				}
82			});
83
84
85			// Attach to playing event
86			$video.on('playing', function(){
87				if(start_time == null){
88					start_time = currentTime();
89				}
90				$video.addClass('is-playing is-visible');
91				$pauseplay.removeClass('play').addClass('pause').find('span').text('Pause');
92				$.fn.bgVideo.fitVideo( $video );
93			});
94
95
96			// If the video is already playing before js loads
97			if( video.currentTime > 0 ) {
98				$video.addClass('is-playing is-visible');
99			}
100
101
102			// Attach to pause event
103			$video.on('pause', function(){
104				$video.removeClass('is-playing');
105				$pauseplay.removeClass('pause').addClass('play').find('span').text('Play');
106				if(el_settings.fadeOnPause) {
107					$video.removeClass('is-visible');
108				}
109			});
110
111
112			// Set default styles
113			$container.css({
114				'position': 'relative',
115				'overflow': 'hidden',
116				'background-size': 'cover',
117				'background-position': 'center center',
118				'background-repeat': 'no-repeat',
119				'background-image': 'url(' + poster + ')'
120			});
121			$video.css({
122				'min-width': 'auto',
123				'min-height': 'auto',
124				'width': '100%',
125				'height': 'auto',
126				'position': 'absolute',
127				'left': '50%',
128				'top': '50%',
129				'transform': 'translate(-50%,-50%)'
130			});
131			if( el_settings.fullScreen ) {
132				$container.css({
133					'position': 'fixed',
134					'top': '0',
135					'bottom': '0',
136					'left': '0',
137					'right': '0',
138					'height': 'auto',
139					'margin': '0',
140					'z-index': '-1'
141				});
142			}
143
144
145			// Fade in video by setting the transition duration
146			$video.css('transition-duration', el_settings.fadeIn + 'ms');
147
148
149			// Remove on iOS
150			if( old_iOS ) {
151				// Unset sources to prevent them from continuing to download
152				$video.attr('src', '');
153				$video.find('source').attr('src', '');
154				$video.remove();
155			}
156
157
158			// Mimic background-size: cover with video element
159			$.fn.bgVideo.fitVideo( $video );
160			$(window).resize(function(){
161				$.fn.bgVideo.fitVideo( $video );
162			});
163
164
165			// Pause after X seconds
166			el_settings.pauseAfter = parseInt( el_settings.pauseAfter, 10 );
167			if( el_settings.pauseAfter > 0 ) {
168				$video.on('timeupdate', function(){
169					var now = currentTime();
170					if( now > start_time + el_settings.pauseAfter ) {
171						video.pause();
172						if( el_settings.fadeOnEnd ) {
173							$video.removeClass('is-visible');
174						}
175					}
176				});
177			}
178
179
180			// Play / pause button
181			if( el_settings.showPausePlay && !old_iOS ) {
182				// Append pauseplay element created earlier
183				$container.append($pauseplay);
184				// Position element
185				$pauseplay.css({
186					'left':   'auto',
187					'right':  'auto',
188					'top':    'auto',
189					'bottom': 'auto'
190				});
191				$pauseplay.css(el_settings.pausePlayXPos, el_settings.pausePlayXOffset);
192				$pauseplay.css(el_settings.pausePlayYPos, el_settings.pausePlayYOffset);
193				if( el_settings.pausePlayXPos === 'center' ) {
194					$pauseplay.css({
195						'left':        '50%',
196						'margin-left': '-10px'
197					});
198				}
199				if( el_settings.pausePlayYPos === 'center' ) {
200					$pauseplay.css({
201						'top':        '50%',
202						'margin-top': '-10px'
203					});
204				}
205				// Add functionality
206				$pauseplay.on('click', function(){
207					if(video.paused) {
208						video.play();
209						start_time = currentTime();
210					} else {
211						video.pause();
212					}
213				});
214			}
215
216
217		});
218
219
220	};
221
222
223	// Default settings
224	$.fn.bgVideo.defaults = {
225		fullScreen: false, // Sets the video to be fixed to the full window
226		fadeIn: 500, // Milliseconds to fade video in/out (0 for no fade)
227		pauseAfter: 120, // Seconds to play before pausing (0 for forever)
228		fadeOnPause: false, // For all (including manual) pauses
229		fadeOnEnd: true, // When we've reached the pauseAfter time
230		showPausePlay: true, // Show pause/play button
231		pausePlayXPos: 'right', // left|right|center
232		pausePlayYPos: 'top', // top|bottom|center
233		pausePlayXOffset: '15px', // pixels or percent from side - ignored if positioned center
234		pausePlayYOffset: '15px' // pixels or percent from top/bottom - ignored if positioned center
235	};
236
237
238	// Fit video
239	$.fn.bgVideo.fitVideo = function( $video ) {
240
241		var $container = $video.parent(),
242			container_height = $container.outerHeight(),
243			container_width = $container.outerWidth();
244
245		// Do this again every time the screen size changes
246		$video.css({
247			'height': 'auto',
248			'width': container_width + 'px'
249		});
250
251		var video_height = $video.height();
252
253		if( container_height > video_height ) {
254			//console.log('Container height > video height');
255			$video.css({
256				'height': container_height + 'px',
257				'width': 'auto'
258			});
259		}
260
261	};
262
263
264	// Auto run based on data attributes
265	$(document).ready(function(){
266		$('[data-bgvideo]').bgVideo();
267	});
268
269
270}(jQuery));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.