/* REQUIRES JQUERY */ var minJavaVer = "1.5"; var minJavaVersion = minJavaVer+"+"; //the minimum Java version a user must have var fullscreenMode=false; var browserName; var isFirefox = false; var isDevMode = ''; version = navigator.appVersion; browserName = navigator.appName; /* * Default Joyplay social functions. * These are overridden for the different distributions such as (Facebook/Moco etc) */ function Joyplay(){ this.notLoggedInExceptionHandler = function(){ alert("Not Logged in - refresh page"); }; this.initThirdParty = function(appId, callback){ // var guest = getUrlParameter("guest"); // if(guest=="true"){ // } warn("Joyplay.initThirdParty() - This should be overriden!"); callback(true); }; this.getFriends = function(b){ b(new Array()); }; this.sendRequest = function(f){ showWarning("This is not available in the guest version"); }; this.getFirstname = function(f){ f("guest"); return "guest"; }; this.inviteFriends = function(){ showWarning("This is only available in the Facebook version"); }; this.postToFeed = function(){ showWarning("This is only available in the Facebook version"); }; this.postToFeedOrInvite = function(){ showWarning("This is only available in the Facebook version"); }; this.redeem = function(){ showWarning("This is not available in the guest version"); }; this.likes = function(appId, a){ a(false); }; this.getPermissions = function(callback) { callback(new Object()); }; this.postScore = function(score){}; this.autoPostToFeed = function(){ /* log("TODO autoPostToFeed"); */ }; this.setStatus = function(){ /* log("TODO setStatus"); */ }; this.fanPage = function(){ /* log("TODO fanPage"); */ }; this.refreshBalance = function(b){ /* log("TODO refreshBalance "+b); */ }; this.showFullProfile = function(b){ /* log("TODO showFullProfile "+b); */ }; this.setDocumentSize = function(b){ /* log("TODO setDocumentSize "+b); */ }; this.logout = function(){}; } var Joyplay = new Joyplay(); if(navigator.userAgent.indexOf("Firefox") != -1){ browserName = "Firefox"; isFirefox = true; }else if(navigator.userAgent.indexOf("MSIE") != -1){ browserName = "Explorer"; } function Dim(){ this.width = 0; this.height = 0; } function jadeInstallJava(){ if(deployJava.installLatestJRE()){ alert("Ok great, Java is updated. Press enter to join the fun"); }else{ alert("Java update was canceled. No problem, it will install automatically later when you enter the rooms, make sure you click accept when prompted"); } } /* * Something went wrong with the applet, give up trying to connect. */ function giveUp() { window.onbeforeunload = null; var sURL = unescape("givenUp.jsp"); window.location.replace( sURL ); } function refreshPage() { window.onbeforeunload = null; // This version does NOT cause an entry in the browser's // page view history. Most browsers will always retrieve // the document from the web-server whether it is already // in the browsers page-cache or not. var sURL = unescape(window.location.pathname); window.location.replace( sURL ); } function refreshPage() { window.onbeforeunload = null; // If we needed to pull the document from // the web-server again (such as where the document contents // change dynamically) we would pass the argument as 'true'. window.location.reload( true ); } function refresh() { window.scroll(0,0); } function openGame(tUrl) { myOpenWindow(tUrl); } function goToGamemoviePage(tGamename, tMoviename){ var sURL = unescape(window.location.pathname); sURL+="?quick=true&gamename="+tGamename+"&moviename="+tMoviename; window.location.replace( sURL ); } var targetRoomId; //Used in the situation where a room is dynamically loaded via AJAX function getTargetRoomId(){ if(targetRoomId!=null){ return targetRoomId; } return getRoomIdFromUrl(); } function getRoomIdFromUrl(){ var roomId = getUrlParameter("roomId"); if(roomId== ""){ try{ var pathArray = document.location.pathname.split( '/' ); roomId = pathArray[pathArray.length-1]; if(roomId.charAt(0)!='@'){ //Room names after the slash must start with a '@' roomId = ""; } }catch(ex){} } return roomId; } function openLobbyHelp() { tUrl = "help.jsp"; myOpenWindow(tUrl); } function openGameHelp(tGame) { //TODO myOpenWindow(tUrl); } function openGetPoints() { tUrl = "../../games/user/u?page=deposit"; myOpenWindow(tUrl); } //--Opens a players profile function openUserProfile(tUser) { tUrl = "../../games/user/u?page=xxx"; myOpenWindow(tUrl); } //--Opens a page that contains this players game statistics function openUsersGameStats(tUser, tGame) { tUrl = "../../games/user/u?page=xxx"; myOpenWindow(tUrl); } function openMyResources(){ openInMainWindow("/games/user/myresources"); } function openMyAccountPage(){ openInMainWindow("/games/user/u?page=myaccount"); } function openInvitePage(){ openInMainWindow("/games/user/u?page=refer"); } function goToSubscribePage(){ openInMainWindow("/games/user/subscribe_page"); } function openInMainWindow(tUrl) { //we use window.parent since the applet will always be hosted in some frameset var mainWindow = window.parent.opener; mainWindow.location.href = tUrl; mainWindow.focus(); if (isFirefox) { //otherwise focus will not be given to the firefox window...very annoying mainWindow.alert('Press OK to continue'); } } function openMyProfile() { openMyAccountPage(); //tUrl = "../../games/user/u?page=myprofile"; //tOptions = "dialogWidth: 800px; dialogHeighth: 700px; resizable:yes; scroll:no"; } function myOpenWindow(tUrl){ var args='width=840,height=700,left=25,top=20,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0'; openURLAndDisplayDivIfBlocked(tUrl,"",args); } //window.onResize = refresh; //window.onLoad = refresh; function writeBrowser(){ document.write("
Browser: "+browserName) } function isFirefoxBrowser(){ browserName = navigator.appName if(navigator.userAgent.indexOf("Firefox") != -1){ return true; } return false; } function checkVersion(version) { var javaID="application/x-java-applet;version=" // Mozilla may not recognize new plugins without this refresh //navigator.plugins.refresh(true); for (var i = 0; i < navigator.mimeTypes.length; ++i) { pluginType = navigator.mimeTypes[i].type; if (pluginType.indexOf(javaID) > -1){ if(pluginType.indexOf(javaID+""+version) > -1){ return true; } } } return false; } //usage: // var desiredJavaVersion = "1.6" // detectBrowser() // if(isFirefox){ // if(checkVersion(desiredJavaVersion)){ // document.write("
OK") // }else{ // window.location.href = " http://jdl.sun.com/webapps/getjava/BrowserRedirect?locale=en&host=java.com " // } // }else{ // document.write("
JRE detection for "+browserName+" not coded yet") // } //Used for detecting a popup being blocked. Use target "_blank" to open a popup. //@ return true if popup was successfully opened function openURL( url, target, args ) { try { var popup = window.open(url, target, args); if (popup == null) return false; if (window.opera) if (!popup.opera) return false; }catch(err) { return false; } return true; } var urlBackup; function openURLAndDisplayDivIfBlocked( url, target, args) { if (openURL(url, target, args) == false) { //the popup was blocked //save the url urlBackup = url; //show the div $('#popupBlockedDiv').show(); $('#appletComponent').css("width","1px"); $('#appletComponent').css("height","1px"); } } function hidePopupBlockedDiv() { $('#popupBlockedDiv').style.display='none'; $('#appletComponent').css("width","100%"); $('#appletComponent').css("height","100%"); } /*Just opens a dummy page that will close immediately. If successful it will return true.*/ function arePopupsAllowed(context) { return (getUrlParameter("continue") != "") || openURL(context+"/popupCheck.jsp","_blank", 'width=50,height=50,left=25,top=20,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0') } /*Tries to open url. Returns true if it manages to open the popup */ function openPopup(url) { return openPopup(url,'popup'); } function openPopup(url, target) { return openURL(url, target, 'width=900,height=680,resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no,status=no,directories=no'); } /*Just opens the URL... doesn't return anything. Useful for using it in href="javascript:justOpenPopup(..." */ function justOpenPopup(url) { openPopup(url); } function justOpenPopup(url, target) { openPopup(url, target); } function getUrlParameter( name ) { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results == null ) return ""; else return results[1]; } function copyToClipboard(s){ if( window.clipboardData && clipboardData.setData ){ clipboardData.setData("Text", s); } } function goToSignUpPage() { window.onbeforeunload = null; //i'm accessing the parent just in case it is in a frame set (guest). It won't effect if we're not in a frameset window.parent.location.href = "/signup_page"; } function openfortunecity(url){ var screenW = 800, screenH = 800; if (parseInt(navigator.appVersion)>3) { screenW = screen.width; screenH = screen.height; } else if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)==3 && navigator.javaEnabled() ) { var jToolkit = java.awt.Toolkit.getDefaultToolkit(); var jScreenSize = jToolkit.getScreenSize(); screenW = jScreenSize.width; screenH = jScreenSize.height; } var args='width='+(screenW-40)+',height='+(screenH-70)+',left=10,top=10,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1'; //if(window.parent.opener==null){ // openURL(url,'fortunecity',args); //}else{ window.location.href = url; //} } function writeAppletForSafari(attributes, parameters) { var html = getObjectTag(attributes, parameters); document.write(html); } function getObjectTag(attributes, parameters) { //var s = '<' + 'object classid="clsid:CAFEEFAC-DEC7-0000-0000-ABCDEFFEDCBA"'; var s = '<' + 'object type="application/x-java-applet;version=1.5+"'; for (var attribute in attributes) { if(attribute=="style"){ //TODO parse the string - "width:1000px;height:601px" var tWidth = "1000"; var tHeight = "601"; s += ' width="'+tWidth+'"'; s += ' height="'+tHeight+'"'; }else{ s += ' ' + attribute + '="' + attributes[attribute] + '"'; } } s += '>'; for (var parameter in parameters) { s += ''; } s += ''; return s; } function getAsEmbedTag(attributes, parameters) { var s = '<' + 'embed '; for (var attribute in attributes) { s += (' ' + attribute + '="' + attributes[attribute] + '"'); } for (var parameter in parameters) { s += (' ' + parameter + '="' + parameters[parameter] + '"'); } s += '>'; return s; } /*Set the main css to be the correct size*/ function setMainCSS(){ var c = "http://"+document.location.host; //because of IE var w = getDocumentDimension().width; if ((w>=700)) { c += "/styles/medium/.css"; } else { c += "/styles/small/.css"; } $("link[rel=stylesheet].mainSizeStyle").attr("href", c); } //Logarithmic function with variable base function customLog(x,base) { return (Math.log(x))/(Math.log(base)); } function initReverseAjax() { if (dwr.engine._scriptSessionId == null) { setTimeout("initReverseAjax()", 2000); } else { dwr.engine.setActiveReverseAjax(true); } } function dummyCallback(arg){ } var scrollEventHandler = function(event) { // if (isIDevice()) { // window.setTimeout(function() { // window.scrollTo(0, 20); // }, 100); // } else { window.setTimeout(function() { window.scrollTo(0, 1); }, 500); // } event.stopPropagation(); event.preventDefault(); }; /* Get the actual size of the document.body */ function getDocumentDimension(){ var d = new Dim(); d.width = $("body").width(); d.height = $("body").height(); return d; } function isPortrait(){ try{ if(window.orientation==0 || window.orientation==180){ return true; }else{ return false; } }catch(ex){ return false; } } /** * Get the the screen size * @param orientation */ function getScreenSize(orientation){ var d = new Dim(); if(orientation==null){ orientation = window.orientation; } if(isIDevice() && (orientation==90 || orientation==270)){ //flip them d.width = screen.height; d.height = screen.width; }else{ d.width = screen.width; d.height = screen.height; } return d; } /** * Get the available size * @param orientation */ function getAvailableScreenSize(orientation){ if(isDesktop){ var d = getContainerDimension(); return d; }else{ if(withinIFrame){ //Because we're within an Iframe we have to rely on the screen size because we can't access the top.window.innerWidth var d = getScreenSize(orientation); if( isIPad()) { d.height -= 80; //allow for the top bar }else if( isIPod() || isIPhone() ){ d.height -= 30; //allow for the top bar } return d; }else{ var d = getContainerDimension(); return d; } } } /* Get the size of the viewport */ function getContainerDimension(){ var d = new Dim(); // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight if (typeof window.innerWidth != 'undefined'){ d.width = window.innerWidth; d.height = window.innerHeight; // if (typeof window.outerHeight != 'undefined' && window.outerHeight > window.innerHeight) { // d.height = window.outerHeight; // } } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){ // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document) d.width = document.documentElement.clientWidth; d.height = document.documentElement.clientHeight; } else { // older versions of IE d.width = document.getElementsByTagName('body')[0].clientWidth; d.height = document.getElementsByTagName('body')[0].clientHeight; } if(isIDevice() && (window.orientation==90 || window.orientation==270)){ var tW = d.width; d.width = d.height; d.height = tW; } return d; } /** * Set the body height to be that of the SCREEN. */ function setBodyHeightToFillWindow(){ var d = getAvailableScreenSize(); if(isTouch()){ //why is this here? need to remove then test on mocospace var d = getContainerDimension(); $("body").css("height",d.height + "px"); //$("body").css("width","100%"); //$("body").css("width",d.width+"px"); $(".mainContainer").css("height","100%"); $(".mainContainer").css("position","absolute"); } } function isTouch(){ return $.support.touch ? true : false; } function isLandscapeView(){ //In theory this should work better. Should try and get it working really. //var d; //if(withinIFrame){ // d = getAvailableScreenSize(); //}else{ var d = getDocumentDimension(); //} return d.width >= d.height; } function displayRotateScreenIfLandscape(){ $(".rotateScreen").remove(); if(!isDesktop && isLandscapeView()){ //IS LANDSCAPE if(!ignoreRotation){ displayRotateScreen(); return true; } } } function displayRotateScreenIfPortrait(){ $(".rotateScreen").remove(); if(!isDesktop && isPortraitView()){ //IS LANDSCAPE if(!ignoreRotation){ displayRotateScreen(); return true; } } } function displayRotateScreen(){ if($(".rotateScreen").length==0){ $("body").append("
Please rotate your device
[ignore]
"); $(".rotateScreen").bind(tapEventName, function(){ ignoreRotation = true; $(".rotateScreen").remove(); }); } } var prevW=0; var prevH=0; var prevDimH=0; var prevDimW=0; function clearPrevSizes(){ prevW=0; prevH=0; prevDimH=0; prevDimW=0; } function hasSizeChanged(){ //if(dist=='MOCOSPACE'){ //TODO we should do this only when in moco as these would not change when we use 100% var w = $("body").css("width"); var h = $("body").css("height"); var dim = getDocumentDimension(); if(w == prevW && h == prevH && dim.width==prevDimW && dim.height==prevDimH){ return false; //no change }else{ prevW = w; prevH = h; prevDimW = dim.width; prevDimH = dim.height; return true; } // }else{ // //TODO perhaps check if $("body").css("width") contains % // var dim = getDocumentDimension(); // if(dim.width == prevW && dim.height == prevH){ // return false; //no change // } // prevW = dim.width; // prevH = dim.height; // return true; // } } /** * Set the game into a full screen mode. * This also blocks handlers on scroll events */ function setFullScreenMode(){ try{ if(true){ log("setFullScreenMode DISABLED FOR NOW"); return; } log("setFullScreenMode called"); fullscreenMode = true; setBodyHeightToFillWindow(); window.scrollTo(0,1); $(document).bind('scroll',scrollEventHandler); //window.addEventListener("scroll", scrollEventHandler, false); /* $(document).bind('touchmove', function(e) { e.preventDefault(); }, false); */ //FIXME This breaks the "click" event maybe we should set tapEventName="tap"; $(document).bind('touchstart',function(event, ui){ if($(event.target).hasClass("allowDefault")){ //without auto focus on the text input panel does not work //showWarning("allow default"); }else{ event.preventDefault(); } //event.stopPropagation(); //event.stopImmediatePropagation(); return event; }); //***FIXME*** - THIS STOPS THE AUTOMATIC CHAT FOCUS WORKING ***************** /* $(document).bind('touchstart touchmove touchend taphold tap',function(event, ui){ //showWarning(event.target.nodeName); if(event.target.nodeName=="INPUT"){ return event; } if(event.target.nodeName=="IMG"){ event.preventDefault(); //prevent the toldhold context menu return event; } //event.stopImmediatePropagation(); // event.stopPropagation(); // event.preventDefault(); //showWarning('event '+event.type); return event; }); */ /* doesn't stop the zoom, using dblclick window.addEventListener("doubleTap", function(event){ alert("double tap"); event.preventDefault(); },false); */ //Disable the taphold context menu on images /* $("img").bind('touchstart touchmove touchend touchcancel',function(){ event.stopPropagation(); event.preventDefault(); }); */ }catch(ex){ showWarning(ex); } } function showWarning(textValue, timeToDisplayMsg, tag){ warn(textValue); if(displayErrorMessage){ if(timeToDisplayMsg==null){ timeToDisplayMsg = 3000; } var d = $('
'+textValue+'
'); d.addClass(tag); $("body").prepend(d); d.show(); setTimeout(function(){ d.remove(); }, timeToDisplayMsg); } } function Rectangle(x,y,width,height){ this.x = x; this.y = y; this.width = width; this.height = height; this.intersects = function(area){ if(area.y>=this.y && area.y<=this.y+this.height || area.y+area.height>=this.y && area.y+area.height<=this.y+this.height){ return true; } return false; }; } /** * Opens a page in an iFrame within the current page */ function openMiniBrowser(url){ var innerBrowserDiv = $("