PageSourceSearch

https://www.renfrewshiregolfunion.co.uk/layouts/terraces_golfnz/js/libs/jquery-bg-video.js

js renfrewshiregolfunion.co.uk collected 2026-09-27 15:22:14 UTC 9,837 bytes, 266 lines download raw bytes

vendor: 9,837 bytes, lines 1-266
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        var iOS = /iPad|iPhone|iPod/.test(navigator.platform) || /iPad|iPhone|iPod/.test(navigator.userAgent);
43
44        // Settings
45        var settings = $.extend({}, $.fn.bgVideo.defaults, options);
46
47        // Do the things
48        return this.each(function () {
49
50            // Set some handy variables
51            var $video = $(this); // jQuery Object
52            var video = $video[0]; // DOM node
53            var poster = $video.attr('poster') || '';
54            var $container = $video.parent();
55            var $pauseplay = $('<button class="jquery-background-video-pauseplay pause" style="display: none;"><span>Pause</span></button>');
56            var start_time; // We'll set this when it starts playing
57
58
59            // Check for any data attributes that will override the settings for this particular element
60            var el_settings = $.extend({}, settings);
61            var data_attrs = $video.data();
62            $.each(data_attrs, function (data_name, data_val) {
63                if (data_name.indexOf('bgvideo') === 0) {
64                    // It's a match! Strip the bgvideo prefix and lowercase the first letter
65                    data_name = data_name.replace('bgvideo', '');
66                    data_name = data_name.charAt(0).toLowerCase() + data_name.slice(1);
67                    // Then set the setting
68                    el_settings[data_name] = data_val;
69                }
70            });
71
72
73            // Attach to playing event
74            $video.on('playing', function () {
75                if (start_time == null) {
76                    start_time = currentTime();
77                }
78                //$video.addClass('is-playing is-visible');
79                var addClasses = function () {
80                    $video.addClass('is-playing is-visible');
81                };
82                setTimeout(addClasses, 500);
83                $pauseplay.removeClass('play').addClass('pause').find('span').text('Pause');
84                $.fn.bgVideo.fitVideo($video);
85            });
86
87
88            // If the video is already playing before js loads
89            if (video.currentTime > 0) {
90                
91                var addClasses = function () {
92                    $video.addClass('is-playing is-visible');
93                };
94                setTimeout(addClasses, 500);
95            }
96
97
98            // Attach to pause event
99            $video.on('pause', function () {
100                $video.removeClass('is-playing');
101                $pauseplay.removeClass('pause').addClass('play').find('span').text('Play');
102                if (el_settings.fadeOnPause) {
103                    $video.removeClass('is-visible');
104                }
105            });
106
107
108            // Set default styles
109            $container.css({
110                'position': 'absolute',
111                'overflow': 'hidden',
112                'background-size': 'cover',
113                'background-position': 'center center',
114                'background-repeat': 'no-repeat',
115                'background-image': 'url(' + poster + ')'
116            });
117            $video.css({
118                'min-width': 'auto',
119                'min-height': 'auto',
120                'width': '100%',
121                'height': 'auto',
122                'position': 'absolute',
123                'left': '50%',
124                'top': '50%',
125                'transform': 'translate(-50%,-50%)'
126            });
127            if (el_settings.fullScreen) {
128                $container.css({
129                    'position': 'fixed',
130                    'top': '0',
131                    'bottom': '0',
132                    'left': '0',
133                    'right': '0',
134                    'height': 'auto',
135                    'margin': '0',
136                    'z-index': '-1'
137                });
138            }
139
140
141            // Fade in video by setting the transition duration
142            $video.css('transition-duration', el_settings.fadeIn + 'ms');
143
144
145            // Remove on iOS
146            // if (iOS) {
147            //     // Unset sources to prevent them from continuing to download
148            //     $video.attr('src', '');
149            //     $video.find('source').attr('src', '');
150            //     $video.remove();
151            // }
152
153
154            // Mimic background-size: cover with video element
155            $.fn.bgVideo.fitVideo($video);
156            $(window).resize(function () {
157                $.fn.bgVideo.fitVideo($video);
158            });
159
160
161            // Pause after X seconds
162            el_settings.pauseAfter = parseInt(el_settings.pauseAfter, 10);
163            if (el_settings.pauseAfter > 0) {
164                $video.on('timeupdate', function () {
165                    var now = currentTime();
166                    if (now > start_time + el_settings.pauseAfter) {
167                        video.pause();
168                        if (el_settings.fadeOnEnd) {
169                            $video.removeClass('is-visible');
170                        }
171                    }
172                });
173            }
174
175
176            // Play / pause button
177            if (el_settings.showPausePlay && !iOS) {
178                // Append pauseplay element created earlier
179                $container.append($pauseplay);
180                // Position element
181                $pauseplay.css({
182                    'left': 'auto',
183                    'right': 'auto',
184                    'top': 'auto',
185                    'bottom': 'auto'
186                });
187                $pauseplay.css(el_settings.pausePlayXPos, el_settings.pausePlayXOffset);
188                $pauseplay.css(el_settings.pausePlayYPos, el_settings.pausePlayYOffset);
189                if (el_settings.pausePlayXPos === 'center') {
190                    $pauseplay.css({
191                        'left': '50%',
192                        'margin-left': '-10px'
193                    });
194                }
195                if (el_settings.pausePlayYPos === 'center') {
196                    $pauseplay.css({
197                        'top': '50%',
198                        'margin-top': '-10px'
199                    });
200                }
201                // Add functionality
202                $pauseplay.on('click', function () {
203                    if (video.paused) {
204                        video.play();
205                        start_time = currentTime();
206                    } else {
207                        video.pause();
208                    }
209                });
210            }
211
212
213        });
214
215
216    };
217
218
219    // Default settings
220    $.fn.bgVideo.defaults = {
221        fullScreen: false, // Sets the video to be fixed to the full window
222        fadeIn: 500, // Milliseconds to fade video in/out (0 for no fade)
223        pauseAfter: 120, // Seconds to play before pausing (0 for forever)
224        fadeOnPause: false, // For all (including manual) pauses
225        fadeOnEnd: true, // When we've reached the pauseAfter time
226        showPausePlay: true, // Show pause/play button
227        pausePlayXPos: 'right', // left|right|center
228        pausePlayYPos: 'top', // top|bottom|center
229        pausePlayXOffset: '15px', // pixels or percent from side - ignored if positioned center
230        pausePlayYOffset: '15px' // pixels or percent from top/bottom - ignored if positioned center
231    };
232
233
234    // Fit video
235    $.fn.bgVideo.fitVideo = function ($video) {
236
237        var $container = $video.parent(),
238            container_height = $container.outerHeight(),
239            container_width = $container.outerWidth();
240
241        // Do this again every time the screen size changes
242        $video.css({
243            'height': 'auto',
244            'width': container_width + 'px'
245        });
246
247        var video_height = $video.height();
248
249        if (container_height > video_height) {
250            //console.log('Container height > video height');
251            $video.css({
252                'height': container_height + 'px',
253                'width': 'auto'
254            });
255        }
256
257    };
258
259
260    // Auto run based on data attributes
261    $(document).ready(function () {
262        $('[data-bgvideo]').bgVideo();
263    });
264
265
266}(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.