text
stringlengths 0
14.1k
|
---|
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; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.