/*******************************************************************************/ // Leander Api Loader /*******************************************************************************/ // Check if LeanderGMApi is already loaded if (typeof(leanderGMApi) != "undefined" || typeof(leanderApiLoader) != "undefined"){ console.log("FATAL ERROR: LeanderApiLoader.php loaded more than once!"); }else{ // Define API properties and error catching functions var leanderGMApi = null; // Catch errors window.onerror = function(message, url, lineNumber, columnNumber, errorObject){ var data = "?"; if (message){ data += "m=" + encodeURIComponent(message); } if (url){ data += "&url=" + encodeURIComponent(url); } if (lineNumber){ data += "&ln=" + encodeURIComponent(lineNumber); } if (columnNumber){ data += "&cn=" + encodeURIComponent(columnNumber); } // Check if LeanderGMApi is initialized if (leanderGMApi && leanderGMApi.initialized){ // Add Session Data data += "&sid=" + leanderGMApi.getSessionId(); // Add Play Data data += "&pid=" + leanderGMApi.getCurrentPlayId(); // Get Preloading Status if (leanderGMApi.getPreloadEnded()){ data += "&pe=1"; }else{ data += "&pp=" + leanderGMApi.getPreloadProgress(); } // Get environent Properties var layoutVars = leanderGMApi.getEnvironmentProperties(); if (layoutVars){ data += "&lv=" + encodeURIComponent(btoa(JSON.stringify(layoutVars))); } } // Check if leanderApiLoader is initialized if (leanderApiLoader && leanderApiLoader.initialized){ // Add Game Data data += "&" + leanderApiLoader.getAllQueryParamValue(); } // Add navigator data data += "&nav=" + encodeURIComponent(navigator.userAgent.toString()); if (errorObject && errorObject.stack){ data += "&eos=" + encodeURIComponent(errorObject.stack); } // Send Data to Debug sendLeanderDebugData(data); return false; }; function sendLeanderDebugData(data){ // Send Data to Debug if (typeof(gameLeanderDebugErrorsJSData) == "undefined"){ // Resend when available setTimeout(function(){ sendLeanderDebugData(data); }, 500); }else if (gameLeanderDebugErrorsJSData){ var leanderAjaxCaller = LeanderCreateAjaxCaller(); leanderAjaxCaller.open("GET", leanderApiLoader.apiPath + "leandergmapi/5/LeanderErrorTracker.php" + data, true); leanderAjaxCaller.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); leanderAjaxCaller.withCredentials = true; leanderAjaxCaller.onreadystatechange = function(){}; leanderAjaxCaller.send(data); } } // Create Ajax Caller object function LeanderCreateAjaxCaller(){ var ajaxCaller = null; try { ajaxCaller = new XMLHttpRequest(); } catch (e) { try { ajaxCaller = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { try { ajaxCaller = new ActiveXObject("Msxml2.XMLHTTP"); } catch (E) { ajaxCaller = null; } } } return ajaxCaller; } } function LeanderApiLoader(){ // Get API Version this.version = '5.0.001'; this.initialized = false; // Define siteId variables this.queryString = document.location.search || document.location.hash; // Get siteId this.siteId = decodeURIComponent(this.getQueryParamValue("siteId")); // Get gameId this.gameId = decodeURIComponent(this.getQueryParamValue("gameId")); // Get gameMode this.gameMode = decodeURIComponent(this.getQueryParamValue("gameMode")); // Get locale this.locale = decodeURIComponent(this.getQueryParamValue("locale")); // Get channel this.channel = decodeURIComponent(this.getQueryParamValue("channel")); // Get Launcher Path this.launcherPath = decodeURIComponent(this.getQueryParamValue("launcherAddress")); // Get Api Path this.apiPath = decodeURIComponent(this.getQueryParamValue("apiAddress")); this.apiPathCasinoLoader = ""; this.scriptsLoaded = document.getElementsByTagName('script'); if (this.scriptsLoaded.length){ if (this.scriptsLoaded[this.scriptsLoaded.length - 1]){ // Get the current api path var scriptPath = this.scriptsLoaded[this.scriptsLoaded.length - 1].src; var scriptPathParts = scriptPath.split("/"); var scriptPathRoot = scriptPathParts[0] + "/" + scriptPathParts[1] + "/" + scriptPathParts[2]; // Check if its the same as apiAddress if (scriptPathRoot + "/mobile/" != this.apiPath){ this.apiPathCasinoLoader = scriptPathRoot; } } } this.apiPathCasinoLoader = (!this.apiPathCasinoLoader) ? this.apiPath : this.apiPathCasinoLoader; // Get MSN (Mobile Session Name) this.msn = decodeURIComponent(this.getQueryParamValue("msn")); // Get Leander Communicator Mode this.lcm = decodeURIComponent(this.getQueryParamValue("lcm")); // Define paths values this.generalPath = this.apiPath + 'leandergmapi/5/'; this.scriptsPath = this.generalPath; this.cssPath = this.generalPath + 'css/'; this.imagePath = this.generalPath + 'images/'; this.connectorsPath = this.apiPath + '../' + 'launcher/'; this.launcherPath = (this.launcherPath) ? this.launcherPath : this.connectorsPath; // Set OS vars this.androidInternetBrowser = false; this.oldVersionIOS = false; this.iOSDevice = false; this.macOSDevice = false; this.ieVersion = false; // Set all parameters this.queryParameters = this.getAllQueryParamValue(); // Define Leander GMApi Files to Load // The Casino Loader file should be always first this.filesToLoad = [ ['Leander Preload Image', 'image', this.imagePath + 'intro_icon_lion.jpg'], ['Leander Preload Image', 'image', this.imagePath + 'intro_icon_lion_last_frame.png'], ['Leander Preload Image', 'image', this.imagePath + 'intro_icon_lion_white.png'], ['Leander Preload Image', 'image', this.imagePath + 'intro_icon_lion_black.png'], ['Leander Preload Image', 'image', this.imagePath + 'progress_bar_mask.png'], ['Leander Preload Image', 'image', this.imagePath + 'txt_leander.png'], ['Leander Preload Image', 'image', this.imagePath + 'txt_powered.png'], ['Leander Preload Image', 'image', this.imagePath + 'txt_leander_black.png'], ['Leander Preload Image', 'image', this.imagePath + 'txt_powered_black.png'], ['Leander GMApi CSS', 'css', this.scriptsPath + 'LeanderApiCss.css'], ['Leander GMApi', 'script', this.scriptsPath + 'LeanderApi.js'], ['Leander Casino Loader', 'script', this.launcherPath + 'CasinoLoader.php?v=' + this.version + '&siteId=' + encodeURIComponent(this.siteId) + '&apiAddress=' + this.apiPathCasinoLoader + '&locale=' + encodeURIComponent(this.locale) + '&gameId=' + encodeURIComponent(this.gameId) + '&gameMode=' + encodeURIComponent(this.gameMode) + '&channel=' + encodeURIComponent(this.channel) + '&msn=' + encodeURIComponent(this.msn) + '&lcm=' + encodeURIComponent(this.lcm)] // ['Leander Casino Loader', 'script', this.launcherPath + 'CasinoLoader.js'] ]; // Define loader values this.filesLoaded = 0; this.loaded = false; } // Initialization (Constructor) LeanderApiLoader.prototype.init = function(){ // Check for double initialization if (this.initialized){ return; } // Initialize this.initialized = true; // Get old versions of browsers (Chrome and mobile) this.iOSDevice = navigator.userAgent.match(/(iPhone|iPad|iPod)/i); this.macOSDevice = navigator.userAgent.match(/AppleWebKit/i); if (this.iOSDevice){ //this.oldVersionIOS = this.isOldVersionIOS(); this.oldVersionIOS = true; }else{ this.androidInternetBrowser = this.isAndroidInternetBrowser(); } // Detect IE <= 8 this.ieVersion = this.getIEVersion(); if (this.ieVersion && this.ieVersion <= 8){ this.filesToLoad.push([ 'JSON Fix for IE', 'script', this.scriptsPath + 'external/json2.min.js?v=' + this.version ]); } // Load Files this.loadFiles(); }; LeanderApiLoader.prototype.getIEVersion = function(){ if (navigator.appVersion.indexOf("MSIE") != -1){ var isIE9 = (navigator.appVersion.indexOf("MSIE 9") == -1); var isIE1x = (navigator.appVersion.indexOf("MSIE 1") == -1); var ieVersion = (isIE9) ? 9 : ((isIE1x) ? 10 : 8); return ieVersion; }else if (!(window.ActiveXObject)){ return 11; }else{ return false; } }; // Get all values from querystring LeanderApiLoader.prototype.getAllQueryParamValue = function(){ if (this.queryString){ var queryVars = this.queryString; if (/\?/.test(this.queryString)){ queryVars = this.queryString.split("?")[1]; } return queryVars; } return ""; }; // Get value from querystring param LeanderApiLoader.prototype.getQueryParamValue = function(parameter){ if (this.queryString){ var queryVars; if (/\?/.test(this.queryString)){ queryVars = this.queryString.split("?")[1]; } if (parameter == null){ return ""; } var pairs = queryVars.split("&"); for (var i = 0; i < pairs.length; i++){ if (pairs[i].substring(0, pairs[i].indexOf("=")) == parameter){ return pairs[i].substring((pairs[i].indexOf("=") + 1)); } } } return ""; }; // Load a SCRIPT into HEAD LeanderApiLoader.prototype.scriptLoader = function(url, callback){ // Adding the script tag to the head as suggested before var head = document.getElementsByTagName('head')[0]; var file = document.createElement('script'); file.type = 'text/javascript'; file.src = url; // Then bind the event to the callback function. // There are several events for cross browser compatibility. if (file.onreadystatechange != undefined){ file.onreadystatechange = callback; }else{ // Detect if is Old Android or old iOS if (this.androidInternetBrowser){ callback(); }else if (this.oldVersionIOS){ callback(); }else{ file.onload = callback; } } // Fire the loading head.appendChild(file); }; // Load a CSS into HEAD LeanderApiLoader.prototype.cssLoader = function(url, callback){ // Adding the script tag to the head as suggested before var head = document.getElementsByTagName('head')[0]; var file = document.createElement('link'); file.type = "text/css"; file.rel = "stylesheet"; file.media = "screen,print"; file.href = url; // Then bind the event to the callback function. // There are several events for cross browser compatibility. if (file.onreadystatechange != undefined){ file.onreadystatechange = callback; }else{ // Detect if is Old Android or old iOS if (this.androidInternetBrowser){ callback(); }else if (this.oldVersionIOS || this.macOSDevice){ callback(); }else{ file.onload = callback; } } // Fire the loading head.appendChild(file); }; // Load an IMAGE LeanderApiLoader.prototype.imageLoader = function(url, callback){ // Creating the image var image = new Image(); // Then bind the event to the callback function. // There are several events for cross browser compatibility. if (image.onreadystatechange != undefined){ image.onreadystatechange = callback; }else{ // Detect if is Old Android or old iOS if (this.androidInternetBrowser){ callback(); }else if (this.oldVersionIOS){ callback(); }else{ image.onload = callback; } } // Fire the loading image.src = url; }; // Detect if the device is Android with browser INTERNET LeanderApiLoader.prototype.isAndroidInternetBrowser = function(){ // Detect if is Android var isAndroid = (navigator.userAgent.match(/Android/i)); if (isAndroid){ return true; // For all Android Browsers /*// Check if is a STOCK Android Browser or not var stockBrowser = (navigator.userAgent.match(/Version\//i)); if (stockBrowser){ return true; }else{ return false; }*/ }else{ return false; } }; // Detect if the device is iPad/iPhone/iPod and iOS is lower than 7 LeanderApiLoader.prototype.isOldVersionIOS = function(){ // if iOS version is lower than 7.0 var ua = navigator.userAgent; var uaindex = ua.indexOf('OS '); var iOSVersion = 0; if (uaindex > -1){ iOSVersion = ua.substr(uaindex + 3, 3).replace('_', '.'); iOSVersion = parseFloat(iOSVersion); } if (iOSVersion > 0 && iOSVersion < 7){ return true; }else{ return false; } }; // Load a file LeanderApiLoader.prototype.loadFiles = function(e){ var that = this; var actualFile; var callback = function(e){ that.filesLoaded++; // Check if all files are loaded if (that.filesLoaded >= that.filesToLoad.length){ that.initGMApi(); } }; // Load Every Script for (var i = 0; i < this.filesToLoad.length; i++){ actualFile = this.filesToLoad[i]; switch (actualFile[1]){ case "script": this.scriptLoader( actualFile[2], callback ); break; case "css": this.cssLoader( actualFile[2], callback ); break; case "image": this.imageLoader( actualFile[2], callback ); break; } } }; // Initialization of GMApi LeanderApiLoader.prototype.initGMApi = function(e){ var that = this; // Check if LeanderGMApi and its components are available var blnLeanderGMApiComponentsLoaded = false; blnLeanderGMApiComponentsLoaded = (typeof LeanderGMApi != 'undefined'); blnLeanderGMApiComponentsLoaded = blnLeanderGMApiComponentsLoaded && (typeof LeanderCommEngine != 'undefined'); blnLeanderGMApiComponentsLoaded = blnLeanderGMApiComponentsLoaded && (typeof LeanderDictionary != 'undefined'); blnLeanderGMApiComponentsLoaded = blnLeanderGMApiComponentsLoaded && (typeof LeanderErrorManager != 'undefined'); blnLeanderGMApiComponentsLoaded = blnLeanderGMApiComponentsLoaded && (typeof LeanderInfoManager != 'undefined'); blnLeanderGMApiComponentsLoaded = blnLeanderGMApiComponentsLoaded && (typeof LeanderPreloadManager != 'undefined'); blnLeanderGMApiComponentsLoaded = blnLeanderGMApiComponentsLoaded && (typeof LeanderPubSub != 'undefined'); blnLeanderGMApiComponentsLoaded = blnLeanderGMApiComponentsLoaded && (typeof LeanderUtils != 'undefined'); blnLeanderGMApiComponentsLoaded = blnLeanderGMApiComponentsLoaded && (typeof LeanderTweener != 'undefined'); blnLeanderGMApiComponentsLoaded = blnLeanderGMApiComponentsLoaded && (typeof LeanderWrapper != 'undefined'); blnLeanderGMApiComponentsLoaded = blnLeanderGMApiComponentsLoaded && (typeof LeanderInfoBar != 'undefined'); blnLeanderGMApiComponentsLoaded = blnLeanderGMApiComponentsLoaded && (typeof LeanderJackpotBar != 'undefined'); blnLeanderGMApiComponentsLoaded = blnLeanderGMApiComponentsLoaded && (typeof LeanderCasinoManager != 'undefined'); /*blnLeanderGMApiComponentsLoaded = blnLeanderGMApiComponentsLoaded && (typeof LeanderDebugPlaysConsole != 'undefined');*/ if (blnLeanderGMApiComponentsLoaded){ leanderGMApi = new LeanderGMApi(); leanderGMApi.setLauncherURL(this.launcherPath); leanderGMApi.init(false); }else{ setTimeout(function(){ that.initGMApi() }, 3000); } }; if (typeof(leanderApiLoader) == "undefined"){ var leanderApiLoader = new LeanderApiLoader(); leanderApiLoader.init(); }