// Newspaper Connector // -------------------------------------------- // Variables var newspaperConnectorId = "IFrameConnector"; var newspaperConnected = false; var newspaperHeight = 0; var initted = false; // Timeouts setTimeout("initConnector()", 500); // set a 500ms delay to resolve google chrome issues setInterval("sendNewspaperHeight()", 1000); // update the newspaper height every second /** Dispose of the SWF on window unload (IE fix) **/ window.onbeforeunload = function() { var swf = document.getElementById(newspaperConnectorId); //if(swf) //swf.dispose(); } /** Embed the Connector SWF to the child page. **/ function initConnector() { if(initted) return; initted = true; // embed the newspaper connector var flashvars = { connectionKey: "", parent: "false", browserVersion : navigator.userAgent, dumpUri : 'http://www.smallworlds.com/swds/gateway', connectCallback : window['connectCallback'] === undefined ? 'onNewspaperConnected' : connectCallback }; var params = { allowScriptAccess: "always" }; swfobject.embedSWF("http://www.smallworlds.com/smallworlds/common/swf/javascriptproxy.swf", newspaperConnectorId, "0", "0", "9.0.0","expressInstall.swf", flashvars, params); } /** Callback on successful connect to SmallWorlds **/ function onNewspaperConnected() { this.newspaperConnected = true; sendNewspaperHeight(); setHomeButtonHighlight(); } var retryCount = 0; /** Send page's height to host page for resize pusposes **/ function sendNewspaperHeight() { if(newspaperConnected) { var newHeight = document.getElementById('marker').offsetTop; if (retryCount < 20) { var swf = document.getElementById(newspaperConnectorId); // when connected, send height over localconnection swf.sendProperty("newspaperHeight", newHeight); retryCount++; } if(newspaperHeight != newHeight) { newspaperHeight = newHeight; retryCount = 0; } } } /** Set Home button highlight status based on child page's content **/ function setHomeButtonHighlight() { if(newspaperConnected) { var swf = document.getElementById(newspaperConnectorId); var url = window.location.href; swf.sendProperty("setHomeButtonHighlight", url); } } /** A property has been recieved from the host page. **/ function onProperty(property, value) { switch(property) { case "purchaseComplete": // Function exists in emedding page onPurchaseComplete(); break; } } /** Embed the avatar selector widget. **/ function embedAvatarsWidget(url) { var flashvars = { configUrl: url }; var avatarsParams = { allowScriptAccess: "always", wmode: "transparent" }; swfobject.embedSWF("http://content.smallworlds.com/content-v831/webassets/home/avatars.swf", "AvatarSelector", "218", "265", "9.0.0","expressInstall.swf", flashvars, avatarsParams); } /** Embed the orientation XP widget. **/ function embedXpStatusWidget(url) { var flashvars = { configUrl: url }; var avatarsParams = { allowScriptAccess: "always", wmode: "transparent" }; swfobject.embedSWF("http://content.smallworlds.com/content-v831/webassets/home/xpstatus.swf", "XpStatus", "218", "150", "9.0.0","expressInstall.swf", flashvars, avatarsParams); } /** User clicked Enter World button. **/ //function enterWorld(address) function setGlobalAddress(address) { if(newspaperConnected) { // when connected, send request to host page to redirect sendProperty("globalAddress", address); } else { // when not connected, attempt to open request in host window, otherwise in a new window try { window.parent.location = address + location.search; } catch (err) { window.open(address + location.search); } } } /** User clicked Enter World button and using community space ID. **/ //change to use enterWorld function navigateToSpace(spaceId) { if(newspaperConnected) { // when connected, send request to host page to redirect sendProperty("spaceId", spaceId); } else { // when not connected, attempt to open request in host window, otherwise in a new window try { window.parent.location = "http://www.smallworlds.com/space/" + spaceId + location.search; } catch (err) { window.open("http://www.smallworlds.com/space/" + spaceId + location.search); } } } /** User clicked Enter World button and is going to newbie space. **/ function navigateToHomespace(avatarName) { if(newspaperConnected) { // when connected, send request to host page to redirect sendProperty("avatarName", avatarName); } else { // when not connected, attempt to open request in host window, otherwise in a new window try { window.parent.location = "http://www.smallworlds.com/home/" + avatarName + location.search; } catch (err) { window.open("http://www.smallworlds.com/home/" + avatarName + location.search); } } } /** User changed their avatar in the avatar selector widget. **/ function selectedAvatarChanged(value) { sendProperty("selectedAvatarChanged", value); } /** User changed pet active in the avatar selector widget. **/ function petActiveChanged(value) { sendProperty("petActiveChanged", value); } /** Send a property over the connection to the host page. **/ function sendProperty(property, value) { if (newspaperConnected) { var swf = document.getElementById(newspaperConnectorId); swf.sendProperty(property, value); } }