123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680 |
- /**
- * @fileOverview
- * Defines UnityObject2
- */
- //TODO: No need to polute the global space, just transfer this control to a 'static' variable insite unityObject!
- /**
- * @namespace
- */
- //var unity = unity || {};
- // We store all unityObject instances in a global scope, needed for IE firstFrameCallback and other internal tasks.
- //unity.instances = [];
- //unity.instanceNumber = 0;
- /**
- * Object expected by the Java Installer. We can move those to UnityObject2 if we update the java Installer.
- */
- var unityObject = {
- /**
- * Callback used bt the Java installer to notify the Install Complete.
- * @private
- * @param {String} id
- * @param {bool} success
- * @param {String} errormessage
- */
- javaInstallDone : function (id, success, errormessage) {
- var instanceId = parseInt(id.substring(id.lastIndexOf('_') + 1), 10);
- if (!isNaN(instanceId)) {
- // javaInstallDoneCallback must not be called directly because it deadlocks google chrome
- setTimeout(function () {
- UnityObject2.instances[instanceId].javaInstallDoneCallback(id, success, errormessage);
- }, 10);
- }
- }
- };
- /**
- * @class
- * @constructor
- */
- var UnityObject2 = function (config) {
- /** @private */
- var logHistory = [],
- win = window,
- doc = document,
- nav = navigator,
- instanceNumber = null,
- //domLoaded = false,
- //domLoadEvents = [],
- embeddedObjects = [], //Could be removed?
- //listeners = [],
- //styleSheet = null,
- //styleSheetMedia = null,
- //autoHideShow = true,
- //fullSizeMissing = true,
- useSSL = (document.location.protocol == 'https:'), //This will turn off enableUnityAnalytics, since enableUnityAnalytics don't have a https version.
- baseDomain = useSSL ? "https://ssl-webplayer.unity3d.com/" : "http://webplayer.unity3d.com/",
- triedJavaCookie = "_unity_triedjava",
- triedJavaInstall = _getCookie(triedJavaCookie),
- triedClickOnceCookie = "_unity_triedclickonce",
- triedClickOnce = _getCookie(triedClickOnceCookie),
- progressCallback = false,
- applets = [],
- //addedClickOnce = false,
- googleAnalyticsLoaded = false,
- googleAnalyticsCallback = null,
- latestStatus = null,
- lastType = null,
- //beginCallback = [],
- //preCallback = [],
- imagesToWaitFor = [],
- //referrer = null,
- pluginStatus = null,
- pluginStatusHistory = [],
- installProcessStarted = false, //not used anymore?
- kInstalled = "installed",
- kMissing = "missing",
- kBroken = "broken",
- kUnsupported = "unsupported",
- kReady = "ready", //not used anymore?
- kStart = "start",
- kError = "error",
- kFirst = "first",
- //kStandard = "standard",
- kJava = "java",
- kClickOnce = "clickonce", //not used anymore?
- wasMissing = false, //identifies if this is a install attempt, or if the plugin was already installed
- unityObject = null, //The <embed> or <object> for the webplayer. This can be used for webPlayer communication.
- //kApplet = "_applet",
- //kBanner = "_banner",
- cfg = {
- pluginName : "Unity Player",
- pluginMimeType : "application/vnd.unity",
- baseDownloadUrl : baseDomain + "download_webplayer-3.x/",
- fullInstall : false,
- autoInstall : false,
- enableJava : true,
- enableJVMPreloading : false,
- enableClickOnce : true,
- enableUnityAnalytics : false,
- enableGoogleAnalytics : true,
- params : {},
- attributes : {},
- referrer : null,
- debugLevel : 0
- };
- // Merge in the given configuration and override defaults.
- cfg = jQuery.extend(true, cfg, config);
- if (cfg.referrer === "") {
- cfg.referrer = null;
- }
- //enableUnityAnalytics does not support SSL yet.
- if (useSSL) {
- cfg.enableUnityAnalytics = false;
- }
- /**
- * Get cookie value
- * @private
- * @param {String} name The param name
- * @return string or false if non-existing.
- */
- function _getCookie(name) {
- var e = new RegExp(escape(name) + "=([^;]+)");
- if (e.test(doc.cookie + ";")) {
- e.exec(doc.cookie + ";");
- return RegExp.$1;
- }
- return false;
- }
- /**
- * Sets session cookie
- * @private
- */
- function _setSessionCookie(name, value) {
-
- document.cookie = escape(name) + "=" + escape(value) + "; path=/";
- }
- /**
- * Converts unity version to number (used for version comparison)
- * @private
- */
- function _getNumericUnityVersion(version) {
- var result = 0,
- major,
- minor,
- fix,
- type,
- release;
- if (version) {
- var m = version.toLowerCase().match(/^(\d+)(?:\.(\d+)(?:\.(\d+)([dabfr])?(\d+)?)?)?$/);
- if (m && m[1]) {
- major = m[1];
- minor = m[2] ? m[2] : 0;
- fix = m[3] ? m[3] : 0;
- type = m[4] ? m[4] : 'r';
- release = m[5] ? m[5] : 0;
- result |= ((major / 10) % 10) << 28;
- result |= (major % 10) << 24;
- result |= (minor % 10) << 20;
- result |= (fix % 10) << 16;
- result |= {d: 2 << 12, a: 4 << 12, b: 6 << 12, f: 8 << 12, r: 8 << 12}[type];
- result |= ((release / 100) % 10) << 8;
- result |= ((release / 10) % 10) << 4;
- result |= (release % 10);
- }
- }
-
- return result;
- }
- /**
- * Gets plugin and unity versions (non-ie)
- * @private
- */
- function _getPluginVersion(callback, versions) {
-
- var b = doc.getElementsByTagName("body")[0];
- var ue = doc.createElement("object");
- var i = 0;
-
- if (b && ue) {
- ue.setAttribute("type", cfg.pluginMimeType);
- ue.style.visibility = "hidden";
- b.appendChild(ue);
- var count = 0;
-
- (function () {
- if (typeof ue.GetPluginVersion === "undefined") {
-
- if (count++ < 10) {
-
- setTimeout(arguments.callee, 10);
- } else {
-
- b.removeChild(ue);
- callback(null);
- }
- } else {
-
- var v = {};
-
- if (versions) {
-
- for (i = 0; i < versions.length; ++i) {
-
- v[versions[i]] = ue.GetUnityVersion(versions[i]);
- }
- }
-
- v.plugin = ue.GetPluginVersion();
- b.removeChild(ue);
- callback(v);
- }
- })();
-
- } else {
-
- callback(null);
- }
- }
-
- /**
- * Retrieves windows installer name
- * @private
- */
- function _getWinInstall() {
-
- var url = cfg.fullInstall ? "UnityWebPlayerFull.exe" : "UnityWebPlayer.exe";
-
- if (cfg.referrer !== null) {
-
- url += "?referrer=" + cfg.referrer;
- }
- return url;
- }
- /**
- * Retrieves mac plugin package name
- * @private
- */
- function _getOSXInstall() {
-
- var url = "UnityPlayer.plugin.zip";
-
- if (cfg.referrer != null) {
-
- url += "?referrer=" + cfg.referrer;
- }
- return url;
- }
- /**
- * retrieves installer name
- * @private
- */
- function _getInstaller() {
-
- return cfg.baseDownloadUrl + (ua.win ? _getWinInstall() : _getOSXInstall() );
- }
- /**
- * sets plugin status
- * @private
- */
- function _setPluginStatus(status, type, data, url) {
-
- if (status === kMissing){
- wasMissing = true;
- }
-
- // debug('setPluginStatus() status:', status, 'type:', type, 'data:', data, 'url:', url);
- // only report to analytics the first time a status occurs.
- if ( jQuery.inArray(status, pluginStatusHistory) === -1 ) {
-
- //Only send analytics for plugins installs. Do not send if plugin is already installed.
- if (wasMissing) {
- _an.send(status, type, data, url);
- }
- pluginStatusHistory.push(status);
- }
- pluginStatus = status;
- }
- /**
- * Contains browser and platform properties
- * @private
- */
- var ua = function () {
-
- var a = nav.userAgent, p = nav.platform;
- var chrome = /chrome/i.test(a);
- var ua = {
- w3 : typeof doc.getElementById != "undefined" && typeof doc.getElementsByTagName != "undefined" && typeof doc.createElement != "undefined",
- win : p ? /win/i.test(p) : /win/i.test(a),
- mac : p ? /mac/i.test(p) : /mac/i.test(a),
- ie : /msie/i.test(a) ? parseFloat(a.replace(/^.*msie ([0-9]+(\.[0-9]+)?).*$/i, "$1")) : false,
- ff : /firefox/i.test(a),
- op : /opera/i.test(a),
- ch : chrome,
- ch_v : /chrome/i.test(a) ? parseFloat(a.replace(/^.*chrome\/(\d+(\.\d+)?).*$/i, "$1")) : false,
- sf : /safari/i.test(a) && !chrome,
- wk : /webkit/i.test(a) ? parseFloat(a.replace(/^.*webkit\/(\d+(\.\d+)?).*$/i, "$1")) : false,
- x64 : /win64/i.test(a) && /x64/i.test(a),
- moz : /mozilla/i.test(a) ? parseFloat(a.replace(/^.*mozilla\/([0-9]+(\.[0-9]+)?).*$/i, "$1")) : 0,
- mobile: /ipad/i.test(p) || /iphone/i.test(p) || /ipod/i.test(p) || /android/i.test(a) || /windows phone/i.test(a)
- };
-
- ua.clientBrand = ua.ch ? 'ch' : ua.ff ? 'ff' : ua.sf ? 'sf' : ua.ie ? 'ie' : ua.op ? 'op' : '??';
- ua.clientPlatform = ua.win ? 'win' : ua.mac ? 'mac' : '???';
-
- // get base url
- var s = doc.getElementsByTagName("script");
-
- for (var i = 0; i < s.length; ++i) {
-
- var m = s[i].src.match(/^(.*)3\.0\/uo\/UnityObject2\.js$/i);
-
- if (m) {
-
- cfg.baseDownloadUrl = m[1];
- break;
- }
- }
-
- /**
- * compares two versions
- * @private
- */
- function _compareVersions(v1, v2) {
-
- for (var i = 0; i < Math.max(v1.length, v2.length); ++i) {
- var n1 = (i < v1.length) && v1[i] ? new Number(v1[i]) : 0;
- var n2 = (i < v2.length) && v2[i] ? new Number(v2[i]) : 0;
- if (n1 < n2) return -1;
- if (n1 > n2) return 1;
- }
- return 0;
- };
-
- /**
- * detect java
- */
- ua.java = function () {
-
- if (nav.javaEnabled()) {
-
- var wj = (ua.win && ua.ff);
- var mj = false;//(ua.mac && (ua.ff || ua.ch || ua.sf));
-
- if (wj || mj) {
-
- if (typeof nav.mimeTypes != "undefined") {
-
- var rv = wj ? [1, 6, 0, 12] : [1, 4, 2, 0];
-
- for (var i = 0; i < nav.mimeTypes.length; ++i) {
-
- if (nav.mimeTypes[i].enabledPlugin) {
-
- var m = nav.mimeTypes[i].type.match(/^application\/x-java-applet;(?:jpi-)?version=(\d+)(?:\.(\d+)(?:\.(\d+)(?:_(\d+))?)?)?$/);
-
- if (m != null) {
-
- if (_compareVersions(rv, m.slice(1)) <= 0) {
-
- return true;
- }
- }
- }
- }
- }
- } else if (ua.win && ua.ie) {
- if (typeof ActiveXObject != "undefined") {
-
- /**
- * ActiveX Test
- */
- function _axTest(v) {
-
- try {
-
- return new ActiveXObject("JavaWebStart.isInstalled." + v + ".0") != null;
- }
- catch (ex) {
-
- return false;
- }
- }
- /**
- * ActiveX Test 2
- */
- function _axTest2(v) {
-
- try {
-
- return new ActiveXObject("JavaPlugin.160_" + v) != null;
- } catch (ex) {
-
- return false;
- }
- }
-
- if (_axTest("1.7.0")) {
-
- return true;
- }
-
- if (ua.ie >= 8) {
-
- if (_axTest("1.6.0")) {
-
- // make sure it's 1.6.0.12 or newer. increment 50 to a larger value if 1.6.0.50 is released
- for (var i = 12; i <= 50; ++i) {
-
- if (_axTest2(i)) {
-
- if (ua.ie == 9 && ua.moz == 5 && i < 24) {
- // when IE9 is not in compatibility mode require at least
- // Java 1.6.0.24: http://support.microsoft.com/kb/2506617
- continue;
- } else {
-
- return true;
- }
- }
- }
-
- return false;
- }
- } else {
-
- return _axTest("1.6.0") || _axTest("1.5.0") || _axTest("1.4.2");
- }
- }
- }
- }
-
- return false;
- }();
-
- // detect clickonce
- ua.co = function () {
-
- if (ua.win && ua.ie) {
- var av = a.match(/(\.NET CLR [0-9.]+)|(\.NET[0-9.]+)/g);
- if (av != null) {
- var rv = [3, 5, 0];
- for (var i = 0; i < av.length; ++i) {
- var versionNumbers = av[i].match(/[0-9.]{2,}/g)[0].split(".");
- if (_compareVersions(rv, versionNumbers) <= 0) {
- return true;
- }
- }
- }
- }
- return false;
-
- }();
-
- return ua;
- }();
- /**
- * analytics
- * @private
- */
- var _an = function () {
- var uid = function () {
-
- var now = new Date();
- var utc = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDay(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds());
- return utc.toString(16) + _getRandomInt().toString(16);
- }();
- var seq = 0;
- var _ugaq = window["_gaq"] = ( window["_gaq"] || [] );
-
- _setUpAnalytics();
- /**
- * generates random integer number
- * @private
- */
- function _getRandomInt() {
- return Math.floor(Math.random() * 2147483647);
- }
-
- /**
- * Checks if there is a need to load analytics, by checking the existance of a _gaq object
- */
- function _setUpAnalytics() {
-
- var gaUrl = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- var ss = doc.getElementsByTagName("script");
- var googleAnalyticsLoaded = false;
- for (var i = 0; i < ss.length; ++i) {
- if (ss[i].src && ss[i].src.toLowerCase() == gaUrl.toLowerCase()) {
- googleAnalyticsLoaded = true;
- break;
- }
- }
-
- if (!googleAnalyticsLoaded) {
- var ga = doc.createElement("script");
- ga.type = "text/javascript";
- ga.async = true;
- ga.src = gaUrl;
- var s = document.getElementsByTagName("script")[0];
- s.parentNode.insertBefore(ga, s);
- }
-
- var gaAccount = (cfg.debugLevel === 0) ? 'UA-16068464-16' : 'UA-16068464-17';
-
- _ugaq.push(["unity._setDomainName", "none"]);
- _ugaq.push(["unity._setAllowLinker", true]);
- _ugaq.push(["unity._setReferrerOverride", ' '+this.location.toString()]);
- _ugaq.push(["unity._setAccount", gaAccount]);
- // $(GoogleRevisionPlaceholder)
- }
- /**
- * sends analytics data to unity
- * @private
- */
- function _sendUnityAnalytics(event, type, data, callback) {
- if (!cfg.enableUnityAnalytics) {
-
- if (callback) {
-
- callback();
- }
-
- return;
- }
-
- var url = "http://unityanalyticscapture.appspot.com/event?u=" + encodeURIComponent(uid) + "&s=" + encodeURIComponent(seq) + "&e=" + encodeURIComponent(event);
- // $(UnityRevisionPlaceholder)
-
- if (cfg.referrer !== null) {
-
- url += "?r=" + cfg.referrer;
- }
-
- if (type) {
-
- url += "&t=" + encodeURIComponent(type);
- }
-
- if (data) {
-
- url += "&d=" + encodeURIComponent(data);
- }
-
- var img = new Image();
-
- if (callback) {
-
- img.onload = img.onerror = callback;
- }
-
- img.src = url;
- }
- /**
- * sends analytics data to google
- * @private
- */
- function _sendGoogleAnalytics(event, type, data, callback) {
- if (!cfg.enableGoogleAnalytics) {
- if (callback) {
- callback();
- }
- return;
- }
- var url = "/webplayer/install/" + event;
- var join = "?";
- if (type) {
-
- url += join + "t=" + encodeURIComponent(type);
- join = "&";
- }
- if (data) {
-
- url += join + "d=" + encodeURIComponent(data);
- join = "&";
- }
- if (callback) {
-
- _ugaq.push(function () {
- setTimeout(callback,1000);
- //this.googleAnalyticsCallback = callback;
- });
- }
-
- //try to shorten the URL to fit into customVariable
- //it will try to replace the early directories to ..
- var gameUrl = cfg.src;
- if (gameUrl.length > 40) {
- gameUrl = gameUrl.replace("http://","");
- var paths = gameUrl.split("/");
-
- var gameUrlFirst = paths.shift();
- var gameUrlLast = paths.pop();
- gameUrl = gameUrlFirst + "/../"+ gameUrlLast;
-
- while(gameUrl.length < 40 && paths.length > 0) {
- var nextpath = paths.pop();
- if(gameUrl.length + nextpath.length + 5 < 40) {
- gameUrlLast = nextpath + "/" + gameUrlLast;
- } else {
- gameUrlLast = "../" + gameUrlLast;
- }
- gameUrl = gameUrlFirst + "/../"+ gameUrlLast;
- }
- }
- _ugaq.push(['unity._setCustomVar',
- 2, // This custom var is set to slot #1. Required parameter.
- 'GameURL', // The name acts as a kind of category for the user activity. Required parameter.
- gameUrl, // This value of the custom variable. Required parameter.
- 3 // Sets the scope to page-level. Optional parameter.
- ]);
- _ugaq.push(['unity._setCustomVar',
- 1, // This custom var is set to slot #1. Required parameter.
- 'UnityObjectVersion', // The name acts as a kind of category for the user activity. Required parameter.
- "2", // This value of the custom variable. Required parameter.
- 3 // Sets the scope to page-level. Optional parameter.
- ]);
- if (type) {
- _ugaq.push(['unity._setCustomVar',
- 3, // This custom var is set to slot #1. Required parameter.
- 'installMethod', // The name acts as a kind of category for the user activity. Required parameter.
- type, // This value of the custom variable. Required parameter.
- 3 // Sets the scope to page-level. Optional parameter.
- ]);
- }
- _ugaq.push(["unity._trackPageview", url]);
- }
- return {
- /**
- * sends analytics data. optionally opens url once data has been sent
- * @public
- */
- send : function (event, type, data, url) {
- if (cfg.enableUnityAnalytics || cfg.enableGoogleAnalytics) {
- debug('Analytics SEND', event, type, data, url);
- }
- ++seq;
- var count = 2;
- var callback = function () {
- if (0 == --count) {
- googleAnalyticsCallback = null;
- window.location = url;
- }
- }
-
- if (data === null || data === undefined) {
- data = "";
- }
- _sendUnityAnalytics(event, type, data, url ? callback : null);
- _sendGoogleAnalytics(event, type, data, url ? callback : null);
- }
- };
- }();
-
-
-
-
-
- /* Java Install - BEGIN */
- /**
- * @private
- */
- function _createObjectElement(attributes, params, elementToReplace) {
-
- var i,
- at,
- pt,
- ue,
- pe;
-
- if (ua.win && ua.ie) {
-
- at = "";
-
- for (i in attributes) {
-
- at += ' ' + i + '="' + attributes[i] + '"';
- }
-
- pt = "";
-
- for (i in params) {
-
- pt += '<param name="' + i + '" value="' + params[i] + '" />';
- }
-
- elementToReplace.outerHTML = '<object' + at + '>' + pt + '</object>';
-
- } else {
-
- ue = doc.createElement("object");
-
- for (i in attributes) {
-
- ue.setAttribute(i, attributes[i]);
- }
-
- for (i in params) {
-
- pe = doc.createElement("param");
- pe.name = i;
- pe.value = params[i];
- ue.appendChild(pe);
- }
-
- elementToReplace.parentNode.replaceChild(ue, elementToReplace);
- }
- }
-
- /**
- * @private
- */
- function _checkImage(img) {
-
- // img element not in the DOM yet
- if (typeof img == "undefined") {
-
- return false;
- }
-
- if (!img.complete) {
-
- return false;
- }
-
- // some browsers always return true in img.complete, for those
- // we can check naturalWidth
- if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
-
- return false;
- }
-
- // no other way of checking, assuming it is ok
- return true;
- }
- /**
- * @private
- */
- function _preloadJVMWhenReady(id) {
-
- var needToWait = false;
-
- for (var i = 0; i < imagesToWaitFor.length; i++) {
- if (!imagesToWaitFor[i]) {
- continue;
- }
- var img = doc.images[imagesToWaitFor[i]];
- if (!_checkImage(img)) {
- needToWait = true;
- }
- else {
- imagesToWaitFor[i] = null;
- }
- }
- if (needToWait) {
- // check again in 100ms
- setTimeout(arguments.callee, 100);
- }
- else {
- // preload after a small delay, to make sure
- // the images have actually rendered
- setTimeout(function () {
- _preloadJVM(id);
- }, 100);
- }
- }
- /**
- * preloads the JVM and the Java Plug-in
- * @private
- */
- function _preloadJVM(id) {
-
- var re = doc.getElementById(id);
-
- if (!re) {
-
- re = doc.createElement("div");
- var lastBodyElem = doc.body.lastChild;
- doc.body.insertBefore(re, lastBodyElem.nextSibling);
- }
-
- var codebase = cfg.baseDownloadUrl + "3.0/jws/";
-
- var a = {
- id : id,
- type : "application/x-java-applet",
- code : "JVMPreloader",
- width : 1,
- height : 1,
- name : "JVM Preloader"
- };
-
- var p = {
- context : id,
- codebase : codebase,
- classloader_cache : false,
- scriptable : true,
- mayscript : true
- };
-
- _createObjectElement(a, p, re);
- jQuery('#' + id).show();
- //setVisibility(id, true);
- }
-
- /**
- * launches java installer
- * @private
- */
- function _doJavaInstall(id) {
-
- triedJavaInstall = true;
- _setSessionCookie(triedJavaCookie, triedJavaInstall);
- var re = doc.getElementById(id);
- var appletID = id + "_applet_" + instanceNumber;
-
- applets[appletID] = {
- attributes : cfg.attributes,
- params : cfg.params,
- callback : cfg.callback,
- broken : cfg.broken
- };
-
- var applet = applets[appletID];
-
- var a = {
- id : appletID,
- type : "application/x-java-applet",
- archive : cfg.baseDownloadUrl + "3.0/jws/UnityWebPlayer.jar",
- code : "UnityWebPlayer",
- width : 1,
- height : 1,
- name : "Unity Web Player"
- };
-
- if (ua.win && ua.ff) {
-
- a["style"] = "visibility: hidden;";
- }
-
- var p = {
- context : appletID,
- jnlp_href : cfg.baseDownloadUrl + "3.0/jws/UnityWebPlayer.jnlp",
- classloader_cache : false,
- installer : _getInstaller(),
- image : baseDomain + "installation/unitylogo.png",
- centerimage : true,
- boxborder : false,
- scriptable : true,
- mayscript : true
- };
-
- for (var i in applet.params) {
-
- if (i == "src") {
-
- continue;
- }
-
- if (applet.params[i] != Object.prototype[i]) {
-
- p[i] = applet.params[i];
-
- if (i.toLowerCase() == "logoimage") {
-
- p["image"] = applet.params[i];
- }
- else if (i.toLowerCase() == "backgroundcolor") {
-
- p["boxbgcolor"] = "#" + applet.params[i];
- }
- else if (i.toLowerCase() == "bordercolor") {
-
- // there's no way to specify border color
- p["boxborder"] = true;
- }
- else if (i.toLowerCase() == "textcolor") {
-
- p["boxfgcolor"] = "#" + applet.params[i];
- }
- }
- }
- // Create a dummy div element in the unityPlayer div
- // so that it can be replaced with the 1x1 px applet.
- // The applet will be resized when it has fully loaded,
- // see appletStarted().
- var divToBeReplacedWithApplet = doc.createElement("div");
- re.appendChild(divToBeReplacedWithApplet);
- _createObjectElement(a, p, divToBeReplacedWithApplet);
- jQuery('#' + id).show();
- //setVisibility(appletID, true);
- }
-
- /**
- * @private
- */
- function _jvmPreloaded(id) {
-
- // timeout prevents crash on ie
- setTimeout(function () {
-
- var re = doc.getElementById(id);
-
- if (re) {
- re.parentNode.removeChild(re);
- }
- }, 0);
- }
-
- /**
- * @private
- */
- function _appletStarted(id) {
- // set the size of the applet to the one from cloned attributes
- var applet = applets[id],
- appletElement = doc.getElementById(id),
- childNode;
- // the applet might have already finished by now
- if (!appletElement) {
-
- return;
- }
-
- appletElement.width = applet.attributes["width"] || 600;
- appletElement.height = applet.attributes["height"] || 450;
- // remove all the siblings of the applet
- var parentNode = appletElement.parentNode;
- var childNodeList = parentNode.childNodes;
-
- for (var i = 0; i < childNodeList.length; i++) {
-
- childNode = childNodeList[i];
- // Compare the child node with our applet element only if
- // it has the same type. Doing the comparison in other cases just
- // jumps out of the loop.
- if (childNode.nodeType == 1 && childNode != appletElement) {
-
- parentNode.removeChild(childNode);
- }
- }
- }
-
-
- // java installation callback
- function _javaInstallDoneCallback(id, success, errormessage) {
-
- debug('_javaInstallDoneCallback', id, success, errormessage);
- //console.log('javaInstallDoneCallback', id, success, errormessage);
-
- if (!success) {
-
- //var applet = applets[id];
- _setPluginStatus(kError, kJava, errormessage);
- //createMissingUnity(id, applet.attributes, applet.params, applet.callback, applet.broken, kJava, errormessage);
- }
- }
-
- /* Java Install - END */
-
- /**
- * @private
- */
- function log() {
-
- logHistory.push(arguments);
-
- if ( cfg.debugLevel > 0 && window.console && window.console.log ) {
-
- console.log(Array.prototype.slice.call(arguments));
- //console.log.apply(console, Array.prototype.slice.call(arguments));
- }
- }
-
- /**
- * @private
- */
- function debug() {
-
- logHistory.push(arguments);
-
- if ( cfg.debugLevel > 1 && window.console && window.console.log ) {
-
- console.log(Array.prototype.slice.call(arguments));
- //console.log.apply(console, Array.prototype.slice.call(arguments));
- }
- }
-
- /**
- * appends px to the value if it's a plain number
- * @private
- */
- function _appendPX(value) {
-
- if (/^[-+]?[0-9]+$/.test(value)) {
- value += "px";
- }
- return value;
- }
-
- var publicAPI = /** @lends UnityObject2.prototype */ {
- /**
- * Get Debug Level (0=Disabled)
- * @public
- * @return {Number} Debug Level
- */
- getLogHistory: function () {
-
- return logHistory; // JSON.stringify()
- },
- /**
- * Get configuration object
- * @public
- * @return {Object} cfg
- */
- getConfig: function () {
-
- return cfg; // JSON.stringify()
- },
- /**
- * @public
- * @return {Object} detailed info about OS and Browser.
- */
- getPlatformInfo: function () {
-
- return ua;
- },
- /**
- * Initialize plugin config and proceed with attempting to start the webplayer.
- * @public
- */
- initPlugin: function (targetEl, src) {
- cfg.targetEl = targetEl;
- cfg.src = src;
- debug('ua:', ua);
- //console.debug('initPlugin this:', this);
- this.detectUnity(this.handlePluginStatus);
- },
-
- /**
- * detects unity web player.
- * @public
- * callback - accepts two parameters.
- * first one contains "installed", "missing", "broken" or "unsupported" value.
- * second one returns requested unity versions. plugin version is included as well.
- * versions - optional array of unity versions to detect.
- */
- detectUnity: function (callback, versions) {
- // console.debug('detectUnity this:', this);
- var self = this;
- var status = kMissing;
- var data;
- nav.plugins.refresh();
-
- if (ua.clientBrand === "??" || ua.clientPlatform === "???" || ua.mobile ) {
- status = kUnsupported;
- } else if (ua.op && ua.mac) { // Opera on MAC is unsupported
- status = kUnsupported;
- data = "OPERA-MAC";
- } else if (
- typeof nav.plugins != "undefined"
- && nav.plugins[cfg.pluginName]
- && typeof nav.mimeTypes != "undefined"
- && nav.mimeTypes[cfg.pluginMimeType]
- && nav.mimeTypes[cfg.pluginMimeType].enabledPlugin
- ) {
- status = kInstalled;
- // make sure web player is compatible with 64-bit safari
- if (ua.sf && /Mac OS X 10_6/.test(nav.appVersion)) {
- _getPluginVersion(function (version) {
- if (!version || !version.plugin) {
- status = kBroken;
- data = "OSX10.6-SFx64";
- }
- _setPluginStatus(status, lastType, data);
- callback.call(self, status, version);
- }, versions);
- return;
- } else if (ua.mac && ua.ch) { // older versions have issues on chrome
- _getPluginVersion(function (version) {
- if (version && (_getNumericUnityVersion(version.plugin) <= _getNumericUnityVersion("2.6.1f3"))) {
- status = kBroken;
- data = "OSX-CH-U<=2.6.1f3";
- }
- _setPluginStatus(status, lastType, data);
- callback.call(self, status, version);
- }, versions);
- return;
- } else if (versions) {
- _getPluginVersion(function (version) {
- _setPluginStatus(status, lastType, data);
- callback.call(self, status, version);
- }, versions);
- return;
- }
- } else if (typeof win.ActiveXObject != "undefined") {
- try {
- var uo = new ActiveXObject("UnityWebPlayer.UnityWebPlayer.1");
- var pv = uo.GetPluginVersion();
- if (versions) {
- var v = {};
- for (var i = 0; i < versions.length; ++i) {
- v[versions[i]] = uo.GetUnityVersion(versions[i]);
- }
- v.plugin = pv;
- }
- status = kInstalled;
- // 2.5.0 auto update has issues on vista and later
- if (pv == "2.5.0f5") {
- var m = /Windows NT \d+\.\d+/.exec(nav.userAgent);
- if (m && m.length > 0) {
- var wv = parseFloat(m[0].split(' ')[2]);
- if (wv >= 6) {
- status = kBroken;
- data = "WIN-U2.5.0f5";
- }
- }
- }
- } catch (ex) {
- if (ua.win && ua.ie && ua.x64) {
- status = kUnsupported;
- data = "WIN-IEx64";
- }
- }
- }
- _setPluginStatus(status, lastType, data);
- callback.call(self, status, v);
- },
- /**
- * @public
- * @return {Object} with info about Unity WebPlayer plugin status (not installed, loading, running etc..)
- */
- handlePluginStatus: function (status, versions) {
-
- // Store targetEl in the closure, to be able to get it back if setTimeout calls again.
- var targetEl = cfg.targetEl;
- var $targetEl = jQuery(targetEl);
- switch(status) {
- case kInstalled:
- // @todo add support for alternate custom handlers.
- this.notifyProgress($targetEl);
- this.embedPlugin($targetEl, cfg.callback);
- break;
- case kMissing:
- this.notifyProgress($targetEl);
- //this.installPlugin($targetEl);
- var self = this;
- var delayTime = (cfg.debugLevel === 0) ? 1000 : 8000;
-
- // Do a delay and re-check for plugin
- setTimeout(function () {
-
- cfg.targetEl = targetEl;
- self.detectUnity(self.handlePluginStatus);
- }, delayTime);
-
- break;
- case kBroken:
- // Browser needs to restart after install
- this.notifyProgress($targetEl);
- break;
- case kUnsupported:
- this.notifyProgress($targetEl);
- break;
- }
- },
- /**
- * @public
- * @return {Object} with detailed plugin info, version number and other info that can be retrieved from the plugin.
- */
- /*getPluginInfo: function () {
-
- },*/
- /**
- * @public
- */
- getPluginURL: function () {
- var url = "http://unity3d.com/webplayer/";
- if (ua.win) {
- url = cfg.baseDownloadUrl + _getWinInstall();
- } else if (nav.platform == "MacIntel") {
- url = cfg.baseDownloadUrl + (cfg.fullInstall ? "webplayer-i386.dmg" : "webplayer-mini.dmg");
- if (cfg.referrer !== null) {
- url += "?referrer=" + cfg.referrer;
- }
- } else if (nav.platform == "MacPPC") {
- url = cfg.baseDownloadUrl + (cfg.fullInstall ? "webplayer-ppc.dmg" : "webplayer-mini.dmg");
- if (cfg.referrer !== null) {
- url += "?referrer=" + cfg.referrer;
- }
- }
- return url;
- },
-
- /**
- * @public
- */
- getClickOnceURL: function () {
-
- return cfg.baseDownloadUrl + "3.0/co/UnityWebPlayer.application?installer=" + encodeURIComponent(cfg.baseDownloadUrl + _getWinInstall());
- },
- /**
- * Embed the plugin into the DOM.
- * @public
- */
- embedPlugin: function (targetEl, callback) {
-
- targetEl = jQuery(targetEl).empty();
-
- var src = cfg.src; //targetEl.data('src'),
- var width = cfg.width || "100%"; //TODO: extract those hardcoded values
- var height = cfg.height || "100%";
- var self = this;
- if (ua.win && ua.ie) {
- // ie, dom and object element do not mix & match
-
- var at = "";
-
- for (var i in cfg.attributes) {
- if (cfg.attributes[i] != Object.prototype[i]) {
- if (i.toLowerCase() == "styleclass") {
- at += ' class="' + cfg.attributes[i] + '"';
- }
- else if (i.toLowerCase() != "classid") {
- at += ' ' + i + '="' + cfg.attributes[i] + '"';
- }
- }
- }
-
- var pt = "";
- // we manually add SRC here, because its now defined on the target element.
- pt += '<param name="src" value="' + src + '" />';
- pt += '<param name="firstFrameCallback" value="UnityObject2.instances[' + instanceNumber + '].firstFrameCallback();" />';
- for (var i in cfg.params) {
-
- if (cfg.params[i] != Object.prototype[i]) {
-
- if (i.toLowerCase() != "classid") {
-
- pt += '<param name="' + i + '" value="' + cfg.params[i] + '" />';
- }
- }
- }
- //var tmpHtml = '<div id="' + targetEl.attr('id') + '" style="width: ' + _appendPX(width) + '; height: ' + _appendPX(height) + ';"><object classid="clsid:444785F1-DE89-4295-863A-D46C3A781394" style="display: block; width: 100%; height: 100%;"' + at + '>' + pt + '</object></div>';
- var tmpHtml = '<object classid="clsid:444785F1-DE89-4295-863A-D46C3A781394" style="display: block; width: ' + _appendPX(width) + '; height: ' + _appendPX(height) + ';"' + at + '>' + pt + '</object>';
- var $object = jQuery(tmpHtml);
- targetEl.append( $object );
- embeddedObjects.push( targetEl.attr('id') );
- unityObject = $object[0];
- } else {
- // Create and append embed element into DOM.
- var $embed = jQuery('<embed/>')
- .attr({
- src: src,
- type: cfg.pluginMimeType,
- width: width,
- height: height,
- firstFrameCallback: 'UnityObject2.instances[' + instanceNumber + '].firstFrameCallback();'
- })
- .attr(cfg.attributes)
- .attr(cfg.params)
- .css({
- display: 'block',
- width: _appendPX(width),
- height: _appendPX(height)
- })
- .appendTo( targetEl );
- unityObject = $embed[0];
- }
-
- //Auto focus the new object/embed, so players dont have to click it before using it.
- //setTimeout is here to workaround a chrome bug.
- //we should not invoke focus on safari on mac. it causes some Input bugs.
- if (!ua.sf || !ua.mac) {
- setTimeout(function() {
- unityObject.focus();
- }, 100);
- }
- if (callback) {
-
- callback();
- }
- },
-
- /**
- * Determine which installation method to use on the current platform, and return an array with their identifiers (i.e. 'ClickOnceIE', 'JavaInstall', 'Manual')
- * Take into account which previous methods might have been attempted (and failed) and skip to next best method.
- * @public
- * @return {String}
- */
- getBestInstallMethod: function () {
-
- // Always fall back to good old manual (download) install.
- var method = 'Manual';
-
- // Is Java available and not yet attempted?
- if (cfg.enableJava && ua.java && triedJavaInstall === false) {
-
- method = 'JavaInstall';
- }
- // Is ClickOnce available and not yet attempted?
- else if (cfg.enableClickOnce && ua.co && triedClickOnce === false) {
-
- method = 'ClickOnceIE';
- }
- return method;
- },
-
- /**
- * Tries to install the plugin using the specified method.
- * If no method is passed, it will try to use this.getBestInstallMethod()
- * @public
- * @param {String} method The desired install method
- */
- installPlugin: function(method) {
- if (method == null || method == undefined) {
- method = this.getBestInstallMethod();
- }
-
- var urlToOpen = null;
- switch(method) {
- case "JavaInstall":
- this.doJavaInstall(cfg.targetEl.id);
- break;
- case "ClickOnceIE":
- //urlToOpen = this.getClickOnceURL();
- //window.location = urlToOpen;
- var $iframe = jQuery("<iframe src='" + this.getClickOnceURL() + "' style='display:none;' />");
- jQuery(cfg.targetEl).append($iframe);
- break;
- default:
- case "Manual":
- //doc.location = this.getPluginURL();
- //urlToOpen = this.getPluginURL();
- var $iframe = jQuery("<iframe src='" + this.getPluginURL() + "' style='display:none;' />");
- jQuery(cfg.targetEl).append($iframe);
- break;
- }
-
- lastType = method;
- _an.send(kStart, method, null, null);
-
- },
- /**
- * Trigger event using jQuery(document).trigger()
- * @public
- */
- //TODO: verify its use.
- trigger: function (event, params) {
- if (params) {
-
- debug('trigger("' + event + '")', params);
-
- } else {
-
- debug('trigger("' + event + '")');
- }
-
- jQuery(document).trigger(event, params);
- },
- /**
- * Notify observers about onProgress event
- * @public
- */
- notifyProgress: function (targetEl) {
-
- //debug('*** notifyProgress ***')
-
- if (typeof progressCallback !== "undefined" && typeof progressCallback === "function") {
-
- var payload = {
-
- ua: ua,
- pluginStatus: pluginStatus,
- bestMethod: null,
- lastType: lastType,
- targetEl: cfg.targetEl,
- unityObj: this
- };
-
- if (pluginStatus === kMissing) {
-
- payload.bestMethod = this.getBestInstallMethod();
- }
-
- if (latestStatus !== pluginStatus) { //Execute only on state change
- latestStatus = pluginStatus;
-
- progressCallback(payload);
- }
- }
- },
- /**
- * Subscribe to onProgress notification
- * @public
- */
- observeProgress: function (callback) {
-
- progressCallback = callback;
- },
-
-
- /**
- * Callback made by the WebPlayer plugin when the first frame is rendered.
- * @public
- */
- firstFrameCallback : function () {
-
- debug('*** firstFrameCallback (' + instanceNumber + ') ***');
- pluginStatus = kFirst;
- this.notifyProgress();
-
- /*
- // What?
- if (status == kFirst) {
- if (pluginStatus == null) {
- return;
- }
- }
- */
- //Webplayer was already installed.
- //Should only log firstframes if it happened after a install.
- if (wasMissing === true) {
- _an.send(pluginStatus, lastType);
- }
-
- //setRunStatus(kFirst, lastType);
- },
- /**
- * Get a string from a session cookie or SessionStorage
- * @public
- * @return {String}
- */
- /*getSessionString: function (key) {
-
- },*/
- /**
- * Set a string via a session cookie or SessionStorage
- * @public
- */
- /* setSessionString: function (key, value) {
-
- },*/
-
- /**
- * Get a string from a persistent cookie
- * @public
- * @return {String}
- */
- /*getCookie: function (key) {
-
- },*/
-
- /**
- * Set a string to a persistent cookie
- * @public
- */
- /*setCookie: function (key, value, expiryDate) {
-
- },*/
-
- /**
- * Exposed private function
- * @public
- */
- setPluginStatus: function (status, type, data, url) {
-
- _setPluginStatus(status, type, data, url);
- },
-
- /**
- * Exposed private function
- * @public
- */
- doJavaInstall : function (id) {
-
- _doJavaInstall(id);
- },
-
- /**
- * Exposed private function
- * @public
- */
- jvmPreloaded : function (id) {
-
- _jvmPreloaded(id);
- },
-
- /**
- * Exposed private function
- * @public
- */
- appletStarted : function (id) {
-
- _appletStarted(id);
- },
-
- /**
- * Exposed private function
- * @public
- */
- javaInstallDoneCallback : function (id, success, errormessage) {
- _javaInstallDoneCallback(id, success, errormessage);
- },
-
- getUnity: function() {
- return unityObject;
- }
- }
-
- // Internal store of each instance.
- instanceNumber = UnityObject2.instances.length;
- UnityObject2.instances.push(publicAPI);
-
- return publicAPI;
- };
- /**
- * @static
- **/
- UnityObject2.instances = [];
|