PageSourceSearch

https://www.deadline.co.uk/wp-content/themes/deadline-couriers/js/vimeo.js

js deadline.co.uk collected 2026-10-05 01:05:07 UTC 9,104 bytes, 255 lines download raw bytes

1;(function($, window) {
2
3    var vimeoJqueryAPI = {
4
5        //catches return messages when methods like getVolume are called. 
6        //counter is if multiple calls are made before one returns.
7        catchMethods : {methodreturn:[], count:0},
8
9        //This kicks things off on window message event
10        init : function(d){
11          
12           // console.log(d);
13
14            var vimeoVideo,
15                vimeoAPIurl,
16                data;
17
18            //is this window message from vimeo?
19            if(!d.originalEvent.origin.match(/vimeo/ig)){
20                return;
21            }
22
23            //make sure data was sent
24            if(!("data" in d.originalEvent)){
25                return;
26            }
27          
28           
29
30            //store data as JSON object
31            data = $.type(d.originalEvent.data) === "string" ? $.parseJSON(d.originalEvent.data) : d.originalEvent.data;
32
33            //make sure data is not blank
34            if(!data){
35                return;
36            }
37
38            //get the id of this vimeo video, hopefully they set it.
39            vimeoVideo = this.setPlayerID(data);
40
41            //check to see if player_ids were set in query string. If not, wait until next message comes through.
42            if(vimeoVideo.length){
43
44                vimeoAPIurl  = this.setVimeoAPIurl(vimeoVideo);
45
46                //If this is an event message, like ready or paused
47                if(data.hasOwnProperty("event"))
48                    this.handleEvent(data, vimeoVideo, vimeoAPIurl);
49
50                //IF this is a return event message, like getVolume or getCurrentTime
51                if(data.hasOwnProperty("method"))
52                    this.handleMethod(data, vimeoVideo, vimeoAPIurl);
53
54            }
55
56        },
57
58        setPlayerID : function(d){
59
60            return $("iframe[src*=" + d.player_id + "]");
61
62        },
63
64        setVimeoAPIurl : function(d){
65
66            //prepend vimeo url with proper protocol
67            if(d.attr('src').substr(0, 4) !== 'http'){
68                return 'https:'+d.attr('src').split('?')[0];
69            } else {
70                return d.attr('src').split('?')[0];
71            }
72        },
73
74        handleMethod : function(d, vid, api){
75
76            //If the message is returned from a method call, store it for later.
77            this.catchMethods.methodreturn.push(d.value);
78
79        },
80
81        handleEvent : function(d, vid, api){
82
83            switch (d.event.toLowerCase()) {
84                case 'ready':
85                
86                    for(var prop in $._data(vid[0], "events")){
87                        if(prop.match(/loadProgress|playProgress|play|pause|finish|seek|cuechange/)){
88                            vid[0].contentWindow.postMessage(JSON.stringify({method: 'addEventListener', value: prop}), api);
89                        }
90                    }
91
92                    //if methods are sent before video is ready, call them now
93                    if(vid.data("vimeoAPICall")){
94                        var vdata = vid.data("vimeoAPICall");
95                        for(var i=0; i< vdata.length; i++){
96                            vid[0].contentWindow.postMessage(JSON.stringify(vdata[i].message), vdata[i].api);
97                        }
98                        vid.removeData("vimeoAPICall");
99                    }
100
101                    //this video is ready
102                    vid.data("vimeoReady", true);
103                    vid.triggerHandler("ready");
104
105                    break;
106
107                case 'seek':
108                    vid.triggerHandler("seek", [d.data]);
109                    break;
110
111                case 'loadprogress':
112                    vid.triggerHandler("loadProgress", [d.data]);
113                    break;
114
115                case 'playprogress':
116                    vid.triggerHandler("playProgress", [d.data]);
117                    break;
118
119                case 'pause':
120                    vid.triggerHandler("pause");
121                    break;
122
123                case 'finish':
124                    vid.triggerHandler("finish");
125                    break;
126
127                case 'play':
128                    vid.triggerHandler("play");
129                    break;
130
131                case 'cuechange':
132                    vid.triggerHandler("cuechange");
133                    break;
134            }
135        }
136    };
137    
138    var loadIframe = $.fn.vimeoLoad = function(){
139
140        //save the current src attribute
141        var url    = $(this).attr('src'),
142            change = false;
143      
144        if(url.substr(0, 6) !== 'https:'){
145            url = url.substr(0,4) === 'http' ? 'https' + url.substr(4) : 'https:' + url;
146            change = true;
147        }
148
149        //if they haven't added "player_id" in their query string, let's add one.
150        if(url.match(/player_id/g) === null){
151          
152            change = true;
153          
154            //is there already a query string? If so, use &, otherwise ?. 
155            var firstSeperator = (url.indexOf('?') === -1 ? '?' : '&');
156
157            //setup a serialized player_id with jQuery (use an unusual name in case someone manually sets the same name)
158            var param = $.param({"api": 1, "player_id": "vvvvimeoVideo-" + Math.floor((Math.random() * 10000000) + 1).toString()});
159          
160            url = url + firstSeperator + param;            
161
162        }
163      
164        if(change){
165          $(this).attr("src", url);
166        }
167  
168
169        return this;
170    };
171
172    jQuery(document).ready(function(){
173
174        //go through every iframe with "vimeo.com" in src attribute, and verify it has "player_id" query string
175        $("iframe[src*='vimeo.com']").each(function(){loadIframe.call(this);});
176    });
177    
178    $(["loadProgress","playProgress","play","pause","finish","seek","cuechange"]).each(function(i,e){
179        jQuery.event.special[e] = {
180          setup: function(data, namespace, eventHandle){
181            
182            var src = $(this).attr("src");
183            if($(this).is("iframe") && src.match(/vimeo/gi)){
184              
185              var element = $(this);
186            
187              if(typeof element.data("vimeoReady") !== "undefined"){
188                  element[0].contentWindow.postMessage(JSON.stringify({
189                    method: 'addEventListener', 
190                    value: e
191                  }), vimeoJqueryAPI.setVimeoAPIurl($(this)));
192              } else {
193                  var _data = typeof element.data("vimeoAPICall") !== "undefined" ? element.data("vimeoAPICall") : [];
194                  _data.push({message:e, api:vimeoJqueryAPI.setVimeoAPIurl(element)});
195                  element.data("vimeoAPICall", _data);
196              }
197            }
198          }
199        };
200    });
201
202
203    //this is what kicks things off. Whenever Vimeo sends window message to us, was check to see what it is.
204    $(window).on("message", function(e){ vimeoJqueryAPI.init(e); });
205
206    /**
207     *  Vimeo jQuery method plugin
208     *
209     * @param element {jQuery Object} The element this was called on (verifies it's an iframe)
210     * @param option1 {string} The method to send to vimeo.
211     * @param option2 {string|function} If a string, it's the value (i.e. setVolume 2) otherwise, it's a callback function
212     */
213    $.vimeo = function(element, option1, option2) {
214
215        var message = {},
216            catchMethodLength = vimeoJqueryAPI.catchMethods.methodreturn.length;
217
218        if(typeof option1 === "string")  
219            message.method = option1;
220
221        if(typeof option2 !== undefined && typeof option2 !== "function") 
222            message.value  = option2;
223
224        //call method, but check if video was ready, otherwise cue it up with jQuery data to be called when video is ready
225        if(element.is('iframe') && message.hasOwnProperty("method")){
226            if(element.data("vimeoReady")){
227                element[0].contentWindow.postMessage(JSON.stringify(message), vimeoJqueryAPI.setVimeoAPIurl(element));
228            } else {
229                var _data = element.data("vimeoAPICall") ? element.data("vimeoAPICall") : [];
230                _data.push({message:message, api:vimeoJqueryAPI.setVimeoAPIurl(element)});
231                element.data("vimeoAPICall", _data);
232            }
233        }
234
235        //If this method will return data, (starts with "get") then use callback once return message comes through
236        if((option1.toString().substr(0, 3) === "get" || option1.toString() === "paused") && typeof option2 === "function"){
237            (function(cml, func, i){
238                var interval = window.setInterval(function(){
239
240                    if(vimeoJqueryAPI.catchMethods.methodreturn.length != cml){
241                        window.clearInterval(interval);
242                        func(vimeoJqueryAPI.catchMethods.methodreturn[i]);
243                    }
244                }, 10);
245            })(catchMethodLength, option2, vimeoJqueryAPI.catchMethods.count);
246            vimeoJqueryAPI.catchMethods.count++;
247        } 
248        return element;
249    };
250
251    $.fn.vimeo = function(option1, option2) {
252            return $.vimeo(this, option1, option2);
253    };
254
255})(jQuery, window);

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.