PageSourceSearch

https://suncast.ca/wp-content/plugins/blueimp-lightbox/js/blueimp-gallery-vimeo.js?ver=1.0.0

js suncast.ca collected 2026-10-07 07:35:53 UTC 6,966 bytes, 215 lines download raw bytes

1/*
2 * blueimp Gallery Vimeo Video Factory JS 1.2.0
3 * https://github.com/blueimp/Gallery
4 *
5 * Copyright 2013, Sebastian Tschan
6 * https://blueimp.net
7 *
8 * Licensed under the MIT license:
9 * http://www.opensource.org/licenses/MIT
10 */
11
12/* global define, window, document, location, $f */
13
14(function (factory) {
15    'use strict';
16    if (typeof define === 'function' && define.amd) {
17        // Register as an anonymous AMD module:
18        define([
19            './blueimp-helper',
20            './blueimp-gallery-video'
21        ], factory);
22    } else {
23        // Browser globals:
24        factory(
25            window.blueimp.helper || window.jQuery,
26            window.blueimp.Gallery
27        );
28    }
29}(function ($, Gallery) {
30    'use strict';
31
32    if (!window.postMessage) {
33        return Gallery;
34    }
35
36    $.extend(Gallery.prototype.options, {
37        // The list object property (or data attribute) with the Vimeo video id:
38        vimeoVideoIdProperty: 'vimeo',
39        // The URL for the Vimeo video player, can be extended with custom parameters:
40        // https://developer.vimeo.com/player/embedding
41        vimeoPlayerUrl: '//player.vimeo.com/video/VIDEO_ID?api=1&player_id=PLAYER_ID',
42        // The prefix for the Vimeo video player ID:
43        vimeoPlayerIdPrefix: 'vimeo-player-',
44        // Require a click on the native Vimeo player for the initial playback:
45        vimeoClickToPlay: true
46    });
47
48    var textFactory = Gallery.prototype.textFactory || Gallery.prototype.imageFactory,
49        VimeoPlayer = function (url, videoId, playerId, clickToPlay) {
50            this.url = url;
51            this.videoId = videoId;
52            this.playerId = playerId;
53            this.clickToPlay = clickToPlay;
54            this.element = document.createElement('div');
55            this.listeners = {};
56        },
57        counter = 0;
58
59    $.extend(VimeoPlayer.prototype, {
60
61        canPlayType: function () {
62            return true;
63        },
64
65        on: function (type, func) {
66            this.listeners[type] = func;
67            return this;
68        },
69
70        loadAPI: function () {
71            var that = this,
72                apiUrl = '//' + (location.protocol === 'https' ? 'secure-' : '') +
73                    'a.vimeocdn.com/js/froogaloop2.min.js',
74                scriptTags = document.getElementsByTagName('script'),
75                i = scriptTags.length,
76                scriptTag,
77                called,
78                callback = function () {
79                    if (!called && that.playOnReady) {
80                        that.play();
81                    }
82                    called = true;
83                };
84            while (i) {
85                i -= 1;
86                if (scriptTags[i].src === apiUrl) {
87                    scriptTag = scriptTags[i];
88                    break;
89                }
90            }
91            if (!scriptTag) {
92                scriptTag = document.createElement('script');
93                scriptTag.src = apiUrl;
94            }
95            $(scriptTag).on('load', callback);
96            scriptTags[0].parentNode.insertBefore(scriptTag, scriptTags[0]);
97            // Fix for cached scripts on IE 8:
98            if (/loaded|complete/.test(scriptTag.readyState)) {
99                callback();
100            }
101        },
102
103        onReady: function () {
104            var that = this;
105            this.ready = true;
106            this.player.addEvent('play', function () {
107                that.hasPlayed = true;
108                that.onPlaying();
109            });
110            this.player.addEvent('pause', function () {
111                that.onPause();
112            });
113            this.player.addEvent('finish', function () {
114                that.onPause();
115            });
116            if (this.playOnReady) {
117                this.play();
118            }
119        },
120
121        onPlaying: function () {
122            if (this.playStatus < 2) {
123                this.listeners.playing();
124                this.playStatus = 2;
125            }
126        },
127
128        onPause: function () {
129            this.listeners.pause();
130            delete this.playStatus;
131        },
132
133        insertIframe: function () {
134            var iframe = document.createElement('iframe');
135            iframe.src = this.url
136                .replace('VIDEO_ID', this.videoId)
137                .replace('PLAYER_ID', this.playerId);
138            iframe.id = this.playerId;
139            this.element.parentNode.replaceChild(iframe, this.element);
140            this.element = iframe;
141        },
142
143        play: function () {
144            var that = this;
145            if (!this.playStatus) {
146                this.listeners.play();
147                this.playStatus = 1;
148            }
149            if (this.ready) {
150                if (!this.hasPlayed && (this.clickToPlay || (window.navigator &&
151                        /iP(hone|od|ad)/.test(window.navigator.platform)))) {
152                    // Manually trigger the playing callback if clickToPlay
153                    // is enabled and to workaround a limitation in iOS,
154                    // which requires synchronous user interaction to start
155                    // the video playback:
156                    this.onPlaying();
157                } else {
158                    this.player.api('play');
159                }
160            } else {
161                this.playOnReady = true;
162                if (!window.$f) {
163                    this.loadAPI();
164                } else if (!this.player) {
165                    this.insertIframe();
166                    this.player = $f(this.element);
167                    this.player.addEvent('ready', function () {
168                        that.onReady();
169                    });
170                }
171            }
172        },
173
174        pause: function () {
175            if (this.ready) {
176                this.player.api('pause');
177            } else if (this.playStatus) {
178                delete this.playOnReady;
179                this.listeners.pause();
180                delete this.playStatus;
181            }
182        }
183
184    });
185
186    $.extend(Gallery.prototype, {
187
188        VimeoPlayer: VimeoPlayer,
189
190        textFactory: function (obj, callback) {
191            var options = this.options,
192                videoId = this.getItemProperty(obj, options.vimeoVideoIdProperty);
193            if (videoId) {
194                if (this.getItemProperty(obj, options.urlProperty) === undefined) {
195                    obj[options.urlProperty] = '//vimeo.com/' + videoId;
196                }
197                counter += 1;
198                return this.videoFactory(
199                    obj,
200                    callback,
201                    new VimeoPlayer(
202                        options.vimeoPlayerUrl,
203                        videoId,
204                        options.vimeoPlayerIdPrefix + counter,
205                        options.vimeoClickToPlay
206                    )
207                );
208            }
209            return textFactory.call(this, obj, callback);
210        }
211
212    });
213
214    return Gallery;
215}));

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.