/* Copyright (c) 2008, Interactive Pulp, LLC All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Interactive Pulp, LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ // PulpCore 0.11 // Global functions accessed via LiveConnect function pulpcore_getCookie(name) { name = name + "="; var i; if (document.cookie.substring(0, name.length) == name) { i = name.length; } else { i = document.cookie.indexOf('; ' + name); if (i == -1) { return null; } i += name.length + 2; } var endIndex = document.cookie.indexOf('; ', i); if (endIndex == -1) { endIndex = document.cookie.length; } return unescape(document.cookie.substring(i, endIndex)); } function pulpcore_setCookie(name, value, expireDate, path, domain, secure) { var expires = new Date(); if (expireDate === null) { // Expires in 90 days expires.setTime(expires.getTime() + (24 * 60 * 60 * 1000) * 90); } else { expires.setTime(expireDate); } document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); } function pulpcore_deleteCookie(name, path, domain) { document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; } function pulpcore_appletLoaded() { pulpCoreObject.hideSplash(); setTimeout(pulpCoreObject.showObject, 50); } // Internal PulpCore code var pulpCoreObject = { // The minimum JRE version requiredJRE: "1.4", // The minimum JRE version, formatted for IE ieRequiredJRE: "1,4,0,0", // The URL to the CAB of the latest JRE (for IE) // See http://java.sun.com/javase/6/docs/technotes/guides/deployment/deployment-guide/autodl-files.html getJavaCAB: "http://java.sun.com/update/1.6.0/jinstall-6-windows-i586.cab", // The URL of the XPI of the latest JRE (for Windows+Firefox) // Currently using the unsigned version (-jc) since the signed version in 6u3 is broken getJavaXPI: "http://java.sun.com/update/1.6.0/jre-6-windows-i586-jc.xpi", //getJavaXPI: "http://java.sun.com/update/1.6.0/jre-6-windows-i586.xpi", //getJavaXPI: "http://java.com/jre-install.xpi", // The URL to the page to visit to install Java getJavaURL: "http://java.sun.com/webapps/getjava/BrowserRedirect?host=java.com" + '&returnPage=' + document.location, // The Applet HTML (inserted after a delay) appletHTML: "", appletInserted: false, // Gets the codebase from the document URL getCodeBase: function() { var codeBase = document.URL; if (codeBase.length <= 7 || codeBase.substr(0, 7) != "http://") { return ""; } if (codeBase.charAt(codeBase.length - 1) != '/') { var index = codeBase.lastIndexOf('/'); // Don't include the http:// if (index > 7) { codeBase = codeBase.substring(0, index + 1); } else { codeBase += '/'; } } return codeBase; }, write: function() { // JLint gives a warning about "eval" here. // Note the HTML uses onload and onfocus attributes in a few places. document.write(pulpCoreObject.getObjectHTML()); }, hideSplash: function() { var splash = document.getElementById('pulpcore_splash'); splash.style.display = "none"; splash.style.visibility = "hidden"; }, showObject: function() { if (pulpCoreObject.browserIsMozillaFamily) { var spacer = document.getElementById('pulpcore_spacer'); spacer.style.display = "none"; spacer.style.visibility = "hidden"; } var gameContainer = document.getElementById('pulpcore_game'); gameContainer.style.display = "block"; gameContainer.style.visibility = "visible"; if (pulpCoreObject.browserName == "Explorer") { gameContainer.style.position = "static"; } }, splashLoaded: function(splash) { // Prevent this call from occuring again // (IE will continue to call onLoad() if the splash loops.) if (splash !== null) { splash.onload = ""; } pulpCoreObject.insertApplet(); }, insertApplet: function() { if (pulpCoreObject.appletInserted) { return; } var gameContainer = document.getElementById('pulpcore_game'); if (gameContainer === null) { setTimeout(pulpCoreObject.insertApplet, 500); } else { pulpCoreObject.appletInserted = true; gameContainer.innerHTML = pulpCoreObject.appletHTML; setTimeout(pulpcore_appletLoaded, navigator.javaEnabled() ? 15000 : 10); } }, getObjectHTML: function() { pulpCoreObject.appletHTML = ""; pulpCoreObject.detectBrowser(); if (!pulpCoreObject.isAcceptableJRE()) { return pulpCoreObject.installLatestJRE(); } var splashHTML; // The splash image to show during JRE boot and jar loading var splash = window.pulpcore_splash || "splash.gif"; // Applet attributes and parameters var code = window.pulpcore_class || "pulpcore.platform.applet.CoreApplet.class"; var width = window.pulpcore_width || 640; var height = window.pulpcore_height || 480; var archive = window.pulpcore_archive || "project.jar"; var bgcolor = window.pulpcore_bgcolor || "#000000"; var fgcolor = window.pulpcore_fgcolor || "#aaaaaa"; var scene = window.pulpcore_scene || ""; var assets = window.pulpcore_assets || ""; var params = window.pulpcore_params || { }; var codebase = window.pulpcore_codebase || pulpCoreObject.getCodeBase(); // Create the object tag parameters var objectParams = ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n'; if (codebase.length > 0) { objectParams += ' \n'; } if (scene.length > 0) { objectParams += ' \n'; } if (assets.length > 0) { objectParams += ' \n'; } for (var i in params) { objectParams += ' \n'; } objectParams += ' \n' + ' \n' + ' ' + pulpCoreObject.getInstallHTML(); // Create the Object tag. if (pulpCoreObject.browserName == "Explorer") { var extraAttributes = ''; if (pulpCoreObject.compareVersions(pulpCoreObject.browserVersion, "7") < 0 && parent.frames.length > 0) { // On IE6 and older, if the site is externally framed, LiveConnect will not work. // However, IE can use onfocus to emulate the appletLoaded() behavior extraAttributes = ' onfocus="pulpcore_appletLoaded();"\n'; } // Use the tag instead of . IE users without Java can get the // latest JRE without leaving the page or restarting the browser. pulpCoreObject.appletHTML = '\n' + objectParams + ''; // Explorer has special code for centering the splash. Also, the game is // positioned far left to avoid flicker when the applet is displayed. splashHTML = '
\n' + '
\n' + ' Loading...\n' + '
\n' + '
\n'; } else { if (pulpCoreObject.osName == "Windows" && pulpCoreObject.browserName == "Safari" && pulpCoreObject.compareVersions(pulpCoreObject.browserVersion, "522.11") >= 0) { // Known versions: 522.11, 522.12, 522.15, 523.12 // Safari 3 beta on Windows doesn't recognize the archive param when // the tag is used. For now, use the tag. // See http://joliclic.free.fr/html/object-tag/en/object-java.html // LiveConnect also does not work. pulpCoreObject.appletHTML = '\n' + objectParams + ''; } else { // Firefox, Safari, Opera, Mozilla, etc. // Note: the minimum version string is ignored on the Mozilla family pulpCoreObject.appletHTML = '\n' + objectParams + ''; } var spacer = ""; if (pulpCoreObject.browserIsMozillaFamily) { // Prevents white flash on Firefox spacer = '
 
\n'; } splashHTML = '
\n' + ' Loading...\n' + '
\n' + spacer + '\n'; } // In case splash.onLoad() is never called setTimeout(pulpCoreObject.insertApplet, 1000); return '
\n' + splashHTML + '
\n'; }, // JRE detection /** Returns true if the installed JRE is Java 1.4 or newer. */ isAcceptableJRE: function() { var version; if (pulpCoreObject.browserName == "Explorer") { // IE can install via the CAB return true; } else if (pulpCoreObject.browserName == "Safari" && pulpCoreObject.osName == "Windows") { // Can't detect the version - let Safari on Windows handle it return true; } else if (pulpCoreObject.browserName == "Safari" && navigator.plugins && navigator.plugins.length) { for (var i = 0; i < navigator.plugins.length; i++) { var s = navigator.plugins[i].description; // Based on code from the Deployment Toolkit if (s.search(/^Java Switchable Plug-in/) != -1) { return true; } var m = s.match(/^Java (1\.4\.2|1\.5|1\.6|1\.7).* Plug-in/); if (m !== null) { version = m[1]; if (pulpCoreObject.isAcceptableJREVersion(version)) { return true; } } } return false; } else if (navigator.mimeTypes && navigator.mimeTypes.length && pulpCoreObject.browserIsMozillaFamily) { if (pulpcore_getCookie("javaRecentlyInstalled") == "true") { return true; } version = pulpCoreObject.getHighestInstalledJavaViaMimeTypes(); return pulpCoreObject.isAcceptableJREVersion(version); } else { // Couldn't detect - let the browser handle it return true; } }, getHighestInstalledJavaViaMimeTypes: function() { var version = "0.0"; var mimeType = "application/x-java-applet;version="; for (var i = 0; i < navigator.mimeTypes.length; i++) { var s = navigator.mimeTypes[i].type; if (s.substr(0, mimeType.length) == mimeType) { var testVersion = s.substr(mimeType.length); if (pulpCoreObject.compareVersions(testVersion, version) == 1) { version = testVersion; } } } return version; }, isAcceptableJREVersion: function(version) { var result = pulpCoreObject.compareVersions(version, pulpCoreObject.requiredJRE); return (result >= 0); }, /** Compares two versions in the form "x.x.x". Returns 1 if versionA is greater than versionB, -1 if versionA is less than versionB, and 0 if versionA is equal to versionB */ compareVersions: function(versionA, versionB) { // Make sure both versions are strings versionA += ''; versionB += ''; var a = versionA.split('.'); var b = versionB.split('.'); var len = Math.max(a.length, b.length); for (var i = 0; i < len; i++) { if (i >= a.length) { a[i] = 0; } if (i >= b.length) { b[i] = 0; } if (a[i] > b[i]) { return 1; } if (a[i] < b[i]) { return -1; } } return 0; }, installLatestJRE: function() { if (pulpCoreObject.shouldInstallXPI()) { pulpCoreObject.installXPI(); } return pulpCoreObject.getInstallHTML(); }, getInstallHTML: function() { var extraAttributes = ''; if (pulpCoreObject.shouldInstallXPI()) { extraAttributes = ' onclick="pulpCoreObject.installXPI();return false;"'; } return '

To play, ' + '' + 'install Java now.

\n'; }, shouldInstallXPI: function() { return pulpCoreObject.browserIsMozillaFamily && pulpCoreObject.osName == "Windows" && InstallTrigger && InstallTrigger.enabled(); }, installXPI: function() { // Note: The user needs to allow the domain to install the plugin. var xpi = { "Java Plug-in": pulpCoreObject.getJavaXPI }; InstallTrigger.install(xpi, pulpCoreObject.installXPIComplete); }, installXPIComplete: function(url, result) { var success = (result === 0); if (success) { // Set a session-only cookie (since Firefox doesn't refresh mime types) document.cookie = "javaRecentlyInstalled=true; path=/"; var version = pulpCoreObject.getHighestInstalledJavaViaMimeTypes().split('.'); if (version[0] == "1" && version[1] == "3") { // If Java 1.3 is previously installed, ask them to restart their browser. // Java 1.3 seems to "take over" and not allow the browser to use Java 6 until // Firefox is restarted. // TODO: re-evaluate if JRE 1.5 is defined as the minimum. Does JRE 1.4 also // "take over"? var install = document.getElementById('pulpcore_install'); install.innerHTML = "Java installed! To play, you may need to restart your browser."; } else { // If no Java previously installed, automagically start the game // (by reloading the page) location.href = document.location; } } }, // Browser detection // Based on a script from Peter-Paul Koch at QuirksMode: // http://www.quirksmode.org/js/detect.html // Up-to-date as of October 19, 2007 versionSearchString: "", browserName: "", browserVersion: "", browserIsMozillaFamily: false, osName: "", detectBrowser: function() { pulpCoreObject.browserName = pulpCoreObject.searchString(pulpCoreObject.dataBrowser) || "An unknown browser"; pulpCoreObject.browserVersion = pulpCoreObject.searchVersion(navigator.userAgent) || pulpCoreObject.searchVersion(navigator.appVersion) || "an unknown version"; pulpCoreObject.osName = pulpCoreObject.searchString(pulpCoreObject.dataOS) || "an unknown OS"; pulpCoreObject.browserIsMozillaFamily = pulpCoreObject.browserName == "Netscape" || pulpCoreObject.browserName == "Mozilla" || pulpCoreObject.browserName == "Firefox"; }, searchString: function(data) { for (var i = 0; i < data.length; i++) { var dataString = data[i].string; var dataProp = data[i].prop; pulpCoreObject.versionSearchString = data[i].versionSearch || data[i].identity; if (dataString) { if (dataString.indexOf(data[i].subString) != -1) { return data[i].identity; } } else if (dataProp) { return data[i].identity; } } }, searchVersion: function(dataString) { var index = dataString.indexOf(pulpCoreObject.versionSearchString); if (index == -1) { return; } return parseFloat(dataString.substring(index+pulpCoreObject.versionSearchString.length+1)); }, dataBrowser: [ { string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb" }, { string: navigator.vendor, subString: "Apple", identity: "Safari" }, { prop: window.opera, identity: "Opera" }, { string: navigator.vendor, subString: "iCab", identity: "iCab" }, { string: navigator.vendor, subString: "KDE", identity: "Konqueror" }, { string: navigator.userAgent, subString: "Firefox", identity: "Firefox" }, { string: navigator.vendor, subString: "Camino", identity: "Camino" }, { // for newer Netscapes (6+) string: navigator.userAgent, subString: "Netscape", identity: "Netscape" }, { string: navigator.userAgent, subString: "MSIE", identity: "Explorer", versionSearch: "MSIE" }, { string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv" }, { // for older Netscapes (4-) string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla" } ], dataOS: [ { string: navigator.platform, subString: "Win", identity: "Windows" }, { string: navigator.platform, subString: "Mac", identity: "Mac" }, { string: navigator.platform, subString: "Linux", identity: "Linux" } ] }; pulpCoreObject.write();