PageSourceSearch

https://matsumoto.ed.jp/wp-content/themes/insp_para/framework/js/pe/froogaloop.js?ver=1561346628

js matsumoto.ed.jp collected 2026-10-05 09:39:29 UTC 8,581 bytes, 273 lines download raw bytes

1/*jslint undef: false, browser: true, devel: false, eqeqeq: false, bitwise: false, white: false, plusplus: false, regexp: false */ 
2/*global jQuery,setTimeout */
3
4// Init style shamelessly stolen from jQuery http://jquery.com
5var Froogaloop = (function(){
6
7    // Define a local copy of Froogaloop
8    function Froogaloop(iframe) {
9        // The Froogaloop object is actually just the init constructor
10        return new Froogaloop.fn.init(iframe);
11    }
12
13    var eventCallbacks = {},
14        hasWindowEvent = false,
15        slice = Array.prototype.slice;
16
17    Froogaloop.fn = Froogaloop.prototype = {
18        playerDomain: '',
19
20        element: null,
21
22        init: function(iframe) {
23            if (typeof iframe === "string") {
24                iframe = document.getElementById(iframe);
25            }
26
27            this.element = iframe;
28            return this;
29        },
30
31        /*
32         * Calls a function to act upon the player.
33         *
34         * @param {string} method The name of the Javascript API method to call. Eg: 'play'.
35         * @param {Array|Function} valueOrCallback params Array of parameters to pass when calling an API method
36         *                                or callback function when the method returns a value.
37         */
38        api: function(method, valueOrCallback) {
39            if (!this.element || !method) {
40                return false;
41            }
42
43            var self = this,
44                element = self.element,
45                target_id = element.id != '' ? element.id : null,
46                params = !isFunction(valueOrCallback) ? valueOrCallback : null,
47                callback = isFunction(valueOrCallback) ? valueOrCallback : null;
48
49            // Store the callback for get functions
50            if (callback) {
51                storeCallback(method, callback, target_id);
52            }
53
54            postMessage(method, params, element);
55            return self;
56        },
57
58        /*
59         * Registers an event listener and a callback function that gets called when the event fires.
60         *
61         * @param eventName (String): Name of the event to listen for.
62         * @param callback (Function): Function that should be called when the event fires.
63         */
64        addEvent: function(eventName, callback) {
65            if (!this.element) {
66                return false;
67            }
68
69            var self = this,
70                element = self.element,
71                target_id = element.id != '' ? element.id : null;
72
73
74            storeCallback(eventName, callback, target_id);
75            
76            // The ready event is not registered via postMessage. It fires regardless.
77            if (eventName != 'ready') {
78                postMessage('addEventListener', eventName, element);
79            }
80
81            // Register message event listeners
82            if (hasWindowEvent) {
83                return self;
84            }
85
86            playerDomain = getDomainFromUrl(element.getAttribute('src'));
87
88            // Listens for the message event.
89            // W3C
90            if (window.addEventListener) {
91                window.addEventListener('message', onMessageReceived, false);
92            }
93            // IE
94            else {
95                window.attachEvent('onmessage', onMessageReceived, false);
96            }
97
98            hasWindowEvent = true;
99            return self;
100        },
101
102        /*
103         * Unregisters an event listener that gets called when the event fires.
104         *
105         * @param eventName (String): Name of the event to stop listening for.
106         */
107        removeEvent: function(eventName) {
108            if (!this.element) {
109                return false;
110            }
111
112            var self = this,
113                element = self.element,
114                target_id = element.id != '' ? element.id : null,
115                removed = removeCallback(eventName, target_id);
116
117            // The ready event is not registered
118            if (eventName != 'ready' && removed) {
119                postMessage('removeEventListener', eventName, element);
120            }
121        }
122    };
123
124    /**
125     * Handles posting a message to the parent window.
126     *
127     * @param method (String): name of the method to call inside the player. For api calls
128     * this is the name of the api method (api_play or api_pause) while for events this method
129     * is api_addEventListener.
130     * @param params (Object or Array): List of parameters to submit to the method. Can be either
131     * a single param or an array list of parameters.
132     * @param target (HTMLElement): Target iframe to post the message to.
133     */
134    function postMessage(method, params, target) {
135        if (!target || !target.contetWindow || !target.contentWindow.postMessage) {
136            return false;
137        }
138
139        var url = target.getAttribute('src').split('?')[0],
140            data = JSON.stringify({
141                method: method,
142                value: params
143            });
144
145        target.contentWindow.postMessage(data, url);
146    }
147
148    /**
149     * Event that fires whenever the window receives a message from its parent
150     * via window.postMessage.
151     */
152    function onMessageReceived(event) {
153        // Handles messages from moogaloop only
154        if (event.origin != playerDomain) {
155            return false;
156        }
157
158        var data = JSON.parse(event.data),
159            value = data.value,
160            method = data.event || data.method,
161            eventData = data.data,
162            target_id = target_id == '' ? null : data.player_id,
163
164            callback = getCallback(method, target_id),
165            params = [];
166
167        if (!callback) {
168            return false;
169        }
170
171        if (value !== undefined) {
172            params.push(value);
173        }
174
175        if (eventData) {
176            params.push(eventData);
177        }
178
179        if (target_id) {
180            params.push(target_id);
181        }
182
183        return params.length > 0 ? callback.apply(null, params) : callback.call();
184    }
185
186
187    /**
188     * Stores submitted callbacks for each iframe being tracked and each
189     * event for that iframe.
190     *
191     * @param eventName (String): Name of the event. Eg. api_onPlay
192     * @param callback (Function): Function that should get executed when the
193     * event is fired.
194     * @param target_id (String) [Optional]: If handling more than one iframe then
195     * it stores the different callbacks for different iframes based on the iframe's
196     * id.
197     */
198    function storeCallback(eventName, callback, target_id) {
199        if (target_id) {
200            if (!eventCallbacks[target_id]) {
201                eventCallbacks[target_id] = {};
202            }
203            eventCallbacks[target_id][eventName] = callback;
204        }
205        else {
206            eventCallbacks[eventName] = callback;
207        }
208    }
209
210    /**
211     * Retrieves stored callbacks.
212     */
213    function getCallback(eventName, target_id) {
214        if (target_id) {
215            return eventCallbacks[target_id][eventName];
216        }
217        else {
218            return eventCallbacks[eventName];
219        }
220    }
221
222    function removeCallback(eventName, target_id) {
223        if (target_id && eventCallbacks[target_id]) {
224            if (!eventCallbacks[target_id][eventName]) {
225                return false;
226            }
227            eventCallbacks[target_id][eventName] = null;
228        }
229        else {
230            if (!eventCallbacks[eventName]) {
231                return false;
232            }
233            eventCallbacks[eventName] = null;
234        }
235
236        return true;
237    }
238
239    /**
240     * Returns a domain's root domain.
241     * Eg. returns http://vimeo.com when http://vimeo.com/channels is sbumitted
242     *
243     * @param url (String): Url to test against.
244     * @return url (String): Root domain of submitted url
245     */
246    function getDomainFromUrl(url) {
247        var url_pieces = url.split('/'),
248            domain_str = '';
249
250        for(var i = 0, length = url_pieces.length; i < length; i++) {
251            if(i<3) {domain_str += url_pieces[i];}
252            else {break;}
253            if(i<2) {domain_str += '/';}
254        }
255
256        return domain_str;
257    }
258
259    function isFunction(obj) {
260        return !!(obj && obj.constructor && obj.call && obj.apply);
261    }
262
263    function isArray(obj) {
264        return toString.call(obj) === '[object Array]';
265    }
266
267    // Give the init function the Froogaloop prototype for later instantiation
268    Froogaloop.fn.init.prototype = Froogaloop.fn;
269
270    // Expose froogaloop to the global object
271    return (window.Froogaloop = Froogaloop);
272
273})();

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.