(function() { try { if (/.*\/_tora_frames\/.*/.test(window.parent.location.href)) { //DOMAIN SETUP document.domain = document.domain .replace(/^.*\.([^\.]*)(\.co\.uk|\.com|\.de|\.uol\.com\.br)$/, "$1$2"); //LEGACY SUPPORT window.iFrameResize = function() {}; /** * TORA External Tools - Core * * @author alucas Anthony_Lucas@discovery-europe.com * @projectDescription Core file which enabled interaction with a main TORA library in a parent window * @version 0.0.1a */ (function() { //##CORE DEFINITION var ORIGTORA; if (!(ORIGTORA = window.$TORA_EXTERN)) var $TORA_EXTERN = {}; /** * TORA External Library core object. This is a static class for use in frames. * @alias $TORA_EXTERN * @type {Function} * * @return {OBJECT} */ $TORA_EXTERN = function ToraExternCore() { return _INTERFACE; }; window.$TORA_EXTERN = $TORA_EXTERN; if (ORIGTORA) { for (var i in ORIGTORA) if (!$TORA_EXTERN[i]) $TORA_EXTERN[i] = ORIGTORA[i]; } if (!$TORA_EXTERN.$callbacks) $TORA_EXTERN.$callbacks = []; //PRIVATE VARS var _INTERFACE, _PARENT, _INTERFACE_ID, _DOC_LOADED = false, _CONFIG = { interfaceType: "IFRAME_MICROSITE"}; //PUBLIC METHODS /** * Initialise TORA main interface. * @alias $TORA_EXTERN.init * @method */ $TORA_EXTERN.init = function() { init(); }; /** * Sets config properties. * @alias $TORA_EXTERN.setConfig * @method * * @param {Object} config */ $TORA_EXTERN.setConfig = function(config) { for (var i in config) _CONFIG[i] = config[i]; }; /** * Provides a cross-browser compatible method to add dom event handlers. * Needs to be called as a method of the element to listen to. * * @see $TORA.packages.common.dom.addEventListener */ $TORA_EXTERN.addEventListener = function addEventListener(event, handler, legacy) { var funcDef; if (this.addEventListener) { funcDef = function(event, handler) { var self = this; event = event.toLowerCase(); if ((self == window) &&(event=="load"||event=="ready") &&_DOC_LOADED) { handler(); return; } if (event == "ready") { event = "DOMContentLoaded"; var origHandler = handler; handler = function(ev){ if (origHandler) { origHandler.call(self, ev); origHandler = null; } }; window.addEventListener("load", handler, false); } this.addEventListener(event, function(ev) { handler.call(self, ev); }, false); return true; }; } else if (this.attachEvent) { funcDef = function(event, handler) { var self = this; event = event.toLowerCase(); if ((self == window) &&(event=="load"||event=="ready") &&_DOC_LOADED) { handler(); return; } if (event == "ready") event = "load", self = window; else self = this; self.attachEvent("on" + event, function(ev) { handler.call(self, ev); }); return true; }; } else { funcDef = function(event, handler, legacy) { var self; event = event.toLowerCase(); if ((self == window) &&(event=="load"||event=="ready") &&_DOC_LOADED) { handler(); return; } if (legacy) { if (event == "ready") event = "load", self = window; else self = this; var oldFunc = this["on" + event]; this["on" + event] = function(ev) { if (oldFunc) oldFunc.call(self, ev); handler.call(self, ev); } } return false; }; } return ($TORA_EXTERN.addEventListener = funcDef) .call(this, event, handler, legacy); }; $TORA_EXTERN.getExternalComponentInterface = function() { if(_PARENT){ var inf = _PARENT("PAGE").getProperty("externalComponentInterface"); if(inf) return inf; } return false; }; //PRIVATE METHODS function init() { //search for tora library instance if ((_PARENT = getParent())) { //initialise interface _INTERFACE = getInterface( _CONFIG.interfaceType, _CONFIG.interfaceSettings, _CONFIG.interfaceUid); if (!_INTERFACE._$config.settings.isFirstRun) _INTERFACE.call("windowLoad", [ window ]); executeCallbacks(true); } else { executeCallbacks(false); throw "TORA library not found"; } }; function getInterface(type, settings, uid) { return _PARENT((_INTERFACE_ID = _PARENT("external") .generateInterfaceId(type, settings, uid))); }; function getParent() { var recursion = 0; var find = function(win){ if (recursion++ > 5) return null; var curWin = win.parent; try { return curWin.$TORA||find(curWin); } catch(e) { return find(win.parent.parent); } }; return find(window); }; function executeCallbacks(result) { var callbacks = $TORA_EXTERN.$callbacks, callbackLen = callbacks.length; if (callbackLen > 0) for (var i = callbackLen-1,k;k=callbacks[i];i--) k(result); } //##END CORE DEFINITION $TORA_EXTERN.addEventListener.call(window, "load", function() { _DOC_LOADED = true; }); })(); /** * TORA External Tools - Iframe Microsite Setup * * @author alucas * @projectDescription TORA External tools implementation for framed microsite content. * @version 0.0.1a */ /** * Ensures that the current page is always loaded within a specified containing window. * @alias $TORA_EXTERN.enforceFrameLocation * @method * * @param {Object} location * @param {Boolean} rootOnly When true matches only the root of the URL. */ $TORA_EXTERN.enforceFrameLocation = function(location, rootOnly) { var regex = '^(' + location + ')'; if (!rootOnly) regex = RegExp(regex + '(?:\\\?.*?|)(?:#.*|)$'); else regex = RegExp(regex + '.*$'); if (!parent.location.href.match(regex)) document.location.assign(location); }; /** * Loads the configuration for a microsite hosted in a subdomain. * @alias $TORA_EXTERN.getMicrositeConfig * @method */ $TORA_EXTERN.getMicrositeConfig = function() { var domainPrefix = !document.domain.match(/\.uol\.com\.br/) ? "www." : ""; var script = document.createElement("script"); script.type = "text/javascript"; script.language = "Javascript"; script.src = "http://" + domainPrefix + document.domain + "/localresources/static/msites/config/" + document.location.href .replace(/^.*\/\/([^\/]*).*$/, "$1") + ".js.shtml"; document.getElementsByTagName("head")[0].appendChild(script); }; //#CONFIGURE & INITIALISE MODULE $TORA_EXTERN.setConfig({ 'interfaceType': "IFRAME_MICROSITE", 'interfaceUid': document.location .href.replace(/^.*\/\/([^\/]*).*$/, "$1") }); $TORA_EXTERN.getMicrositeConfig(); } else { try { mozHeightOffset=20; function showDiv() { parent.document.getElementById('micrositeLoading').style.display='none'; parent.document.getElementById('micrositeBody').style.visibility = 'visible'; } function refreshFrame() { parent.document.getElementById('micrositeBody').style.visibility = 'hidden'; parent.document.getElementById('micrositeLoading').style.display='block'; } if (document.getElementById&&!document.all) { // FF window.captureEvents(Event.CLICK); window.onclick = refreshFrame(); } else { // IE try { document.onclick = refreshFrame(); } catch (err) {} } window.iFrameResize = function iFrameResize() { if(parent.document.getElementById("micrositeContainer_id")) { parent.document.getElementById("micrositeContainer_id").height=34; if (document.getElementById&&!document.all) parent.document.getElementById("micrositeContainer_id").height= parent.document.getElementById("micrositeContainer_id").contentDocument.body.offsetHeight+mozHeightOffset; else parent.document.getElementById("micrositeContainer_id").height= parent.window.frames["micrositeContainer_name"].document.body.scrollHeight+20; showDiv(); } } } catch(e) {} } } catch(e) {} })();