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