diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-10-20 15:24:16 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-10-20 15:24:16 +0200 |
| commit | eb73811e6ead48d4ef32b5ee7e3ce0f7868b7e29 (patch) | |
| tree | c9e29e2112706996cdb643e92b4a9ad082fdb0d7 /frontend/static | |
| parent | 9963c7446d5ec047318430b650417df580bf5de8 (diff) | |
rebuild
Diffstat (limited to 'frontend/static')
| -rwxr-xr-x | frontend/static/js/sj_compiled.js | 361 |
1 files changed, 332 insertions, 29 deletions
diff --git a/frontend/static/js/sj_compiled.js b/frontend/static/js/sj_compiled.js index 9d6888b..7ba2ad7 100755 --- a/frontend/static/js/sj_compiled.js +++ b/frontend/static/js/sj_compiled.js @@ -281,7 +281,293 @@ } }; -}(typeof jQuery === 'function' ? jQuery : this));var d = +}(typeof jQuery === 'function' ? jQuery : this));// Init style shamelessly stolen from jQuery http://jquery.com +var Froogaloop = (function(){ + // Define a local copy of Froogaloop + function Froogaloop(iframe) { + // The Froogaloop object is actually just the init constructor + return new Froogaloop.fn.init(iframe); + } + + var eventCallbacks = {}, + hasWindowEvent = false, + isReady = false, + slice = Array.prototype.slice, + playerDomain = ''; + + Froogaloop.fn = Froogaloop.prototype = { + element: null, + + init: function(iframe) { + if (typeof iframe === "string") { + iframe = document.getElementById(iframe); + } + + this.element = iframe; + + // Register message event listeners + playerDomain = getDomainFromUrl(this.element.getAttribute('src')); + + return this; + }, + + /* + * Calls a function to act upon the player. + * + * @param {string} method The name of the Javascript API method to call. Eg: 'play'. + * @param {Array|Function} valueOrCallback params Array of parameters to pass when calling an API method + * or callback function when the method returns a value. + */ + api: function(method, valueOrCallback) { + if (!this.element || !method) { + return false; + } + + var self = this, + element = self.element, + target_id = element.id !== '' ? element.id : null, + params = !isFunction(valueOrCallback) ? valueOrCallback : null, + callback = isFunction(valueOrCallback) ? valueOrCallback : null; + + // Store the callback for get functions + if (callback) { + storeCallback(method, callback, target_id); + } + + postMessage(method, params, element); + return self; + }, + + /* + * Registers an event listener and a callback function that gets called when the event fires. + * + * @param eventName (String): Name of the event to listen for. + * @param callback (Function): Function that should be called when the event fires. + */ + addEvent: function(eventName, callback) { + if (!this.element) { + return false; + } + + var self = this, + element = self.element, + target_id = element.id !== '' ? element.id : null; + + storeCallback(eventName, callback, target_id); + + // The ready event is not registered via postMessage. It fires regardless. + if (eventName != 'ready') { + postMessage('addEventListener', eventName, element); + } + else if (eventName == 'ready' && isReady) { + callback.call(null, target_id); + } + + return self; + }, + + /* + * Unregisters an event listener that gets called when the event fires. + * + * @param eventName (String): Name of the event to stop listening for. + */ + removeEvent: function(eventName) { + if (!this.element) { + return false; + } + + var self = this, + element = self.element, + target_id = element.id !== '' ? element.id : null, + removed = removeCallback(eventName, target_id); + + // The ready event is not registered + if (eventName != 'ready' && removed) { + postMessage('removeEventListener', eventName, element); + } + } + }; + + /** + * Handles posting a message to the parent window. + * + * @param method (String): name of the method to call inside the player. For api calls + * this is the name of the api method (api_play or api_pause) while for events this method + * is api_addEventListener. + * @param params (Object or Array): List of parameters to submit to the method. Can be either + * a single param or an array list of parameters. + * @param target (HTMLElement): Target iframe to post the message to. + */ + function postMessage(method, params, target) { + if (!target.contentWindow.postMessage) { + return false; + } + + var url = target.getAttribute('src').split('?')[0], + data = JSON.stringify({ + method: method, + value: params + }); + + if (url.substr(0, 2) === '//') { + url = window.location.protocol + url; + } + + target.contentWindow.postMessage(data, url); + } + + /** + * Event that fires whenever the window receives a message from its parent + * via window.postMessage. + */ + function onMessageReceived(event) { + var data, method; + + try { + data = JSON.parse(event.data); + method = data.event || data.method; + } + catch(e) { + //fail silently... like a ninja! + } + + if (method == 'ready' && !isReady) { + isReady = true; + } + + // Handles messages from moogaloop only + if (event.origin != playerDomain) { + return false; + } + + var value = data.value, + eventData = data.data, + target_id = target_id === '' ? null : data.player_id, + + callback = getCallback(method, target_id), + params = []; + + if (!callback) { + return false; + } + + if (value !== undefined) { + params.push(value); + } + + if (eventData) { + params.push(eventData); + } + + if (target_id) { + params.push(target_id); + } + + return params.length > 0 ? callback.apply(null, params) : callback.call(); + } + + + /** + * Stores submitted callbacks for each iframe being tracked and each + * event for that iframe. + * + * @param eventName (String): Name of the event. Eg. api_onPlay + * @param callback (Function): Function that should get executed when the + * event is fired. + * @param target_id (String) [Optional]: If handling more than one iframe then + * it stores the different callbacks for different iframes based on the iframe's + * id. + */ + function storeCallback(eventName, callback, target_id) { + if (target_id) { + if (!eventCallbacks[target_id]) { + eventCallbacks[target_id] = {}; + } + eventCallbacks[target_id][eventName] = callback; + } + else { + eventCallbacks[eventName] = callback; + } + } + + /** + * Retrieves stored callbacks. + */ + function getCallback(eventName, target_id) { + if (target_id) { + return eventCallbacks[target_id][eventName]; + } + else { + return eventCallbacks[eventName]; + } + } + + function removeCallback(eventName, target_id) { + if (target_id && eventCallbacks[target_id]) { + if (!eventCallbacks[target_id][eventName]) { + return false; + } + eventCallbacks[target_id][eventName] = null; + } + else { + if (!eventCallbacks[eventName]) { + return false; + } + eventCallbacks[eventName] = null; + } + + return true; + } + + /** + * Returns a domain's root domain. + * Eg. returns http://vimeo.com when http://vimeo.com/channels is sbumitted + * + * @param url (String): Url to test against. + * @return url (String): Root domain of submitted url + */ + function getDomainFromUrl(url) { + if (url.substr(0, 2) === '//') { + url = window.location.protocol + url; + } + + var url_pieces = url.split('/'), + domain_str = ''; + + for(var i = 0, length = url_pieces.length; i < length; i++) { + if(i<3) {domain_str += url_pieces[i];} + else {break;} + if(i<2) {domain_str += '/';} + } + + return domain_str; + } + + function isFunction(obj) { + return !!(obj && obj.constructor && obj.call && obj.apply); + } + + function isArray(obj) { + return toString.call(obj) === '[object Array]'; + } + + // Give the init function the Froogaloop prototype for later instantiation + Froogaloop.fn.init.prototype = Froogaloop.fn; + + // Listens for the message event. + // W3C + if (window.addEventListener) { + window.addEventListener('message', onMessageReceived, false); + } + // IE + else { + window.attachEvent('onmessage', onMessageReceived); + } + + // Expose froogaloop to the global object + return (window.Froogaloop = window.$f = Froogaloop); + +})();var d = { DEBUG: false, act: function (s) @@ -1396,13 +1682,33 @@ var Vimeo = $("#screen").html("<div id='vimeo'></div>") Vimeo.video = video Vimeo.playing = true - var params = { allowScriptAccess: "always", wmode: "opaque", } - var atts = { id: "vimeo" } - var flashvars = { api: 1 } - swfobject.embedSWF("http://vimeo.com/moogaloop.swf?clip_id="+video.name+"&server=vimeo.com&color=00adef&api=1", - "vimeo", "100%","100%", "8", null, flashvars, params, atts) + + var preload = document.createElement("iframe") + preload.id = uid + preload.setAttribute("src", "//player.vimeo.com/video/" + this.media.token + "?api=1&badge=0&controls=0branding=0&byline=0&portrait=0&title=0&" + loop + "&player_id=" + uid) + preload.style.backgroundImage = "url(" + this.media.thumbnail + ")" + preload.style.width = "100%" + preload.style.height = "100%" + preload.style.border = "0" + preload.style.pointerEvents = "none" + preload.className = "preload" + $("#vimeo").appendChild(preload) + Vimeo.player = $f(preload) + + Vimeo.player.addEvent('ready', Vimeo.ready) + + //var atts = { id: "vimeo" } + //var flashvars = { api: 1 } + //swfobject.embedSWF("http://vimeo.com/moogaloop.swf?clip_id="+video.name+"&server=vimeo.com&color=00adef&api=1", + // "vimeo", "100%","100%", "8", null, flashvars, params, atts) // $("#vimeo").html('<iframe src="http://player.vimeo.com/video/'+video.name+'?api=1" width="100%" height="100%" frameborder="0"></iframe>') }, + ready: function () { + Vimeo.player.addEvent('play', Vimeo.onPlay) + Vimeo.player.addEvent('pause', Vimeo.onPause) + Vimeo.player.addEvent('finish', Vimeo.finish) + Vimeo.player.api('play') + }, toggle: function () { if (Vimeo.player.api_paused()) @@ -1418,20 +1724,26 @@ var Vimeo = setVolume: function (vol) { Vimeo.volume = vol - Vimeo.player.api_setVolume(vol) + Vimeo.player.api('setVolume', vol) }, + onPlay: function(){ + Vimeo.playing = true + }, + onPause: function(){ + Vimeo.playing = false + }, pause: function () { d.warn("PAUSED PLAYBACK") Vimeo.playing = false - Vimeo.player.api_pause() + Vimeo.player.api('pause') return true }, resume: function () { d.warn("RESUME PLAYBACK") Vimeo.playing = true - Vimeo.player.api_play() + Vimeo.player.api('play') return false }, stop: function () @@ -1443,7 +1755,7 @@ var Vimeo = { d.warn("VIMEO FINISH") Vimeo.playing = false - swfobject.removeSWF("vimeo") + Vimeo.unload() Player.finish() }, load: function () @@ -1454,23 +1766,14 @@ var Vimeo = unload: function () { d.warn("VIMEO UNLOADED") - swfobject.removeSWF("vimeo") + $("#vimeo").empty() Vimeo.loaded = false }, init: function () { d.warn("VIMEO INIT") - } - } -function vimeo_player_loaded() - { - d.warn("VIMEO LOADED") - Vimeo.player = document.getElementById('vimeo') - Vimeo.player.api_play() - // Vimeo.player.addEventListener("finish", "Vimeo.finish") - Vimeo.player.api_addEventListener("finish", "Vimeo.finish") - Vimeo.player.api_setVolume(Vimeo.volume) - } + }, + }; Player.register(Vimeo) YOUTUBE_SEARCH_URL = "https://gdata.youtube.com/feeds/api/videos" YOUTUBE_URL_PREFIX = "http://youtube.com/watch?v=" @@ -1899,15 +2202,15 @@ var Soundcloud = if (Soundcloud.player) { Soundcloud.player = null - swfobject.removeSWF("soundcloud") + // swfobject.removeSWF("soundcloud") } - var flashvars = { enable_api: true, object_id: "soundcloud", url: video.src, theme_color: "#657b83", } - var attributes = { id: "soundcloud", name: "soundcloud" } - var params = { allowscriptaccess: "always", wmode: "opaque", } - - swfobject.embedSWF("http://player.soundcloud.com/player.swf", "soundcloud", "81", "81", "9.0.0", - "expressInstall.swf", flashvars, params, attributes, Soundcloud.playerDidLoad); +// var flashvars = { enable_api: true, object_id: "soundcloud", url: video.src, theme_color: "#657b83", } +// var attributes = { id: "soundcloud", name: "soundcloud" } +// var params = { allowscriptaccess: "always", wmode: "opaque", } +// +// swfobject.embedSWF("http://player.soundcloud.com/player.swf", "soundcloud", "81", "81", "9.0.0", +// "expressInstall.swf", flashvars, params, attributes, Soundcloud.playerDidLoad); }, playerDidLoad: function (e) { |
