var api;
if (typeof window !== "undefined" && !window.famobi) {
! function(a, b) {
var famobi = {
orientationChangeCallback: null,
brandingLogo: null,
config: null,
reached_home: false,
splashComplete: false,
init: function() {
return new Promise(function(resolve, reject) {
this.log("init...");
this.game.init();
this.includeCSS("html5games/gameapi/v1/play.css");
this.includeCSS("https://swagapi.shockwave.com/dist/swag-api.css");
window.famobi_gameJS.unshift("html5games/gameapi/detection.js");
window.famobi_gameJS.unshift("html5games/gameapi/zepto.min.js");
window.famobi_gameJS.unshift("html5games/gameapi/famobi_analytics_v1.js");
window.famobi_gameJS.unshift("https://swagapi.shockwave.com/dist/swag-api.js");
// orientation change
window.addEventListener("orientationchange", function() {
if (typeof this.orientationChangeCallback == "function") {
this.orientationChangeCallback();
}
}.bind(this), false);
// famobi.json
if(!this.config) {
readTextFile("famobi.json", function(text){
var data = JSON.parse(text);
if(!data.game_i18n) {
console.error("famobi.json: field name 'game_i18n' is missing. For more information please visit: https://sites.google.com/a/famobi.com/api-docs/api-implementation/localization");
return;
}
this.config = data;
// aid
var aid = this.getUrlParams()["fg_aid"];
if(typeof aid !== "undefined") {
this.config.aid = aid;
}
window.famobi_multiplayer = this.config.features.multiplayer || false;
window.addEventListener("famobi_tracking_screen",(e)=>{
if(this.config.autoShowMenuScreens && this.config.autoShowMenuScreens.includes(e.detail.screen))
{
this.reached_home = true;
setTimeout(()=>{ //<< DIRTY FIX
if(this.splashComplete)window.famobi.menu.show();},1000); //Menu wouldn't reopen because of some timing issue where it was immediatellzy closed after this command ran, so now the call is delayed by 1 second - performance wise not the best option
}
})
if(this.config.show_splash && this.config.show_splash !== "api") this.showSplashScreen(()=>{
this.splashComplete = true;
if(this.reached_home)window.famobi.menu.show();
});
var getGameTitle = function() {
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.split(search).join(replacement);
};
function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt){
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
return toTitleCase(window.famobi_gameID.replaceAll("-", " "));
};
document.title = this.config.title || getGameTitle();
if(this.config.swagAPIOverlay) {
var swagAPIOverlayDiv = document.createElement("div");
swagAPIOverlayDiv.setAttribute("id", "swagAPIOverlay");
swagAPIOverlayDiv.classList.add("swag-api-wrapper");
document.body.appendChild(swagAPIOverlayDiv);
swagAPIOverlayDiv.addEventListener("touchstart",
function(t) {
t.stopPropagation();
});
swagAPIOverlayDiv.addEventListener("touchend",
function(t) {
t.stopPropagation();
});
swagAPIOverlayDiv.addEventListener("touchmove",
function(t) {
t.stopPropagation();
});
}
if(!document.getElementsByClassName("swag-api-wrapper").length) {
var wrapperList = [
document.getElementById("canvasHolder"),
document.getElementById("c2canvasdiv"),
document.getElementById("canvas-wrapper"),
document.getElementsByTagName("canvas")[0],
document.body
];
for(var i = 0; i < wrapperList.length; i++) {
if(wrapperList[i]) {
wrapperList[i].classList.add("swag-api-wrapper");
break;
}
}
if(["jewelish-blitz", "bubble-woods", "jungle-run"].indexOf(window.famobi_gameID) >= 0) {
let theGreatObserver = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
mutation.addedNodes.forEach((node)=> {
if(node.id === "swag-dialog-wrapper")
{
//console.log(">> Found changes for swag-dialog-wrapper");
node.addEventListener("touchstart",
function(t) {
t.stopPropagation();
});
node.addEventListener("touchend",
function(t) {
t.stopPropagation();
});
node.addEventListener("touchmove",
function(t) {
t.stopPropagation();
});
}
});
});
});
theGreatObserver.observe(document.querySelector('.swag-api-wrapper'),{childList:true});
}
}
resolve(true);
}.bind(this));
}
function readTextFile(file, callback) {
var rawFile = new XMLHttpRequest();
rawFile.overrideMimeType("application/json");
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4 && rawFile.status == "200") {
callback(rawFile.responseText);
}
};
rawFile.send(null);
}
}.bind(this));
},
forceAd: function(callback) {
this.showAd(callback);
},
rewardedAd: function(callback) {
if (typeof callback == "function") {
callback();
}
},
showAd: function(callback) {
this.log("showing ad...");
this.game.pause();
api.showAd().then(function(){
this.log("ad finished");
if (typeof callback == "function") {
callback();
}
setTimeout(function() {
this.game.resume();
}.bind(this), 100);
}.bind(this), function(){
this.log("ad finished");
if (typeof callback == "function") {
callback();
}
setTimeout(function() {
this.game.resume();
}.bind(this), 100);
}.bind(this));
},
// Localization
gametranslation: {
init: function() {
window.famobi.gametranslation.curLangString = window.famobi.gametranslation.getUserLang();
// Always fall back to 'en' when the user locale is not supported or translated
if (window.famobi.gametranslation.getSupportedLanguages().indexOf(window.famobi.gametranslation.curLangString) === -1) {
window.famobi.gametranslation.curLangString = "en";
}
window.famobi.gametranslation.translationData = window.famobi.gametranslation.getGameTranslations();
window.famobi.gametranslation.translateHtml(faZepto("body"));
},
getSupportedLanguages: function() {
return window.famobi.config.languages || Object.keys(window.famobi.config.game_i18n) || [];
},
getGameTranslations: function() {
var i18n = window.famobi.config.game_i18n,
lang = window.famobi.gametranslation.curLangString;
if (i18n.current) {
return i18n.current;
}
faZepto.each(i18n, function(language, translations) {
faZepto.each(translations, function(key, value) {
if (value == null) {
i18n[language][key] = "";
} else if (typeof i18n[language][key] === "string") {
i18n[language][key] = value.replace(/\{lang\}/g, language);
}
});
});
i18n.current = faZepto.extend(
{},
i18n["default"],
i18n[window.famobi.config.aid + ".default"],
i18n[lang],
i18n[window.famobi.config.aid + "." + lang]
);
return (window.famobi.config.game_i18n.current = i18n.current);
},
translateString: function(key) {
return window.famobi.gametranslation.translationData.hasOwnProperty(key)
? window.famobi.gametranslation.translationData[key]
: null;
},
getNavigatorLocale: function() {
var language = "";
if (navigator.languages && window.famobi.sizeOf(navigator.languages)) {
language = navigator.languages[0];
} else if (navigator.language) {
language = navigator.language;
} else if (navigator.userLanguage) {
language = navigator.userLanguage;
} else if (navigator.browserLanguage) {
language = navigator.browserLanguage;
}
return language;
},
getNavigatorLanguage: function() {
return window.famobi.gametranslation.getNavigatorLocale().substr(0, 2);
},
getUserLang: function() {
var urlParams = window.famobi.getUrlParams(),
lang = window.famobi.gametranslation.getNavigatorLanguage();
if (urlParams.locale && urlParams.locale.length == 2) {
return urlParams.locale;
}
switch (lang) {
case "ch":
case "at":
return "de";
default:
return lang;
}
},
translateHtml: function($selector) {
$selector.find("[data-i18n]").each(function() {
var textkey = this.getAttribute("data-i18n");
this.innerHTML = window.famobi.gametranslation.translateString(textkey);
});
return $selector;
}
},
__: function(key) {
switch(key) {
case "test_preload_image":
return "html5games/images/testPreloadImage.png";
case "preload_image":
return "html5games/images/" + (this.config.preload_image || "preloadImage") + ".png";
default:
// do nothing
}
var lang = this.getCurrentLanguage();
if(this.config.game_i18n) {
if(this.config.game_i18n[lang]) {
this.config.game_i18n[lang] = Object.assign(this.config.game_i18n[lang], this.config.game_i18n[this.config.aid+"."+lang]);
}
if(this.config.game_i18n[lang] && this.config.game_i18n[lang][key]) {
if(typeof this.config.game_i18n[lang][key] === "string") {
return this.config.game_i18n[lang][key].replace("{lang}", lang);
}
return this.config.game_i18n[lang][key];
}
if(this.config.game_i18n.default) {
this.config.game_i18n.default = Object.assign(this.config.game_i18n.default, this.config.game_i18n[this.config.aid+".default"]);
}
if(this.config.game_i18n.default && this.config.game_i18n.default[key]) {
if(typeof this.config.game_i18n.default[key] === "string") {
return this.config.game_i18n.default[key].replace("{lang}", lang);
}
return this.config.game_i18n.default[key];
}
}
this.warn("No translation found for '" + key + "'");
return null;
},
getAbsolutePath: function(relativePath) {
var absolutePath =
document.location.protocol + "//" + document.location.pathname;
// this method is only used for compatibility with Loaders in Cordova Apps,
// otherwise absolute URIs with https://games.cdn.famobi.com are used
if (document.location.protocol !== "file:") {
return relativePath;
}
if (relativePath.startsWith("/")) {
relativePath = relativePath.substr(1);
}
return (
absolutePath.substr(0, absolutePath.lastIndexOf("/") + 1) + relativePath
);
},
getCurrentLanguage: function() {
var locale;
try{
locale = new URL(window.location.href).searchParams.get("locale") ;
} catch(e) {
console.error(e);
}
return locale || (navigator.language || navigator.userLanguage).substr(0, 2);
},
showSplashScreen: function(pCallback, pShowTill_EVENT, pModal) {
console.log("famobi splash");
if(!document.getElementById("famobi_splash")) {
//Splash Screen doesn't exist yet - Creating new Splash Screen from files in html5games/splash
function readSplashFile(file, callback) {
var rawFile = new XMLHttpRequest();
rawFile.overrideMimeType("application/xhtml+xml");
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4 && rawFile.status == "200") {
callback(rawFile.responseText);
}
};
rawFile.send(null);
}
readSplashFile("html5games/splash/splash.html",(response)=>{
this.includeCSS("html5games/splash/splash.css");
let splashScreen = document.createElement("div");
splashScreen.classList.add("splash-screen");
splashScreen.style.position = "absolute";
splashScreen.style.top = "0";
splashScreen.style.left = "0";
splashScreen.style.width = "100%";
splashScreen.style.height = "100%";
splashScreen.innerHTML = response;
if(this.config.preload_image)splashScreen.querySelector(".logo").src = "html5games/images/"+this.config.preload_image+".png";
document.body.appendChild(splashScreen);
this.splashScreen = splashScreen;
if(pModal) return; //Show Modal does not define a closing condition and will keep the splash visible untill hideSplash is called manually
if(!pShowTill_EVENT) {
setTimeout(()=>this.hideSplashScreen(pCallback),this.config.splash_duration);
} else {
window.addEventListener(pShowTill_EVENT,()=>this.hideSplashScreen(pCallback));
}
});
}
else {
//Splash Screen already exists, just need to reenable it.
splashScreen.style.display = "block";
splashScreen.style.animation = splashScreen._orgAni;
if(pModal) return; //Show Modal does not define a closing condition and will keep the splash visible untill hideSplash is called manually
if(!pShowTill_EVENT) {
setTimeout(()=>this.hideSplashScreen(pCallback),this.config.splash_duration);
} else {
window.removeEventListener(pShowTill_EVENT,()=>this.hideSplashScreen(pCallback));
window.addEventListener(pShowTill_EVENT,()=>this.hideSplashScreen(pCallback));
}
}
},
hideSplashScreen: function(pCallback) {
this.splashScreen.style.display = "none";
if(!this.splashScreen._orgAni)this.splashScreen._orgAni = this.splashScreen.style.animation; //This saves the original animation - this is required to be able to rerun the animation the next time the splash is shown
this.splashScreen.style.animation = "none";
if(pCallback)pCallback(this.splashScreen);
},
menu: {
create: function() {
window.famobi.menu.rootElement = document.getElementById("fg-root");
window.famobi.menu.bodyElement = document.getElementsByTagName("body")[0];
window.famobi.menu.headElement = document.getElementsByTagName("head")[0];
if (!window.famobi.menu.rootElement) {
window.famobi.menu.rootElement = document.createElement("div");
window.famobi.menu.rootElement.setAttribute("id", "fg-root");
window.famobi.menu.rootElement.classList.add("fg_root");
window.famobi.menu.rootElement.style = "color: #999;font-weight:normal;";
document.body.insertBefore(window.famobi.menu.rootElement, document.body.firstChild);
}
// overlay
window.famobi.menu.fgOverlay = document.createElement("div");
window.famobi.menu.fgOverlay.setAttribute("id","fg-overlay");
if (window.famobi.config.overlay_position)
window.famobi.menu.fgOverlay.className =
"overlay-" +
window.famobi.config.overlay_position +
" clip-" +
window.famobi.config.overlay_position;
if (
window.famobi.config.overlay_distance &&
window.famobi.config.overlay_distance !== ""
) {
if (
window.famobi.config.overlay_position &&
window.famobi.config.overlay_position == "bottom"
)
window.famobi.menu.fgOverlay.style.bottom = isNaN(
window.famobi.config.overlay_distance
)
? window.famobi.config.overlay_distance
: window.famobi.config.overlay_distance + "px";
else
window.famobi.menu.fgOverlay.style.top = isNaN(
window.famobi.config.overlay_distance
)
? window.famobi.config.overlay_distance
: window.famobi.config.overlay_distance + "px";
}
window.famobi.menu.rootElement.appendChild(window.famobi.menu.fgOverlay);
window.famobi.menu.fgOverlay.innerHTML = '