From b2b8353e8e22eac2237719ecc6620a9d90a54de9 Mon Sep 17 00:00:00 2001 From: Mirco Cipriani Date: Wed, 5 Jul 2017 12:40:32 +0200 Subject: [PATCH 01/13] OnStargateReady syncronous initialization to debug initializtion issues. --- src/stargate.js | 54 +++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/stargate.js b/src/stargate.js index db9da3e..b6453a4 100644 --- a/src/stargate.js +++ b/src/stargate.js @@ -482,34 +482,36 @@ var onDeviceReady = function (resolve, reject) { // get connection information initializeConnectionStatus(); - // request all asyncronous initialization to complete - Promise.all([ - // include here all needed asyncronous initializazion - cordova.getAppVersion.getVersionNumber(), - getManifest(), - cordova.getAppVersion.getPackageName(), - cordova.getAppVersion.getVersionCode(), - getAppIsDebug() - ]) - .then(function(results) { - // save async initialization result - - appVersion = results[0]; - - if (typeof results[1] !== 'object') { - results[1] = JSON.parse(results[1]); + getManifest() + .then(function(resultManifest){ + log("onDeviceReady() [1/4] got manifest"); + if (typeof resultManifest !== 'object') { + resultManifest = JSON.parse(resultManifest); } - - appPackageName = results[2]; - appBuild = results[3]; - - if (results[4] && ( typeof(results[4]) === 'object') ) { - if (results[4].debug) { - appIsDebug = true; - } - } - stargateConf = results[1].stargateConf; + // save stargateConf got from manifest.json + stargateConf = resultManifest.stargateConf; + + // execute next promise + return cordova.getAppVersion.getVersionNumber(); + }) + .then(function(resultAppVersionNumber) { + log("onDeviceReady() [2/4] got appVersionNumber"); + appVersion = resultAppVersionNumber; + + // execute next promise + return cordova.getAppVersion.getPackageName(); + }) + .then(function(resultAppPackageName){ + log("onDeviceReady() [3/4] got appPackageName"); + appPackageName = resultAppPackageName; + + // execute next promise + return cordova.getAppVersion.getVersionCode(); + }) + .then(function(resultAppVersionCode){ + log("onDeviceReady() [4/4] got appPackageName"); + appBuild = resultAppVersionCode; // execute remaining initialization onPluginReady(resolve, reject); From 0d54e92acc8b0f26f2e4368862c3574fd35c5ef3 Mon Sep 17 00:00:00 2001 From: Mirco Cipriani Date: Wed, 5 Jul 2017 12:43:39 +0200 Subject: [PATCH 02/13] 0.11.1 --- dist/bower/stargate.js | 56 ++++++++++++++++++++------------------ dist/bower/stargate.min.js | 8 +++--- dist/stargate.js | 56 ++++++++++++++++++++------------------ dist/stargate.min.js | 8 +++--- package.json | 2 +- 5 files changed, 67 insertions(+), 63 deletions(-) diff --git a/dist/bower/stargate.js b/dist/bower/stargate.js index 1d046a7..9306052 100644 --- a/dist/bower/stargate.js +++ b/dist/bower/stargate.js @@ -18,7 +18,7 @@ } }(this, function () { // Public interface - var stargatePackageVersion = "0.11.0"; + var stargatePackageVersion = "0.11.1"; var stargatePublic = {}; var stargateModules = {}; @@ -3318,34 +3318,36 @@ var onDeviceReady = function (resolve, reject) { // get connection information initializeConnectionStatus(); - // request all asyncronous initialization to complete - Promise.all([ - // include here all needed asyncronous initializazion - cordova.getAppVersion.getVersionNumber(), - getManifest(), - cordova.getAppVersion.getPackageName(), - cordova.getAppVersion.getVersionCode(), - getAppIsDebug() - ]) - .then(function(results) { - // save async initialization result - - appVersion = results[0]; - - if (typeof results[1] !== 'object') { - results[1] = JSON.parse(results[1]); + getManifest() + .then(function(resultManifest){ + log("onDeviceReady() [1/4] got manifest"); + if (typeof resultManifest !== 'object') { + resultManifest = JSON.parse(resultManifest); } - - appPackageName = results[2]; - appBuild = results[3]; - - if (results[4] && ( typeof(results[4]) === 'object') ) { - if (results[4].debug) { - appIsDebug = true; - } - } - stargateConf = results[1].stargateConf; + // save stargateConf got from manifest.json + stargateConf = resultManifest.stargateConf; + + // execute next promise + return cordova.getAppVersion.getVersionNumber(); + }) + .then(function(resultAppVersionNumber) { + log("onDeviceReady() [2/4] got appVersionNumber"); + appVersion = resultAppVersionNumber; + + // execute next promise + return cordova.getAppVersion.getPackageName(); + }) + .then(function(resultAppPackageName){ + log("onDeviceReady() [3/4] got appPackageName"); + appPackageName = resultAppPackageName; + + // execute next promise + return cordova.getAppVersion.getVersionCode(); + }) + .then(function(resultAppVersionCode){ + log("onDeviceReady() [4/4] got appPackageName"); + appBuild = resultAppVersionCode; // execute remaining initialization onPluginReady(resolve, reject); diff --git a/dist/bower/stargate.min.js b/dist/bower/stargate.min.js index 0fa54d4..50e5b01 100644 --- a/dist/bower/stargate.min.js +++ b/dist/bower/stargate.min.js @@ -1,9 +1,9 @@ /*! * StargateJS Apps - * v0.11.0 + * v0.11.1 * Copyright 2015 DMobileLab. http://buongiorno.com/ * See LICENSE in this repository for license information */ -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.Stargate=t()}(this,function(){function e(e){p.type=e.type,p.networkState=navigator.connection.type,"function"==typeof f&&f(p)}function t(){document.addEventListener("offline",e,!1),document.addEventListener("online",e,!1)}function n(){p.networkState=navigator.connection.type,"none"===navigator.connection.type?p.type="offline":p.type="online"}function r(e){if("android"==window.device.platform.toLowerCase())window.navigator.app.loadUrl(e);else if("ios"==window.device.platform.toLowerCase()&&-1!==e.indexOf("file:///")){var t=e.split("?")[0];h("Without qs",t),window.resolveLocalFileSystemURL(t,function(e){var t=e.toInternalURL()+"?hybrid=1";h("Redirect to",t),window.location.href=t},m)}else window.location.href=e}function i(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.AppIsDebug?new Promise(function(e,t){window.cordova.plugins.AppIsDebug.get(function(t){e(t)},function(e){m("getAppIsDebug(): "+e,e),t(new Error(e))})}):(m("getAppIsDebug(): plugin not available!"),Promise.resolve({}))}function o(){return window.cordova.file?s.file.readFileAsJSON(window.cordova.file.applicationDirectory+"www/manifest.json"):window.hostedwebapp?new Promise(function(e,t){window.hostedwebapp.getManifest(function(t){e(t)},function(e){m(e),t(new Error(e))})}):(m("getManifest() no available reading mechanism!"),Promise.resolve({}))}var a={},s={};!function(e){function t(e,n,r){this.level=t.levels[e.toUpperCase()],this.styles=r||{background:"white",color:"black"},this.tag="%c "+n+" ",this.isstaging="1"==="IS_STAGING = 1".slice(-1),this.styleString="background:"+this.styles.background+";color:"+this.styles.color+";";var i=function(){if(arguments.length<1)return"";for(var e=Array.prototype.slice.call(arguments[0]),t="",n=0;n0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(s),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(s,s.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(T=O(T,t)),N.d("Initialized called with:",T),!e)return Promise.reject("Missing file module!");try{b=window.cordova.file.applicationStorageDirectory,S=window.cordova.file.cacheDirectory,A=window.cordova.file.tempDirectory,P=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",_=window.cordova.file.dataDirectory}catch(e){return N.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(b+="Documents/"),"android"==window.device.platform.toLowerCase()&&(A=S),k.SDK_DIR=b+"scripts/",k.SDK_RELATIVE_DIR="../../scripts/",k.GAMEOVER_RELATIVE_DIR="../../gameover_template/",k.GAMES_DIR=b+"games/",k.BASE_DIR=b,k.CACHE_DIR=S,k.TEMP_DIR=A,k.CORDOVAJS=P+"cordova.js",k.CORDOVA_PLUGINS_JS=P+"cordova_plugins.js",k.STARGATEJS=P+"js/stargate.js",k.DATA_DIR=_,k.GAMEOVER_DIR=k.BASE_DIR+"gameover_template/",k.WWW_DIR=P,N.i("cordova JS dir to include",k.CORDOVAJS),n.game._public.BASE_DIR=k.BASE_DIR,n.game._public.OFFLINE_INDEX=k.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(k.BASE_DIR,"games"),a=e.createDir(k.BASE_DIR,"scripts"),u=e.fileExists(k.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(C))}),l=e.fileExists(k.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return N.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(k.BASE_DIR+"gameover_template"),e.dirExists(k.SDK_DIR+"plugins"),e.fileExists(k.SDK_DIR+"cordova.js"),e.fileExists(k.SDK_DIR+"cordova_plugins.js"),e.fileExists(k.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(k.WWW_DIR+"gameover_template",k.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(k.WWW_DIR+"plugins",k.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(k.CORDOVAJS,k.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(k.CORDOVA_PLUGINS_JS,k.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(k.WWW_DIR+"js/gamesFixes.js",k.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=D(T.sdk_url,{v:t.getTime()});return""===T.sdk_url||void 0===T.sdk_url||null===T.sdk_url?(N.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(k.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(N.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,k.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(k.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return N.d("Serialized dom",r),r}).then(function(t){return N.d("Write dom:",r,t),e.write(r,t)})}function w(e){return new RegExp(/.*\.html?$/i).test(e)}function h(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=k.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return N.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function m(){return N.i("readUserJson",k.BASE_DIR+"user.json"),e.readFileAsJSON(k.BASE_DIR+"user.json")}function v(e){return m().then(function(t){if(!t.ponyUrl)throw N.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];N.d("PONYVALUE",n);var r=D(T.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,N.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return N.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(k.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return N.d("writing offlineData.json",t),e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var b,S,A,P,_,I,E=t.Logger,D=t.composeApiString,R=t.jsonpRequest,O=t.extend,k={},T={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},L=!1,C={GaForGame:{},GamifiveInfo:{},queues:{}},j={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},N=new E("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,m);return N.d("Get GameInfo, fly my minipony!"),n.then(function(e){return N.i("Space is ok, can download:",m,e),v(y)}).then(function(n){return N.d("Ga for game and gamifive info stored!",n),N.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,k.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),N.d("unzip:",t.id,k.TEMP_DIR+y),e._promiseZip(n.path,k.TEMP_DIR+y,r("unzip"))}).then(function(n){N.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,m=d*Math.pow(1024,p?f.MB:f.KB),y=t.id;return s.then(function(e){return N.d("Exists",e),e?(L=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(L=!0,i())})},r.prototype.play=function(t){N.d("Play",t);var n=k.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return w(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){N.d("Removing game",t);var n=e.dirExists(k.CACHE_DIR+t+".zip"),r=e.dirExists(k.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(N.d("Removed in cache",n[0]),r.push(e.removeFile(k.CACHE_DIR+t+".zip"))),n[1]&&(N.d("Removed",n[1]),r.push(e.removeDir(k.GAMES_DIR+t))),0===r.length&&N.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return L},r.prototype.abortDownload=function(){return this.isDownloading()?(N.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,L=!1),!0):(N.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return N.d("Get games list"),e.readDir(k.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=k.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(N.d("Read meta.json:",n),N.d("GAMEOVER_TEMPLATE path",k.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(k.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return N.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(k.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(k.GAMES_DIR).then(function(t){return N.d("All games deleted!",t),e.createDir(k.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){N.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){N.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(H.hasOwnProperty("webappsfixes")&&"object"==typeof H.webappsfixes){t=!0;for(var e in H.webappsfixes)if(H.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){h("[webappsFixes] applying fix: "+e);var r=n[e](H.webappsfixes[e]);r&&m("[webappsFixes] fix '"+e+"' failed: "+r)}else m("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(S()&&!e.platforms.ios)return void h("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(b()&&!e.platforms.android)return void h("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(h("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),h("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return m("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!H.statusbar)return;e=H.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},$=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(S()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){h("[share] Share completed? "+e.completed),h("[share] Shared to app: "+e.app),n(e)},a=function(e){m("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){h("[share] Facebook share completed, result: ",e),t(e)},i=function(e){m("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){h("[share] Twitter share completed, result: ",e),t(e)},i=function(e){m("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){h("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){m("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){h("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){h("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(h("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(m("[share] type not valid"),n("type not valid"))):(m("[share] missing parameter url"),n("missing parameter url")):(m("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return I?E?new Promise(function(t,n){$.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return I?E?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push($.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){m(e),n(e)})}):(m("[share] missing parameter url"),Promise.reject("missing parameter url")):(m("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(m("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var ee=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){g().then(function(e){p&&p.type&&"online"===p.type?(h("[push] going to url: ",e),P(e)):m("[push] i'm offline not going to url")}).catch(function(e){m("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var f=function(){var e=window.cordova.file.applicationStorageDirectory;return S()&&(e+="Documents/"),e},g=function(){return s.file.fileExists(f()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(f()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},w=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(f(),"SGpushUrl").then(function(e){return h("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){m("[push] error sg create SGpushUrl file",e)})},b=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();h("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,f=1732584193,p=-271733879,g=-1732584194,w=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function f(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function p(e){return unescape(encodeURIComponent(e))}function g(e){return l(p(e))}function w(e){return f(g(e))}function h(e,t){return d(p(e),p(t))}function m(e,t){return f(h(e,t))}function v(e,t,n){return t?n?h(t,e):m(t,e):n?g(e):w(e)}return v}(),re=function(e){if(void 0===window.SpinnerDialog)return m("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},ie=function(){return void 0===window.SpinnerDialog?m("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=re,window.stopLoading=ie,a.inAppPurchaseSubscription=function(e,t,n,r){return I?E?(W(!0),void 0!==r&&(ae.returnUrl=r),void 0!==n&&(ae.subscribeMethod=n),ae.callbackSuccess=e,ae.callbackError=t,ae.inappPurchaseCalled=!0,ae.lastCreateUserProduct&&ae.lastCreateUserToken?(ae.createUser(ae.lastCreateUserProduct,ae.lastCreateUserToken),!0):(ae.doRefresh(),window.store.order(ae.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.inAppRestore=function(e,t,n,r){return I?E?(void 0!==n&&(ae.subscribeMethod=n),void 0!==r&&(ae.returnUrl=r),ae.callbackSuccess=e,ae.callbackError=t,ae.inappPurchaseCalled=!0,void ae.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},a.inAppProductInfo=function(e){if(e.productId||(e.productId=ae.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return m("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!I)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!E)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(ae.subscribeMethod=e.subscriptionUrl,ae.requestedListingProductId=e.productId,ae.callbackListingSuccess=e.callbackListingSuccess,ae.callbackPurchaseSuccess=e.callbackPurchaseSuccess,ae.callbackListingError=e.callbackError,ae.inappProductInfoCalled=!0,ae.productsInfo[e.productId])try{ae.callbackListingSuccess(ae.productsInfo[e.productId])}catch(e){m("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return ae.lastCreateUserProduct&&ae.lastCreateUserToken?(ae.createUser(ae.lastCreateUserProduct,ae.lastCreateUserToken),!0):(ae.doRefresh(!0),!0)};var oe=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(b()?n=e.productsIdAndroid:S()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,h("[IAPlight] getProducts ok",e),e}).catch(function(e){m("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(h("[IAPlight] subscribe ok",t),S())return e.getActiveSubscriptionsInfo().then(function(e){if(h("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(b()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return m("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw m("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){h("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),h(JSON.stringify(e)),h(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){h("IAP> Purchase approved."),h(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){h("subscription verified ",e)},onStoreReady:function(){h("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(h("[IAP] > Product Owned."),!e.transaction.id&&S())return m("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),S()&&window.localStorage.setItem("transaction_id",e.transaction.id),b()){var t=e.transaction.purchaseToken+"|"+k+"|"+ae.id;h("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||ae.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(h("[IAP] appStoreReceipt: "+t.appStoreReceipt),ae.createUser(e,t.appStoreReceipt)):h("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){W(!1),ae.callbackError({iap_cancelled:1,return_url:ae.returnUrl}),h("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){h("[IAP] ORDER APPROVED "+ae.id),e.finish()},error:function(e){W(!1),m("[IAP] error: "+e),ae.callbackError({iap_error:1,return_url:ae.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(h("[IAP] createUser start "),!ae.inappProductInfoCalled&&!ae.inappPurchaseCalled)return ae.lastCreateUserProduct=e,void(ae.lastCreateUserToken=t);if(!ae.subscribeMethod)return void m("[IAP] createUser configuration error: missing api url.");var n=ae.getRandomEmail(),r=1;b()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=ae.subscribeMethod,o={paymethod:ae.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:ae.returnUrl,inapp_pwd:ae.getPassword(t),hybrid:1};ae.lastCreateuserUrl=i,ae.lastCreateuserData=o;var a=function(e){if(ae.createUserAttempt<=ae.maxCreateUserAttempt)m("[IAP] createUser failed "+ae.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{m("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:ae.returnUrl};W(!1),ae.inappPurchaseCalled?ae.callbackError(t):ae.inappProductInfoCalled&&ae.callbackListingError(t)}},s=function(e){h("[IAP] createUser success ",e);try{e.device_id=y.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),W(!1),ae.callbackSuccess(e),ae.inappPurchaseCalled?ae.callbackSuccess(e):ae.inappProductInfoCalled&&ae.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ae.createUserAttempt=ae.createUserAttempt+1,h("[IAP] createUser attempt: "+ae.createUserAttempt+" with timeout: "+c+"sec."),h("[IAP] POST createUser: "+ae.lastCreateuserUrl+" params: "+JSON.stringify(ae.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(ae.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(ae.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e) -}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){h("[IAP] createUser end"),W(!1)}).go(),c+=5},10)};ae.createUserAttempt=0,u()}},se=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return m("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return m("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});h("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){m("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return m("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});h("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){m("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(m("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(m("[globalization] getLocaleName: not initialized!"),!1)},e}();a.facebookLogin=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){h("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){m("Got FB login error:",e),n({error:e})})},a.facebookShare=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){m("Got FB share error:",e),n({error:e})})};var ce=function(){deltadna.registerPushCallback(le)},ue=function(e){m("[DeltaDNA] error: "+e)},le=function(e){return b()&&e.payload&&e.payload.url&&!e.foreground?P(e.payload.url):S()&&e.url?P(e.url):void 0},de=function(){var e={},t={},n=function(n){h("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(m("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(m("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&h("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return m("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),fe=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return m("[appsflyer] missing cordova plugin");if(void 0===H.appsflyer_devkey)return m("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:H.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(S()){if(void 0===H.appstore_appid)return m("[appsflyer] missing manifest configuration: appstore_appid");n.appId=H.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}te.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();a.setConversionDataCallback=function(e){fe.setCallback(e)};var pe=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return h("[analytics] callback not set!");try{e(t)}catch(e){m("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();a.setAnalyticsCallback=function(e){pe.setCallback(e)};var ge={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(ge.DefaultOptions=e),AdMob&&(ge.AdMobSupport=!0,ge.initAdMob(e,t,n)),MoPub&&(ge.MoPubSupport=!0),!0},isAdMobSupported:function(){return ge.AdMobSupport},isMoPubSupported:function(){return ge.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=ge.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=ge.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=ge.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?ge.AdSize.LEADERBOARD:t>=468&&e>=60?ge.AdSize.BANNER:t>=320&&e>=50?ge.AdSize.BANNER:void 0}};return a.game=s.game._public,a.file=s.file,a.AdManager=s.AdManager,a}); \ No newline at end of file +!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.Stargate=t()}(this,function(){function e(e){f.type=e.type,f.networkState=navigator.connection.type,"function"==typeof d&&d(f)}function t(){document.addEventListener("offline",e,!1),document.addEventListener("online",e,!1)}function n(){f.networkState=navigator.connection.type,"none"===navigator.connection.type?f.type="offline":f.type="online"}function r(e){if("android"==window.device.platform.toLowerCase())window.navigator.app.loadUrl(e);else if("ios"==window.device.platform.toLowerCase()&&-1!==e.indexOf("file:///")){var t=e.split("?")[0];w("Without qs",t),window.resolveLocalFileSystemURL(t,function(e){var t=e.toInternalURL()+"?hybrid=1";w("Redirect to",t),window.location.href=t},h)}else window.location.href=e}function i(){return window.cordova.file?a.file.readFileAsJSON(window.cordova.file.applicationDirectory+"www/manifest.json"):window.hostedwebapp?new Promise(function(e,t){window.hostedwebapp.getManifest(function(t){e(t)},function(e){h(e),t(new Error(e))})}):(h("getManifest() no available reading mechanism!"),Promise.resolve({}))}var o={},a={};!function(e){function t(e,n,r){this.level=t.levels[e.toUpperCase()],this.styles=r||{background:"white",color:"black"},this.tag="%c "+n+" ",this.isstaging="1"==="IS_STAGING = 1".slice(-1),this.styleString="background:"+this.styles.background+";color:"+this.styles.color+";";var i=function(){if(arguments.length<1)return"";for(var e=Array.prototype.slice.call(arguments[0]),t="",n=0;n0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(a),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(a,a.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(T=O(T,t)),j.d("Initialized called with:",T),!e)return Promise.reject("Missing file module!");try{S=window.cordova.file.applicationStorageDirectory,b=window.cordova.file.cacheDirectory,A=window.cordova.file.tempDirectory,_=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",P=window.cordova.file.dataDirectory}catch(e){return j.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(S+="Documents/"),"android"==window.device.platform.toLowerCase()&&(A=b),k.SDK_DIR=S+"scripts/",k.SDK_RELATIVE_DIR="../../scripts/",k.GAMEOVER_RELATIVE_DIR="../../gameover_template/",k.GAMES_DIR=S+"games/",k.BASE_DIR=S,k.CACHE_DIR=b,k.TEMP_DIR=A,k.CORDOVAJS=_+"cordova.js",k.CORDOVA_PLUGINS_JS=_+"cordova_plugins.js",k.STARGATEJS=_+"js/stargate.js",k.DATA_DIR=P,k.GAMEOVER_DIR=k.BASE_DIR+"gameover_template/",k.WWW_DIR=_,j.i("cordova JS dir to include",k.CORDOVAJS),n.game._public.BASE_DIR=k.BASE_DIR,n.game._public.OFFLINE_INDEX=k.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(k.BASE_DIR,"games"),a=e.createDir(k.BASE_DIR,"scripts"),u=e.fileExists(k.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(C))}),l=e.fileExists(k.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return j.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(k.BASE_DIR+"gameover_template"),e.dirExists(k.SDK_DIR+"plugins"),e.fileExists(k.SDK_DIR+"cordova.js"),e.fileExists(k.SDK_DIR+"cordova_plugins.js"),e.fileExists(k.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(k.WWW_DIR+"gameover_template",k.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(k.WWW_DIR+"plugins",k.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(k.CORDOVAJS,k.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(k.CORDOVA_PLUGINS_JS,k.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(k.WWW_DIR+"js/gamesFixes.js",k.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=E(T.sdk_url,{v:t.getTime()});return""===T.sdk_url||void 0===T.sdk_url||null===T.sdk_url?(j.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(k.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(j.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,k.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(k.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return j.d("Serialized dom",r),r}).then(function(t){return j.d("Write dom:",r,t),e.write(r,t)})}function w(e){return new RegExp(/.*\.html?$/i).test(e)}function h(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=k.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return j.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function m(){return j.i("readUserJson",k.BASE_DIR+"user.json"),e.readFileAsJSON(k.BASE_DIR+"user.json")}function v(e){return m().then(function(t){if(!t.ponyUrl)throw j.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];j.d("PONYVALUE",n);var r=E(T.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,j.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return j.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(k.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return j.d("writing offlineData.json",t),e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var S,b,A,_,P,I,D=t.Logger,E=t.composeApiString,R=t.jsonpRequest,O=t.extend,k={},T={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},L=!1,C={GaForGame:{},GamifiveInfo:{},queues:{}},N={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},j=new D("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,m);return j.d("Get GameInfo, fly my minipony!"),n.then(function(e){return j.i("Space is ok, can download:",m,e),v(y)}).then(function(n){return j.d("Ga for game and gamifive info stored!",n),j.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,k.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),j.d("unzip:",t.id,k.TEMP_DIR+y),e._promiseZip(n.path,k.TEMP_DIR+y,r("unzip"))}).then(function(n){j.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,m=d*Math.pow(1024,p?f.MB:f.KB),y=t.id;return s.then(function(e){return j.d("Exists",e),e?(L=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(L=!0,i())})},r.prototype.play=function(t){j.d("Play",t);var n=k.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return w(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){j.d("Removing game",t);var n=e.dirExists(k.CACHE_DIR+t+".zip"),r=e.dirExists(k.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(j.d("Removed in cache",n[0]),r.push(e.removeFile(k.CACHE_DIR+t+".zip"))),n[1]&&(j.d("Removed",n[1]),r.push(e.removeDir(k.GAMES_DIR+t))),0===r.length&&j.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return L},r.prototype.abortDownload=function(){return this.isDownloading()?(j.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,L=!1),!0):(j.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return j.d("Get games list"),e.readDir(k.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=k.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(j.d("Read meta.json:",n),j.d("GAMEOVER_TEMPLATE path",k.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(k.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return j.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(k.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(k.GAMES_DIR).then(function(t){return j.d("All games deleted!",t),e.createDir(k.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){j.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){j.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(a),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(a),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(a.Utils,a.Decorators,a);var s=function(){var e={},t=!1;e.init=function(){if(J.hasOwnProperty("webappsfixes")&&"object"==typeof J.webappsfixes){t=!0;for(var e in J.webappsfixes)if(J.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){w("[webappsFixes] applying fix: "+e);var r=n[e](J.webappsfixes[e]);r&&h("[webappsFixes] fix '"+e+"' failed: "+r)}else h("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(S()&&!e.platforms.ios)return void w("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(y()&&!e.platforms.android)return void w("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(w("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),w("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();a.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return h("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!J.statusbar)return;e=J.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},Z=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(S()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){w("[share] Share completed? "+e.completed),w("[share] Shared to app: "+e.app),n(e)},a=function(e){h("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){w("[share] Facebook share completed, result: ",e),t(e)},i=function(e){h("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){w("[share] Twitter share completed, result: ",e),t(e)},i=function(e){h("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){w("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){h("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){w("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){w("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},m("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(w("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(h("[share] type not valid"),n("type not valid"))):(h("[share] missing parameter url"),n("missing parameter url")):(h("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();o.socialShare=function(e){return P?I?new Promise(function(t,n){Z.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},o.socialShareAvailable=function(e){return P?I?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Z.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){h(e),n(e)})}):(h("[share] missing parameter url"),Promise.reject("missing parameter url")):(h("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(h("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var Q=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){g().then(function(e){f&&f.type&&"online"===f.type?(w("[push] going to url: ",e),A(e)):h("[push] i'm offline not going to url")}).catch(function(e){h("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],s=!1,u=!1,l=function(){u||i()&&(u=!0,window.cordova.plugins.notification.local.on("click",function(e){s?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var p=function(){var e=window.cordova.file.applicationStorageDirectory;return S()&&(e+="Documents/"),e},g=function(){return a.file.fileExists(p()+"SGpushUrl").then(function(e){return e?a.file.readFileAsJSON(p()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},y=function(e){var t={url:c(e,{source:"localpush"})};return a.file.createFile(p(),"SGpushUrl").then(function(e){return w("[push] writing offline data",t,"in: ",e.path),a.file.write(e.path,JSON.stringify(t))}).catch(function(e){h("[push] error sg create SGpushUrl file",e)})},b=function(){var t=v.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(u||d();o.length>0;){var t=o.pop();w("[push] processing queued event: ",t),r()}s=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,f=1732584193,p=-271733879,g=-1732584194,w=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function f(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function p(e){return unescape(encodeURIComponent(e))}function g(e){return l(p(e))}function w(e){return f(g(e))}function h(e,t){return d(p(e),p(t))}function m(e,t){return f(h(e,t))}function v(e,t,n){return t?n?h(t,e):m(t,e):n?g(e):w(e)}return v}(),te=function(e){if(void 0===window.SpinnerDialog)return h("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},ne=function(){return void 0===window.SpinnerDialog?h("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=te,window.stopLoading=ne,o.inAppPurchaseSubscription=function(e,t,n,r){return P?I?(q(!0),void 0!==r&&(ie.returnUrl=r),void 0!==n&&(ie.subscribeMethod=n),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0,ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(),window.store.order(ie.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},o.inAppRestore=function(e,t,n,r){return P?I?(void 0!==n&&(ie.subscribeMethod=n),void 0!==r&&(ie.returnUrl=r),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0,void ie.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},o.inAppProductInfo=function(e){if(e.productId||(e.productId=ie.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return h("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!P)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!I)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(ie.subscribeMethod=e.subscriptionUrl,ie.requestedListingProductId=e.productId,ie.callbackListingSuccess=e.callbackListingSuccess,ie.callbackPurchaseSuccess=e.callbackPurchaseSuccess,ie.callbackListingError=e.callbackError,ie.inappProductInfoCalled=!0,ie.productsInfo[e.productId])try{ie.callbackListingSuccess(ie.productsInfo[e.productId])}catch(e){h("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(!0),!0)};var re=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(y()?n=e.productsIdAndroid:S()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,w("[IAPlight] getProducts ok",e),e}).catch(function(e){h("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(w("[IAPlight] subscribe ok",t),S())return e.getActiveSubscriptionsInfo().then(function(e){if(w("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(y()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return h("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw h("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){w("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),w(JSON.stringify(e)),w(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){w("IAP> Purchase approved."),w(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){w("subscription verified ",e)},onStoreReady:function(){w("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(w("[IAP] > Product Owned."),!e.transaction.id&&S())return h("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),S()&&window.localStorage.setItem("transaction_id",e.transaction.id),y()){var t=e.transaction.purchaseToken+"|"+O+"|"+ie.id;w("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||ie.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(w("[IAP] appStoreReceipt: "+t.appStoreReceipt),ie.createUser(e,t.appStoreReceipt)):w("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){q(!1),ie.callbackError({iap_cancelled:1,return_url:ie.returnUrl}),w("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){w("[IAP] ORDER APPROVED "+ie.id),e.finish()},error:function(e){q(!1),h("[IAP] error: "+e),ie.callbackError({iap_error:1,return_url:ie.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(w("[IAP] createUser start "),!ie.inappProductInfoCalled&&!ie.inappPurchaseCalled)return ie.lastCreateUserProduct=e,void(ie.lastCreateUserToken=t);if(!ie.subscribeMethod)return void h("[IAP] createUser configuration error: missing api url.");var n=ie.getRandomEmail(),r=1;y()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=ie.subscribeMethod,o={paymethod:ie.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:ie.returnUrl,inapp_pwd:ie.getPassword(t),hybrid:1};ie.lastCreateuserUrl=i,ie.lastCreateuserData=o;var a=function(e){if(ie.createUserAttempt<=ie.maxCreateUserAttempt)h("[IAP] createUser failed "+ie.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{h("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:ie.returnUrl};q(!1),ie.inappPurchaseCalled?ie.callbackError(t):ie.inappProductInfoCalled&&ie.callbackListingError(t)}},s=function(e){w("[IAP] createUser success ",e);try{e.device_id=v.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),q(!1),ie.callbackSuccess(e),ie.inappPurchaseCalled?ie.callbackSuccess(e):ie.inappProductInfoCalled&&ie.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ie.createUserAttempt=ie.createUserAttempt+1,w("[IAP] createUser attempt: "+ie.createUserAttempt+" with timeout: "+c+"sec."),w("[IAP] POST createUser: "+ie.lastCreateuserUrl+" params: "+JSON.stringify(ie.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(ie.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(ie.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){w("[IAP] createUser end"),q(!1)}).go(),c+=5},10)} +;ie.createUserAttempt=0,u()}},oe=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return h("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return h("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});w("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){h("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return h("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});w("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){h("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(h("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(h("[globalization] getLocaleName: not initialized!"),!1)},e}();o.facebookLogin=function(e,t,n){if(!P)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){w("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){h("Got FB login error:",e),n({error:e})})},o.facebookShare=function(e,t,n){if(!P)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){h("Got FB share error:",e),n({error:e})})};var ae=function(){deltadna.registerPushCallback(ce)},se=function(e){h("[DeltaDNA] error: "+e)},ce=function(e){return y()&&e.payload&&e.payload.url&&!e.foreground?A(e.payload.url):S()&&e.url?A(e.url):void 0},ue=function(){var e={},t={},n=function(n){w("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(h("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(h("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&w("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return h("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),le=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return h("[appsflyer] missing cordova plugin");if(void 0===J.appsflyer_devkey)return h("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:J.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(S()){if(void 0===J.appstore_appid)return h("[appsflyer] missing manifest configuration: appstore_appid");n.appId=J.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}$.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();o.setConversionDataCallback=function(e){le.setCallback(e)};var de=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return w("[analytics] callback not set!");try{e(t)}catch(e){h("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();o.setAnalyticsCallback=function(e){de.setCallback(e)};var fe={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(fe.DefaultOptions=e),AdMob&&(fe.AdMobSupport=!0,fe.initAdMob(e,t,n)),MoPub&&(fe.MoPubSupport=!0),!0},isAdMobSupported:function(){return fe.AdMobSupport},isMoPubSupported:function(){return fe.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=fe.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=fe.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=fe.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?fe.AdSize.LEADERBOARD:t>=468&&e>=60?fe.AdSize.BANNER:t>=320&&e>=50?fe.AdSize.BANNER:void 0}};return o.game=a.game._public,o.file=a.file,o.AdManager=a.AdManager,o}); \ No newline at end of file diff --git a/dist/stargate.js b/dist/stargate.js index 115294a..50bcbf7 100644 --- a/dist/stargate.js +++ b/dist/stargate.js @@ -3935,7 +3935,7 @@ } }(this, function () { // Public interface - var stargatePackageVersion = "0.11.0"; + var stargatePackageVersion = "0.11.1"; var stargatePublic = {}; var stargateModules = {}; @@ -7235,34 +7235,36 @@ var onDeviceReady = function (resolve, reject) { // get connection information initializeConnectionStatus(); - // request all asyncronous initialization to complete - Promise.all([ - // include here all needed asyncronous initializazion - cordova.getAppVersion.getVersionNumber(), - getManifest(), - cordova.getAppVersion.getPackageName(), - cordova.getAppVersion.getVersionCode(), - getAppIsDebug() - ]) - .then(function(results) { - // save async initialization result - - appVersion = results[0]; - - if (typeof results[1] !== 'object') { - results[1] = JSON.parse(results[1]); + getManifest() + .then(function(resultManifest){ + log("onDeviceReady() [1/4] got manifest"); + if (typeof resultManifest !== 'object') { + resultManifest = JSON.parse(resultManifest); } - - appPackageName = results[2]; - appBuild = results[3]; - - if (results[4] && ( typeof(results[4]) === 'object') ) { - if (results[4].debug) { - appIsDebug = true; - } - } - stargateConf = results[1].stargateConf; + // save stargateConf got from manifest.json + stargateConf = resultManifest.stargateConf; + + // execute next promise + return cordova.getAppVersion.getVersionNumber(); + }) + .then(function(resultAppVersionNumber) { + log("onDeviceReady() [2/4] got appVersionNumber"); + appVersion = resultAppVersionNumber; + + // execute next promise + return cordova.getAppVersion.getPackageName(); + }) + .then(function(resultAppPackageName){ + log("onDeviceReady() [3/4] got appPackageName"); + appPackageName = resultAppPackageName; + + // execute next promise + return cordova.getAppVersion.getVersionCode(); + }) + .then(function(resultAppVersionCode){ + log("onDeviceReady() [4/4] got appPackageName"); + appBuild = resultAppVersionCode; // execute remaining initialization onPluginReady(resolve, reject); diff --git a/dist/stargate.min.js b/dist/stargate.min.js index 3ce5c6f..9cf3b13 100644 --- a/dist/stargate.min.js +++ b/dist/stargate.min.js @@ -1,10 +1,10 @@ /*! * StargateJS Apps - * v0.11.0 + * v0.11.1 * Copyright 2015 DMobileLab. http://buongiorno.com/ * See LICENSE in this repository for license information */ !function(e,t){"use strict";"object"==typeof exports?module.exports=t(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"==typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],t):e.URI=t(e.punycode,e.IPv6,e.SecondLevelDomains,e)}(this,function(e,t,n,r){"use strict";function i(e,t){var n=arguments.length>=1,r=arguments.length>=2;if(!(this instanceof i))return n?r?new i(e,t):new i(e):new i;if(void 0===e){if(n)throw new TypeError("undefined is not a valid argument for URI");e="undefined"!=typeof location?location.href+"":""}return this.href(e),void 0!==t?this.absoluteTo(t):this}function o(e){return e.replace(/([.*+?^=!:()|[\]\/\\])/g,"\\$1")}function a(e){return void 0===e?"Undefined":String(Object.prototype.toString.call(e)).slice(8,-1)}function s(e){return"Array"===a(e)}function c(e,t){var n,r,i={};if("RegExp"===a(t))i=null;else if(s(t))for(n=0,r=t.length;n]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,i.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?«»“”„‘’]+$/},i.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},i.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/,i.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"},i.getDomAttribute=function(e){if(e&&e.nodeName){var t=e.nodeName.toLowerCase();if("input"!==t||"image"===e.type)return i.domAttributes[t]}},i.encode=f,i.decode=decodeURIComponent,i.iso8859=function(){i.encode=escape,i.decode=unescape},i.unicode=function(){i.encode=f,i.decode=decodeURIComponent},i.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/gi,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}},i.encodeQuery=function(e,t){var n=i.encode(e+"");return void 0===t&&(t=i.escapeQuerySpace),t?n.replace(/%20/g,"+"):n},i.decodeQuery=function(e,t){e+="",void 0===t&&(t=i.escapeQuerySpace);try{return i.decode(t?e.replace(/\+/g,"%20"):e)}catch(t){return e}};var y,b={encode:"encode",decode:"decode"},_=function(e,t){return function(n){try{return i[t](n+"").replace(i.characters[e][t].expression,function(n){return i.characters[e][t].map[n]})}catch(e){return n}}};for(y in b)i[y+"PathSegment"]=_("pathname",b[y]),i[y+"UrnPathSegment"]=_("urnpath",b[y]);var S=function(e,t,n){return function(r){var o;o=n?function(e){return i[t](i[n](e))}:i[t];for(var a=(r+"").split(e),s=0,c=a.length;s-1&&(t.fragment=e.substring(n+1)||null,e=e.substring(0,n)),n=e.indexOf("?"),n>-1&&(t.query=e.substring(n+1)||null,e=e.substring(0,n)),"//"===e.substring(0,2)?(t.protocol=null,e=e.substring(2),e=i.parseAuthority(e,t)):(n=e.indexOf(":"))>-1&&(t.protocol=e.substring(0,n)||null,t.protocol&&!t.protocol.match(i.protocol_expression)?t.protocol=void 0:"//"===e.substring(n+1,n+3)?(e=e.substring(n+3),e=i.parseAuthority(e,t)):(e=e.substring(n+1),t.urn=!0)),t.path=e,t},i.parseHost=function(e,t){e=e.replace(/\\/g,"/");var n,r,i=e.indexOf("/");if(-1===i&&(i=e.length),"["===e.charAt(0))n=e.indexOf("]"),t.hostname=e.substring(1,n)||null,t.port=e.substring(n+2,i)||null,"/"===t.port&&(t.port=null);else{var o=e.indexOf(":"),a=e.indexOf("/"),s=e.indexOf(":",o+1);-1!==s&&(-1===a||s-1?r:e.length-1);return o>-1&&(-1===r||o3?Object.keys(n).forEach(function(e){var n=e.match(/^([0-9])([0-9x])([0-9x])$/i);!(n&&n.length>3&&o[1]===n[1])||"x"!==n[2]&&o[2]!==n[2]||"x"!==n[3]&&o[3]!==n[3]||i(e,t)}):n[e]&&i(e,t)}return this},go:function(){var e=t.type||(t.into?"html":"json"),n=u();if("function"==typeof a[e])return a[e].call(this,n)}},a={json:function(e){var t=this;a._xhr.call(this,e,function(e){if(e)try{e=JSON.parse(e)}catch(e){return t.trigger("error",e),null}return e})},html:function(e){a._xhr.call(this,e,function(e){return t.into&&t.into.length&&[].forEach.call(t.into,function(t){t.innerHTML=e}),e})},_xhr:function(e,n){var r,i,o,a,s,u=this,l=t.method||"get",d=!0!==t.sync,p=new XMLHttpRequest,f=t.data,h=t.body,g=(t.headers,this.header("Content-Type")),m=t.timeout;if(!g&&f&&c()&&(this.header("Content-Type","application/x-www-form-urlencoded;charset=utf-8"),g=this.header("Content-Type")),f&&c())if("string"!=typeof h&&(h=""),g.indexOf("json")>-1)try{h=JSON.stringify(f)}catch(e){throw new TypeError("Unable to stringify body's content : "+e.name)}else{a=g&&g.indexOf("x-www-form-urlencoded")>1;for(r in f)h+=a?encodeURIComponent(r)+"="+encodeURIComponent(f[r])+"&":r+"="+f[r]+"\n\r"}s=[l,e,d],t.auth&&(s.push(t.auth.user),s.push(t.auth.passwd)),p.open.apply(p,s);for(i in t.headers)p.setRequestHeader(i,t.headers[i]);p.onprogress=function(e){e.lengthComputable&&u.trigger("progress",e.loaded/e.total)},p.onload=function(){var e=p.responseText;o&&clearTimeout(o),this.status>=200&&this.status<300&&("function"==typeof n&&(e=n(e)),u.trigger("success",e)),u.trigger(this.status,e),u.trigger("end",e)},p.onerror=function(e){o&&clearTimeout(o),u.trigger("error",e,arguments)},m&&(o=setTimeout(function(){u.trigger("timeout",{type:"timeout",expiredAfter:m},p,arguments),p.abort()},m)),p.send(h)},jsonp:function(n){var r,o=this,a=document.querySelector("head"),s=!0!==t.sync,c=t.jsonPaddingName||"callback",u=t.jsonPadding||"_padd"+(new Date).getTime()+Math.floor(1e4*Math.random()),l={};if(e[u])throw new Error("Padding "+u+" already exists. It must be unique.");/^ajajsonp_/.test(u)||(u="ajajsonp_"+u),window[u]=function(e){o.trigger("success",e),a.removeChild(r),window[u]=void 0},l[c]=u,n=i(n,l),r=document.createElement("script"),r.async=s,r.src=n,r.onerror=function(){o.trigger("error",arguments),a.removeChild(r),window[u]=void 0},a.appendChild(r)},script:function(e){var n,r=this,i=document.querySelector("head")||document.querySelector("body"),o=!0!==t.sync;if(!i)throw new Error("Ok, wait a second, you want to load a script, but you don't have at least a head or body tag...");n=document.createElement("script"),n.async=o,n.src=e,n.onerror=function(){r.trigger("error",arguments),i.removeChild(n)},n.onload=function(){r.trigger("success",arguments)},i.appendChild(n)}},s=function(e,n,i,o){if(void 0!==n){if("function"==typeof i)try{n=i.call(r,n)}catch(t){throw new TypeError("Failed to set "+e+" : "+t.message)}return t[e]="function"==typeof o?o.call(this,n):n,this}return"undefined"===t[e]?null:t[e]},c=function(){return["delete","patch","post","put"].indexOf(t.method)>-1},u=function(){var e=t.url,n=void 0===t.cache||!!t.cache,r=t.queryString||"",o=t.data;return!1===n&&(r+="&ajabuster="+(new Date).getTime()),e=i(e,r),o&&!c()&&(e=i(e,o)),e};return o},r={bool:function(e){return!!e},string:function(e){if("string"!=typeof e)throw new TypeError("a string is expected, but "+e+" ["+typeof e+"] given");return e},positiveInteger:function(e){if(parseInt(e)!==e||e<=0)throw new TypeError("an integer is expected, but "+e+" ["+typeof e+"] given");return e},plainObject:function(e){if("object"!=typeof e||e.constructor!==Object)throw new TypeError("an object is expected, but "+e+" ["+typeof e+"] given");return e},type:function(t){if(t=this.string(t),e.indexOf(t.toLowerCase())<0)throw new TypeError("a type in ["+e.join(", ")+"] is expected, but "+t+" given");return t.toLowerCase()},method:function(e){if(e=this.string(e),t.indexOf(e.toLowerCase())<0)throw new TypeError("a method in ["+t.join(", ")+"] is expected, but "+e+" given");return e.toLowerCase()},queryString:function(e){var t={};return"string"==typeof e?e.replace("?","").split("&").forEach(function(e){var n=e.split("=");2===n.length&&(t[decodeURIComponent(n[0])]=decodeURIComponent(n[1]))}):t=e,this.plainObject(t)},selector:function(e){if("string"!=typeof e&&!(e instanceof HTMLElement))throw new TypeError("a selector or an HTMLElement is expected, "+e+" ["+typeof e+"] given");return e},func:function(e){if(e=this.string(e),!/^([a-zA-Z_])([a-zA-Z0-9_\-])+$/.test(e))throw new TypeError("a valid function name is expected, "+e+" ["+typeof e+"] given");return e}},i=function(e,t){var n;if(e=e||"",t)if(-1===e.indexOf("?")&&(e+="?"),"string"==typeof t)e+=t;else if("object"==typeof t)for(n in t)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(t[n]);return e};"function"==typeof define&&define.amd?define([],function(){return n}):"object"==typeof exports?module.exports=n:window.aja=window.aja||n}(),function(e){function t(e,t){return function(){e.apply(t,arguments)}}function n(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],c(e,t(i,this),t(o,this))}function r(e){var t=this;if(null===this._state)return void this._deferreds.push(e);l(function(){var n=t._state?e.onFulfilled:e.onRejected;if(null===n)return void(t._state?e.resolve:e.reject)(t._value);var r;try{r=n(t._value)}catch(t){return void e.reject(t)}e.resolve(r)})}function i(e){try{if(e===this)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void c(t(n,e),t(i,this),t(o,this))}this._state=!0,this._value=e,a.call(this)}catch(e){o.call(this,e)}}function o(e){this._state=!1,this._value=e,a.call(this)}function a(){for(var e=0,t=this._deferreds.length;e0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(s),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(s,s.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(T=x(T,t)),U.d("Initialized called with:",T),!e)return Promise.reject("Missing file module!");try{b=window.cordova.file.applicationStorageDirectory,_=window.cordova.file.cacheDirectory,S=window.cordova.file.tempDirectory,A=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",P=window.cordova.file.dataDirectory}catch(e){return U.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(b+="Documents/"),"android"==window.device.platform.toLowerCase()&&(S=_),O.SDK_DIR=b+"scripts/",O.SDK_RELATIVE_DIR="../../scripts/",O.GAMEOVER_RELATIVE_DIR="../../gameover_template/",O.GAMES_DIR=b+"games/",O.BASE_DIR=b,O.CACHE_DIR=_,O.TEMP_DIR=S,O.CORDOVAJS=A+"cordova.js",O.CORDOVA_PLUGINS_JS=A+"cordova_plugins.js",O.STARGATEJS=A+"js/stargate.js",O.DATA_DIR=P,O.GAMEOVER_DIR=O.BASE_DIR+"gameover_template/",O.WWW_DIR=A,U.i("cordova JS dir to include",O.CORDOVAJS),n.game._public.BASE_DIR=O.BASE_DIR,n.game._public.OFFLINE_INDEX=O.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(O.BASE_DIR,"games"),a=e.createDir(O.BASE_DIR,"scripts"),u=e.fileExists(O.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(k))}),l=e.fileExists(O.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return U.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(O.BASE_DIR+"gameover_template"),e.dirExists(O.SDK_DIR+"plugins"),e.fileExists(O.SDK_DIR+"cordova.js"),e.fileExists(O.SDK_DIR+"cordova_plugins.js"),e.fileExists(O.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(O.WWW_DIR+"gameover_template",O.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(O.WWW_DIR+"plugins",O.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(O.CORDOVAJS,O.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(O.CORDOVA_PLUGINS_JS,O.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(O.WWW_DIR+"js/gamesFixes.js",O.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=D(T.sdk_url,{v:t.getTime()});return""===T.sdk_url||void 0===T.sdk_url||null===T.sdk_url?(U.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(O.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(U.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,O.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(O.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return U.d("Serialized dom",r),r}).then(function(t){return U.d("Write dom:",r,t),e.write(r,t)})}function g(e){return new RegExp(/.*\.html?$/i).test(e)}function m(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=O.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return U.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function w(){return U.i("readUserJson",O.BASE_DIR+"user.json"),e.readFileAsJSON(O.BASE_DIR+"user.json")}function v(e){return w().then(function(t){if(!t.ponyUrl)throw U.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];U.d("PONYVALUE",n);var r=D(T.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,U.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return U.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(O.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return U.d("writing offlineData.json",t),e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var b,_,S,A,P,I,E=t.Logger,D=t.composeApiString,R=t.jsonpRequest,x=t.extend,O={},T={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},j=!1,k={GaForGame:{},GamifiveInfo:{},queues:{}},C={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},U=new E("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,w);return U.d("Get GameInfo, fly my minipony!"),n.then(function(e){return U.i("Space is ok, can download:",w,e),v(y)}).then(function(n){ -return U.d("Ga for game and gamifive info stored!",n),U.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,O.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),U.d("unzip:",t.id,O.TEMP_DIR+y),e._promiseZip(n.path,O.TEMP_DIR+y,r("unzip"))}).then(function(n){U.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,w=d*Math.pow(1024,f?p.MB:p.KB),y=t.id;return s.then(function(e){return U.d("Exists",e),e?(j=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(j=!0,i())})},r.prototype.play=function(t){U.d("Play",t);var n=O.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return g(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){U.d("Removing game",t);var n=e.dirExists(O.CACHE_DIR+t+".zip"),r=e.dirExists(O.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(U.d("Removed in cache",n[0]),r.push(e.removeFile(O.CACHE_DIR+t+".zip"))),n[1]&&(U.d("Removed",n[1]),r.push(e.removeDir(O.GAMES_DIR+t))),0===r.length&&U.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return j},r.prototype.abortDownload=function(){return this.isDownloading()?(U.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,j=!1),!0):(U.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return U.d("Get games list"),e.readDir(O.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=O.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(U.d("Read meta.json:",n),U.d("GAMEOVER_TEMPLATE path",O.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(O.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return U.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(O.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(O.GAMES_DIR).then(function(t){return U.d("All games deleted!",t),e.createDir(O.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){U.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){U.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(J.hasOwnProperty("webappsfixes")&&"object"==typeof J.webappsfixes){t=!0;for(var e in J.webappsfixes)if(J.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){m("[webappsFixes] applying fix: "+e);var r=n[e](J.webappsfixes[e]);r&&w("[webappsFixes] fix '"+e+"' failed: "+r)}else w("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(_()&&!e.platforms.ios)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(b()&&!e.platforms.android)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(m("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),m("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return w("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!J.statusbar)return;e=J.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},Y=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(_()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){m("[share] Share completed? "+e.completed),m("[share] Shared to app: "+e.app),n(e)},a=function(e){w("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){m("[share] Facebook share completed, result: ",e),t(e)},i=function(e){w("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){m("[share] Twitter share completed, result: ",e),t(e)},i=function(e){w("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){m("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){w("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){m("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){m("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(m("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(w("[share] type not valid"),n("type not valid"))):(w("[share] missing parameter url"),n("missing parameter url")):(w("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return I?E?new Promise(function(t,n){Y.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return I?E?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Y.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){w(e),n(e)})}):(w("[share] missing parameter url"),Promise.reject("missing parameter url")):(w("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(w("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var ee=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){h().then(function(e){f&&f.type&&"online"===f.type?(m("[push] going to url: ",e),A(e)):w("[push] i'm offline not going to url")}).catch(function(e){w("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var p=function(){var e=window.cordova.file.applicationStorageDirectory;return _()&&(e+="Documents/"),e},h=function(){return s.file.fileExists(p()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(p()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},g=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(p(),"SGpushUrl").then(function(e){return m("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){w("[push] error sg create SGpushUrl file",e)})},b=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();m("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,p=1732584193,f=-271733879,h=-1732584194,g=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function p(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function f(e){return unescape(encodeURIComponent(e))}function h(e){return l(f(e))}function g(e){return p(h(e))}function m(e,t){return d(f(e),f(t))}function w(e,t){return p(m(e,t))}function v(e,t,n){return t?n?m(t,e):w(t,e):n?h(e):g(e)}return v}(),re=function(e){if(void 0===window.SpinnerDialog)return w("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},ie=function(){return void 0===window.SpinnerDialog?w("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=re,window.stopLoading=ie,a.inAppPurchaseSubscription=function(e,t,n,r){return I?E?(K(!0),void 0!==r&&(ae.returnUrl=r),void 0!==n&&(ae.subscribeMethod=n),ae.callbackSuccess=e,ae.callbackError=t,ae.inappPurchaseCalled=!0,ae.lastCreateUserProduct&&ae.lastCreateUserToken?(ae.createUser(ae.lastCreateUserProduct,ae.lastCreateUserToken),!0):(ae.doRefresh(),window.store.order(ae.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.inAppRestore=function(e,t,n,r){return I?E?(void 0!==n&&(ae.subscribeMethod=n), -void 0!==r&&(ae.returnUrl=r),ae.callbackSuccess=e,ae.callbackError=t,ae.inappPurchaseCalled=!0,void ae.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},a.inAppProductInfo=function(e){if(e.productId||(e.productId=ae.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return w("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!I)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!E)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(ae.subscribeMethod=e.subscriptionUrl,ae.requestedListingProductId=e.productId,ae.callbackListingSuccess=e.callbackListingSuccess,ae.callbackPurchaseSuccess=e.callbackPurchaseSuccess,ae.callbackListingError=e.callbackError,ae.inappProductInfoCalled=!0,ae.productsInfo[e.productId])try{ae.callbackListingSuccess(ae.productsInfo[e.productId])}catch(e){w("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return ae.lastCreateUserProduct&&ae.lastCreateUserToken?(ae.createUser(ae.lastCreateUserProduct,ae.lastCreateUserToken),!0):(ae.doRefresh(!0),!0)};var oe=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(b()?n=e.productsIdAndroid:_()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,m("[IAPlight] getProducts ok",e),e}).catch(function(e){w("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(m("[IAPlight] subscribe ok",t),_())return e.getActiveSubscriptionsInfo().then(function(e){if(m("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(b()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return w("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw w("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){m("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),m(JSON.stringify(e)),m(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){m("IAP> Purchase approved."),m(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){m("subscription verified ",e)},onStoreReady:function(){m("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(m("[IAP] > Product Owned."),!e.transaction.id&&_())return w("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),_()&&window.localStorage.setItem("transaction_id",e.transaction.id),b()){var t=e.transaction.purchaseToken+"|"+O+"|"+ae.id;m("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||ae.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(m("[IAP] appStoreReceipt: "+t.appStoreReceipt),ae.createUser(e,t.appStoreReceipt)):m("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){K(!1),ae.callbackError({iap_cancelled:1,return_url:ae.returnUrl}),m("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){m("[IAP] ORDER APPROVED "+ae.id),e.finish()},error:function(e){K(!1),w("[IAP] error: "+e),ae.callbackError({iap_error:1,return_url:ae.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(m("[IAP] createUser start "),!ae.inappProductInfoCalled&&!ae.inappPurchaseCalled)return ae.lastCreateUserProduct=e,void(ae.lastCreateUserToken=t);if(!ae.subscribeMethod)return void w("[IAP] createUser configuration error: missing api url.");var n=ae.getRandomEmail(),r=1;b()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=ae.subscribeMethod,o={paymethod:ae.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:ae.returnUrl,inapp_pwd:ae.getPassword(t),hybrid:1};ae.lastCreateuserUrl=i,ae.lastCreateuserData=o;var a=function(e){if(ae.createUserAttempt<=ae.maxCreateUserAttempt)w("[IAP] createUser failed "+ae.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{w("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:ae.returnUrl};K(!1),ae.inappPurchaseCalled?ae.callbackError(t):ae.inappProductInfoCalled&&ae.callbackListingError(t)}},s=function(e){m("[IAP] createUser success ",e);try{e.device_id=y.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),K(!1),ae.callbackSuccess(e),ae.inappPurchaseCalled?ae.callbackSuccess(e):ae.inappProductInfoCalled&&ae.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ae.createUserAttempt=ae.createUserAttempt+1,m("[IAP] createUser attempt: "+ae.createUserAttempt+" with timeout: "+c+"sec."),m("[IAP] POST createUser: "+ae.lastCreateuserUrl+" params: "+JSON.stringify(ae.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(ae.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(ae.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){m("[IAP] createUser end"),K(!1)}).go(),c+=5},10)};ae.createUserAttempt=0,u()}},se=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return w("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return w("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});m("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){w("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return w("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});m("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){w("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(w("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(w("[globalization] getLocaleName: not initialized!"),!1)},e}();a.facebookLogin=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){m("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){w("Got FB login error:",e),n({error:e})})},a.facebookShare=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){w("Got FB share error:",e),n({error:e})})};var ce=function(){deltadna.registerPushCallback(le)},ue=function(e){w("[DeltaDNA] error: "+e)},le=function(e){return b()&&e.payload&&e.payload.url&&!e.foreground?A(e.payload.url):_()&&e.url?A(e.url):void 0},de=function(){var e={},t={},n=function(n){m("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(w("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(w("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&m("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return w("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),pe=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return w("[appsflyer] missing cordova plugin");if(void 0===J.appsflyer_devkey)return w("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:J.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(_()){if(void 0===J.appstore_appid)return w("[appsflyer] missing manifest configuration: appstore_appid");n.appId=J.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}te.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();a.setConversionDataCallback=function(e){pe.setCallback(e)};var fe=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return m("[analytics] callback not set!");try{e(t)}catch(e){w("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();a.setAnalyticsCallback=function(e){fe.setCallback(e)};var he={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(he.DefaultOptions=e),AdMob&&(he.AdMobSupport=!0,he.initAdMob(e,t,n)),MoPub&&(he.MoPubSupport=!0),!0},isAdMobSupported:function(){return he.AdMobSupport},isMoPubSupported:function(){return he.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=he.getUserAgent();e||he.isObjEmpty(he.DefaultOptions)||(e=he.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=he.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=he.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=he.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=he.getUserAgent();e||he.isObjEmpty(he.DefaultOptions)||(e=he.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=he.getUserAgent();e||he.isObjEmpty(he.DefaultOptions)||(e=he.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=he.getUserAgent();e||he.isObjEmpty(he.DefaultOptions)||(e=he.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=he.getUserAgent();e||he.isObjEmpty(he.DefaultOptions)||(e=he.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=he.getUserAgent();e||he.isObjEmpty(he.DefaultOptions)||(e=he.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=he.getUserAgent();e||he.isObjEmpty(he.DefaultOptions)||(e=he.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?he.AdSize.LEADERBOARD:t>=468&&e>=60?he.AdSize.BANNER:t>=320&&e>=50?he.AdSize.BANNER:void 0}};return a.game=s.game._public,a.file=s.file,a.AdManager=s.AdManager,a}); \ No newline at end of file +void 0===(r="[object Function]"===String(Object.prototype.toString.call(i))?i(e):"[object Function]"===String(Object.prototype.toString.call(i[e]))?i[e](e):i[e])||null===r)return a;if("[object Array]"===String(Object.prototype.toString.call(r))){for(t=0,n=r.length;t3?Object.keys(n).forEach(function(e){var n=e.match(/^([0-9])([0-9x])([0-9x])$/i);!(n&&n.length>3&&o[1]===n[1])||"x"!==n[2]&&o[2]!==n[2]||"x"!==n[3]&&o[3]!==n[3]||i(e,t)}):n[e]&&i(e,t)}return this},go:function(){var e=t.type||(t.into?"html":"json"),n=u();if("function"==typeof a[e])return a[e].call(this,n)}},a={json:function(e){var t=this;a._xhr.call(this,e,function(e){if(e)try{e=JSON.parse(e)}catch(e){return t.trigger("error",e),null}return e})},html:function(e){a._xhr.call(this,e,function(e){return t.into&&t.into.length&&[].forEach.call(t.into,function(t){t.innerHTML=e}),e})},_xhr:function(e,n){var r,i,o,a,s,u=this,l=t.method||"get",d=!0!==t.sync,p=new XMLHttpRequest,f=t.data,h=t.body,g=(t.headers,this.header("Content-Type")),m=t.timeout;if(!g&&f&&c()&&(this.header("Content-Type","application/x-www-form-urlencoded;charset=utf-8"),g=this.header("Content-Type")),f&&c())if("string"!=typeof h&&(h=""),g.indexOf("json")>-1)try{h=JSON.stringify(f)}catch(e){throw new TypeError("Unable to stringify body's content : "+e.name)}else{a=g&&g.indexOf("x-www-form-urlencoded")>1;for(r in f)h+=a?encodeURIComponent(r)+"="+encodeURIComponent(f[r])+"&":r+"="+f[r]+"\n\r"}s=[l,e,d],t.auth&&(s.push(t.auth.user),s.push(t.auth.passwd)),p.open.apply(p,s);for(i in t.headers)p.setRequestHeader(i,t.headers[i]);p.onprogress=function(e){e.lengthComputable&&u.trigger("progress",e.loaded/e.total)},p.onload=function(){var e=p.responseText;o&&clearTimeout(o),this.status>=200&&this.status<300&&("function"==typeof n&&(e=n(e)),u.trigger("success",e)),u.trigger(this.status,e),u.trigger("end",e)},p.onerror=function(e){o&&clearTimeout(o),u.trigger("error",e,arguments)},m&&(o=setTimeout(function(){u.trigger("timeout",{type:"timeout",expiredAfter:m},p,arguments),p.abort()},m)),p.send(h)},jsonp:function(n){var r,o=this,a=document.querySelector("head"),s=!0!==t.sync,c=t.jsonPaddingName||"callback",u=t.jsonPadding||"_padd"+(new Date).getTime()+Math.floor(1e4*Math.random()),l={};if(e[u])throw new Error("Padding "+u+" already exists. It must be unique.");/^ajajsonp_/.test(u)||(u="ajajsonp_"+u),window[u]=function(e){o.trigger("success",e),a.removeChild(r),window[u]=void 0},l[c]=u,n=i(n,l),r=document.createElement("script"),r.async=s,r.src=n,r.onerror=function(){o.trigger("error",arguments),a.removeChild(r),window[u]=void 0},a.appendChild(r)},script:function(e){var n,r=this,i=document.querySelector("head")||document.querySelector("body"),o=!0!==t.sync;if(!i)throw new Error("Ok, wait a second, you want to load a script, but you don't have at least a head or body tag...");n=document.createElement("script"),n.async=o,n.src=e,n.onerror=function(){r.trigger("error",arguments),i.removeChild(n)},n.onload=function(){r.trigger("success",arguments)},i.appendChild(n)}},s=function(e,n,i,o){if(void 0!==n){if("function"==typeof i)try{n=i.call(r,n)}catch(t){throw new TypeError("Failed to set "+e+" : "+t.message)}return t[e]="function"==typeof o?o.call(this,n):n,this}return"undefined"===t[e]?null:t[e]},c=function(){return["delete","patch","post","put"].indexOf(t.method)>-1},u=function(){var e=t.url,n=void 0===t.cache||!!t.cache,r=t.queryString||"",o=t.data;return!1===n&&(r+="&ajabuster="+(new Date).getTime()),e=i(e,r),o&&!c()&&(e=i(e,o)),e};return o},r={bool:function(e){return!!e},string:function(e){if("string"!=typeof e)throw new TypeError("a string is expected, but "+e+" ["+typeof e+"] given");return e},positiveInteger:function(e){if(parseInt(e)!==e||e<=0)throw new TypeError("an integer is expected, but "+e+" ["+typeof e+"] given");return e},plainObject:function(e){if("object"!=typeof e||e.constructor!==Object)throw new TypeError("an object is expected, but "+e+" ["+typeof e+"] given");return e},type:function(t){if(t=this.string(t),e.indexOf(t.toLowerCase())<0)throw new TypeError("a type in ["+e.join(", ")+"] is expected, but "+t+" given");return t.toLowerCase()},method:function(e){if(e=this.string(e),t.indexOf(e.toLowerCase())<0)throw new TypeError("a method in ["+t.join(", ")+"] is expected, but "+e+" given");return e.toLowerCase()},queryString:function(e){var t={};return"string"==typeof e?e.replace("?","").split("&").forEach(function(e){var n=e.split("=");2===n.length&&(t[decodeURIComponent(n[0])]=decodeURIComponent(n[1]))}):t=e,this.plainObject(t)},selector:function(e){if("string"!=typeof e&&!(e instanceof HTMLElement))throw new TypeError("a selector or an HTMLElement is expected, "+e+" ["+typeof e+"] given");return e},func:function(e){if(e=this.string(e),!/^([a-zA-Z_])([a-zA-Z0-9_\-])+$/.test(e))throw new TypeError("a valid function name is expected, "+e+" ["+typeof e+"] given");return e}},i=function(e,t){var n;if(e=e||"",t)if(-1===e.indexOf("?")&&(e+="?"),"string"==typeof t)e+=t;else if("object"==typeof t)for(n in t)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(t[n]);return e};"function"==typeof define&&define.amd?define([],function(){return n}):"object"==typeof exports?module.exports=n:window.aja=window.aja||n}(),function(e){function t(e,t){return function(){e.apply(t,arguments)}}function n(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],c(e,t(i,this),t(o,this))}function r(e){var t=this;if(null===this._state)return void this._deferreds.push(e);l(function(){var n=t._state?e.onFulfilled:e.onRejected;if(null===n)return void(t._state?e.resolve:e.reject)(t._value);var r;try{r=n(t._value)}catch(t){return void e.reject(t)}e.resolve(r)})}function i(e){try{if(e===this)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void c(t(n,e),t(i,this),t(o,this))}this._state=!0,this._value=e,a.call(this)}catch(e){o.call(this,e)}}function o(e){this._state=!1,this._value=e,a.call(this)}function a(){for(var e=0,t=this._deferreds.length;e0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(a),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(a,a.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(T=x(T,t)),U.d("Initialized called with:",T),!e)return Promise.reject("Missing file module!");try{b=window.cordova.file.applicationStorageDirectory,_=window.cordova.file.cacheDirectory,S=window.cordova.file.tempDirectory,A=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",P=window.cordova.file.dataDirectory}catch(e){return U.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(b+="Documents/"),"android"==window.device.platform.toLowerCase()&&(S=_),O.SDK_DIR=b+"scripts/",O.SDK_RELATIVE_DIR="../../scripts/",O.GAMEOVER_RELATIVE_DIR="../../gameover_template/",O.GAMES_DIR=b+"games/",O.BASE_DIR=b,O.CACHE_DIR=_,O.TEMP_DIR=S,O.CORDOVAJS=A+"cordova.js",O.CORDOVA_PLUGINS_JS=A+"cordova_plugins.js",O.STARGATEJS=A+"js/stargate.js",O.DATA_DIR=P,O.GAMEOVER_DIR=O.BASE_DIR+"gameover_template/",O.WWW_DIR=A,U.i("cordova JS dir to include",O.CORDOVAJS),n.game._public.BASE_DIR=O.BASE_DIR,n.game._public.OFFLINE_INDEX=O.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(O.BASE_DIR,"games"),a=e.createDir(O.BASE_DIR,"scripts"),u=e.fileExists(O.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(j))}),l=e.fileExists(O.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return U.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(O.BASE_DIR+"gameover_template"),e.dirExists(O.SDK_DIR+"plugins"),e.fileExists(O.SDK_DIR+"cordova.js"),e.fileExists(O.SDK_DIR+"cordova_plugins.js"),e.fileExists(O.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(O.WWW_DIR+"gameover_template",O.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(O.WWW_DIR+"plugins",O.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(O.CORDOVAJS,O.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(O.CORDOVA_PLUGINS_JS,O.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(O.WWW_DIR+"js/gamesFixes.js",O.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=D(T.sdk_url,{v:t.getTime()});return""===T.sdk_url||void 0===T.sdk_url||null===T.sdk_url?(U.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(O.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(U.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,O.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(O.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return U.d("Serialized dom",r),r}).then(function(t){return U.d("Write dom:",r,t),e.write(r,t)})}function g(e){return new RegExp(/.*\.html?$/i).test(e)}function m(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=O.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return U.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function w(){return U.i("readUserJson",O.BASE_DIR+"user.json"),e.readFileAsJSON(O.BASE_DIR+"user.json")}function v(e){return w().then(function(t){if(!t.ponyUrl)throw U.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];U.d("PONYVALUE",n);var r=D(T.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,U.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return U.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(O.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return U.d("writing offlineData.json",t),e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var b,_,S,A,P,I,E=t.Logger,D=t.composeApiString,R=t.jsonpRequest,x=t.extend,O={},T={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},k=!1,j={GaForGame:{},GamifiveInfo:{},queues:{}},C={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},U=new E("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,w);return U.d("Get GameInfo, fly my minipony!"),n.then(function(e){return U.i("Space is ok, can download:",w,e),v(y)}).then(function(n){return U.d("Ga for game and gamifive info stored!",n),U.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,O.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),U.d("unzip:",t.id,O.TEMP_DIR+y), +e._promiseZip(n.path,O.TEMP_DIR+y,r("unzip"))}).then(function(n){U.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,w=d*Math.pow(1024,f?p.MB:p.KB),y=t.id;return s.then(function(e){return U.d("Exists",e),e?(k=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(k=!0,i())})},r.prototype.play=function(t){U.d("Play",t);var n=O.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return g(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){U.d("Removing game",t);var n=e.dirExists(O.CACHE_DIR+t+".zip"),r=e.dirExists(O.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(U.d("Removed in cache",n[0]),r.push(e.removeFile(O.CACHE_DIR+t+".zip"))),n[1]&&(U.d("Removed",n[1]),r.push(e.removeDir(O.GAMES_DIR+t))),0===r.length&&U.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return k},r.prototype.abortDownload=function(){return this.isDownloading()?(U.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,k=!1),!0):(U.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return U.d("Get games list"),e.readDir(O.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=O.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(U.d("Read meta.json:",n),U.d("GAMEOVER_TEMPLATE path",O.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(O.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return U.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(O.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(O.GAMES_DIR).then(function(t){return U.d("All games deleted!",t),e.createDir(O.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){U.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){U.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(a),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(a),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(a.Utils,a.Decorators,a);var s=function(){var e={},t=!1;e.init=function(){if(H.hasOwnProperty("webappsfixes")&&"object"==typeof H.webappsfixes){t=!0;for(var e in H.webappsfixes)if(H.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){g("[webappsFixes] applying fix: "+e);var r=n[e](H.webappsfixes[e]);r&&m("[webappsFixes] fix '"+e+"' failed: "+r)}else m("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(b()&&!e.platforms.ios)return void g("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(y()&&!e.platforms.android)return void g("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(g("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),g("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();a.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return m("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!H.statusbar)return;e=H.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},Z=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(b()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){g("[share] Share completed? "+e.completed),g("[share] Shared to app: "+e.app),n(e)},a=function(e){m("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){g("[share] Facebook share completed, result: ",e),t(e)},i=function(e){m("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){g("[share] Twitter share completed, result: ",e),t(e)},i=function(e){m("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){g("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){m("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){g("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){g("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},w("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(g("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(m("[share] type not valid"),n("type not valid"))):(m("[share] missing parameter url"),n("missing parameter url")):(m("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();o.socialShare=function(e){return P?I?new Promise(function(t,n){Z.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},o.socialShareAvailable=function(e){return P?I?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Z.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){m(e),n(e)})}):(m("[share] missing parameter url"),Promise.reject("missing parameter url")):(m("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(m("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var X=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){h().then(function(e){p&&p.type&&"online"===p.type?(g("[push] going to url: ",e),S(e)):m("[push] i'm offline not going to url")}).catch(function(e){m("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],s=!1,u=!1,l=function(){u||i()&&(u=!0,window.cordova.plugins.notification.local.on("click",function(e){s?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var f=function(){var e=window.cordova.file.applicationStorageDirectory;return b()&&(e+="Documents/"),e},h=function(){return a.file.fileExists(f()+"SGpushUrl").then(function(e){return e?a.file.readFileAsJSON(f()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},y=function(e){var t={url:c(e,{source:"localpush"})};return a.file.createFile(f(),"SGpushUrl").then(function(e){return g("[push] writing offline data",t,"in: ",e.path),a.file.write(e.path,JSON.stringify(t))}).catch(function(e){m("[push] error sg create SGpushUrl file",e)})},_=function(){var t=v.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(u||d();o.length>0;){var t=o.pop();g("[push] processing queued event: ",t),r()}s=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,p=1732584193,f=-271733879,h=-1732584194,g=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function p(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function f(e){return unescape(encodeURIComponent(e))}function h(e){return l(f(e))}function g(e){return p(h(e))}function m(e,t){return d(f(e),f(t))}function w(e,t){return p(m(e,t))}function v(e,t,n){return t?n?m(t,e):w(t,e):n?h(e):g(e)}return v}(),te=function(e){if(void 0===window.SpinnerDialog)return m("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},ne=function(){return void 0===window.SpinnerDialog?m("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=te,window.stopLoading=ne,o.inAppPurchaseSubscription=function(e,t,n,r){return P?I?(V(!0),void 0!==r&&(ie.returnUrl=r),void 0!==n&&(ie.subscribeMethod=n),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0,ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(),window.store.order(ie.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},o.inAppRestore=function(e,t,n,r){return P?I?(void 0!==n&&(ie.subscribeMethod=n),void 0!==r&&(ie.returnUrl=r),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0, +void ie.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},o.inAppProductInfo=function(e){if(e.productId||(e.productId=ie.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return m("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!P)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!I)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(ie.subscribeMethod=e.subscriptionUrl,ie.requestedListingProductId=e.productId,ie.callbackListingSuccess=e.callbackListingSuccess,ie.callbackPurchaseSuccess=e.callbackPurchaseSuccess,ie.callbackListingError=e.callbackError,ie.inappProductInfoCalled=!0,ie.productsInfo[e.productId])try{ie.callbackListingSuccess(ie.productsInfo[e.productId])}catch(e){m("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(!0),!0)};var re=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(y()?n=e.productsIdAndroid:b()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,g("[IAPlight] getProducts ok",e),e}).catch(function(e){m("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(g("[IAPlight] subscribe ok",t),b())return e.getActiveSubscriptionsInfo().then(function(e){if(g("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(y()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return m("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw m("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){g("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),g(JSON.stringify(e)),g(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){g("IAP> Purchase approved."),g(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){g("subscription verified ",e)},onStoreReady:function(){g("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(g("[IAP] > Product Owned."),!e.transaction.id&&b())return m("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),b()&&window.localStorage.setItem("transaction_id",e.transaction.id),y()){var t=e.transaction.purchaseToken+"|"+x+"|"+ie.id;g("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||ie.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(g("[IAP] appStoreReceipt: "+t.appStoreReceipt),ie.createUser(e,t.appStoreReceipt)):g("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){V(!1),ie.callbackError({iap_cancelled:1,return_url:ie.returnUrl}),g("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){g("[IAP] ORDER APPROVED "+ie.id),e.finish()},error:function(e){V(!1),m("[IAP] error: "+e),ie.callbackError({iap_error:1,return_url:ie.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(g("[IAP] createUser start "),!ie.inappProductInfoCalled&&!ie.inappPurchaseCalled)return ie.lastCreateUserProduct=e,void(ie.lastCreateUserToken=t);if(!ie.subscribeMethod)return void m("[IAP] createUser configuration error: missing api url.");var n=ie.getRandomEmail(),r=1;y()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=ie.subscribeMethod,o={paymethod:ie.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:ie.returnUrl,inapp_pwd:ie.getPassword(t),hybrid:1};ie.lastCreateuserUrl=i,ie.lastCreateuserData=o;var a=function(e){if(ie.createUserAttempt<=ie.maxCreateUserAttempt)m("[IAP] createUser failed "+ie.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{m("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:ie.returnUrl};V(!1),ie.inappPurchaseCalled?ie.callbackError(t):ie.inappProductInfoCalled&&ie.callbackListingError(t)}},s=function(e){g("[IAP] createUser success ",e);try{e.device_id=v.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),V(!1),ie.callbackSuccess(e),ie.inappPurchaseCalled?ie.callbackSuccess(e):ie.inappProductInfoCalled&&ie.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ie.createUserAttempt=ie.createUserAttempt+1,g("[IAP] createUser attempt: "+ie.createUserAttempt+" with timeout: "+c+"sec."),g("[IAP] POST createUser: "+ie.lastCreateuserUrl+" params: "+JSON.stringify(ie.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(ie.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(ie.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){g("[IAP] createUser end"),V(!1)}).go(),c+=5},10)};ie.createUserAttempt=0,u()}},oe=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return m("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return m("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});g("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){m("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return m("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});g("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){m("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(m("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(m("[globalization] getLocaleName: not initialized!"),!1)},e}();o.facebookLogin=function(e,t,n){if(!P)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){g("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){m("Got FB login error:",e),n({error:e})})},o.facebookShare=function(e,t,n){if(!P)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){m("Got FB share error:",e),n({error:e})})};var ae=function(){deltadna.registerPushCallback(ce)},se=function(e){m("[DeltaDNA] error: "+e)},ce=function(e){return y()&&e.payload&&e.payload.url&&!e.foreground?S(e.payload.url):b()&&e.url?S(e.url):void 0},ue=function(){var e={},t={},n=function(n){g("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(m("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(m("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&g("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return m("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),le=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return m("[appsflyer] missing cordova plugin");if(void 0===H.appsflyer_devkey)return m("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:H.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(b()){if(void 0===H.appstore_appid)return m("[appsflyer] missing manifest configuration: appstore_appid");n.appId=H.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}Y.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();o.setConversionDataCallback=function(e){le.setCallback(e)};var de=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return g("[analytics] callback not set!");try{e(t)}catch(e){m("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();o.setAnalyticsCallback=function(e){de.setCallback(e)};var pe={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(pe.DefaultOptions=e),AdMob&&(pe.AdMobSupport=!0,pe.initAdMob(e,t,n)),MoPub&&(pe.MoPubSupport=!0),!0},isAdMobSupported:function(){return pe.AdMobSupport},isMoPubSupported:function(){return pe.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=pe.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=pe.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=pe.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?pe.AdSize.LEADERBOARD:t>=468&&e>=60?pe.AdSize.BANNER:t>=320&&e>=50?pe.AdSize.BANNER:void 0}};return o.game=a.game._public,o.file=a.file,o.AdManager=a.AdManager,o}); \ No newline at end of file diff --git a/package.json b/package.json index e230f78..7ab6647 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stargatejs-apps", - "version": "0.11.0", + "version": "0.11.1", "description": "StargateJS for HTML5 apps", "main": "dist/stargate.js", "scripts": { From ccf11831fefe0da0995e03c585067599a3f17818 Mon Sep 17 00:00:00 2001 From: Mirco Cipriani Date: Mon, 10 Jul 2017 17:04:24 +0200 Subject: [PATCH 03/13] Proper versioning across all branches --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7ab6647..859de5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stargatejs-apps", - "version": "0.11.1", + "version": "0.13.1", "description": "StargateJS for HTML5 apps", "main": "dist/stargate.js", "scripts": { From 182f275ebea2e6cc248bdc056ed067f30481ea0a Mon Sep 17 00:00:00 2001 From: Mirco Cipriani Date: Mon, 10 Jul 2017 17:05:40 +0200 Subject: [PATCH 04/13] 0.13.2 --- dist/bower/stargate.js | 2 +- dist/bower/stargate.min.js | 6 +++--- dist/stargate.js | 2 +- dist/stargate.min.js | 4 ++-- package.json | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dist/bower/stargate.js b/dist/bower/stargate.js index 9306052..df82dcb 100644 --- a/dist/bower/stargate.js +++ b/dist/bower/stargate.js @@ -18,7 +18,7 @@ } }(this, function () { // Public interface - var stargatePackageVersion = "0.11.1"; + var stargatePackageVersion = "0.13.2"; var stargatePublic = {}; var stargateModules = {}; diff --git a/dist/bower/stargate.min.js b/dist/bower/stargate.min.js index 50e5b01..70bfd87 100644 --- a/dist/bower/stargate.min.js +++ b/dist/bower/stargate.min.js @@ -1,9 +1,9 @@ /*! * StargateJS Apps - * v0.11.1 + * v0.13.2 * Copyright 2015 DMobileLab. http://buongiorno.com/ * See LICENSE in this repository for license information */ -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.Stargate=t()}(this,function(){function e(e){f.type=e.type,f.networkState=navigator.connection.type,"function"==typeof d&&d(f)}function t(){document.addEventListener("offline",e,!1),document.addEventListener("online",e,!1)}function n(){f.networkState=navigator.connection.type,"none"===navigator.connection.type?f.type="offline":f.type="online"}function r(e){if("android"==window.device.platform.toLowerCase())window.navigator.app.loadUrl(e);else if("ios"==window.device.platform.toLowerCase()&&-1!==e.indexOf("file:///")){var t=e.split("?")[0];w("Without qs",t),window.resolveLocalFileSystemURL(t,function(e){var t=e.toInternalURL()+"?hybrid=1";w("Redirect to",t),window.location.href=t},h)}else window.location.href=e}function i(){return window.cordova.file?a.file.readFileAsJSON(window.cordova.file.applicationDirectory+"www/manifest.json"):window.hostedwebapp?new Promise(function(e,t){window.hostedwebapp.getManifest(function(t){e(t)},function(e){h(e),t(new Error(e))})}):(h("getManifest() no available reading mechanism!"),Promise.resolve({}))}var o={},a={};!function(e){function t(e,n,r){this.level=t.levels[e.toUpperCase()],this.styles=r||{background:"white",color:"black"},this.tag="%c "+n+" ",this.isstaging="1"==="IS_STAGING = 1".slice(-1),this.styleString="background:"+this.styles.background+";color:"+this.styles.color+";";var i=function(){if(arguments.length<1)return"";for(var e=Array.prototype.slice.call(arguments[0]),t="",n=0;n0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(a),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(a,a.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(T=O(T,t)),j.d("Initialized called with:",T),!e)return Promise.reject("Missing file module!");try{S=window.cordova.file.applicationStorageDirectory,b=window.cordova.file.cacheDirectory,A=window.cordova.file.tempDirectory,_=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",P=window.cordova.file.dataDirectory}catch(e){return j.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(S+="Documents/"),"android"==window.device.platform.toLowerCase()&&(A=b),k.SDK_DIR=S+"scripts/",k.SDK_RELATIVE_DIR="../../scripts/",k.GAMEOVER_RELATIVE_DIR="../../gameover_template/",k.GAMES_DIR=S+"games/",k.BASE_DIR=S,k.CACHE_DIR=b,k.TEMP_DIR=A,k.CORDOVAJS=_+"cordova.js",k.CORDOVA_PLUGINS_JS=_+"cordova_plugins.js",k.STARGATEJS=_+"js/stargate.js",k.DATA_DIR=P,k.GAMEOVER_DIR=k.BASE_DIR+"gameover_template/",k.WWW_DIR=_,j.i("cordova JS dir to include",k.CORDOVAJS),n.game._public.BASE_DIR=k.BASE_DIR,n.game._public.OFFLINE_INDEX=k.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(k.BASE_DIR,"games"),a=e.createDir(k.BASE_DIR,"scripts"),u=e.fileExists(k.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(C))}),l=e.fileExists(k.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return j.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(k.BASE_DIR+"gameover_template"),e.dirExists(k.SDK_DIR+"plugins"),e.fileExists(k.SDK_DIR+"cordova.js"),e.fileExists(k.SDK_DIR+"cordova_plugins.js"),e.fileExists(k.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(k.WWW_DIR+"gameover_template",k.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(k.WWW_DIR+"plugins",k.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(k.CORDOVAJS,k.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(k.CORDOVA_PLUGINS_JS,k.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(k.WWW_DIR+"js/gamesFixes.js",k.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=E(T.sdk_url,{v:t.getTime()});return""===T.sdk_url||void 0===T.sdk_url||null===T.sdk_url?(j.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(k.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(j.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,k.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(k.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return j.d("Serialized dom",r),r}).then(function(t){return j.d("Write dom:",r,t),e.write(r,t)})}function w(e){return new RegExp(/.*\.html?$/i).test(e)}function h(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=k.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return j.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function m(){return j.i("readUserJson",k.BASE_DIR+"user.json"),e.readFileAsJSON(k.BASE_DIR+"user.json")}function v(e){return m().then(function(t){if(!t.ponyUrl)throw j.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];j.d("PONYVALUE",n);var r=E(T.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,j.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return j.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(k.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return j.d("writing offlineData.json",t),e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var S,b,A,_,P,I,D=t.Logger,E=t.composeApiString,R=t.jsonpRequest,O=t.extend,k={},T={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},L=!1,C={GaForGame:{},GamifiveInfo:{},queues:{}},N={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},j=new D("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,m);return j.d("Get GameInfo, fly my minipony!"),n.then(function(e){return j.i("Space is ok, can download:",m,e),v(y)}).then(function(n){return j.d("Ga for game and gamifive info stored!",n),j.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,k.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),j.d("unzip:",t.id,k.TEMP_DIR+y),e._promiseZip(n.path,k.TEMP_DIR+y,r("unzip"))}).then(function(n){j.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,m=d*Math.pow(1024,p?f.MB:f.KB),y=t.id;return s.then(function(e){return j.d("Exists",e),e?(L=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(L=!0,i())})},r.prototype.play=function(t){j.d("Play",t);var n=k.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return w(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){j.d("Removing game",t);var n=e.dirExists(k.CACHE_DIR+t+".zip"),r=e.dirExists(k.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(j.d("Removed in cache",n[0]),r.push(e.removeFile(k.CACHE_DIR+t+".zip"))),n[1]&&(j.d("Removed",n[1]),r.push(e.removeDir(k.GAMES_DIR+t))),0===r.length&&j.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return L},r.prototype.abortDownload=function(){return this.isDownloading()?(j.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,L=!1),!0):(j.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return j.d("Get games list"),e.readDir(k.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=k.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(j.d("Read meta.json:",n),j.d("GAMEOVER_TEMPLATE path",k.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(k.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return j.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(k.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(k.GAMES_DIR).then(function(t){return j.d("All games deleted!",t),e.createDir(k.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){j.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){j.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(a),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(a),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(a.Utils,a.Decorators,a);var s=function(){var e={},t=!1;e.init=function(){if(J.hasOwnProperty("webappsfixes")&&"object"==typeof J.webappsfixes){t=!0;for(var e in J.webappsfixes)if(J.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){w("[webappsFixes] applying fix: "+e);var r=n[e](J.webappsfixes[e]);r&&h("[webappsFixes] fix '"+e+"' failed: "+r)}else h("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(S()&&!e.platforms.ios)return void w("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(y()&&!e.platforms.android)return void w("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(w("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),w("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();a.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return h("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!J.statusbar)return;e=J.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},Z=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(S()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){w("[share] Share completed? "+e.completed),w("[share] Shared to app: "+e.app),n(e)},a=function(e){h("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){w("[share] Facebook share completed, result: ",e),t(e)},i=function(e){h("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){w("[share] Twitter share completed, result: ",e),t(e)},i=function(e){h("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){w("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){h("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){w("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){w("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},m("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(w("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(h("[share] type not valid"),n("type not valid"))):(h("[share] missing parameter url"),n("missing parameter url")):(h("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();o.socialShare=function(e){return P?I?new Promise(function(t,n){Z.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},o.socialShareAvailable=function(e){return P?I?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Z.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){h(e),n(e)})}):(h("[share] missing parameter url"),Promise.reject("missing parameter url")):(h("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(h("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var Q=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){g().then(function(e){f&&f.type&&"online"===f.type?(w("[push] going to url: ",e),A(e)):h("[push] i'm offline not going to url")}).catch(function(e){h("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],s=!1,u=!1,l=function(){u||i()&&(u=!0,window.cordova.plugins.notification.local.on("click",function(e){s?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var p=function(){var e=window.cordova.file.applicationStorageDirectory;return S()&&(e+="Documents/"),e},g=function(){return a.file.fileExists(p()+"SGpushUrl").then(function(e){return e?a.file.readFileAsJSON(p()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},y=function(e){var t={url:c(e,{source:"localpush"})};return a.file.createFile(p(),"SGpushUrl").then(function(e){return w("[push] writing offline data",t,"in: ",e.path),a.file.write(e.path,JSON.stringify(t))}).catch(function(e){h("[push] error sg create SGpushUrl file",e)})},b=function(){var t=v.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(u||d();o.length>0;){var t=o.pop();w("[push] processing queued event: ",t),r()}s=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,f=1732584193,p=-271733879,g=-1732584194,w=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function f(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function p(e){return unescape(encodeURIComponent(e))}function g(e){return l(p(e))}function w(e){return f(g(e))}function h(e,t){return d(p(e),p(t))}function m(e,t){return f(h(e,t))}function v(e,t,n){return t?n?h(t,e):m(t,e):n?g(e):w(e)}return v}(),te=function(e){if(void 0===window.SpinnerDialog)return h("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},ne=function(){return void 0===window.SpinnerDialog?h("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=te,window.stopLoading=ne,o.inAppPurchaseSubscription=function(e,t,n,r){return P?I?(q(!0),void 0!==r&&(ie.returnUrl=r),void 0!==n&&(ie.subscribeMethod=n),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0,ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(),window.store.order(ie.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},o.inAppRestore=function(e,t,n,r){return P?I?(void 0!==n&&(ie.subscribeMethod=n),void 0!==r&&(ie.returnUrl=r),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0,void ie.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},o.inAppProductInfo=function(e){if(e.productId||(e.productId=ie.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return h("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!P)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!I)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(ie.subscribeMethod=e.subscriptionUrl,ie.requestedListingProductId=e.productId,ie.callbackListingSuccess=e.callbackListingSuccess,ie.callbackPurchaseSuccess=e.callbackPurchaseSuccess,ie.callbackListingError=e.callbackError,ie.inappProductInfoCalled=!0,ie.productsInfo[e.productId])try{ie.callbackListingSuccess(ie.productsInfo[e.productId])}catch(e){h("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(!0),!0)};var re=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(y()?n=e.productsIdAndroid:S()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,w("[IAPlight] getProducts ok",e),e}).catch(function(e){h("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(w("[IAPlight] subscribe ok",t),S())return e.getActiveSubscriptionsInfo().then(function(e){if(w("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(y()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return h("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw h("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){w("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),w(JSON.stringify(e)),w(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){w("IAP> Purchase approved."),w(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){w("subscription verified ",e)},onStoreReady:function(){w("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(w("[IAP] > Product Owned."),!e.transaction.id&&S())return h("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),S()&&window.localStorage.setItem("transaction_id",e.transaction.id),y()){var t=e.transaction.purchaseToken+"|"+O+"|"+ie.id;w("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||ie.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(w("[IAP] appStoreReceipt: "+t.appStoreReceipt),ie.createUser(e,t.appStoreReceipt)):w("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){q(!1),ie.callbackError({iap_cancelled:1,return_url:ie.returnUrl}),w("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){w("[IAP] ORDER APPROVED "+ie.id),e.finish()},error:function(e){q(!1),h("[IAP] error: "+e),ie.callbackError({iap_error:1,return_url:ie.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(w("[IAP] createUser start "),!ie.inappProductInfoCalled&&!ie.inappPurchaseCalled)return ie.lastCreateUserProduct=e,void(ie.lastCreateUserToken=t);if(!ie.subscribeMethod)return void h("[IAP] createUser configuration error: missing api url.");var n=ie.getRandomEmail(),r=1;y()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=ie.subscribeMethod,o={paymethod:ie.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:ie.returnUrl,inapp_pwd:ie.getPassword(t),hybrid:1};ie.lastCreateuserUrl=i,ie.lastCreateuserData=o;var a=function(e){if(ie.createUserAttempt<=ie.maxCreateUserAttempt)h("[IAP] createUser failed "+ie.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{h("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:ie.returnUrl};q(!1),ie.inappPurchaseCalled?ie.callbackError(t):ie.inappProductInfoCalled&&ie.callbackListingError(t)}},s=function(e){w("[IAP] createUser success ",e);try{e.device_id=v.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),q(!1),ie.callbackSuccess(e),ie.inappPurchaseCalled?ie.callbackSuccess(e):ie.inappProductInfoCalled&&ie.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ie.createUserAttempt=ie.createUserAttempt+1,w("[IAP] createUser attempt: "+ie.createUserAttempt+" with timeout: "+c+"sec."),w("[IAP] POST createUser: "+ie.lastCreateuserUrl+" params: "+JSON.stringify(ie.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(ie.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(ie.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){w("[IAP] createUser end"),q(!1)}).go(),c+=5},10)} +!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.Stargate=t()}(this,function(){function e(e){f.type=e.type,f.networkState=navigator.connection.type,"function"==typeof d&&d(f)}function t(){document.addEventListener("offline",e,!1),document.addEventListener("online",e,!1)}function n(){f.networkState=navigator.connection.type,"none"===navigator.connection.type?f.type="offline":f.type="online"}function r(e){if("android"==window.device.platform.toLowerCase())window.navigator.app.loadUrl(e);else if("ios"==window.device.platform.toLowerCase()&&-1!==e.indexOf("file:///")){var t=e.split("?")[0];w("Without qs",t),window.resolveLocalFileSystemURL(t,function(e){var t=e.toInternalURL()+"?hybrid=1";w("Redirect to",t),window.location.href=t},h)}else window.location.href=e}function i(){return window.cordova.file?a.file.readFileAsJSON(window.cordova.file.applicationDirectory+"www/manifest.json"):window.hostedwebapp?new Promise(function(e,t){window.hostedwebapp.getManifest(function(t){e(t)},function(e){h(e),t(new Error(e))})}):(h("getManifest() no available reading mechanism!"),Promise.resolve({}))}var o={},a={};!function(e){function t(e,n,r){this.level=t.levels[e.toUpperCase()],this.styles=r||{background:"white",color:"black"},this.tag="%c "+n+" ",this.isstaging="1"==="IS_STAGING = 1".slice(-1),this.styleString="background:"+this.styles.background+";color:"+this.styles.color+";";var i=function(){if(arguments.length<1)return"";for(var e=Array.prototype.slice.call(arguments[0]),t="",n=0;n0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(a),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(a,a.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(T=O(T,t)),j.d("Initialized called with:",T),!e)return Promise.reject("Missing file module!");try{S=window.cordova.file.applicationStorageDirectory,b=window.cordova.file.cacheDirectory,A=window.cordova.file.tempDirectory,_=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",P=window.cordova.file.dataDirectory}catch(e){return j.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(S+="Documents/"),"android"==window.device.platform.toLowerCase()&&(A=b),k.SDK_DIR=S+"scripts/",k.SDK_RELATIVE_DIR="../../scripts/",k.GAMEOVER_RELATIVE_DIR="../../gameover_template/",k.GAMES_DIR=S+"games/",k.BASE_DIR=S,k.CACHE_DIR=b,k.TEMP_DIR=A,k.CORDOVAJS=_+"cordova.js",k.CORDOVA_PLUGINS_JS=_+"cordova_plugins.js",k.STARGATEJS=_+"js/stargate.js",k.DATA_DIR=P,k.GAMEOVER_DIR=k.BASE_DIR+"gameover_template/",k.WWW_DIR=_,j.i("cordova JS dir to include",k.CORDOVAJS),n.game._public.BASE_DIR=k.BASE_DIR,n.game._public.OFFLINE_INDEX=k.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(k.BASE_DIR,"games"),a=e.createDir(k.BASE_DIR,"scripts"),u=e.fileExists(k.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(C))}),l=e.fileExists(k.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return j.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(k.BASE_DIR+"gameover_template"),e.dirExists(k.SDK_DIR+"plugins"),e.fileExists(k.SDK_DIR+"cordova.js"),e.fileExists(k.SDK_DIR+"cordova_plugins.js"),e.fileExists(k.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(k.WWW_DIR+"gameover_template",k.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(k.WWW_DIR+"plugins",k.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(k.CORDOVAJS,k.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(k.CORDOVA_PLUGINS_JS,k.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(k.WWW_DIR+"js/gamesFixes.js",k.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=E(T.sdk_url,{v:t.getTime()});return""===T.sdk_url||void 0===T.sdk_url||null===T.sdk_url?(j.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(k.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(j.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,k.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(k.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return j.d("Serialized dom",r),r}).then(function(t){return j.d("Write dom:",r,t),e.write(r,t)})}function w(e){return new RegExp(/.*\.html?$/i).test(e)}function h(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=k.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return j.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function m(){return j.i("readUserJson",k.BASE_DIR+"user.json"),e.readFileAsJSON(k.BASE_DIR+"user.json")}function v(e){return m().then(function(t){if(!t.ponyUrl)throw j.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];j.d("PONYVALUE",n);var r=E(T.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,j.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return j.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(k.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return j.d("writing offlineData.json",t),e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var S,b,A,_,P,I,D=t.Logger,E=t.composeApiString,R=t.jsonpRequest,O=t.extend,k={},T={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},L=!1,C={GaForGame:{},GamifiveInfo:{},queues:{}},N={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},j=new D("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,m);return j.d("Get GameInfo, fly my minipony!"),n.then(function(e){return j.i("Space is ok, can download:",m,e),v(y)}).then(function(n){return j.d("Ga for game and gamifive info stored!",n),j.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,k.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),j.d("unzip:",t.id,k.TEMP_DIR+y),e._promiseZip(n.path,k.TEMP_DIR+y,r("unzip"))}).then(function(n){j.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,m=d*Math.pow(1024,p?f.MB:f.KB),y=t.id;return s.then(function(e){return j.d("Exists",e),e?(L=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(L=!0,i())})},r.prototype.play=function(t){j.d("Play",t);var n=k.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return w(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){j.d("Removing game",t);var n=e.dirExists(k.CACHE_DIR+t+".zip"),r=e.dirExists(k.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(j.d("Removed in cache",n[0]),r.push(e.removeFile(k.CACHE_DIR+t+".zip"))),n[1]&&(j.d("Removed",n[1]),r.push(e.removeDir(k.GAMES_DIR+t))),0===r.length&&j.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return L},r.prototype.abortDownload=function(){return this.isDownloading()?(j.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,L=!1),!0):(j.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return j.d("Get games list"),e.readDir(k.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=k.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(j.d("Read meta.json:",n),j.d("GAMEOVER_TEMPLATE path",k.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(k.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return j.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(k.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(k.GAMES_DIR).then(function(t){return j.d("All games deleted!",t),e.createDir(k.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){j.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){j.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(a),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(a),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(a.Utils,a.Decorators,a);var s=function(){var e={},t=!1;e.init=function(){if(J.hasOwnProperty("webappsfixes")&&"object"==typeof J.webappsfixes){t=!0;for(var e in J.webappsfixes)if(J.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){w("[webappsFixes] applying fix: "+e);var r=n[e](J.webappsfixes[e]);r&&h("[webappsFixes] fix '"+e+"' failed: "+r)}else h("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(S()&&!e.platforms.ios)return void w("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(y()&&!e.platforms.android)return void w("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(w("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),w("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();a.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return h("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!J.statusbar)return;e=J.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},Z=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(S()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){w("[share] Share completed? "+e.completed),w("[share] Shared to app: "+e.app),n(e)},a=function(e){h("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){w("[share] Facebook share completed, result: ",e),t(e)},i=function(e){h("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){w("[share] Twitter share completed, result: ",e),t(e)},i=function(e){h("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){w("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){h("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){w("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){w("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},m("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(w("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(h("[share] type not valid"),n("type not valid"))):(h("[share] missing parameter url"),n("missing parameter url")):(h("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();o.socialShare=function(e){return P?I?new Promise(function(t,n){Z.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},o.socialShareAvailable=function(e){return P?I?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Z.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){h(e),n(e)})}):(h("[share] missing parameter url"),Promise.reject("missing parameter url")):(h("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(h("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var Q=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){g().then(function(e){f&&f.type&&"online"===f.type?(w("[push] going to url: ",e),A(e)):h("[push] i'm offline not going to url")}).catch(function(e){h("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],s=!1,u=!1,l=function(){u||i()&&(u=!0,window.cordova.plugins.notification.local.on("click",function(e){s?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var p=function(){var e=window.cordova.file.applicationStorageDirectory;return S()&&(e+="Documents/"),e},g=function(){return a.file.fileExists(p()+"SGpushUrl").then(function(e){return e?a.file.readFileAsJSON(p()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},y=function(e){var t={url:c(e,{source:"localpush"})};return a.file.createFile(p(),"SGpushUrl").then(function(e){return w("[push] writing offline data",t,"in: ",e.path),a.file.write(e.path,JSON.stringify(t))}).catch(function(e){h("[push] error sg create SGpushUrl file",e)})},b=function(){var t=v.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(u||d();o.length>0;){var t=o.pop();w("[push] processing queued event: ",t),r()}s=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,f=1732584193,p=-271733879,g=-1732584194,w=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function f(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function p(e){return unescape(encodeURIComponent(e))}function g(e){return l(p(e))}function w(e){return f(g(e))}function h(e,t){return d(p(e),p(t))}function m(e,t){return f(h(e,t))}function v(e,t,n){return t?n?h(t,e):m(t,e):n?g(e):w(e)}return v}(),te=function(e){if(void 0===window.SpinnerDialog)return h("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},ne=function(){return void 0===window.SpinnerDialog?h("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=te,window.stopLoading=ne,o.inAppPurchaseSubscription=function(e,t,n,r){return P?I?(q(!0),void 0!==r&&(ie.returnUrl=r),void 0!==n&&(ie.subscribeMethod=n),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0,ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(),window.store.order(ie.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},o.inAppRestore=function(e,t,n,r){return P?I?(void 0!==n&&(ie.subscribeMethod=n),void 0!==r&&(ie.returnUrl=r),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0,void ie.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},o.inAppProductInfo=function(e){if(e.productId||(e.productId=ie.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return h("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!P)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!I)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(ie.subscribeMethod=e.subscriptionUrl,ie.requestedListingProductId=e.productId,ie.callbackListingSuccess=e.callbackListingSuccess,ie.callbackPurchaseSuccess=e.callbackPurchaseSuccess,ie.callbackListingError=e.callbackError,ie.inappProductInfoCalled=!0,ie.productsInfo[e.productId])try{ie.callbackListingSuccess(ie.productsInfo[e.productId])}catch(e){h("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(!0),!0)};var re=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(y()?n=e.productsIdAndroid:S()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,w("[IAPlight] getProducts ok",e),e}).catch(function(e){h("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(w("[IAPlight] subscribe ok",t),S())return e.getActiveSubscriptionsInfo().then(function(e){if(w("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(y()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return h("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw h("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){w("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),w(JSON.stringify(e)),w(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){w("IAP> Purchase approved."),w(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){w("subscription verified ",e)},onStoreReady:function(){w("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(w("[IAP] > Product Owned."),!e.transaction.id&&S())return h("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),S()&&window.localStorage.setItem("transaction_id",e.transaction.id),y()){var t=e.transaction.purchaseToken+"|"+O+"|"+ie.id;w("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||ie.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(w("[IAP] appStoreReceipt: "+t.appStoreReceipt),ie.createUser(e,t.appStoreReceipt)):w("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){q(!1),ie.callbackError({iap_cancelled:1,return_url:ie.returnUrl}),w("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){w("[IAP] ORDER APPROVED "+ie.id),e.finish()},error:function(e){q(!1),h("[IAP] error: "+e),ie.callbackError({iap_error:1,return_url:ie.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(w("[IAP] createUser start "),!ie.inappProductInfoCalled&&!ie.inappPurchaseCalled)return ie.lastCreateUserProduct=e,void(ie.lastCreateUserToken=t);if(!ie.subscribeMethod)return void h("[IAP] createUser configuration error: missing api url.");var n=ie.getRandomEmail(),r=1;y()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=ie.subscribeMethod,o={paymethod:ie.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:ie.returnUrl,inapp_pwd:ie.getPassword(t),hybrid:1};ie.lastCreateuserUrl=i,ie.lastCreateuserData=o;var a=function(e){if(ie.createUserAttempt<=ie.maxCreateUserAttempt)h("[IAP] createUser failed "+ie.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{h("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:ie.returnUrl};q(!1),ie.inappPurchaseCalled?ie.callbackError(t):ie.inappProductInfoCalled&&ie.callbackListingError(t)}},s=function(e){w("[IAP] createUser success ",e);try{e.device_id=v.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),q(!1),ie.callbackSuccess(e),ie.inappPurchaseCalled?ie.callbackSuccess(e):ie.inappProductInfoCalled&&ie.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ie.createUserAttempt=ie.createUserAttempt+1,w("[IAP] createUser attempt: "+ie.createUserAttempt+" with timeout: "+c+"sec."),w("[IAP] POST createUser: "+ie.lastCreateuserUrl+" params: "+JSON.stringify(ie.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(ie.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(ie.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){w("[IAP] createUser end"),q(!1)}).go(),c+=5},10)} ;ie.createUserAttempt=0,u()}},oe=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return h("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return h("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});w("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){h("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return h("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});w("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){h("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(h("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(h("[globalization] getLocaleName: not initialized!"),!1)},e}();o.facebookLogin=function(e,t,n){if(!P)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){w("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){h("Got FB login error:",e),n({error:e})})},o.facebookShare=function(e,t,n){if(!P)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){h("Got FB share error:",e),n({error:e})})};var ae=function(){deltadna.registerPushCallback(ce)},se=function(e){h("[DeltaDNA] error: "+e)},ce=function(e){return y()&&e.payload&&e.payload.url&&!e.foreground?A(e.payload.url):S()&&e.url?A(e.url):void 0},ue=function(){var e={},t={},n=function(n){w("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(h("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(h("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&w("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return h("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),le=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return h("[appsflyer] missing cordova plugin");if(void 0===J.appsflyer_devkey)return h("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:J.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(S()){if(void 0===J.appstore_appid)return h("[appsflyer] missing manifest configuration: appstore_appid");n.appId=J.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}$.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();o.setConversionDataCallback=function(e){le.setCallback(e)};var de=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return w("[analytics] callback not set!");try{e(t)}catch(e){h("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();o.setAnalyticsCallback=function(e){de.setCallback(e)};var fe={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(fe.DefaultOptions=e),AdMob&&(fe.AdMobSupport=!0,fe.initAdMob(e,t,n)),MoPub&&(fe.MoPubSupport=!0),!0},isAdMobSupported:function(){return fe.AdMobSupport},isMoPubSupported:function(){return fe.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=fe.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=fe.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=fe.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?fe.AdSize.LEADERBOARD:t>=468&&e>=60?fe.AdSize.BANNER:t>=320&&e>=50?fe.AdSize.BANNER:void 0}};return o.game=a.game._public,o.file=a.file,o.AdManager=a.AdManager,o}); \ No newline at end of file diff --git a/dist/stargate.js b/dist/stargate.js index 50bcbf7..4d5629c 100644 --- a/dist/stargate.js +++ b/dist/stargate.js @@ -3935,7 +3935,7 @@ } }(this, function () { // Public interface - var stargatePackageVersion = "0.11.1"; + var stargatePackageVersion = "0.13.2"; var stargatePublic = {}; var stargateModules = {}; diff --git a/dist/stargate.min.js b/dist/stargate.min.js index 9cf3b13..0325f79 100644 --- a/dist/stargate.min.js +++ b/dist/stargate.min.js @@ -1,10 +1,10 @@ /*! * StargateJS Apps - * v0.11.1 + * v0.13.2 * Copyright 2015 DMobileLab. http://buongiorno.com/ * See LICENSE in this repository for license information */ !function(e,t){"use strict";"object"==typeof exports?module.exports=t(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"==typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],t):e.URI=t(e.punycode,e.IPv6,e.SecondLevelDomains,e)}(this,function(e,t,n,r){"use strict";function i(e,t){var n=arguments.length>=1,r=arguments.length>=2;if(!(this instanceof i))return n?r?new i(e,t):new i(e):new i;if(void 0===e){if(n)throw new TypeError("undefined is not a valid argument for URI");e="undefined"!=typeof location?location.href+"":""}return this.href(e),void 0!==t?this.absoluteTo(t):this}function o(e){return e.replace(/([.*+?^=!:()|[\]\/\\])/g,"\\$1")}function a(e){return void 0===e?"Undefined":String(Object.prototype.toString.call(e)).slice(8,-1)}function s(e){return"Array"===a(e)}function c(e,t){var n,r,i={};if("RegExp"===a(t))i=null;else if(s(t))for(n=0,r=t.length;n]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,i.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?«»“”„‘’]+$/},i.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},i.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/,i.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"},i.getDomAttribute=function(e){if(e&&e.nodeName){var t=e.nodeName.toLowerCase();if("input"!==t||"image"===e.type)return i.domAttributes[t]}},i.encode=f,i.decode=decodeURIComponent,i.iso8859=function(){i.encode=escape,i.decode=unescape},i.unicode=function(){i.encode=f,i.decode=decodeURIComponent},i.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/gi,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}},i.encodeQuery=function(e,t){var n=i.encode(e+"");return void 0===t&&(t=i.escapeQuerySpace),t?n.replace(/%20/g,"+"):n},i.decodeQuery=function(e,t){e+="",void 0===t&&(t=i.escapeQuerySpace);try{return i.decode(t?e.replace(/\+/g,"%20"):e)}catch(t){return e}};var y,b={encode:"encode",decode:"decode"},_=function(e,t){return function(n){try{return i[t](n+"").replace(i.characters[e][t].expression,function(n){return i.characters[e][t].map[n]})}catch(e){return n}}};for(y in b)i[y+"PathSegment"]=_("pathname",b[y]),i[y+"UrnPathSegment"]=_("urnpath",b[y]);var S=function(e,t,n){return function(r){var o;o=n?function(e){return i[t](i[n](e))}:i[t];for(var a=(r+"").split(e),s=0,c=a.length;s-1&&(t.fragment=e.substring(n+1)||null,e=e.substring(0,n)),n=e.indexOf("?"),n>-1&&(t.query=e.substring(n+1)||null,e=e.substring(0,n)),"//"===e.substring(0,2)?(t.protocol=null,e=e.substring(2),e=i.parseAuthority(e,t)):(n=e.indexOf(":"))>-1&&(t.protocol=e.substring(0,n)||null,t.protocol&&!t.protocol.match(i.protocol_expression)?t.protocol=void 0:"//"===e.substring(n+1,n+3)?(e=e.substring(n+3),e=i.parseAuthority(e,t)):(e=e.substring(n+1),t.urn=!0)),t.path=e,t},i.parseHost=function(e,t){e=e.replace(/\\/g,"/");var n,r,i=e.indexOf("/");if(-1===i&&(i=e.length),"["===e.charAt(0))n=e.indexOf("]"),t.hostname=e.substring(1,n)||null,t.port=e.substring(n+2,i)||null,"/"===t.port&&(t.port=null);else{var o=e.indexOf(":"),a=e.indexOf("/"),s=e.indexOf(":",o+1);-1!==s&&(-1===a||s-1?r:e.length-1);return o>-1&&(-1===r||o3?Object.keys(n).forEach(function(e){var n=e.match(/^([0-9])([0-9x])([0-9x])$/i);!(n&&n.length>3&&o[1]===n[1])||"x"!==n[2]&&o[2]!==n[2]||"x"!==n[3]&&o[3]!==n[3]||i(e,t)}):n[e]&&i(e,t)}return this},go:function(){var e=t.type||(t.into?"html":"json"),n=u();if("function"==typeof a[e])return a[e].call(this,n)}},a={json:function(e){var t=this;a._xhr.call(this,e,function(e){if(e)try{e=JSON.parse(e)}catch(e){return t.trigger("error",e),null}return e})},html:function(e){a._xhr.call(this,e,function(e){return t.into&&t.into.length&&[].forEach.call(t.into,function(t){t.innerHTML=e}),e})},_xhr:function(e,n){var r,i,o,a,s,u=this,l=t.method||"get",d=!0!==t.sync,p=new XMLHttpRequest,f=t.data,h=t.body,g=(t.headers,this.header("Content-Type")),m=t.timeout;if(!g&&f&&c()&&(this.header("Content-Type","application/x-www-form-urlencoded;charset=utf-8"),g=this.header("Content-Type")),f&&c())if("string"!=typeof h&&(h=""),g.indexOf("json")>-1)try{h=JSON.stringify(f)}catch(e){throw new TypeError("Unable to stringify body's content : "+e.name)}else{a=g&&g.indexOf("x-www-form-urlencoded")>1;for(r in f)h+=a?encodeURIComponent(r)+"="+encodeURIComponent(f[r])+"&":r+"="+f[r]+"\n\r"}s=[l,e,d],t.auth&&(s.push(t.auth.user),s.push(t.auth.passwd)),p.open.apply(p,s);for(i in t.headers)p.setRequestHeader(i,t.headers[i]);p.onprogress=function(e){e.lengthComputable&&u.trigger("progress",e.loaded/e.total)},p.onload=function(){var e=p.responseText;o&&clearTimeout(o),this.status>=200&&this.status<300&&("function"==typeof n&&(e=n(e)),u.trigger("success",e)),u.trigger(this.status,e),u.trigger("end",e)},p.onerror=function(e){o&&clearTimeout(o),u.trigger("error",e,arguments)},m&&(o=setTimeout(function(){u.trigger("timeout",{type:"timeout",expiredAfter:m},p,arguments),p.abort()},m)),p.send(h)},jsonp:function(n){var r,o=this,a=document.querySelector("head"),s=!0!==t.sync,c=t.jsonPaddingName||"callback",u=t.jsonPadding||"_padd"+(new Date).getTime()+Math.floor(1e4*Math.random()),l={};if(e[u])throw new Error("Padding "+u+" already exists. It must be unique.");/^ajajsonp_/.test(u)||(u="ajajsonp_"+u),window[u]=function(e){o.trigger("success",e),a.removeChild(r),window[u]=void 0},l[c]=u,n=i(n,l),r=document.createElement("script"),r.async=s,r.src=n,r.onerror=function(){o.trigger("error",arguments),a.removeChild(r),window[u]=void 0},a.appendChild(r)},script:function(e){var n,r=this,i=document.querySelector("head")||document.querySelector("body"),o=!0!==t.sync;if(!i)throw new Error("Ok, wait a second, you want to load a script, but you don't have at least a head or body tag...");n=document.createElement("script"),n.async=o,n.src=e,n.onerror=function(){r.trigger("error",arguments),i.removeChild(n)},n.onload=function(){r.trigger("success",arguments)},i.appendChild(n)}},s=function(e,n,i,o){if(void 0!==n){if("function"==typeof i)try{n=i.call(r,n)}catch(t){throw new TypeError("Failed to set "+e+" : "+t.message)}return t[e]="function"==typeof o?o.call(this,n):n,this}return"undefined"===t[e]?null:t[e]},c=function(){return["delete","patch","post","put"].indexOf(t.method)>-1},u=function(){var e=t.url,n=void 0===t.cache||!!t.cache,r=t.queryString||"",o=t.data;return!1===n&&(r+="&ajabuster="+(new Date).getTime()),e=i(e,r),o&&!c()&&(e=i(e,o)),e};return o},r={bool:function(e){return!!e},string:function(e){if("string"!=typeof e)throw new TypeError("a string is expected, but "+e+" ["+typeof e+"] given");return e},positiveInteger:function(e){if(parseInt(e)!==e||e<=0)throw new TypeError("an integer is expected, but "+e+" ["+typeof e+"] given");return e},plainObject:function(e){if("object"!=typeof e||e.constructor!==Object)throw new TypeError("an object is expected, but "+e+" ["+typeof e+"] given");return e},type:function(t){if(t=this.string(t),e.indexOf(t.toLowerCase())<0)throw new TypeError("a type in ["+e.join(", ")+"] is expected, but "+t+" given");return t.toLowerCase()},method:function(e){if(e=this.string(e),t.indexOf(e.toLowerCase())<0)throw new TypeError("a method in ["+t.join(", ")+"] is expected, but "+e+" given");return e.toLowerCase()},queryString:function(e){var t={};return"string"==typeof e?e.replace("?","").split("&").forEach(function(e){var n=e.split("=");2===n.length&&(t[decodeURIComponent(n[0])]=decodeURIComponent(n[1]))}):t=e,this.plainObject(t)},selector:function(e){if("string"!=typeof e&&!(e instanceof HTMLElement))throw new TypeError("a selector or an HTMLElement is expected, "+e+" ["+typeof e+"] given");return e},func:function(e){if(e=this.string(e),!/^([a-zA-Z_])([a-zA-Z0-9_\-])+$/.test(e))throw new TypeError("a valid function name is expected, "+e+" ["+typeof e+"] given");return e}},i=function(e,t){var n;if(e=e||"",t)if(-1===e.indexOf("?")&&(e+="?"),"string"==typeof t)e+=t;else if("object"==typeof t)for(n in t)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(t[n]);return e};"function"==typeof define&&define.amd?define([],function(){return n}):"object"==typeof exports?module.exports=n:window.aja=window.aja||n}(),function(e){function t(e,t){return function(){e.apply(t,arguments)}}function n(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],c(e,t(i,this),t(o,this))}function r(e){var t=this;if(null===this._state)return void this._deferreds.push(e);l(function(){var n=t._state?e.onFulfilled:e.onRejected;if(null===n)return void(t._state?e.resolve:e.reject)(t._value);var r;try{r=n(t._value)}catch(t){return void e.reject(t)}e.resolve(r)})}function i(e){try{if(e===this)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void c(t(n,e),t(i,this),t(o,this))}this._state=!0,this._value=e,a.call(this)}catch(e){o.call(this,e)}}function o(e){this._state=!1,this._value=e,a.call(this)}function a(){for(var e=0,t=this._deferreds.length;e0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(a),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(a,a.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(T=x(T,t)),U.d("Initialized called with:",T),!e)return Promise.reject("Missing file module!");try{b=window.cordova.file.applicationStorageDirectory,_=window.cordova.file.cacheDirectory,S=window.cordova.file.tempDirectory,A=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",P=window.cordova.file.dataDirectory}catch(e){return U.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(b+="Documents/"),"android"==window.device.platform.toLowerCase()&&(S=_),O.SDK_DIR=b+"scripts/",O.SDK_RELATIVE_DIR="../../scripts/",O.GAMEOVER_RELATIVE_DIR="../../gameover_template/",O.GAMES_DIR=b+"games/",O.BASE_DIR=b,O.CACHE_DIR=_,O.TEMP_DIR=S,O.CORDOVAJS=A+"cordova.js",O.CORDOVA_PLUGINS_JS=A+"cordova_plugins.js",O.STARGATEJS=A+"js/stargate.js",O.DATA_DIR=P,O.GAMEOVER_DIR=O.BASE_DIR+"gameover_template/",O.WWW_DIR=A,U.i("cordova JS dir to include",O.CORDOVAJS),n.game._public.BASE_DIR=O.BASE_DIR,n.game._public.OFFLINE_INDEX=O.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(O.BASE_DIR,"games"),a=e.createDir(O.BASE_DIR,"scripts"),u=e.fileExists(O.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(j))}),l=e.fileExists(O.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return U.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(O.BASE_DIR+"gameover_template"),e.dirExists(O.SDK_DIR+"plugins"),e.fileExists(O.SDK_DIR+"cordova.js"),e.fileExists(O.SDK_DIR+"cordova_plugins.js"),e.fileExists(O.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(O.WWW_DIR+"gameover_template",O.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(O.WWW_DIR+"plugins",O.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(O.CORDOVAJS,O.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(O.CORDOVA_PLUGINS_JS,O.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(O.WWW_DIR+"js/gamesFixes.js",O.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=D(T.sdk_url,{v:t.getTime()});return""===T.sdk_url||void 0===T.sdk_url||null===T.sdk_url?(U.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(O.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(U.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,O.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(O.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return U.d("Serialized dom",r),r}).then(function(t){return U.d("Write dom:",r,t),e.write(r,t)})}function g(e){return new RegExp(/.*\.html?$/i).test(e)}function m(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=O.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return U.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function w(){return U.i("readUserJson",O.BASE_DIR+"user.json"),e.readFileAsJSON(O.BASE_DIR+"user.json")}function v(e){return w().then(function(t){if(!t.ponyUrl)throw U.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];U.d("PONYVALUE",n);var r=D(T.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,U.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return U.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(O.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return U.d("writing offlineData.json",t),e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var b,_,S,A,P,I,E=t.Logger,D=t.composeApiString,R=t.jsonpRequest,x=t.extend,O={},T={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},k=!1,j={GaForGame:{},GamifiveInfo:{},queues:{}},C={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},U=new E("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,w);return U.d("Get GameInfo, fly my minipony!"),n.then(function(e){return U.i("Space is ok, can download:",w,e),v(y)}).then(function(n){return U.d("Ga for game and gamifive info stored!",n),U.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,O.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),U.d("unzip:",t.id,O.TEMP_DIR+y), -e._promiseZip(n.path,O.TEMP_DIR+y,r("unzip"))}).then(function(n){U.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,w=d*Math.pow(1024,f?p.MB:p.KB),y=t.id;return s.then(function(e){return U.d("Exists",e),e?(k=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(k=!0,i())})},r.prototype.play=function(t){U.d("Play",t);var n=O.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return g(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){U.d("Removing game",t);var n=e.dirExists(O.CACHE_DIR+t+".zip"),r=e.dirExists(O.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(U.d("Removed in cache",n[0]),r.push(e.removeFile(O.CACHE_DIR+t+".zip"))),n[1]&&(U.d("Removed",n[1]),r.push(e.removeDir(O.GAMES_DIR+t))),0===r.length&&U.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return k},r.prototype.abortDownload=function(){return this.isDownloading()?(U.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,k=!1),!0):(U.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return U.d("Get games list"),e.readDir(O.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=O.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(U.d("Read meta.json:",n),U.d("GAMEOVER_TEMPLATE path",O.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(O.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return U.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(O.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(O.GAMES_DIR).then(function(t){return U.d("All games deleted!",t),e.createDir(O.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){U.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){U.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(a),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(a),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(a.Utils,a.Decorators,a);var s=function(){var e={},t=!1;e.init=function(){if(H.hasOwnProperty("webappsfixes")&&"object"==typeof H.webappsfixes){t=!0;for(var e in H.webappsfixes)if(H.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){g("[webappsFixes] applying fix: "+e);var r=n[e](H.webappsfixes[e]);r&&m("[webappsFixes] fix '"+e+"' failed: "+r)}else m("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(b()&&!e.platforms.ios)return void g("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(y()&&!e.platforms.android)return void g("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(g("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),g("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();a.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return m("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!H.statusbar)return;e=H.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},Z=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(b()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){g("[share] Share completed? "+e.completed),g("[share] Shared to app: "+e.app),n(e)},a=function(e){m("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){g("[share] Facebook share completed, result: ",e),t(e)},i=function(e){m("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){g("[share] Twitter share completed, result: ",e),t(e)},i=function(e){m("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){g("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){m("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){g("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){g("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},w("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(g("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(m("[share] type not valid"),n("type not valid"))):(m("[share] missing parameter url"),n("missing parameter url")):(m("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();o.socialShare=function(e){return P?I?new Promise(function(t,n){Z.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},o.socialShareAvailable=function(e){return P?I?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Z.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){m(e),n(e)})}):(m("[share] missing parameter url"),Promise.reject("missing parameter url")):(m("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(m("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var X=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){h().then(function(e){p&&p.type&&"online"===p.type?(g("[push] going to url: ",e),S(e)):m("[push] i'm offline not going to url")}).catch(function(e){m("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],s=!1,u=!1,l=function(){u||i()&&(u=!0,window.cordova.plugins.notification.local.on("click",function(e){s?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var f=function(){var e=window.cordova.file.applicationStorageDirectory;return b()&&(e+="Documents/"),e},h=function(){return a.file.fileExists(f()+"SGpushUrl").then(function(e){return e?a.file.readFileAsJSON(f()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},y=function(e){var t={url:c(e,{source:"localpush"})};return a.file.createFile(f(),"SGpushUrl").then(function(e){return g("[push] writing offline data",t,"in: ",e.path),a.file.write(e.path,JSON.stringify(t))}).catch(function(e){m("[push] error sg create SGpushUrl file",e)})},_=function(){var t=v.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(u||d();o.length>0;){var t=o.pop();g("[push] processing queued event: ",t),r()}s=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,p=1732584193,f=-271733879,h=-1732584194,g=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function p(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function f(e){return unescape(encodeURIComponent(e))}function h(e){return l(f(e))}function g(e){return p(h(e))}function m(e,t){return d(f(e),f(t))}function w(e,t){return p(m(e,t))}function v(e,t,n){return t?n?m(t,e):w(t,e):n?h(e):g(e)}return v}(),te=function(e){if(void 0===window.SpinnerDialog)return m("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},ne=function(){return void 0===window.SpinnerDialog?m("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=te,window.stopLoading=ne,o.inAppPurchaseSubscription=function(e,t,n,r){return P?I?(V(!0),void 0!==r&&(ie.returnUrl=r),void 0!==n&&(ie.subscribeMethod=n),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0,ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(),window.store.order(ie.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},o.inAppRestore=function(e,t,n,r){return P?I?(void 0!==n&&(ie.subscribeMethod=n),void 0!==r&&(ie.returnUrl=r),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0, +e._promiseZip(n.path,O.TEMP_DIR+y,r("unzip"))}).then(function(n){U.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,w=d*Math.pow(1024,f?p.MB:p.KB),y=t.id;return s.then(function(e){return U.d("Exists",e),e?(k=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(k=!0,i())})},r.prototype.play=function(t){U.d("Play",t);var n=O.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return g(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){U.d("Removing game",t);var n=e.dirExists(O.CACHE_DIR+t+".zip"),r=e.dirExists(O.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(U.d("Removed in cache",n[0]),r.push(e.removeFile(O.CACHE_DIR+t+".zip"))),n[1]&&(U.d("Removed",n[1]),r.push(e.removeDir(O.GAMES_DIR+t))),0===r.length&&U.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return k},r.prototype.abortDownload=function(){return this.isDownloading()?(U.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,k=!1),!0):(U.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return U.d("Get games list"),e.readDir(O.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=O.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(U.d("Read meta.json:",n),U.d("GAMEOVER_TEMPLATE path",O.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(O.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return U.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(O.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(O.GAMES_DIR).then(function(t){return U.d("All games deleted!",t),e.createDir(O.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){U.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){U.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(a),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(a),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(a.Utils,a.Decorators,a);var s=function(){var e={},t=!1;e.init=function(){if(H.hasOwnProperty("webappsfixes")&&"object"==typeof H.webappsfixes){t=!0;for(var e in H.webappsfixes)if(H.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){g("[webappsFixes] applying fix: "+e);var r=n[e](H.webappsfixes[e]);r&&m("[webappsFixes] fix '"+e+"' failed: "+r)}else m("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(b()&&!e.platforms.ios)return void g("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(y()&&!e.platforms.android)return void g("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(g("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),g("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();a.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return m("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!H.statusbar)return;e=H.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},Z=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(b()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){g("[share] Share completed? "+e.completed),g("[share] Shared to app: "+e.app),n(e)},a=function(e){m("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){g("[share] Facebook share completed, result: ",e),t(e)},i=function(e){m("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){g("[share] Twitter share completed, result: ",e),t(e)},i=function(e){m("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){g("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){m("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){g("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){g("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},w("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(g("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(m("[share] type not valid"),n("type not valid"))):(m("[share] missing parameter url"),n("missing parameter url")):(m("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();o.socialShare=function(e){return P?I?new Promise(function(t,n){Z.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},o.socialShareAvailable=function(e){return P?I?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Z.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){m(e),n(e)})}):(m("[share] missing parameter url"),Promise.reject("missing parameter url")):(m("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(m("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var X=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){h().then(function(e){p&&p.type&&"online"===p.type?(g("[push] going to url: ",e),S(e)):m("[push] i'm offline not going to url")}).catch(function(e){m("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],s=!1,u=!1,l=function(){u||i()&&(u=!0,window.cordova.plugins.notification.local.on("click",function(e){s?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var f=function(){var e=window.cordova.file.applicationStorageDirectory;return b()&&(e+="Documents/"),e},h=function(){return a.file.fileExists(f()+"SGpushUrl").then(function(e){return e?a.file.readFileAsJSON(f()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},y=function(e){var t={url:c(e,{source:"localpush"})};return a.file.createFile(f(),"SGpushUrl").then(function(e){return g("[push] writing offline data",t,"in: ",e.path),a.file.write(e.path,JSON.stringify(t))}).catch(function(e){m("[push] error sg create SGpushUrl file",e)})},_=function(){var t=v.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(u||d();o.length>0;){var t=o.pop();g("[push] processing queued event: ",t),r()}s=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,p=1732584193,f=-271733879,h=-1732584194,g=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function p(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function f(e){return unescape(encodeURIComponent(e))}function h(e){return l(f(e))}function g(e){return p(h(e))}function m(e,t){return d(f(e),f(t))}function w(e,t){return p(m(e,t))}function v(e,t,n){return t?n?m(t,e):w(t,e):n?h(e):g(e)}return v}(),te=function(e){if(void 0===window.SpinnerDialog)return m("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},ne=function(){return void 0===window.SpinnerDialog?m("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=te,window.stopLoading=ne,o.inAppPurchaseSubscription=function(e,t,n,r){return P?I?(V(!0),void 0!==r&&(ie.returnUrl=r),void 0!==n&&(ie.subscribeMethod=n),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0,ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(),window.store.order(ie.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},o.inAppRestore=function(e,t,n,r){return P?I?(void 0!==n&&(ie.subscribeMethod=n),void 0!==r&&(ie.returnUrl=r),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0, void ie.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},o.inAppProductInfo=function(e){if(e.productId||(e.productId=ie.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return m("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!P)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!I)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(ie.subscribeMethod=e.subscriptionUrl,ie.requestedListingProductId=e.productId,ie.callbackListingSuccess=e.callbackListingSuccess,ie.callbackPurchaseSuccess=e.callbackPurchaseSuccess,ie.callbackListingError=e.callbackError,ie.inappProductInfoCalled=!0,ie.productsInfo[e.productId])try{ie.callbackListingSuccess(ie.productsInfo[e.productId])}catch(e){m("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(!0),!0)};var re=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(y()?n=e.productsIdAndroid:b()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,g("[IAPlight] getProducts ok",e),e}).catch(function(e){m("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(g("[IAPlight] subscribe ok",t),b())return e.getActiveSubscriptionsInfo().then(function(e){if(g("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(y()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return m("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw m("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){g("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),g(JSON.stringify(e)),g(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){g("IAP> Purchase approved."),g(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){g("subscription verified ",e)},onStoreReady:function(){g("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(g("[IAP] > Product Owned."),!e.transaction.id&&b())return m("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),b()&&window.localStorage.setItem("transaction_id",e.transaction.id),y()){var t=e.transaction.purchaseToken+"|"+x+"|"+ie.id;g("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||ie.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(g("[IAP] appStoreReceipt: "+t.appStoreReceipt),ie.createUser(e,t.appStoreReceipt)):g("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){V(!1),ie.callbackError({iap_cancelled:1,return_url:ie.returnUrl}),g("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){g("[IAP] ORDER APPROVED "+ie.id),e.finish()},error:function(e){V(!1),m("[IAP] error: "+e),ie.callbackError({iap_error:1,return_url:ie.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(g("[IAP] createUser start "),!ie.inappProductInfoCalled&&!ie.inappPurchaseCalled)return ie.lastCreateUserProduct=e,void(ie.lastCreateUserToken=t);if(!ie.subscribeMethod)return void m("[IAP] createUser configuration error: missing api url.");var n=ie.getRandomEmail(),r=1;y()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=ie.subscribeMethod,o={paymethod:ie.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:ie.returnUrl,inapp_pwd:ie.getPassword(t),hybrid:1};ie.lastCreateuserUrl=i,ie.lastCreateuserData=o;var a=function(e){if(ie.createUserAttempt<=ie.maxCreateUserAttempt)m("[IAP] createUser failed "+ie.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{m("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:ie.returnUrl};V(!1),ie.inappPurchaseCalled?ie.callbackError(t):ie.inappProductInfoCalled&&ie.callbackListingError(t)}},s=function(e){g("[IAP] createUser success ",e);try{e.device_id=v.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),V(!1),ie.callbackSuccess(e),ie.inappPurchaseCalled?ie.callbackSuccess(e):ie.inappProductInfoCalled&&ie.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ie.createUserAttempt=ie.createUserAttempt+1,g("[IAP] createUser attempt: "+ie.createUserAttempt+" with timeout: "+c+"sec."),g("[IAP] POST createUser: "+ie.lastCreateuserUrl+" params: "+JSON.stringify(ie.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(ie.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(ie.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){g("[IAP] createUser end"),V(!1)}).go(),c+=5},10)};ie.createUserAttempt=0,u()}},oe=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return m("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return m("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});g("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){m("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return m("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});g("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){m("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(m("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(m("[globalization] getLocaleName: not initialized!"),!1)},e}();o.facebookLogin=function(e,t,n){if(!P)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){g("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){m("Got FB login error:",e),n({error:e})})},o.facebookShare=function(e,t,n){if(!P)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){m("Got FB share error:",e),n({error:e})})};var ae=function(){deltadna.registerPushCallback(ce)},se=function(e){m("[DeltaDNA] error: "+e)},ce=function(e){return y()&&e.payload&&e.payload.url&&!e.foreground?S(e.payload.url):b()&&e.url?S(e.url):void 0},ue=function(){var e={},t={},n=function(n){g("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(m("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(m("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&g("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return m("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),le=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return m("[appsflyer] missing cordova plugin");if(void 0===H.appsflyer_devkey)return m("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:H.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(b()){if(void 0===H.appstore_appid)return m("[appsflyer] missing manifest configuration: appstore_appid");n.appId=H.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}Y.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();o.setConversionDataCallback=function(e){le.setCallback(e)};var de=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return g("[analytics] callback not set!");try{e(t)}catch(e){m("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();o.setAnalyticsCallback=function(e){de.setCallback(e)};var pe={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(pe.DefaultOptions=e),AdMob&&(pe.AdMobSupport=!0,pe.initAdMob(e,t,n)),MoPub&&(pe.MoPubSupport=!0),!0},isAdMobSupported:function(){return pe.AdMobSupport},isMoPubSupported:function(){return pe.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=pe.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=pe.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=pe.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?pe.AdSize.LEADERBOARD:t>=468&&e>=60?pe.AdSize.BANNER:t>=320&&e>=50?pe.AdSize.BANNER:void 0}};return o.game=a.game._public,o.file=a.file,o.AdManager=a.AdManager,o}); \ No newline at end of file diff --git a/package.json b/package.json index 859de5e..23e2726 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stargatejs-apps", - "version": "0.13.1", + "version": "0.13.2", "description": "StargateJS for HTML5 apps", "main": "dist/stargate.js", "scripts": { From 8628e48eb9572d3e52a0a48ac7190b8e15dec4b4 Mon Sep 17 00:00:00 2001 From: Mirco Cipriani Date: Tue, 11 Jul 2017 16:49:10 +0200 Subject: [PATCH 05/13] new get manifest method --- src/stargate.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/stargate.js b/src/stargate.js index b6453a4..d491d5a 100644 --- a/src/stargate.js +++ b/src/stargate.js @@ -104,10 +104,48 @@ function getAppIsDebug() { return Promise.resolve({}); } +function getManifestWithCordovaFilePlugin() { + var url = window.cordova.file.applicationDirectory + "www/manifest.json"; + + return new Promise(function(resolve, reject){ + window.resolveLocalFileSystemURL(url, resolve, reject); + }) + .then(function(fileEntry) { + + return new Promise(function(resolve, reject){ + fileEntry.file(function(file) { + var reader = new FileReader(); + reader.onerror = reject; + reader.onabort = reject; + + reader.onloadend = function() { + var textToParse = this.result; + resolve(textToParse); + }; + reader.readAsText(file); + }); + }); + }) + .then(function(fileContent) { + var jsonParsed = ''; + try{ + jsonParsed = window.JSON.parse(fileContent); + } + catch(e){ + return Promise.reject(e); + } + + return Promise.resolve(jsonParsed); + }) + .catch(function(e) { + console.error("getManifestWithCordovaFilePlugin() error:"+e, e); + }); +} + function getManifest() { if (window.cordova.file) { - return stargateModules.file.readFileAsJSON(window.cordova.file.applicationDirectory + "www/manifest.json"); + return getManifestWithCordovaFilePlugin(); } if (window.hostedwebapp) { From a6ec32eb24ba3dbd3cdd71b7e5e0b33cab8b244c Mon Sep 17 00:00:00 2001 From: Mirco Cipriani Date: Tue, 11 Jul 2017 16:50:27 +0200 Subject: [PATCH 06/13] 0.13.3 --- dist/bower/stargate.js | 42 ++++++++++++++++++++++++++++++++++++-- dist/bower/stargate.min.js | 8 ++++---- dist/stargate.js | 42 ++++++++++++++++++++++++++++++++++++-- dist/stargate.min.js | 8 ++++---- package.json | 2 +- 5 files changed, 89 insertions(+), 13 deletions(-) diff --git a/dist/bower/stargate.js b/dist/bower/stargate.js index df82dcb..ed55e37 100644 --- a/dist/bower/stargate.js +++ b/dist/bower/stargate.js @@ -18,7 +18,7 @@ } }(this, function () { // Public interface - var stargatePackageVersion = "0.13.2"; + var stargatePackageVersion = "0.13.3"; var stargatePublic = {}; var stargateModules = {}; @@ -2940,10 +2940,48 @@ function getAppIsDebug() { return Promise.resolve({}); } +function getManifestWithCordovaFilePlugin() { + var url = window.cordova.file.applicationDirectory + "www/manifest.json"; + + return new Promise(function(resolve, reject){ + window.resolveLocalFileSystemURL(url, resolve, reject); + }) + .then(function(fileEntry) { + + return new Promise(function(resolve, reject){ + fileEntry.file(function(file) { + var reader = new FileReader(); + reader.onerror = reject; + reader.onabort = reject; + + reader.onloadend = function() { + var textToParse = this.result; + resolve(textToParse); + }; + reader.readAsText(file); + }); + }); + }) + .then(function(fileContent) { + var jsonParsed = ''; + try{ + jsonParsed = window.JSON.parse(fileContent); + } + catch(e){ + return Promise.reject(e); + } + + return Promise.resolve(jsonParsed); + }) + .catch(function(e) { + console.error("getManifestWithCordovaFilePlugin() error:"+e, e); + }); +} + function getManifest() { if (window.cordova.file) { - return stargateModules.file.readFileAsJSON(window.cordova.file.applicationDirectory + "www/manifest.json"); + return getManifestWithCordovaFilePlugin(); } if (window.hostedwebapp) { diff --git a/dist/bower/stargate.min.js b/dist/bower/stargate.min.js index 70bfd87..dddd958 100644 --- a/dist/bower/stargate.min.js +++ b/dist/bower/stargate.min.js @@ -1,9 +1,9 @@ /*! * StargateJS Apps - * v0.13.2 + * v0.13.3 * Copyright 2015 DMobileLab. http://buongiorno.com/ * See LICENSE in this repository for license information */ -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.Stargate=t()}(this,function(){function e(e){f.type=e.type,f.networkState=navigator.connection.type,"function"==typeof d&&d(f)}function t(){document.addEventListener("offline",e,!1),document.addEventListener("online",e,!1)}function n(){f.networkState=navigator.connection.type,"none"===navigator.connection.type?f.type="offline":f.type="online"}function r(e){if("android"==window.device.platform.toLowerCase())window.navigator.app.loadUrl(e);else if("ios"==window.device.platform.toLowerCase()&&-1!==e.indexOf("file:///")){var t=e.split("?")[0];w("Without qs",t),window.resolveLocalFileSystemURL(t,function(e){var t=e.toInternalURL()+"?hybrid=1";w("Redirect to",t),window.location.href=t},h)}else window.location.href=e}function i(){return window.cordova.file?a.file.readFileAsJSON(window.cordova.file.applicationDirectory+"www/manifest.json"):window.hostedwebapp?new Promise(function(e,t){window.hostedwebapp.getManifest(function(t){e(t)},function(e){h(e),t(new Error(e))})}):(h("getManifest() no available reading mechanism!"),Promise.resolve({}))}var o={},a={};!function(e){function t(e,n,r){this.level=t.levels[e.toUpperCase()],this.styles=r||{background:"white",color:"black"},this.tag="%c "+n+" ",this.isstaging="1"==="IS_STAGING = 1".slice(-1),this.styleString="background:"+this.styles.background+";color:"+this.styles.color+";";var i=function(){if(arguments.length<1)return"";for(var e=Array.prototype.slice.call(arguments[0]),t="",n=0;n0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(a),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(a,a.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(T=O(T,t)),j.d("Initialized called with:",T),!e)return Promise.reject("Missing file module!");try{S=window.cordova.file.applicationStorageDirectory,b=window.cordova.file.cacheDirectory,A=window.cordova.file.tempDirectory,_=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",P=window.cordova.file.dataDirectory}catch(e){return j.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(S+="Documents/"),"android"==window.device.platform.toLowerCase()&&(A=b),k.SDK_DIR=S+"scripts/",k.SDK_RELATIVE_DIR="../../scripts/",k.GAMEOVER_RELATIVE_DIR="../../gameover_template/",k.GAMES_DIR=S+"games/",k.BASE_DIR=S,k.CACHE_DIR=b,k.TEMP_DIR=A,k.CORDOVAJS=_+"cordova.js",k.CORDOVA_PLUGINS_JS=_+"cordova_plugins.js",k.STARGATEJS=_+"js/stargate.js",k.DATA_DIR=P,k.GAMEOVER_DIR=k.BASE_DIR+"gameover_template/",k.WWW_DIR=_,j.i("cordova JS dir to include",k.CORDOVAJS),n.game._public.BASE_DIR=k.BASE_DIR,n.game._public.OFFLINE_INDEX=k.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(k.BASE_DIR,"games"),a=e.createDir(k.BASE_DIR,"scripts"),u=e.fileExists(k.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(C))}),l=e.fileExists(k.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return j.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(k.BASE_DIR+"gameover_template"),e.dirExists(k.SDK_DIR+"plugins"),e.fileExists(k.SDK_DIR+"cordova.js"),e.fileExists(k.SDK_DIR+"cordova_plugins.js"),e.fileExists(k.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(k.WWW_DIR+"gameover_template",k.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(k.WWW_DIR+"plugins",k.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(k.CORDOVAJS,k.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(k.CORDOVA_PLUGINS_JS,k.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(k.WWW_DIR+"js/gamesFixes.js",k.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=E(T.sdk_url,{v:t.getTime()});return""===T.sdk_url||void 0===T.sdk_url||null===T.sdk_url?(j.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(k.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(j.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,k.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(k.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return j.d("Serialized dom",r),r}).then(function(t){return j.d("Write dom:",r,t),e.write(r,t)})}function w(e){return new RegExp(/.*\.html?$/i).test(e)}function h(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=k.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return j.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function m(){return j.i("readUserJson",k.BASE_DIR+"user.json"),e.readFileAsJSON(k.BASE_DIR+"user.json")}function v(e){return m().then(function(t){if(!t.ponyUrl)throw j.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];j.d("PONYVALUE",n);var r=E(T.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,j.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return j.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(k.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return j.d("writing offlineData.json",t),e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var S,b,A,_,P,I,D=t.Logger,E=t.composeApiString,R=t.jsonpRequest,O=t.extend,k={},T={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},L=!1,C={GaForGame:{},GamifiveInfo:{},queues:{}},N={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},j=new D("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,m);return j.d("Get GameInfo, fly my minipony!"),n.then(function(e){return j.i("Space is ok, can download:",m,e),v(y)}).then(function(n){return j.d("Ga for game and gamifive info stored!",n),j.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,k.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),j.d("unzip:",t.id,k.TEMP_DIR+y),e._promiseZip(n.path,k.TEMP_DIR+y,r("unzip"))}).then(function(n){j.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,m=d*Math.pow(1024,p?f.MB:f.KB),y=t.id;return s.then(function(e){return j.d("Exists",e),e?(L=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(L=!0,i())})},r.prototype.play=function(t){j.d("Play",t);var n=k.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return w(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){j.d("Removing game",t);var n=e.dirExists(k.CACHE_DIR+t+".zip"),r=e.dirExists(k.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(j.d("Removed in cache",n[0]),r.push(e.removeFile(k.CACHE_DIR+t+".zip"))),n[1]&&(j.d("Removed",n[1]),r.push(e.removeDir(k.GAMES_DIR+t))),0===r.length&&j.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return L},r.prototype.abortDownload=function(){return this.isDownloading()?(j.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,L=!1),!0):(j.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return j.d("Get games list"),e.readDir(k.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=k.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(j.d("Read meta.json:",n),j.d("GAMEOVER_TEMPLATE path",k.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(k.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return j.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(k.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(k.GAMES_DIR).then(function(t){return j.d("All games deleted!",t),e.createDir(k.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){j.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){j.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(a),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(a),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(a.Utils,a.Decorators,a);var s=function(){var e={},t=!1;e.init=function(){if(J.hasOwnProperty("webappsfixes")&&"object"==typeof J.webappsfixes){t=!0;for(var e in J.webappsfixes)if(J.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){w("[webappsFixes] applying fix: "+e);var r=n[e](J.webappsfixes[e]);r&&h("[webappsFixes] fix '"+e+"' failed: "+r)}else h("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(S()&&!e.platforms.ios)return void w("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(y()&&!e.platforms.android)return void w("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(w("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),w("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();a.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return h("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!J.statusbar)return;e=J.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},Z=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(S()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){w("[share] Share completed? "+e.completed),w("[share] Shared to app: "+e.app),n(e)},a=function(e){h("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){w("[share] Facebook share completed, result: ",e),t(e)},i=function(e){h("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){w("[share] Twitter share completed, result: ",e),t(e)},i=function(e){h("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){w("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){h("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){w("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){w("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},m("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(w("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(h("[share] type not valid"),n("type not valid"))):(h("[share] missing parameter url"),n("missing parameter url")):(h("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();o.socialShare=function(e){return P?I?new Promise(function(t,n){Z.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},o.socialShareAvailable=function(e){return P?I?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Z.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){h(e),n(e)})}):(h("[share] missing parameter url"),Promise.reject("missing parameter url")):(h("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(h("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var Q=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){g().then(function(e){f&&f.type&&"online"===f.type?(w("[push] going to url: ",e),A(e)):h("[push] i'm offline not going to url")}).catch(function(e){h("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],s=!1,u=!1,l=function(){u||i()&&(u=!0,window.cordova.plugins.notification.local.on("click",function(e){s?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var p=function(){var e=window.cordova.file.applicationStorageDirectory;return S()&&(e+="Documents/"),e},g=function(){return a.file.fileExists(p()+"SGpushUrl").then(function(e){return e?a.file.readFileAsJSON(p()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},y=function(e){var t={url:c(e,{source:"localpush"})};return a.file.createFile(p(),"SGpushUrl").then(function(e){return w("[push] writing offline data",t,"in: ",e.path),a.file.write(e.path,JSON.stringify(t))}).catch(function(e){h("[push] error sg create SGpushUrl file",e)})},b=function(){var t=v.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(u||d();o.length>0;){var t=o.pop();w("[push] processing queued event: ",t),r()}s=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,f=1732584193,p=-271733879,g=-1732584194,w=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function f(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function p(e){return unescape(encodeURIComponent(e))}function g(e){return l(p(e))}function w(e){return f(g(e))}function h(e,t){return d(p(e),p(t))}function m(e,t){return f(h(e,t))}function v(e,t,n){return t?n?h(t,e):m(t,e):n?g(e):w(e)}return v}(),te=function(e){if(void 0===window.SpinnerDialog)return h("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},ne=function(){return void 0===window.SpinnerDialog?h("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=te,window.stopLoading=ne,o.inAppPurchaseSubscription=function(e,t,n,r){return P?I?(q(!0),void 0!==r&&(ie.returnUrl=r),void 0!==n&&(ie.subscribeMethod=n),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0,ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(),window.store.order(ie.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},o.inAppRestore=function(e,t,n,r){return P?I?(void 0!==n&&(ie.subscribeMethod=n),void 0!==r&&(ie.returnUrl=r),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0,void ie.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},o.inAppProductInfo=function(e){if(e.productId||(e.productId=ie.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return h("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!P)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!I)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(ie.subscribeMethod=e.subscriptionUrl,ie.requestedListingProductId=e.productId,ie.callbackListingSuccess=e.callbackListingSuccess,ie.callbackPurchaseSuccess=e.callbackPurchaseSuccess,ie.callbackListingError=e.callbackError,ie.inappProductInfoCalled=!0,ie.productsInfo[e.productId])try{ie.callbackListingSuccess(ie.productsInfo[e.productId])}catch(e){h("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(!0),!0)};var re=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(y()?n=e.productsIdAndroid:S()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,w("[IAPlight] getProducts ok",e),e}).catch(function(e){h("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(w("[IAPlight] subscribe ok",t),S())return e.getActiveSubscriptionsInfo().then(function(e){if(w("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(y()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return h("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw h("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){w("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),w(JSON.stringify(e)),w(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){w("IAP> Purchase approved."),w(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){w("subscription verified ",e)},onStoreReady:function(){w("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(w("[IAP] > Product Owned."),!e.transaction.id&&S())return h("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),S()&&window.localStorage.setItem("transaction_id",e.transaction.id),y()){var t=e.transaction.purchaseToken+"|"+O+"|"+ie.id;w("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||ie.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(w("[IAP] appStoreReceipt: "+t.appStoreReceipt),ie.createUser(e,t.appStoreReceipt)):w("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){q(!1),ie.callbackError({iap_cancelled:1,return_url:ie.returnUrl}),w("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){w("[IAP] ORDER APPROVED "+ie.id),e.finish()},error:function(e){q(!1),h("[IAP] error: "+e),ie.callbackError({iap_error:1,return_url:ie.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(w("[IAP] createUser start "),!ie.inappProductInfoCalled&&!ie.inappPurchaseCalled)return ie.lastCreateUserProduct=e,void(ie.lastCreateUserToken=t);if(!ie.subscribeMethod)return void h("[IAP] createUser configuration error: missing api url.");var n=ie.getRandomEmail(),r=1;y()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=ie.subscribeMethod,o={paymethod:ie.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:ie.returnUrl,inapp_pwd:ie.getPassword(t),hybrid:1};ie.lastCreateuserUrl=i,ie.lastCreateuserData=o;var a=function(e){if(ie.createUserAttempt<=ie.maxCreateUserAttempt)h("[IAP] createUser failed "+ie.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{h("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:ie.returnUrl};q(!1),ie.inappPurchaseCalled?ie.callbackError(t):ie.inappProductInfoCalled&&ie.callbackListingError(t)}},s=function(e){w("[IAP] createUser success ",e);try{e.device_id=v.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),q(!1),ie.callbackSuccess(e),ie.inappPurchaseCalled?ie.callbackSuccess(e):ie.inappProductInfoCalled&&ie.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ie.createUserAttempt=ie.createUserAttempt+1,w("[IAP] createUser attempt: "+ie.createUserAttempt+" with timeout: "+c+"sec."),w("[IAP] POST createUser: "+ie.lastCreateuserUrl+" params: "+JSON.stringify(ie.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(ie.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(ie.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){w("[IAP] createUser end"),q(!1)}).go(),c+=5},10)} -;ie.createUserAttempt=0,u()}},oe=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return h("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return h("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});w("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){h("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return h("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});w("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){h("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(h("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(h("[globalization] getLocaleName: not initialized!"),!1)},e}();o.facebookLogin=function(e,t,n){if(!P)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){w("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){h("Got FB login error:",e),n({error:e})})},o.facebookShare=function(e,t,n){if(!P)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){h("Got FB share error:",e),n({error:e})})};var ae=function(){deltadna.registerPushCallback(ce)},se=function(e){h("[DeltaDNA] error: "+e)},ce=function(e){return y()&&e.payload&&e.payload.url&&!e.foreground?A(e.payload.url):S()&&e.url?A(e.url):void 0},ue=function(){var e={},t={},n=function(n){w("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(h("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(h("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&w("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return h("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),le=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return h("[appsflyer] missing cordova plugin");if(void 0===J.appsflyer_devkey)return h("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:J.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(S()){if(void 0===J.appstore_appid)return h("[appsflyer] missing manifest configuration: appstore_appid");n.appId=J.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}$.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();o.setConversionDataCallback=function(e){le.setCallback(e)};var de=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return w("[analytics] callback not set!");try{e(t)}catch(e){h("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();o.setAnalyticsCallback=function(e){de.setCallback(e)};var fe={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(fe.DefaultOptions=e),AdMob&&(fe.AdMobSupport=!0,fe.initAdMob(e,t,n)),MoPub&&(fe.MoPubSupport=!0),!0},isAdMobSupported:function(){return fe.AdMobSupport},isMoPubSupported:function(){return fe.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=fe.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=fe.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=fe.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?fe.AdSize.LEADERBOARD:t>=468&&e>=60?fe.AdSize.BANNER:t>=320&&e>=50?fe.AdSize.BANNER:void 0}};return o.game=a.game._public,o.file=a.file,o.AdManager=a.AdManager,o}); \ No newline at end of file +!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.Stargate=t()}(this,function(){function e(e){p.type=e.type,p.networkState=navigator.connection.type,"function"==typeof f&&f(p)}function t(){document.addEventListener("offline",e,!1),document.addEventListener("online",e,!1)}function n(){p.networkState=navigator.connection.type,"none"===navigator.connection.type?p.type="offline":p.type="online"}function r(e){if("android"==window.device.platform.toLowerCase())window.navigator.app.loadUrl(e);else if("ios"==window.device.platform.toLowerCase()&&-1!==e.indexOf("file:///")){var t=e.split("?")[0];h("Without qs",t),window.resolveLocalFileSystemURL(t,function(e){var t=e.toInternalURL()+"?hybrid=1";h("Redirect to",t),window.location.href=t},m)}else window.location.href=e}function i(){var e=window.cordova.file.applicationDirectory+"www/manifest.json";return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)}).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})}).then(function(e){var t="";try{t=window.JSON.parse(e)}catch(e){return Promise.reject(e)}return Promise.resolve(t)}).catch(function(e){console.error("getManifestWithCordovaFilePlugin() error:"+e,e)})}function o(){return window.cordova.file?i():window.hostedwebapp?new Promise(function(e,t){window.hostedwebapp.getManifest(function(t){e(t)},function(e){m(e),t(new Error(e))})}):(m("getManifest() no available reading mechanism!"),Promise.resolve({}))}var a={},s={};!function(e){function t(e,n,r){this.level=t.levels[e.toUpperCase()],this.styles=r||{background:"white",color:"black"},this.tag="%c "+n+" ",this.isstaging="1"==="IS_STAGING = 1".slice(-1),this.styleString="background:"+this.styles.background+";color:"+this.styles.color+";";var i=function(){if(arguments.length<1)return"";for(var e=Array.prototype.slice.call(arguments[0]),t="",n=0;n0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(s),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(s,s.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(L=O(L,t)),j.d("Initialized called with:",L),!e)return Promise.reject("Missing file module!");try{S=window.cordova.file.applicationStorageDirectory,b=window.cordova.file.cacheDirectory,A=window.cordova.file.tempDirectory,P=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",_=window.cordova.file.dataDirectory}catch(e){return j.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(S+="Documents/"),"android"==window.device.platform.toLowerCase()&&(A=b),k.SDK_DIR=S+"scripts/",k.SDK_RELATIVE_DIR="../../scripts/",k.GAMEOVER_RELATIVE_DIR="../../gameover_template/",k.GAMES_DIR=S+"games/",k.BASE_DIR=S,k.CACHE_DIR=b,k.TEMP_DIR=A,k.CORDOVAJS=P+"cordova.js",k.CORDOVA_PLUGINS_JS=P+"cordova_plugins.js",k.STARGATEJS=P+"js/stargate.js",k.DATA_DIR=_,k.GAMEOVER_DIR=k.BASE_DIR+"gameover_template/",k.WWW_DIR=P,j.i("cordova JS dir to include",k.CORDOVAJS),n.game._public.BASE_DIR=k.BASE_DIR,n.game._public.OFFLINE_INDEX=k.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(k.BASE_DIR,"games"),a=e.createDir(k.BASE_DIR,"scripts"),u=e.fileExists(k.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(C))}),l=e.fileExists(k.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return j.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(k.BASE_DIR+"gameover_template"),e.dirExists(k.SDK_DIR+"plugins"),e.fileExists(k.SDK_DIR+"cordova.js"),e.fileExists(k.SDK_DIR+"cordova_plugins.js"),e.fileExists(k.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(k.WWW_DIR+"gameover_template",k.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(k.WWW_DIR+"plugins",k.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(k.CORDOVAJS,k.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(k.CORDOVA_PLUGINS_JS,k.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(k.WWW_DIR+"js/gamesFixes.js",k.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=E(L.sdk_url,{v:t.getTime()});return""===L.sdk_url||void 0===L.sdk_url||null===L.sdk_url?(j.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(k.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(j.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,k.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(k.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return j.d("Serialized dom",r),r}).then(function(t){return j.d("Write dom:",r,t),e.write(r,t)})}function w(e){return new RegExp(/.*\.html?$/i).test(e)}function h(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=k.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return j.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function m(){return j.i("readUserJson",k.BASE_DIR+"user.json"),e.readFileAsJSON(k.BASE_DIR+"user.json")}function v(e){return m().then(function(t){if(!t.ponyUrl)throw j.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];j.d("PONYVALUE",n);var r=E(L.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,j.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return j.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(k.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return j.d("writing offlineData.json",t),e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var S,b,A,P,_,I,D=t.Logger,E=t.composeApiString,R=t.jsonpRequest,O=t.extend,k={},L={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},T=!1,C={GaForGame:{},GamifiveInfo:{},queues:{}},N={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},j=new D("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,m);return j.d("Get GameInfo, fly my minipony!"),n.then(function(e){return j.i("Space is ok, can download:",m,e),v(y)}).then(function(n){return j.d("Ga for game and gamifive info stored!",n),j.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,k.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),j.d("unzip:",t.id,k.TEMP_DIR+y),e._promiseZip(n.path,k.TEMP_DIR+y,r("unzip"))}).then(function(n){j.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,m=d*Math.pow(1024,p?f.MB:f.KB),y=t.id;return s.then(function(e){return j.d("Exists",e),e?(T=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(T=!0,i())})},r.prototype.play=function(t){j.d("Play",t);var n=k.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return w(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){j.d("Removing game",t);var n=e.dirExists(k.CACHE_DIR+t+".zip"),r=e.dirExists(k.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(j.d("Removed in cache",n[0]),r.push(e.removeFile(k.CACHE_DIR+t+".zip"))),n[1]&&(j.d("Removed",n[1]),r.push(e.removeDir(k.GAMES_DIR+t))),0===r.length&&j.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return T},r.prototype.abortDownload=function(){return this.isDownloading()?(j.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,T=!1),!0):(j.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return j.d("Get games list"),e.readDir(k.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=k.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(j.d("Read meta.json:",n),j.d("GAMEOVER_TEMPLATE path",k.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(k.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return j.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(k.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(k.GAMES_DIR).then(function(t){return j.d("All games deleted!",t),e.createDir(k.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(L.bundle_games.length>0){j.d("Games bundle in configuration",L.bundle_games);var t,n=L.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){j.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(W.hasOwnProperty("webappsfixes")&&"object"==typeof W.webappsfixes){t=!0;for(var e in W.webappsfixes)if(W.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){h("[webappsFixes] applying fix: "+e);var r=n[e](W.webappsfixes[e]);r&&m("[webappsFixes] fix '"+e+"' failed: "+r)}else m("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(b()&&!e.platforms.ios)return void h("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(S()&&!e.platforms.android)return void h("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(h("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),h("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return m("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!W.statusbar)return;e=W.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},Q=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(b()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){h("[share] Share completed? "+e.completed),h("[share] Shared to app: "+e.app),n(e)},a=function(e){m("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){h("[share] Facebook share completed, result: ",e),t(e)},i=function(e){m("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){h("[share] Twitter share completed, result: ",e),t(e)},i=function(e){m("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){h("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){m("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){h("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){h("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(h("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(m("[share] type not valid"),n("type not valid"))):(m("[share] missing parameter url"),n("missing parameter url")):(m("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return I?D?new Promise(function(t,n){Q.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return I?D?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Q.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){m(e),n(e)})}):(m("[share] missing parameter url"),Promise.reject("missing parameter url")):(m("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(m("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var $=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){g().then(function(e){p&&p.type&&"online"===p.type?(h("[push] going to url: ",e),P(e)):m("[push] i'm offline not going to url")}).catch(function(e){m("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var f=function(){var e=window.cordova.file.applicationStorageDirectory;return b()&&(e+="Documents/"),e},g=function(){return s.file.fileExists(f()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(f()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},w=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(f(),"SGpushUrl").then(function(e){return h("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){m("[push] error sg create SGpushUrl file",e)})},S=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();h("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,f=1732584193,p=-271733879,g=-1732584194,w=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function f(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function p(e){return unescape(encodeURIComponent(e))}function g(e){return l(p(e))}function w(e){return f(g(e))}function h(e,t){return d(p(e),p(t))}function m(e,t){return f(h(e,t))}function v(e,t,n){return t?n?h(t,e):m(t,e):n?g(e):w(e)}return v}(),ne=function(e){if(void 0===window.SpinnerDialog)return m("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},re=function(){return void 0===window.SpinnerDialog?m("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=ne,window.stopLoading=re,a.inAppPurchaseSubscription=function(e,t,n,r){return I?D?(J(!0),void 0!==r&&(oe.returnUrl=r),void 0!==n&&(oe.subscribeMethod=n),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0,oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(),window.store.order(oe.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.inAppRestore=function(e,t,n,r){return I?D?(void 0!==n&&(oe.subscribeMethod=n),void 0!==r&&(oe.returnUrl=r),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0,void oe.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},a.inAppProductInfo=function(e){if(e.productId||(e.productId=oe.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return m("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!I)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!D)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(oe.subscribeMethod=e.subscriptionUrl,oe.requestedListingProductId=e.productId,oe.callbackListingSuccess=e.callbackListingSuccess,oe.callbackPurchaseSuccess=e.callbackPurchaseSuccess,oe.callbackListingError=e.callbackError,oe.inappProductInfoCalled=!0,oe.productsInfo[e.productId])try{oe.callbackListingSuccess(oe.productsInfo[e.productId])}catch(e){m("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(!0),!0)};var ie=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(S()?n=e.productsIdAndroid:b()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,h("[IAPlight] getProducts ok",e),e}).catch(function(e){m("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(h("[IAPlight] subscribe ok",t),b())return e.getActiveSubscriptionsInfo().then(function(e){if(h("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(S()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return m("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw m("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){h("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),h(JSON.stringify(e)),h(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){h("IAP> Purchase approved."),h(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){h("subscription verified ",e)},onStoreReady:function(){h("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(h("[IAP] > Product Owned."),!e.transaction.id&&b())return m("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),b()&&window.localStorage.setItem("transaction_id",e.transaction.id),S()){var t=e.transaction.purchaseToken+"|"+k+"|"+oe.id;h("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||oe.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(h("[IAP] appStoreReceipt: "+t.appStoreReceipt),oe.createUser(e,t.appStoreReceipt)):h("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){J(!1),oe.callbackError({iap_cancelled:1,return_url:oe.returnUrl}),h("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){h("[IAP] ORDER APPROVED "+oe.id),e.finish()},error:function(e){J(!1),m("[IAP] error: "+e),oe.callbackError({iap_error:1,return_url:oe.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(h("[IAP] createUser start "),!oe.inappProductInfoCalled&&!oe.inappPurchaseCalled)return oe.lastCreateUserProduct=e,void(oe.lastCreateUserToken=t);if(!oe.subscribeMethod)return void m("[IAP] createUser configuration error: missing api url.");var n=oe.getRandomEmail(),r=1;S()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=oe.subscribeMethod,o={paymethod:oe.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:oe.returnUrl,inapp_pwd:oe.getPassword(t),hybrid:1};oe.lastCreateuserUrl=i,oe.lastCreateuserData=o;var a=function(e){if(oe.createUserAttempt<=oe.maxCreateUserAttempt)m("[IAP] createUser failed "+oe.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{m("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:oe.returnUrl};J(!1),oe.inappPurchaseCalled?oe.callbackError(t):oe.inappProductInfoCalled&&oe.callbackListingError(t)}},s=function(e){h("[IAP] createUser success ",e);try{e.device_id=y.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),J(!1),oe.callbackSuccess(e),oe.inappPurchaseCalled?oe.callbackSuccess(e):oe.inappProductInfoCalled&&oe.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ +oe.createUserAttempt=oe.createUserAttempt+1,h("[IAP] createUser attempt: "+oe.createUserAttempt+" with timeout: "+c+"sec."),h("[IAP] POST createUser: "+oe.lastCreateuserUrl+" params: "+JSON.stringify(oe.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(oe.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(oe.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){h("[IAP] createUser end"),J(!1)}).go(),c+=5},10)};oe.createUserAttempt=0,u()}},ae=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return m("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return m("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});h("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){m("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return m("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});h("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){m("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(m("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(m("[globalization] getLocaleName: not initialized!"),!1)},e}();a.facebookLogin=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){h("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){m("Got FB login error:",e),n({error:e})})},a.facebookShare=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){m("Got FB share error:",e),n({error:e})})};var se=function(){deltadna.registerPushCallback(ue)},ce=function(e){m("[DeltaDNA] error: "+e)},ue=function(e){return S()&&e.payload&&e.payload.url&&!e.foreground?P(e.payload.url):b()&&e.url?P(e.url):void 0},le=function(){var e={},t={},n=function(n){h("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(m("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(m("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&h("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return m("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),de=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return m("[appsflyer] missing cordova plugin");if(void 0===W.appsflyer_devkey)return m("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:W.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(b()){if(void 0===W.appstore_appid)return m("[appsflyer] missing manifest configuration: appstore_appid");n.appId=W.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}ee.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();a.setConversionDataCallback=function(e){de.setCallback(e)};var fe=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return h("[analytics] callback not set!");try{e(t)}catch(e){m("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();a.setAnalyticsCallback=function(e){fe.setCallback(e)};var pe={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(pe.DefaultOptions=e),AdMob&&(pe.AdMobSupport=!0,pe.initAdMob(e,t,n)),MoPub&&(pe.MoPubSupport=!0),!0},isAdMobSupported:function(){return pe.AdMobSupport},isMoPubSupported:function(){return pe.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=pe.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=pe.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=pe.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?pe.AdSize.LEADERBOARD:t>=468&&e>=60?pe.AdSize.BANNER:t>=320&&e>=50?pe.AdSize.BANNER:void 0}};return a.game=s.game._public,a.file=s.file,a.AdManager=s.AdManager,a}); \ No newline at end of file diff --git a/dist/stargate.js b/dist/stargate.js index 4d5629c..b1ad7a4 100644 --- a/dist/stargate.js +++ b/dist/stargate.js @@ -3935,7 +3935,7 @@ } }(this, function () { // Public interface - var stargatePackageVersion = "0.13.2"; + var stargatePackageVersion = "0.13.3"; var stargatePublic = {}; var stargateModules = {}; @@ -6857,10 +6857,48 @@ function getAppIsDebug() { return Promise.resolve({}); } +function getManifestWithCordovaFilePlugin() { + var url = window.cordova.file.applicationDirectory + "www/manifest.json"; + + return new Promise(function(resolve, reject){ + window.resolveLocalFileSystemURL(url, resolve, reject); + }) + .then(function(fileEntry) { + + return new Promise(function(resolve, reject){ + fileEntry.file(function(file) { + var reader = new FileReader(); + reader.onerror = reject; + reader.onabort = reject; + + reader.onloadend = function() { + var textToParse = this.result; + resolve(textToParse); + }; + reader.readAsText(file); + }); + }); + }) + .then(function(fileContent) { + var jsonParsed = ''; + try{ + jsonParsed = window.JSON.parse(fileContent); + } + catch(e){ + return Promise.reject(e); + } + + return Promise.resolve(jsonParsed); + }) + .catch(function(e) { + console.error("getManifestWithCordovaFilePlugin() error:"+e, e); + }); +} + function getManifest() { if (window.cordova.file) { - return stargateModules.file.readFileAsJSON(window.cordova.file.applicationDirectory + "www/manifest.json"); + return getManifestWithCordovaFilePlugin(); } if (window.hostedwebapp) { diff --git a/dist/stargate.min.js b/dist/stargate.min.js index 0325f79..323f6ae 100644 --- a/dist/stargate.min.js +++ b/dist/stargate.min.js @@ -1,10 +1,10 @@ /*! * StargateJS Apps - * v0.13.2 + * v0.13.3 * Copyright 2015 DMobileLab. http://buongiorno.com/ * See LICENSE in this repository for license information */ !function(e,t){"use strict";"object"==typeof exports?module.exports=t(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"==typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],t):e.URI=t(e.punycode,e.IPv6,e.SecondLevelDomains,e)}(this,function(e,t,n,r){"use strict";function i(e,t){var n=arguments.length>=1,r=arguments.length>=2;if(!(this instanceof i))return n?r?new i(e,t):new i(e):new i;if(void 0===e){if(n)throw new TypeError("undefined is not a valid argument for URI");e="undefined"!=typeof location?location.href+"":""}return this.href(e),void 0!==t?this.absoluteTo(t):this}function o(e){return e.replace(/([.*+?^=!:()|[\]\/\\])/g,"\\$1")}function a(e){return void 0===e?"Undefined":String(Object.prototype.toString.call(e)).slice(8,-1)}function s(e){return"Array"===a(e)}function c(e,t){var n,r,i={};if("RegExp"===a(t))i=null;else if(s(t))for(n=0,r=t.length;n]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,i.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?«»“”„‘’]+$/},i.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},i.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/,i.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"},i.getDomAttribute=function(e){if(e&&e.nodeName){var t=e.nodeName.toLowerCase();if("input"!==t||"image"===e.type)return i.domAttributes[t]}},i.encode=f,i.decode=decodeURIComponent,i.iso8859=function(){i.encode=escape,i.decode=unescape},i.unicode=function(){i.encode=f,i.decode=decodeURIComponent},i.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/gi,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}},i.encodeQuery=function(e,t){var n=i.encode(e+"");return void 0===t&&(t=i.escapeQuerySpace),t?n.replace(/%20/g,"+"):n},i.decodeQuery=function(e,t){e+="",void 0===t&&(t=i.escapeQuerySpace);try{return i.decode(t?e.replace(/\+/g,"%20"):e)}catch(t){return e}};var y,b={encode:"encode",decode:"decode"},_=function(e,t){return function(n){try{return i[t](n+"").replace(i.characters[e][t].expression,function(n){return i.characters[e][t].map[n]})}catch(e){return n}}};for(y in b)i[y+"PathSegment"]=_("pathname",b[y]),i[y+"UrnPathSegment"]=_("urnpath",b[y]);var S=function(e,t,n){return function(r){var o;o=n?function(e){return i[t](i[n](e))}:i[t];for(var a=(r+"").split(e),s=0,c=a.length;s-1&&(t.fragment=e.substring(n+1)||null,e=e.substring(0,n)),n=e.indexOf("?"),n>-1&&(t.query=e.substring(n+1)||null,e=e.substring(0,n)),"//"===e.substring(0,2)?(t.protocol=null,e=e.substring(2),e=i.parseAuthority(e,t)):(n=e.indexOf(":"))>-1&&(t.protocol=e.substring(0,n)||null,t.protocol&&!t.protocol.match(i.protocol_expression)?t.protocol=void 0:"//"===e.substring(n+1,n+3)?(e=e.substring(n+3),e=i.parseAuthority(e,t)):(e=e.substring(n+1),t.urn=!0)),t.path=e,t},i.parseHost=function(e,t){e=e.replace(/\\/g,"/");var n,r,i=e.indexOf("/");if(-1===i&&(i=e.length),"["===e.charAt(0))n=e.indexOf("]"),t.hostname=e.substring(1,n)||null,t.port=e.substring(n+2,i)||null,"/"===t.port&&(t.port=null);else{var o=e.indexOf(":"),a=e.indexOf("/"),s=e.indexOf(":",o+1);-1!==s&&(-1===a||s-1?r:e.length-1);return o>-1&&(-1===r||o3?Object.keys(n).forEach(function(e){var n=e.match(/^([0-9])([0-9x])([0-9x])$/i);!(n&&n.length>3&&o[1]===n[1])||"x"!==n[2]&&o[2]!==n[2]||"x"!==n[3]&&o[3]!==n[3]||i(e,t)}):n[e]&&i(e,t)}return this},go:function(){var e=t.type||(t.into?"html":"json"),n=u();if("function"==typeof a[e])return a[e].call(this,n)}},a={json:function(e){var t=this;a._xhr.call(this,e,function(e){if(e)try{e=JSON.parse(e)}catch(e){return t.trigger("error",e),null}return e})},html:function(e){a._xhr.call(this,e,function(e){return t.into&&t.into.length&&[].forEach.call(t.into,function(t){t.innerHTML=e}),e})},_xhr:function(e,n){var r,i,o,a,s,u=this,l=t.method||"get",d=!0!==t.sync,p=new XMLHttpRequest,f=t.data,h=t.body,g=(t.headers,this.header("Content-Type")),m=t.timeout;if(!g&&f&&c()&&(this.header("Content-Type","application/x-www-form-urlencoded;charset=utf-8"),g=this.header("Content-Type")),f&&c())if("string"!=typeof h&&(h=""),g.indexOf("json")>-1)try{h=JSON.stringify(f)}catch(e){throw new TypeError("Unable to stringify body's content : "+e.name)}else{a=g&&g.indexOf("x-www-form-urlencoded")>1;for(r in f)h+=a?encodeURIComponent(r)+"="+encodeURIComponent(f[r])+"&":r+"="+f[r]+"\n\r"}s=[l,e,d],t.auth&&(s.push(t.auth.user),s.push(t.auth.passwd)),p.open.apply(p,s);for(i in t.headers)p.setRequestHeader(i,t.headers[i]);p.onprogress=function(e){e.lengthComputable&&u.trigger("progress",e.loaded/e.total)},p.onload=function(){var e=p.responseText;o&&clearTimeout(o),this.status>=200&&this.status<300&&("function"==typeof n&&(e=n(e)),u.trigger("success",e)),u.trigger(this.status,e),u.trigger("end",e)},p.onerror=function(e){o&&clearTimeout(o),u.trigger("error",e,arguments)},m&&(o=setTimeout(function(){u.trigger("timeout",{type:"timeout",expiredAfter:m},p,arguments),p.abort()},m)),p.send(h)},jsonp:function(n){var r,o=this,a=document.querySelector("head"),s=!0!==t.sync,c=t.jsonPaddingName||"callback",u=t.jsonPadding||"_padd"+(new Date).getTime()+Math.floor(1e4*Math.random()),l={};if(e[u])throw new Error("Padding "+u+" already exists. It must be unique.");/^ajajsonp_/.test(u)||(u="ajajsonp_"+u),window[u]=function(e){o.trigger("success",e),a.removeChild(r),window[u]=void 0},l[c]=u,n=i(n,l),r=document.createElement("script"),r.async=s,r.src=n,r.onerror=function(){o.trigger("error",arguments),a.removeChild(r),window[u]=void 0},a.appendChild(r)},script:function(e){var n,r=this,i=document.querySelector("head")||document.querySelector("body"),o=!0!==t.sync;if(!i)throw new Error("Ok, wait a second, you want to load a script, but you don't have at least a head or body tag...");n=document.createElement("script"),n.async=o,n.src=e,n.onerror=function(){r.trigger("error",arguments),i.removeChild(n)},n.onload=function(){r.trigger("success",arguments)},i.appendChild(n)}},s=function(e,n,i,o){if(void 0!==n){if("function"==typeof i)try{n=i.call(r,n)}catch(t){throw new TypeError("Failed to set "+e+" : "+t.message)}return t[e]="function"==typeof o?o.call(this,n):n,this}return"undefined"===t[e]?null:t[e]},c=function(){return["delete","patch","post","put"].indexOf(t.method)>-1},u=function(){var e=t.url,n=void 0===t.cache||!!t.cache,r=t.queryString||"",o=t.data;return!1===n&&(r+="&ajabuster="+(new Date).getTime()),e=i(e,r),o&&!c()&&(e=i(e,o)),e};return o},r={bool:function(e){return!!e},string:function(e){if("string"!=typeof e)throw new TypeError("a string is expected, but "+e+" ["+typeof e+"] given");return e},positiveInteger:function(e){if(parseInt(e)!==e||e<=0)throw new TypeError("an integer is expected, but "+e+" ["+typeof e+"] given");return e},plainObject:function(e){if("object"!=typeof e||e.constructor!==Object)throw new TypeError("an object is expected, but "+e+" ["+typeof e+"] given");return e},type:function(t){if(t=this.string(t),e.indexOf(t.toLowerCase())<0)throw new TypeError("a type in ["+e.join(", ")+"] is expected, but "+t+" given");return t.toLowerCase()},method:function(e){if(e=this.string(e),t.indexOf(e.toLowerCase())<0)throw new TypeError("a method in ["+t.join(", ")+"] is expected, but "+e+" given");return e.toLowerCase()},queryString:function(e){var t={};return"string"==typeof e?e.replace("?","").split("&").forEach(function(e){var n=e.split("=");2===n.length&&(t[decodeURIComponent(n[0])]=decodeURIComponent(n[1]))}):t=e,this.plainObject(t)},selector:function(e){if("string"!=typeof e&&!(e instanceof HTMLElement))throw new TypeError("a selector or an HTMLElement is expected, "+e+" ["+typeof e+"] given");return e},func:function(e){if(e=this.string(e),!/^([a-zA-Z_])([a-zA-Z0-9_\-])+$/.test(e))throw new TypeError("a valid function name is expected, "+e+" ["+typeof e+"] given");return e}},i=function(e,t){var n;if(e=e||"",t)if(-1===e.indexOf("?")&&(e+="?"),"string"==typeof t)e+=t;else if("object"==typeof t)for(n in t)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(t[n]);return e};"function"==typeof define&&define.amd?define([],function(){return n}):"object"==typeof exports?module.exports=n:window.aja=window.aja||n}(),function(e){function t(e,t){return function(){e.apply(t,arguments)}}function n(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],c(e,t(i,this),t(o,this))}function r(e){var t=this;if(null===this._state)return void this._deferreds.push(e);l(function(){var n=t._state?e.onFulfilled:e.onRejected;if(null===n)return void(t._state?e.resolve:e.reject)(t._value);var r;try{r=n(t._value)}catch(t){return void e.reject(t)}e.resolve(r)})}function i(e){try{if(e===this)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void c(t(n,e),t(i,this),t(o,this))}this._state=!0,this._value=e,a.call(this)}catch(e){o.call(this,e)}}function o(e){this._state=!1,this._value=e,a.call(this)}function a(){for(var e=0,t=this._deferreds.length;e0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(a),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(a,a.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(T=x(T,t)),U.d("Initialized called with:",T),!e)return Promise.reject("Missing file module!");try{b=window.cordova.file.applicationStorageDirectory,_=window.cordova.file.cacheDirectory,S=window.cordova.file.tempDirectory,A=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",P=window.cordova.file.dataDirectory}catch(e){return U.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(b+="Documents/"),"android"==window.device.platform.toLowerCase()&&(S=_),O.SDK_DIR=b+"scripts/",O.SDK_RELATIVE_DIR="../../scripts/",O.GAMEOVER_RELATIVE_DIR="../../gameover_template/",O.GAMES_DIR=b+"games/",O.BASE_DIR=b,O.CACHE_DIR=_,O.TEMP_DIR=S,O.CORDOVAJS=A+"cordova.js",O.CORDOVA_PLUGINS_JS=A+"cordova_plugins.js",O.STARGATEJS=A+"js/stargate.js",O.DATA_DIR=P,O.GAMEOVER_DIR=O.BASE_DIR+"gameover_template/",O.WWW_DIR=A,U.i("cordova JS dir to include",O.CORDOVAJS),n.game._public.BASE_DIR=O.BASE_DIR,n.game._public.OFFLINE_INDEX=O.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(O.BASE_DIR,"games"),a=e.createDir(O.BASE_DIR,"scripts"),u=e.fileExists(O.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(j))}),l=e.fileExists(O.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return U.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(O.BASE_DIR+"gameover_template"),e.dirExists(O.SDK_DIR+"plugins"),e.fileExists(O.SDK_DIR+"cordova.js"),e.fileExists(O.SDK_DIR+"cordova_plugins.js"),e.fileExists(O.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(O.WWW_DIR+"gameover_template",O.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(O.WWW_DIR+"plugins",O.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(O.CORDOVAJS,O.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(O.CORDOVA_PLUGINS_JS,O.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(O.WWW_DIR+"js/gamesFixes.js",O.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=D(T.sdk_url,{v:t.getTime()});return""===T.sdk_url||void 0===T.sdk_url||null===T.sdk_url?(U.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(O.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(U.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,O.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(O.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return U.d("Serialized dom",r),r}).then(function(t){return U.d("Write dom:",r,t),e.write(r,t)})}function g(e){return new RegExp(/.*\.html?$/i).test(e)}function m(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=O.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return U.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function w(){return U.i("readUserJson",O.BASE_DIR+"user.json"),e.readFileAsJSON(O.BASE_DIR+"user.json")}function v(e){return w().then(function(t){if(!t.ponyUrl)throw U.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];U.d("PONYVALUE",n);var r=D(T.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,U.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return U.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(O.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return U.d("writing offlineData.json",t),e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var b,_,S,A,P,I,E=t.Logger,D=t.composeApiString,R=t.jsonpRequest,x=t.extend,O={},T={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},k=!1,j={GaForGame:{},GamifiveInfo:{},queues:{}},C={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},U=new E("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,w);return U.d("Get GameInfo, fly my minipony!"),n.then(function(e){return U.i("Space is ok, can download:",w,e),v(y)}).then(function(n){return U.d("Ga for game and gamifive info stored!",n),U.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,O.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),U.d("unzip:",t.id,O.TEMP_DIR+y), -e._promiseZip(n.path,O.TEMP_DIR+y,r("unzip"))}).then(function(n){U.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,w=d*Math.pow(1024,f?p.MB:p.KB),y=t.id;return s.then(function(e){return U.d("Exists",e),e?(k=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(k=!0,i())})},r.prototype.play=function(t){U.d("Play",t);var n=O.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return g(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){U.d("Removing game",t);var n=e.dirExists(O.CACHE_DIR+t+".zip"),r=e.dirExists(O.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(U.d("Removed in cache",n[0]),r.push(e.removeFile(O.CACHE_DIR+t+".zip"))),n[1]&&(U.d("Removed",n[1]),r.push(e.removeDir(O.GAMES_DIR+t))),0===r.length&&U.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return k},r.prototype.abortDownload=function(){return this.isDownloading()?(U.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,k=!1),!0):(U.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return U.d("Get games list"),e.readDir(O.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=O.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(U.d("Read meta.json:",n),U.d("GAMEOVER_TEMPLATE path",O.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(O.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return U.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(O.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(O.GAMES_DIR).then(function(t){return U.d("All games deleted!",t),e.createDir(O.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){U.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){U.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(a),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(a),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(a.Utils,a.Decorators,a);var s=function(){var e={},t=!1;e.init=function(){if(H.hasOwnProperty("webappsfixes")&&"object"==typeof H.webappsfixes){t=!0;for(var e in H.webappsfixes)if(H.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){g("[webappsFixes] applying fix: "+e);var r=n[e](H.webappsfixes[e]);r&&m("[webappsFixes] fix '"+e+"' failed: "+r)}else m("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(b()&&!e.platforms.ios)return void g("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(y()&&!e.platforms.android)return void g("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(g("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),g("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();a.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return m("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!H.statusbar)return;e=H.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},Z=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(b()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){g("[share] Share completed? "+e.completed),g("[share] Shared to app: "+e.app),n(e)},a=function(e){m("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){g("[share] Facebook share completed, result: ",e),t(e)},i=function(e){m("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){g("[share] Twitter share completed, result: ",e),t(e)},i=function(e){m("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){g("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){m("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){g("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){g("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},w("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(g("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(m("[share] type not valid"),n("type not valid"))):(m("[share] missing parameter url"),n("missing parameter url")):(m("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();o.socialShare=function(e){return P?I?new Promise(function(t,n){Z.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},o.socialShareAvailable=function(e){return P?I?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Z.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){m(e),n(e)})}):(m("[share] missing parameter url"),Promise.reject("missing parameter url")):(m("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(m("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var X=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){h().then(function(e){p&&p.type&&"online"===p.type?(g("[push] going to url: ",e),S(e)):m("[push] i'm offline not going to url")}).catch(function(e){m("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],s=!1,u=!1,l=function(){u||i()&&(u=!0,window.cordova.plugins.notification.local.on("click",function(e){s?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var f=function(){var e=window.cordova.file.applicationStorageDirectory;return b()&&(e+="Documents/"),e},h=function(){return a.file.fileExists(f()+"SGpushUrl").then(function(e){return e?a.file.readFileAsJSON(f()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},y=function(e){var t={url:c(e,{source:"localpush"})};return a.file.createFile(f(),"SGpushUrl").then(function(e){return g("[push] writing offline data",t,"in: ",e.path),a.file.write(e.path,JSON.stringify(t))}).catch(function(e){m("[push] error sg create SGpushUrl file",e)})},_=function(){var t=v.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(u||d();o.length>0;){var t=o.pop();g("[push] processing queued event: ",t),r()}s=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,p=1732584193,f=-271733879,h=-1732584194,g=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function p(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function f(e){return unescape(encodeURIComponent(e))}function h(e){return l(f(e))}function g(e){return p(h(e))}function m(e,t){return d(f(e),f(t))}function w(e,t){return p(m(e,t))}function v(e,t,n){return t?n?m(t,e):w(t,e):n?h(e):g(e)}return v}(),te=function(e){if(void 0===window.SpinnerDialog)return m("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},ne=function(){return void 0===window.SpinnerDialog?m("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=te,window.stopLoading=ne,o.inAppPurchaseSubscription=function(e,t,n,r){return P?I?(V(!0),void 0!==r&&(ie.returnUrl=r),void 0!==n&&(ie.subscribeMethod=n),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0,ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(),window.store.order(ie.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},o.inAppRestore=function(e,t,n,r){return P?I?(void 0!==n&&(ie.subscribeMethod=n),void 0!==r&&(ie.returnUrl=r),ie.callbackSuccess=e,ie.callbackError=t,ie.inappPurchaseCalled=!0, -void ie.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},o.inAppProductInfo=function(e){if(e.productId||(e.productId=ie.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return m("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!P)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!I)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(ie.subscribeMethod=e.subscriptionUrl,ie.requestedListingProductId=e.productId,ie.callbackListingSuccess=e.callbackListingSuccess,ie.callbackPurchaseSuccess=e.callbackPurchaseSuccess,ie.callbackListingError=e.callbackError,ie.inappProductInfoCalled=!0,ie.productsInfo[e.productId])try{ie.callbackListingSuccess(ie.productsInfo[e.productId])}catch(e){m("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return ie.lastCreateUserProduct&&ie.lastCreateUserToken?(ie.createUser(ie.lastCreateUserProduct,ie.lastCreateUserToken),!0):(ie.doRefresh(!0),!0)};var re=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(y()?n=e.productsIdAndroid:b()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,g("[IAPlight] getProducts ok",e),e}).catch(function(e){m("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(g("[IAPlight] subscribe ok",t),b())return e.getActiveSubscriptionsInfo().then(function(e){if(g("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(y()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return m("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw m("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){g("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),g(JSON.stringify(e)),g(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){g("IAP> Purchase approved."),g(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){g("subscription verified ",e)},onStoreReady:function(){g("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(g("[IAP] > Product Owned."),!e.transaction.id&&b())return m("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),b()&&window.localStorage.setItem("transaction_id",e.transaction.id),y()){var t=e.transaction.purchaseToken+"|"+x+"|"+ie.id;g("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||ie.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(g("[IAP] appStoreReceipt: "+t.appStoreReceipt),ie.createUser(e,t.appStoreReceipt)):g("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){V(!1),ie.callbackError({iap_cancelled:1,return_url:ie.returnUrl}),g("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){g("[IAP] ORDER APPROVED "+ie.id),e.finish()},error:function(e){V(!1),m("[IAP] error: "+e),ie.callbackError({iap_error:1,return_url:ie.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(g("[IAP] createUser start "),!ie.inappProductInfoCalled&&!ie.inappPurchaseCalled)return ie.lastCreateUserProduct=e,void(ie.lastCreateUserToken=t);if(!ie.subscribeMethod)return void m("[IAP] createUser configuration error: missing api url.");var n=ie.getRandomEmail(),r=1;y()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=ie.subscribeMethod,o={paymethod:ie.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:ie.returnUrl,inapp_pwd:ie.getPassword(t),hybrid:1};ie.lastCreateuserUrl=i,ie.lastCreateuserData=o;var a=function(e){if(ie.createUserAttempt<=ie.maxCreateUserAttempt)m("[IAP] createUser failed "+ie.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{m("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:ie.returnUrl};V(!1),ie.inappPurchaseCalled?ie.callbackError(t):ie.inappProductInfoCalled&&ie.callbackListingError(t)}},s=function(e){g("[IAP] createUser success ",e);try{e.device_id=v.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),V(!1),ie.callbackSuccess(e),ie.inappPurchaseCalled?ie.callbackSuccess(e):ie.inappProductInfoCalled&&ie.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ie.createUserAttempt=ie.createUserAttempt+1,g("[IAP] createUser attempt: "+ie.createUserAttempt+" with timeout: "+c+"sec."),g("[IAP] POST createUser: "+ie.lastCreateuserUrl+" params: "+JSON.stringify(ie.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(ie.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(ie.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){g("[IAP] createUser end"),V(!1)}).go(),c+=5},10)};ie.createUserAttempt=0,u()}},oe=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return m("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return m("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});g("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){m("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return m("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});g("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){m("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(m("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(m("[globalization] getLocaleName: not initialized!"),!1)},e}();o.facebookLogin=function(e,t,n){if(!P)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){g("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){m("Got FB login error:",e),n({error:e})})},o.facebookShare=function(e,t,n){if(!P)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){m("Got FB share error:",e),n({error:e})})};var ae=function(){deltadna.registerPushCallback(ce)},se=function(e){m("[DeltaDNA] error: "+e)},ce=function(e){return y()&&e.payload&&e.payload.url&&!e.foreground?S(e.payload.url):b()&&e.url?S(e.url):void 0},ue=function(){var e={},t={},n=function(n){g("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(m("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(m("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&g("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return m("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),le=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return m("[appsflyer] missing cordova plugin");if(void 0===H.appsflyer_devkey)return m("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:H.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(b()){if(void 0===H.appstore_appid)return m("[appsflyer] missing manifest configuration: appstore_appid");n.appId=H.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}Y.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();o.setConversionDataCallback=function(e){le.setCallback(e)};var de=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return g("[analytics] callback not set!");try{e(t)}catch(e){m("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();o.setAnalyticsCallback=function(e){de.setCallback(e)};var pe={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(pe.DefaultOptions=e),AdMob&&(pe.AdMobSupport=!0,pe.initAdMob(e,t,n)),MoPub&&(pe.MoPubSupport=!0),!0},isAdMobSupported:function(){return pe.AdMobSupport},isMoPubSupported:function(){return pe.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=pe.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=pe.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=pe.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?pe.AdSize.LEADERBOARD:t>=468&&e>=60?pe.AdSize.BANNER:t>=320&&e>=50?pe.AdSize.BANNER:void 0}};return o.game=a.game._public,o.file=a.file,o.AdManager=a.AdManager,o}); \ No newline at end of file +void 0===(r="[object Function]"===String(Object.prototype.toString.call(i))?i(e):"[object Function]"===String(Object.prototype.toString.call(i[e]))?i[e](e):i[e])||null===r)return a;if("[object Array]"===String(Object.prototype.toString.call(r))){for(t=0,n=r.length;t3?Object.keys(n).forEach(function(e){var n=e.match(/^([0-9])([0-9x])([0-9x])$/i);!(n&&n.length>3&&o[1]===n[1])||"x"!==n[2]&&o[2]!==n[2]||"x"!==n[3]&&o[3]!==n[3]||i(e,t)}):n[e]&&i(e,t)}return this},go:function(){var e=t.type||(t.into?"html":"json"),n=u();if("function"==typeof a[e])return a[e].call(this,n)}},a={json:function(e){var t=this;a._xhr.call(this,e,function(e){if(e)try{e=JSON.parse(e)}catch(e){return t.trigger("error",e),null}return e})},html:function(e){a._xhr.call(this,e,function(e){return t.into&&t.into.length&&[].forEach.call(t.into,function(t){t.innerHTML=e}),e})},_xhr:function(e,n){var r,i,o,a,s,u=this,l=t.method||"get",d=!0!==t.sync,p=new XMLHttpRequest,f=t.data,h=t.body,g=(t.headers,this.header("Content-Type")),m=t.timeout;if(!g&&f&&c()&&(this.header("Content-Type","application/x-www-form-urlencoded;charset=utf-8"),g=this.header("Content-Type")),f&&c())if("string"!=typeof h&&(h=""),g.indexOf("json")>-1)try{h=JSON.stringify(f)}catch(e){throw new TypeError("Unable to stringify body's content : "+e.name)}else{a=g&&g.indexOf("x-www-form-urlencoded")>1;for(r in f)h+=a?encodeURIComponent(r)+"="+encodeURIComponent(f[r])+"&":r+"="+f[r]+"\n\r"}s=[l,e,d],t.auth&&(s.push(t.auth.user),s.push(t.auth.passwd)),p.open.apply(p,s);for(i in t.headers)p.setRequestHeader(i,t.headers[i]);p.onprogress=function(e){e.lengthComputable&&u.trigger("progress",e.loaded/e.total)},p.onload=function(){var e=p.responseText;o&&clearTimeout(o),this.status>=200&&this.status<300&&("function"==typeof n&&(e=n(e)),u.trigger("success",e)),u.trigger(this.status,e),u.trigger("end",e)},p.onerror=function(e){o&&clearTimeout(o),u.trigger("error",e,arguments)},m&&(o=setTimeout(function(){u.trigger("timeout",{type:"timeout",expiredAfter:m},p,arguments),p.abort()},m)),p.send(h)},jsonp:function(n){var r,o=this,a=document.querySelector("head"),s=!0!==t.sync,c=t.jsonPaddingName||"callback",u=t.jsonPadding||"_padd"+(new Date).getTime()+Math.floor(1e4*Math.random()),l={};if(e[u])throw new Error("Padding "+u+" already exists. It must be unique.");/^ajajsonp_/.test(u)||(u="ajajsonp_"+u),window[u]=function(e){o.trigger("success",e),a.removeChild(r),window[u]=void 0},l[c]=u,n=i(n,l),r=document.createElement("script"),r.async=s,r.src=n,r.onerror=function(){o.trigger("error",arguments),a.removeChild(r),window[u]=void 0},a.appendChild(r)},script:function(e){var n,r=this,i=document.querySelector("head")||document.querySelector("body"),o=!0!==t.sync;if(!i)throw new Error("Ok, wait a second, you want to load a script, but you don't have at least a head or body tag...");n=document.createElement("script"),n.async=o,n.src=e,n.onerror=function(){r.trigger("error",arguments),i.removeChild(n)},n.onload=function(){r.trigger("success",arguments)},i.appendChild(n)}},s=function(e,n,i,o){if(void 0!==n){if("function"==typeof i)try{n=i.call(r,n)}catch(t){throw new TypeError("Failed to set "+e+" : "+t.message)}return t[e]="function"==typeof o?o.call(this,n):n,this}return"undefined"===t[e]?null:t[e]},c=function(){return["delete","patch","post","put"].indexOf(t.method)>-1},u=function(){var e=t.url,n=void 0===t.cache||!!t.cache,r=t.queryString||"",o=t.data;return!1===n&&(r+="&ajabuster="+(new Date).getTime()),e=i(e,r),o&&!c()&&(e=i(e,o)),e};return o},r={bool:function(e){return!!e},string:function(e){if("string"!=typeof e)throw new TypeError("a string is expected, but "+e+" ["+typeof e+"] given");return e},positiveInteger:function(e){if(parseInt(e)!==e||e<=0)throw new TypeError("an integer is expected, but "+e+" ["+typeof e+"] given");return e},plainObject:function(e){if("object"!=typeof e||e.constructor!==Object)throw new TypeError("an object is expected, but "+e+" ["+typeof e+"] given");return e},type:function(t){if(t=this.string(t),e.indexOf(t.toLowerCase())<0)throw new TypeError("a type in ["+e.join(", ")+"] is expected, but "+t+" given");return t.toLowerCase()},method:function(e){if(e=this.string(e),t.indexOf(e.toLowerCase())<0)throw new TypeError("a method in ["+t.join(", ")+"] is expected, but "+e+" given");return e.toLowerCase()},queryString:function(e){var t={};return"string"==typeof e?e.replace("?","").split("&").forEach(function(e){var n=e.split("=");2===n.length&&(t[decodeURIComponent(n[0])]=decodeURIComponent(n[1]))}):t=e,this.plainObject(t)},selector:function(e){if("string"!=typeof e&&!(e instanceof HTMLElement))throw new TypeError("a selector or an HTMLElement is expected, "+e+" ["+typeof e+"] given");return e},func:function(e){if(e=this.string(e),!/^([a-zA-Z_])([a-zA-Z0-9_\-])+$/.test(e))throw new TypeError("a valid function name is expected, "+e+" ["+typeof e+"] given");return e}},i=function(e,t){var n;if(e=e||"",t)if(-1===e.indexOf("?")&&(e+="?"),"string"==typeof t)e+=t;else if("object"==typeof t)for(n in t)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(t[n]);return e};"function"==typeof define&&define.amd?define([],function(){return n}):"object"==typeof exports?module.exports=n:window.aja=window.aja||n}(),function(e){function t(e,t){return function(){e.apply(t,arguments)}}function n(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],c(e,t(i,this),t(o,this))}function r(e){var t=this;if(null===this._state)return void this._deferreds.push(e);l(function(){var n=t._state?e.onFulfilled:e.onRejected;if(null===n)return void(t._state?e.resolve:e.reject)(t._value);var r;try{r=n(t._value)}catch(t){return void e.reject(t)}e.resolve(r)})}function i(e){try{if(e===this)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void c(t(n,e),t(i,this),t(o,this))}this._state=!0,this._value=e,a.call(this)}catch(e){o.call(this,e)}}function o(e){this._state=!1,this._value=e,a.call(this)}function a(){for(var e=0,t=this._deferreds.length;e0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(s),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(s,s.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(T=x(T,t)),U.d("Initialized called with:",T),!e)return Promise.reject("Missing file module!");try{b=window.cordova.file.applicationStorageDirectory,_=window.cordova.file.cacheDirectory,S=window.cordova.file.tempDirectory,A=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",P=window.cordova.file.dataDirectory}catch(e){return U.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(b+="Documents/"),"android"==window.device.platform.toLowerCase()&&(S=_),O.SDK_DIR=b+"scripts/",O.SDK_RELATIVE_DIR="../../scripts/",O.GAMEOVER_RELATIVE_DIR="../../gameover_template/",O.GAMES_DIR=b+"games/",O.BASE_DIR=b,O.CACHE_DIR=_,O.TEMP_DIR=S,O.CORDOVAJS=A+"cordova.js",O.CORDOVA_PLUGINS_JS=A+"cordova_plugins.js",O.STARGATEJS=A+"js/stargate.js",O.DATA_DIR=P,O.GAMEOVER_DIR=O.BASE_DIR+"gameover_template/",O.WWW_DIR=A,U.i("cordova JS dir to include",O.CORDOVAJS),n.game._public.BASE_DIR=O.BASE_DIR,n.game._public.OFFLINE_INDEX=O.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(O.BASE_DIR,"games"),a=e.createDir(O.BASE_DIR,"scripts"),u=e.fileExists(O.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(j))}),l=e.fileExists(O.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return U.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(O.BASE_DIR+"gameover_template"),e.dirExists(O.SDK_DIR+"plugins"),e.fileExists(O.SDK_DIR+"cordova.js"),e.fileExists(O.SDK_DIR+"cordova_plugins.js"),e.fileExists(O.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(O.WWW_DIR+"gameover_template",O.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(O.WWW_DIR+"plugins",O.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(O.CORDOVAJS,O.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(O.CORDOVA_PLUGINS_JS,O.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(O.WWW_DIR+"js/gamesFixes.js",O.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=D(T.sdk_url,{v:t.getTime()});return""===T.sdk_url||void 0===T.sdk_url||null===T.sdk_url?(U.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(O.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(U.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,O.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(O.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return U.d("Serialized dom",r),r}).then(function(t){return U.d("Write dom:",r,t),e.write(r,t)})}function g(e){return new RegExp(/.*\.html?$/i).test(e)}function m(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=O.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return U.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function w(){return U.i("readUserJson",O.BASE_DIR+"user.json"),e.readFileAsJSON(O.BASE_DIR+"user.json")}function v(e){return w().then(function(t){if(!t.ponyUrl)throw U.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];U.d("PONYVALUE",n);var r=D(T.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,U.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return U.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(O.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return U.d("writing offlineData.json",t),e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var b,_,S,A,P,I,E=t.Logger,D=t.composeApiString,R=t.jsonpRequest,x=t.extend,O={},T={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},k=!1,j={GaForGame:{},GamifiveInfo:{},queues:{}},C={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},U=new E("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"}) +;var n=e.requestFileSystem(1,w);return U.d("Get GameInfo, fly my minipony!"),n.then(function(e){return U.i("Space is ok, can download:",w,e),v(y)}).then(function(n){return U.d("Ga for game and gamifive info stored!",n),U.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,O.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),U.d("unzip:",t.id,O.TEMP_DIR+y),e._promiseZip(n.path,O.TEMP_DIR+y,r("unzip"))}).then(function(n){U.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,w=d*Math.pow(1024,f?p.MB:p.KB),y=t.id;return s.then(function(e){return U.d("Exists",e),e?(k=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(k=!0,i())})},r.prototype.play=function(t){U.d("Play",t);var n=O.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return g(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){U.d("Removing game",t);var n=e.dirExists(O.CACHE_DIR+t+".zip"),r=e.dirExists(O.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(U.d("Removed in cache",n[0]),r.push(e.removeFile(O.CACHE_DIR+t+".zip"))),n[1]&&(U.d("Removed",n[1]),r.push(e.removeDir(O.GAMES_DIR+t))),0===r.length&&U.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return k},r.prototype.abortDownload=function(){return this.isDownloading()?(U.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,k=!1),!0):(U.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return U.d("Get games list"),e.readDir(O.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=O.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(U.d("Read meta.json:",n),U.d("GAMEOVER_TEMPLATE path",O.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(O.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return U.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(O.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(O.GAMES_DIR).then(function(t){return U.d("All games deleted!",t),e.createDir(O.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){U.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){U.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(K.hasOwnProperty("webappsfixes")&&"object"==typeof K.webappsfixes){t=!0;for(var e in K.webappsfixes)if(K.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){m("[webappsFixes] applying fix: "+e);var r=n[e](K.webappsfixes[e]);r&&w("[webappsFixes] fix '"+e+"' failed: "+r)}else w("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(_()&&!e.platforms.ios)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(b()&&!e.platforms.android)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(m("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),m("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return w("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!K.statusbar)return;e=K.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},X=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(_()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){m("[share] Share completed? "+e.completed),m("[share] Shared to app: "+e.app),n(e)},a=function(e){w("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){m("[share] Facebook share completed, result: ",e),t(e)},i=function(e){w("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){m("[share] Twitter share completed, result: ",e),t(e)},i=function(e){w("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){m("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){w("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){m("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){m("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(m("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(w("[share] type not valid"),n("type not valid"))):(w("[share] missing parameter url"),n("missing parameter url")):(w("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return I?E?new Promise(function(t,n){X.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return I?E?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(X.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){w(e),n(e)})}):(w("[share] missing parameter url"),Promise.reject("missing parameter url")):(w("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(w("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var Y=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){h().then(function(e){f&&f.type&&"online"===f.type?(m("[push] going to url: ",e),A(e)):w("[push] i'm offline not going to url")}).catch(function(e){w("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var p=function(){var e=window.cordova.file.applicationStorageDirectory;return _()&&(e+="Documents/"),e},h=function(){return s.file.fileExists(p()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(p()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},g=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(p(),"SGpushUrl").then(function(e){return m("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){w("[push] error sg create SGpushUrl file",e)})},b=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();m("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,p=1732584193,f=-271733879,h=-1732584194,g=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function p(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function f(e){return unescape(encodeURIComponent(e))}function h(e){return l(f(e))}function g(e){return p(h(e))}function m(e,t){return d(f(e),f(t))}function w(e,t){return p(m(e,t))}function v(e,t,n){return t?n?m(t,e):w(t,e):n?h(e):g(e)}return v}(),ne=function(e){if(void 0===window.SpinnerDialog)return w("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},re=function(){return void 0===window.SpinnerDialog?w("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=ne,window.stopLoading=re,a.inAppPurchaseSubscription=function(e,t,n,r){return I?E?(H(!0),void 0!==r&&(oe.returnUrl=r),void 0!==n&&(oe.subscribeMethod=n),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0, +oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(),window.store.order(oe.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.inAppRestore=function(e,t,n,r){return I?E?(void 0!==n&&(oe.subscribeMethod=n),void 0!==r&&(oe.returnUrl=r),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0,void oe.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},a.inAppProductInfo=function(e){if(e.productId||(e.productId=oe.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return w("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!I)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!E)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(oe.subscribeMethod=e.subscriptionUrl,oe.requestedListingProductId=e.productId,oe.callbackListingSuccess=e.callbackListingSuccess,oe.callbackPurchaseSuccess=e.callbackPurchaseSuccess,oe.callbackListingError=e.callbackError,oe.inappProductInfoCalled=!0,oe.productsInfo[e.productId])try{oe.callbackListingSuccess(oe.productsInfo[e.productId])}catch(e){w("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(!0),!0)};var ie=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(b()?n=e.productsIdAndroid:_()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,m("[IAPlight] getProducts ok",e),e}).catch(function(e){w("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(m("[IAPlight] subscribe ok",t),_())return e.getActiveSubscriptionsInfo().then(function(e){if(m("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(b()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return w("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw w("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){m("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),m(JSON.stringify(e)),m(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){m("IAP> Purchase approved."),m(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){m("subscription verified ",e)},onStoreReady:function(){m("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(m("[IAP] > Product Owned."),!e.transaction.id&&_())return w("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),_()&&window.localStorage.setItem("transaction_id",e.transaction.id),b()){var t=e.transaction.purchaseToken+"|"+O+"|"+oe.id;m("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||oe.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(m("[IAP] appStoreReceipt: "+t.appStoreReceipt),oe.createUser(e,t.appStoreReceipt)):m("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){H(!1),oe.callbackError({iap_cancelled:1,return_url:oe.returnUrl}),m("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){m("[IAP] ORDER APPROVED "+oe.id),e.finish()},error:function(e){H(!1),w("[IAP] error: "+e),oe.callbackError({iap_error:1,return_url:oe.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(m("[IAP] createUser start "),!oe.inappProductInfoCalled&&!oe.inappPurchaseCalled)return oe.lastCreateUserProduct=e,void(oe.lastCreateUserToken=t);if(!oe.subscribeMethod)return void w("[IAP] createUser configuration error: missing api url.");var n=oe.getRandomEmail(),r=1;b()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=oe.subscribeMethod,o={paymethod:oe.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:oe.returnUrl,inapp_pwd:oe.getPassword(t),hybrid:1};oe.lastCreateuserUrl=i,oe.lastCreateuserData=o;var a=function(e){if(oe.createUserAttempt<=oe.maxCreateUserAttempt)w("[IAP] createUser failed "+oe.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{w("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:oe.returnUrl};H(!1),oe.inappPurchaseCalled?oe.callbackError(t):oe.inappProductInfoCalled&&oe.callbackListingError(t)}},s=function(e){m("[IAP] createUser success ",e);try{e.device_id=y.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),H(!1),oe.callbackSuccess(e),oe.inappPurchaseCalled?oe.callbackSuccess(e):oe.inappProductInfoCalled&&oe.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){oe.createUserAttempt=oe.createUserAttempt+1,m("[IAP] createUser attempt: "+oe.createUserAttempt+" with timeout: "+c+"sec."),m("[IAP] POST createUser: "+oe.lastCreateuserUrl+" params: "+JSON.stringify(oe.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(oe.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(oe.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){m("[IAP] createUser end"),H(!1)}).go(),c+=5},10)};oe.createUserAttempt=0,u()}},ae=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return w("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return w("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});m("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){w("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return w("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});m("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){w("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(w("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(w("[globalization] getLocaleName: not initialized!"),!1)},e}();a.facebookLogin=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){m("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){w("Got FB login error:",e),n({error:e})})},a.facebookShare=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){w("Got FB share error:",e),n({error:e})})};var se=function(){deltadna.registerPushCallback(ue)},ce=function(e){w("[DeltaDNA] error: "+e)},ue=function(e){return b()&&e.payload&&e.payload.url&&!e.foreground?A(e.payload.url):_()&&e.url?A(e.url):void 0},le=function(){var e={},t={},n=function(n){m("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(w("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(w("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&m("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return w("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),de=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return w("[appsflyer] missing cordova plugin");if(void 0===K.appsflyer_devkey)return w("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:K.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(_()){if(void 0===K.appstore_appid)return w("[appsflyer] missing manifest configuration: appstore_appid");n.appId=K.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}ee.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();a.setConversionDataCallback=function(e){de.setCallback(e)};var pe=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return m("[analytics] callback not set!");try{e(t)}catch(e){w("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();a.setAnalyticsCallback=function(e){pe.setCallback(e)};var fe={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(fe.DefaultOptions=e),AdMob&&(fe.AdMobSupport=!0,fe.initAdMob(e,t,n)),MoPub&&(fe.MoPubSupport=!0),!0},isAdMobSupported:function(){return fe.AdMobSupport},isMoPubSupported:function(){return fe.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=fe.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=fe.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=fe.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?fe.AdSize.LEADERBOARD:t>=468&&e>=60?fe.AdSize.BANNER:t>=320&&e>=50?fe.AdSize.BANNER:void 0}};return a.game=s.game._public,a.file=s.file,a.AdManager=s.AdManager,a}); \ No newline at end of file diff --git a/package.json b/package.json index 23e2726..a8fad7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stargatejs-apps", - "version": "0.13.2", + "version": "0.13.3", "description": "StargateJS for HTML5 apps", "main": "dist/stargate.js", "scripts": { From f3dc1a7d7dcf66b4a229c854aaba59d9e264114e Mon Sep 17 00:00:00 2001 From: Mirco Cipriani Date: Wed, 12 Jul 2017 08:43:35 +0200 Subject: [PATCH 07/13] new get manifest method --- src/stargate.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/stargate.js b/src/stargate.js index d491d5a..983c5ad 100644 --- a/src/stargate.js +++ b/src/stargate.js @@ -144,10 +144,6 @@ function getManifestWithCordovaFilePlugin() { function getManifest() { - if (window.cordova.file) { - return getManifestWithCordovaFilePlugin(); - } - if (window.hostedwebapp) { return new Promise(function(resolve,reject){ window.hostedwebapp.getManifest( @@ -161,6 +157,10 @@ function getManifest() { ); }); } + + if (window.cordova.file) { + return getManifestWithCordovaFilePlugin(); + } err("getManifest() no available reading mechanism!"); return Promise.resolve({}); From 727297166bf770ea32614c686e944759aca4d0b4 Mon Sep 17 00:00:00 2001 From: Mirco Cipriani Date: Wed, 12 Jul 2017 08:45:01 +0200 Subject: [PATCH 08/13] 0.13.4 --- dist/bower/stargate.js | 10 +++++----- dist/bower/stargate.min.js | 6 +++--- dist/stargate.js | 10 +++++----- dist/stargate.min.js | 6 +++--- package.json | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/dist/bower/stargate.js b/dist/bower/stargate.js index ed55e37..b090385 100644 --- a/dist/bower/stargate.js +++ b/dist/bower/stargate.js @@ -18,7 +18,7 @@ } }(this, function () { // Public interface - var stargatePackageVersion = "0.13.3"; + var stargatePackageVersion = "0.13.4"; var stargatePublic = {}; var stargateModules = {}; @@ -2980,10 +2980,6 @@ function getManifestWithCordovaFilePlugin() { function getManifest() { - if (window.cordova.file) { - return getManifestWithCordovaFilePlugin(); - } - if (window.hostedwebapp) { return new Promise(function(resolve,reject){ window.hostedwebapp.getManifest( @@ -2997,6 +2993,10 @@ function getManifest() { ); }); } + + if (window.cordova.file) { + return getManifestWithCordovaFilePlugin(); + } err("getManifest() no available reading mechanism!"); return Promise.resolve({}); diff --git a/dist/bower/stargate.min.js b/dist/bower/stargate.min.js index dddd958..9822648 100644 --- a/dist/bower/stargate.min.js +++ b/dist/bower/stargate.min.js @@ -1,9 +1,9 @@ /*! * StargateJS Apps - * v0.13.3 + * v0.13.4 * Copyright 2015 DMobileLab. http://buongiorno.com/ * See LICENSE in this repository for license information */ -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.Stargate=t()}(this,function(){function e(e){p.type=e.type,p.networkState=navigator.connection.type,"function"==typeof f&&f(p)}function t(){document.addEventListener("offline",e,!1),document.addEventListener("online",e,!1)}function n(){p.networkState=navigator.connection.type,"none"===navigator.connection.type?p.type="offline":p.type="online"}function r(e){if("android"==window.device.platform.toLowerCase())window.navigator.app.loadUrl(e);else if("ios"==window.device.platform.toLowerCase()&&-1!==e.indexOf("file:///")){var t=e.split("?")[0];h("Without qs",t),window.resolveLocalFileSystemURL(t,function(e){var t=e.toInternalURL()+"?hybrid=1";h("Redirect to",t),window.location.href=t},m)}else window.location.href=e}function i(){var e=window.cordova.file.applicationDirectory+"www/manifest.json";return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)}).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})}).then(function(e){var t="";try{t=window.JSON.parse(e)}catch(e){return Promise.reject(e)}return Promise.resolve(t)}).catch(function(e){console.error("getManifestWithCordovaFilePlugin() error:"+e,e)})}function o(){return window.cordova.file?i():window.hostedwebapp?new Promise(function(e,t){window.hostedwebapp.getManifest(function(t){e(t)},function(e){m(e),t(new Error(e))})}):(m("getManifest() no available reading mechanism!"),Promise.resolve({}))}var a={},s={};!function(e){function t(e,n,r){this.level=t.levels[e.toUpperCase()],this.styles=r||{background:"white",color:"black"},this.tag="%c "+n+" ",this.isstaging="1"==="IS_STAGING = 1".slice(-1),this.styleString="background:"+this.styles.background+";color:"+this.styles.color+";";var i=function(){if(arguments.length<1)return"";for(var e=Array.prototype.slice.call(arguments[0]),t="",n=0;n0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(s),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(s,s.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(L=O(L,t)),j.d("Initialized called with:",L),!e)return Promise.reject("Missing file module!");try{S=window.cordova.file.applicationStorageDirectory,b=window.cordova.file.cacheDirectory,A=window.cordova.file.tempDirectory,P=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",_=window.cordova.file.dataDirectory}catch(e){return j.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(S+="Documents/"),"android"==window.device.platform.toLowerCase()&&(A=b),k.SDK_DIR=S+"scripts/",k.SDK_RELATIVE_DIR="../../scripts/",k.GAMEOVER_RELATIVE_DIR="../../gameover_template/",k.GAMES_DIR=S+"games/",k.BASE_DIR=S,k.CACHE_DIR=b,k.TEMP_DIR=A,k.CORDOVAJS=P+"cordova.js",k.CORDOVA_PLUGINS_JS=P+"cordova_plugins.js",k.STARGATEJS=P+"js/stargate.js",k.DATA_DIR=_,k.GAMEOVER_DIR=k.BASE_DIR+"gameover_template/",k.WWW_DIR=P,j.i("cordova JS dir to include",k.CORDOVAJS),n.game._public.BASE_DIR=k.BASE_DIR,n.game._public.OFFLINE_INDEX=k.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(k.BASE_DIR,"games"),a=e.createDir(k.BASE_DIR,"scripts"),u=e.fileExists(k.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(C))}),l=e.fileExists(k.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return j.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(k.BASE_DIR+"gameover_template"),e.dirExists(k.SDK_DIR+"plugins"),e.fileExists(k.SDK_DIR+"cordova.js"),e.fileExists(k.SDK_DIR+"cordova_plugins.js"),e.fileExists(k.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(k.WWW_DIR+"gameover_template",k.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(k.WWW_DIR+"plugins",k.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(k.CORDOVAJS,k.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(k.CORDOVA_PLUGINS_JS,k.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(k.WWW_DIR+"js/gamesFixes.js",k.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=E(L.sdk_url,{v:t.getTime()});return""===L.sdk_url||void 0===L.sdk_url||null===L.sdk_url?(j.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(k.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(j.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,k.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(k.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return j.d("Serialized dom",r),r}).then(function(t){return j.d("Write dom:",r,t),e.write(r,t)})}function w(e){return new RegExp(/.*\.html?$/i).test(e)}function h(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=k.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return j.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function m(){return j.i("readUserJson",k.BASE_DIR+"user.json"),e.readFileAsJSON(k.BASE_DIR+"user.json")}function v(e){return m().then(function(t){if(!t.ponyUrl)throw j.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];j.d("PONYVALUE",n);var r=E(L.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,j.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return j.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(k.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return j.d("writing offlineData.json",t),e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var S,b,A,P,_,I,D=t.Logger,E=t.composeApiString,R=t.jsonpRequest,O=t.extend,k={},L={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},T=!1,C={GaForGame:{},GamifiveInfo:{},queues:{}},N={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},j=new D("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,m);return j.d("Get GameInfo, fly my minipony!"),n.then(function(e){return j.i("Space is ok, can download:",m,e),v(y)}).then(function(n){return j.d("Ga for game and gamifive info stored!",n),j.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,k.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),j.d("unzip:",t.id,k.TEMP_DIR+y),e._promiseZip(n.path,k.TEMP_DIR+y,r("unzip"))}).then(function(n){j.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,m=d*Math.pow(1024,p?f.MB:f.KB),y=t.id;return s.then(function(e){return j.d("Exists",e),e?(T=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(T=!0,i())})},r.prototype.play=function(t){j.d("Play",t);var n=k.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return w(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){j.d("Removing game",t);var n=e.dirExists(k.CACHE_DIR+t+".zip"),r=e.dirExists(k.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(j.d("Removed in cache",n[0]),r.push(e.removeFile(k.CACHE_DIR+t+".zip"))),n[1]&&(j.d("Removed",n[1]),r.push(e.removeDir(k.GAMES_DIR+t))),0===r.length&&j.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return T},r.prototype.abortDownload=function(){return this.isDownloading()?(j.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,T=!1),!0):(j.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return j.d("Get games list"),e.readDir(k.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=k.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(j.d("Read meta.json:",n),j.d("GAMEOVER_TEMPLATE path",k.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(k.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return j.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(k.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(k.GAMES_DIR).then(function(t){return j.d("All games deleted!",t),e.createDir(k.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(L.bundle_games.length>0){j.d("Games bundle in configuration",L.bundle_games);var t,n=L.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){j.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(W.hasOwnProperty("webappsfixes")&&"object"==typeof W.webappsfixes){t=!0;for(var e in W.webappsfixes)if(W.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){h("[webappsFixes] applying fix: "+e);var r=n[e](W.webappsfixes[e]);r&&m("[webappsFixes] fix '"+e+"' failed: "+r)}else m("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(b()&&!e.platforms.ios)return void h("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(S()&&!e.platforms.android)return void h("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(h("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),h("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return m("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!W.statusbar)return;e=W.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},Q=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(b()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){h("[share] Share completed? "+e.completed),h("[share] Shared to app: "+e.app),n(e)},a=function(e){m("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){h("[share] Facebook share completed, result: ",e),t(e)},i=function(e){m("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){h("[share] Twitter share completed, result: ",e),t(e)},i=function(e){m("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){h("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){m("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){h("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){h("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(h("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(m("[share] type not valid"),n("type not valid"))):(m("[share] missing parameter url"),n("missing parameter url")):(m("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return I?D?new Promise(function(t,n){Q.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return I?D?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Q.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){m(e),n(e)})}):(m("[share] missing parameter url"),Promise.reject("missing parameter url")):(m("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(m("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var $=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){g().then(function(e){p&&p.type&&"online"===p.type?(h("[push] going to url: ",e),P(e)):m("[push] i'm offline not going to url")}).catch(function(e){m("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var f=function(){var e=window.cordova.file.applicationStorageDirectory;return b()&&(e+="Documents/"),e},g=function(){return s.file.fileExists(f()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(f()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},w=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(f(),"SGpushUrl").then(function(e){return h("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){m("[push] error sg create SGpushUrl file",e)})},S=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();h("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,f=1732584193,p=-271733879,g=-1732584194,w=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function f(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function p(e){return unescape(encodeURIComponent(e))}function g(e){return l(p(e))}function w(e){return f(g(e))}function h(e,t){return d(p(e),p(t))}function m(e,t){return f(h(e,t))}function v(e,t,n){return t?n?h(t,e):m(t,e):n?g(e):w(e)}return v}(),ne=function(e){if(void 0===window.SpinnerDialog)return m("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},re=function(){return void 0===window.SpinnerDialog?m("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=ne,window.stopLoading=re,a.inAppPurchaseSubscription=function(e,t,n,r){return I?D?(J(!0),void 0!==r&&(oe.returnUrl=r),void 0!==n&&(oe.subscribeMethod=n),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0,oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(),window.store.order(oe.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.inAppRestore=function(e,t,n,r){return I?D?(void 0!==n&&(oe.subscribeMethod=n),void 0!==r&&(oe.returnUrl=r),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0,void oe.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},a.inAppProductInfo=function(e){if(e.productId||(e.productId=oe.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return m("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!I)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!D)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(oe.subscribeMethod=e.subscriptionUrl,oe.requestedListingProductId=e.productId,oe.callbackListingSuccess=e.callbackListingSuccess,oe.callbackPurchaseSuccess=e.callbackPurchaseSuccess,oe.callbackListingError=e.callbackError,oe.inappProductInfoCalled=!0,oe.productsInfo[e.productId])try{oe.callbackListingSuccess(oe.productsInfo[e.productId])}catch(e){m("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(!0),!0)};var ie=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(S()?n=e.productsIdAndroid:b()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,h("[IAPlight] getProducts ok",e),e}).catch(function(e){m("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(h("[IAPlight] subscribe ok",t),b())return e.getActiveSubscriptionsInfo().then(function(e){if(h("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(S()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return m("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw m("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){h("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),h(JSON.stringify(e)),h(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){h("IAP> Purchase approved."),h(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){h("subscription verified ",e)},onStoreReady:function(){h("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(h("[IAP] > Product Owned."),!e.transaction.id&&b())return m("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),b()&&window.localStorage.setItem("transaction_id",e.transaction.id),S()){var t=e.transaction.purchaseToken+"|"+k+"|"+oe.id;h("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||oe.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(h("[IAP] appStoreReceipt: "+t.appStoreReceipt),oe.createUser(e,t.appStoreReceipt)):h("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){J(!1),oe.callbackError({iap_cancelled:1,return_url:oe.returnUrl}),h("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){h("[IAP] ORDER APPROVED "+oe.id),e.finish()},error:function(e){J(!1),m("[IAP] error: "+e),oe.callbackError({iap_error:1,return_url:oe.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(h("[IAP] createUser start "),!oe.inappProductInfoCalled&&!oe.inappPurchaseCalled)return oe.lastCreateUserProduct=e,void(oe.lastCreateUserToken=t);if(!oe.subscribeMethod)return void m("[IAP] createUser configuration error: missing api url.");var n=oe.getRandomEmail(),r=1;S()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=oe.subscribeMethod,o={paymethod:oe.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:oe.returnUrl,inapp_pwd:oe.getPassword(t),hybrid:1};oe.lastCreateuserUrl=i,oe.lastCreateuserData=o;var a=function(e){if(oe.createUserAttempt<=oe.maxCreateUserAttempt)m("[IAP] createUser failed "+oe.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{m("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:oe.returnUrl};J(!1),oe.inappPurchaseCalled?oe.callbackError(t):oe.inappProductInfoCalled&&oe.callbackListingError(t)}},s=function(e){h("[IAP] createUser success ",e);try{e.device_id=y.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),J(!1),oe.callbackSuccess(e),oe.inappPurchaseCalled?oe.callbackSuccess(e):oe.inappProductInfoCalled&&oe.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ +!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.Stargate=t()}(this,function(){function e(e){p.type=e.type,p.networkState=navigator.connection.type,"function"==typeof f&&f(p)}function t(){document.addEventListener("offline",e,!1),document.addEventListener("online",e,!1)}function n(){p.networkState=navigator.connection.type,"none"===navigator.connection.type?p.type="offline":p.type="online"}function r(e){if("android"==window.device.platform.toLowerCase())window.navigator.app.loadUrl(e);else if("ios"==window.device.platform.toLowerCase()&&-1!==e.indexOf("file:///")){var t=e.split("?")[0];h("Without qs",t),window.resolveLocalFileSystemURL(t,function(e){var t=e.toInternalURL()+"?hybrid=1";h("Redirect to",t),window.location.href=t},m)}else window.location.href=e}function i(){var e=window.cordova.file.applicationDirectory+"www/manifest.json";return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)}).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})}).then(function(e){var t="";try{t=window.JSON.parse(e)}catch(e){return Promise.reject(e)}return Promise.resolve(t)}).catch(function(e){console.error("getManifestWithCordovaFilePlugin() error:"+e,e)})}function o(){return window.hostedwebapp?new Promise(function(e,t){window.hostedwebapp.getManifest(function(t){e(t)},function(e){m(e),t(new Error(e))})}):window.cordova.file?i():(m("getManifest() no available reading mechanism!"),Promise.resolve({}))}var a={},s={};!function(e){function t(e,n,r){this.level=t.levels[e.toUpperCase()],this.styles=r||{background:"white",color:"black"},this.tag="%c "+n+" ",this.isstaging="1"==="IS_STAGING = 1".slice(-1),this.styleString="background:"+this.styles.background+";color:"+this.styles.color+";";var i=function(){if(arguments.length<1)return"";for(var e=Array.prototype.slice.call(arguments[0]),t="",n=0;n0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(s),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(s,s.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(L=O(L,t)),j.d("Initialized called with:",L),!e)return Promise.reject("Missing file module!");try{S=window.cordova.file.applicationStorageDirectory,b=window.cordova.file.cacheDirectory,A=window.cordova.file.tempDirectory,P=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",_=window.cordova.file.dataDirectory}catch(e){return j.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(S+="Documents/"),"android"==window.device.platform.toLowerCase()&&(A=b),k.SDK_DIR=S+"scripts/",k.SDK_RELATIVE_DIR="../../scripts/",k.GAMEOVER_RELATIVE_DIR="../../gameover_template/",k.GAMES_DIR=S+"games/",k.BASE_DIR=S,k.CACHE_DIR=b,k.TEMP_DIR=A,k.CORDOVAJS=P+"cordova.js",k.CORDOVA_PLUGINS_JS=P+"cordova_plugins.js",k.STARGATEJS=P+"js/stargate.js",k.DATA_DIR=_,k.GAMEOVER_DIR=k.BASE_DIR+"gameover_template/",k.WWW_DIR=P,j.i("cordova JS dir to include",k.CORDOVAJS),n.game._public.BASE_DIR=k.BASE_DIR,n.game._public.OFFLINE_INDEX=k.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(k.BASE_DIR,"games"),a=e.createDir(k.BASE_DIR,"scripts"),u=e.fileExists(k.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(C))}),l=e.fileExists(k.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return j.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(k.BASE_DIR+"gameover_template"),e.dirExists(k.SDK_DIR+"plugins"),e.fileExists(k.SDK_DIR+"cordova.js"),e.fileExists(k.SDK_DIR+"cordova_plugins.js"),e.fileExists(k.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(k.WWW_DIR+"gameover_template",k.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(k.WWW_DIR+"plugins",k.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(k.CORDOVAJS,k.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(k.CORDOVA_PLUGINS_JS,k.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(k.WWW_DIR+"js/gamesFixes.js",k.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=E(L.sdk_url,{v:t.getTime()});return""===L.sdk_url||void 0===L.sdk_url||null===L.sdk_url?(j.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(k.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(j.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,k.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(k.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return j.d("Serialized dom",r),r}).then(function(t){return j.d("Write dom:",r,t),e.write(r,t)})}function w(e){return new RegExp(/.*\.html?$/i).test(e)}function h(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=k.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return j.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function m(){return j.i("readUserJson",k.BASE_DIR+"user.json"),e.readFileAsJSON(k.BASE_DIR+"user.json")}function v(e){return m().then(function(t){if(!t.ponyUrl)throw j.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];j.d("PONYVALUE",n);var r=E(L.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,j.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return j.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(k.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return j.d("writing offlineData.json",t),e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var S,b,A,P,_,I,D=t.Logger,E=t.composeApiString,R=t.jsonpRequest,O=t.extend,k={},L={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},T=!1,C={GaForGame:{},GamifiveInfo:{},queues:{}},N={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},j=new D("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,m);return j.d("Get GameInfo, fly my minipony!"),n.then(function(e){return j.i("Space is ok, can download:",m,e),v(y)}).then(function(n){return j.d("Ga for game and gamifive info stored!",n),j.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,k.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),j.d("unzip:",t.id,k.TEMP_DIR+y),e._promiseZip(n.path,k.TEMP_DIR+y,r("unzip"))}).then(function(n){j.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,m=d*Math.pow(1024,p?f.MB:f.KB),y=t.id;return s.then(function(e){return j.d("Exists",e),e?(T=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(T=!0,i())})},r.prototype.play=function(t){j.d("Play",t);var n=k.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return w(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){j.d("Removing game",t);var n=e.dirExists(k.CACHE_DIR+t+".zip"),r=e.dirExists(k.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(j.d("Removed in cache",n[0]),r.push(e.removeFile(k.CACHE_DIR+t+".zip"))),n[1]&&(j.d("Removed",n[1]),r.push(e.removeDir(k.GAMES_DIR+t))),0===r.length&&j.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return T},r.prototype.abortDownload=function(){return this.isDownloading()?(j.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,T=!1),!0):(j.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return j.d("Get games list"),e.readDir(k.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=k.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(j.d("Read meta.json:",n),j.d("GAMEOVER_TEMPLATE path",k.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(k.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return j.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(k.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(k.GAMES_DIR).then(function(t){return j.d("All games deleted!",t),e.createDir(k.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(L.bundle_games.length>0){j.d("Games bundle in configuration",L.bundle_games);var t,n=L.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){j.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(W.hasOwnProperty("webappsfixes")&&"object"==typeof W.webappsfixes){t=!0;for(var e in W.webappsfixes)if(W.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){h("[webappsFixes] applying fix: "+e);var r=n[e](W.webappsfixes[e]);r&&m("[webappsFixes] fix '"+e+"' failed: "+r)}else m("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(b()&&!e.platforms.ios)return void h("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(S()&&!e.platforms.android)return void h("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(h("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),h("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return m("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!W.statusbar)return;e=W.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},Q=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(b()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){h("[share] Share completed? "+e.completed),h("[share] Shared to app: "+e.app),n(e)},a=function(e){m("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){h("[share] Facebook share completed, result: ",e),t(e)},i=function(e){m("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){h("[share] Twitter share completed, result: ",e),t(e)},i=function(e){m("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){h("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){m("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){h("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){h("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(h("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(m("[share] type not valid"),n("type not valid"))):(m("[share] missing parameter url"),n("missing parameter url")):(m("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return I?D?new Promise(function(t,n){Q.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return I?D?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Q.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){m(e),n(e)})}):(m("[share] missing parameter url"),Promise.reject("missing parameter url")):(m("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(m("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var $=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){g().then(function(e){p&&p.type&&"online"===p.type?(h("[push] going to url: ",e),P(e)):m("[push] i'm offline not going to url")}).catch(function(e){m("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var f=function(){var e=window.cordova.file.applicationStorageDirectory;return b()&&(e+="Documents/"),e},g=function(){return s.file.fileExists(f()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(f()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},w=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(f(),"SGpushUrl").then(function(e){return h("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){m("[push] error sg create SGpushUrl file",e)})},S=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();h("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,f=1732584193,p=-271733879,g=-1732584194,w=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function f(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function p(e){return unescape(encodeURIComponent(e))}function g(e){return l(p(e))}function w(e){return f(g(e))}function h(e,t){return d(p(e),p(t))}function m(e,t){return f(h(e,t))}function v(e,t,n){return t?n?h(t,e):m(t,e):n?g(e):w(e)}return v}(),ne=function(e){if(void 0===window.SpinnerDialog)return m("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},re=function(){return void 0===window.SpinnerDialog?m("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=ne,window.stopLoading=re,a.inAppPurchaseSubscription=function(e,t,n,r){return I?D?(J(!0),void 0!==r&&(oe.returnUrl=r),void 0!==n&&(oe.subscribeMethod=n),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0,oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(),window.store.order(oe.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.inAppRestore=function(e,t,n,r){return I?D?(void 0!==n&&(oe.subscribeMethod=n),void 0!==r&&(oe.returnUrl=r),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0,void oe.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},a.inAppProductInfo=function(e){if(e.productId||(e.productId=oe.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return m("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!I)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!D)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(oe.subscribeMethod=e.subscriptionUrl,oe.requestedListingProductId=e.productId,oe.callbackListingSuccess=e.callbackListingSuccess,oe.callbackPurchaseSuccess=e.callbackPurchaseSuccess,oe.callbackListingError=e.callbackError,oe.inappProductInfoCalled=!0,oe.productsInfo[e.productId])try{oe.callbackListingSuccess(oe.productsInfo[e.productId])}catch(e){m("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(!0),!0)};var ie=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(S()?n=e.productsIdAndroid:b()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,h("[IAPlight] getProducts ok",e),e}).catch(function(e){m("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(h("[IAPlight] subscribe ok",t),b())return e.getActiveSubscriptionsInfo().then(function(e){if(h("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(S()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return m("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw m("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){h("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),h(JSON.stringify(e)),h(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){h("IAP> Purchase approved."),h(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){h("subscription verified ",e)},onStoreReady:function(){h("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(h("[IAP] > Product Owned."),!e.transaction.id&&b())return m("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),b()&&window.localStorage.setItem("transaction_id",e.transaction.id),S()){var t=e.transaction.purchaseToken+"|"+k+"|"+oe.id;h("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||oe.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(h("[IAP] appStoreReceipt: "+t.appStoreReceipt),oe.createUser(e,t.appStoreReceipt)):h("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){J(!1),oe.callbackError({iap_cancelled:1,return_url:oe.returnUrl}),h("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){h("[IAP] ORDER APPROVED "+oe.id),e.finish()},error:function(e){J(!1),m("[IAP] error: "+e),oe.callbackError({iap_error:1,return_url:oe.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(h("[IAP] createUser start "),!oe.inappProductInfoCalled&&!oe.inappPurchaseCalled)return oe.lastCreateUserProduct=e,void(oe.lastCreateUserToken=t);if(!oe.subscribeMethod)return void m("[IAP] createUser configuration error: missing api url.");var n=oe.getRandomEmail(),r=1;S()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=oe.subscribeMethod,o={paymethod:oe.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:oe.returnUrl,inapp_pwd:oe.getPassword(t),hybrid:1};oe.lastCreateuserUrl=i,oe.lastCreateuserData=o;var a=function(e){if(oe.createUserAttempt<=oe.maxCreateUserAttempt)m("[IAP] createUser failed "+oe.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{m("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:oe.returnUrl};J(!1),oe.inappPurchaseCalled?oe.callbackError(t):oe.inappProductInfoCalled&&oe.callbackListingError(t)}},s=function(e){h("[IAP] createUser success ",e);try{e.device_id=y.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),J(!1),oe.callbackSuccess(e),oe.inappPurchaseCalled?oe.callbackSuccess(e):oe.inappProductInfoCalled&&oe.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ oe.createUserAttempt=oe.createUserAttempt+1,h("[IAP] createUser attempt: "+oe.createUserAttempt+" with timeout: "+c+"sec."),h("[IAP] POST createUser: "+oe.lastCreateuserUrl+" params: "+JSON.stringify(oe.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(oe.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(oe.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){h("[IAP] createUser end"),J(!1)}).go(),c+=5},10)};oe.createUserAttempt=0,u()}},ae=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return m("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return m("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});h("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){m("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return m("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});h("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){m("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(m("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(m("[globalization] getLocaleName: not initialized!"),!1)},e}();a.facebookLogin=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){h("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){m("Got FB login error:",e),n({error:e})})},a.facebookShare=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){m("Got FB share error:",e),n({error:e})})};var se=function(){deltadna.registerPushCallback(ue)},ce=function(e){m("[DeltaDNA] error: "+e)},ue=function(e){return S()&&e.payload&&e.payload.url&&!e.foreground?P(e.payload.url):b()&&e.url?P(e.url):void 0},le=function(){var e={},t={},n=function(n){h("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(m("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(m("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&h("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return m("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),de=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return m("[appsflyer] missing cordova plugin");if(void 0===W.appsflyer_devkey)return m("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:W.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(b()){if(void 0===W.appstore_appid)return m("[appsflyer] missing manifest configuration: appstore_appid");n.appId=W.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}ee.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();a.setConversionDataCallback=function(e){de.setCallback(e)};var fe=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return h("[analytics] callback not set!");try{e(t)}catch(e){m("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();a.setAnalyticsCallback=function(e){fe.setCallback(e)};var pe={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(pe.DefaultOptions=e),AdMob&&(pe.AdMobSupport=!0,pe.initAdMob(e,t,n)),MoPub&&(pe.MoPubSupport=!0),!0},isAdMobSupported:function(){return pe.AdMobSupport},isMoPubSupported:function(){return pe.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=pe.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=pe.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=pe.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?pe.AdSize.LEADERBOARD:t>=468&&e>=60?pe.AdSize.BANNER:t>=320&&e>=50?pe.AdSize.BANNER:void 0}};return a.game=s.game._public,a.file=s.file,a.AdManager=s.AdManager,a}); \ No newline at end of file diff --git a/dist/stargate.js b/dist/stargate.js index b1ad7a4..7dd9414 100644 --- a/dist/stargate.js +++ b/dist/stargate.js @@ -3935,7 +3935,7 @@ } }(this, function () { // Public interface - var stargatePackageVersion = "0.13.3"; + var stargatePackageVersion = "0.13.4"; var stargatePublic = {}; var stargateModules = {}; @@ -6897,10 +6897,6 @@ function getManifestWithCordovaFilePlugin() { function getManifest() { - if (window.cordova.file) { - return getManifestWithCordovaFilePlugin(); - } - if (window.hostedwebapp) { return new Promise(function(resolve,reject){ window.hostedwebapp.getManifest( @@ -6914,6 +6910,10 @@ function getManifest() { ); }); } + + if (window.cordova.file) { + return getManifestWithCordovaFilePlugin(); + } err("getManifest() no available reading mechanism!"); return Promise.resolve({}); diff --git a/dist/stargate.min.js b/dist/stargate.min.js index 323f6ae..0fb0f71 100644 --- a/dist/stargate.min.js +++ b/dist/stargate.min.js @@ -1,10 +1,10 @@ /*! * StargateJS Apps - * v0.13.3 + * v0.13.4 * Copyright 2015 DMobileLab. http://buongiorno.com/ * See LICENSE in this repository for license information */ !function(e,t){"use strict";"object"==typeof exports?module.exports=t(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"==typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],t):e.URI=t(e.punycode,e.IPv6,e.SecondLevelDomains,e)}(this,function(e,t,n,r){"use strict";function i(e,t){var n=arguments.length>=1,r=arguments.length>=2;if(!(this instanceof i))return n?r?new i(e,t):new i(e):new i;if(void 0===e){if(n)throw new TypeError("undefined is not a valid argument for URI");e="undefined"!=typeof location?location.href+"":""}return this.href(e),void 0!==t?this.absoluteTo(t):this}function o(e){return e.replace(/([.*+?^=!:()|[\]\/\\])/g,"\\$1")}function a(e){return void 0===e?"Undefined":String(Object.prototype.toString.call(e)).slice(8,-1)}function s(e){return"Array"===a(e)}function c(e,t){var n,r,i={};if("RegExp"===a(t))i=null;else if(s(t))for(n=0,r=t.length;n]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,i.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?«»“”„‘’]+$/},i.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},i.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/,i.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"},i.getDomAttribute=function(e){if(e&&e.nodeName){var t=e.nodeName.toLowerCase();if("input"!==t||"image"===e.type)return i.domAttributes[t]}},i.encode=f,i.decode=decodeURIComponent,i.iso8859=function(){i.encode=escape,i.decode=unescape},i.unicode=function(){i.encode=f,i.decode=decodeURIComponent},i.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/gi,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}},i.encodeQuery=function(e,t){var n=i.encode(e+"");return void 0===t&&(t=i.escapeQuerySpace),t?n.replace(/%20/g,"+"):n},i.decodeQuery=function(e,t){e+="",void 0===t&&(t=i.escapeQuerySpace);try{return i.decode(t?e.replace(/\+/g,"%20"):e)}catch(t){return e}};var y,b={encode:"encode",decode:"decode"},_=function(e,t){return function(n){try{return i[t](n+"").replace(i.characters[e][t].expression,function(n){return i.characters[e][t].map[n]})}catch(e){return n}}};for(y in b)i[y+"PathSegment"]=_("pathname",b[y]),i[y+"UrnPathSegment"]=_("urnpath",b[y]);var S=function(e,t,n){return function(r){var o;o=n?function(e){return i[t](i[n](e))}:i[t];for(var a=(r+"").split(e),s=0,c=a.length;s-1&&(t.fragment=e.substring(n+1)||null,e=e.substring(0,n)),n=e.indexOf("?"),n>-1&&(t.query=e.substring(n+1)||null,e=e.substring(0,n)),"//"===e.substring(0,2)?(t.protocol=null,e=e.substring(2),e=i.parseAuthority(e,t)):(n=e.indexOf(":"))>-1&&(t.protocol=e.substring(0,n)||null,t.protocol&&!t.protocol.match(i.protocol_expression)?t.protocol=void 0:"//"===e.substring(n+1,n+3)?(e=e.substring(n+3),e=i.parseAuthority(e,t)):(e=e.substring(n+1),t.urn=!0)),t.path=e,t},i.parseHost=function(e,t){e=e.replace(/\\/g,"/");var n,r,i=e.indexOf("/");if(-1===i&&(i=e.length),"["===e.charAt(0))n=e.indexOf("]"),t.hostname=e.substring(1,n)||null,t.port=e.substring(n+2,i)||null,"/"===t.port&&(t.port=null);else{var o=e.indexOf(":"),a=e.indexOf("/"),s=e.indexOf(":",o+1);-1!==s&&(-1===a||s-1?r:e.length-1);return o>-1&&(-1===r||o3?Object.keys(n).forEach(function(e){var n=e.match(/^([0-9])([0-9x])([0-9x])$/i);!(n&&n.length>3&&o[1]===n[1])||"x"!==n[2]&&o[2]!==n[2]||"x"!==n[3]&&o[3]!==n[3]||i(e,t)}):n[e]&&i(e,t)}return this},go:function(){var e=t.type||(t.into?"html":"json"),n=u();if("function"==typeof a[e])return a[e].call(this,n)}},a={json:function(e){var t=this;a._xhr.call(this,e,function(e){if(e)try{e=JSON.parse(e)}catch(e){return t.trigger("error",e),null}return e})},html:function(e){a._xhr.call(this,e,function(e){return t.into&&t.into.length&&[].forEach.call(t.into,function(t){t.innerHTML=e}),e})},_xhr:function(e,n){var r,i,o,a,s,u=this,l=t.method||"get",d=!0!==t.sync,p=new XMLHttpRequest,f=t.data,h=t.body,g=(t.headers,this.header("Content-Type")),m=t.timeout;if(!g&&f&&c()&&(this.header("Content-Type","application/x-www-form-urlencoded;charset=utf-8"),g=this.header("Content-Type")),f&&c())if("string"!=typeof h&&(h=""),g.indexOf("json")>-1)try{h=JSON.stringify(f)}catch(e){throw new TypeError("Unable to stringify body's content : "+e.name)}else{a=g&&g.indexOf("x-www-form-urlencoded")>1;for(r in f)h+=a?encodeURIComponent(r)+"="+encodeURIComponent(f[r])+"&":r+"="+f[r]+"\n\r"}s=[l,e,d],t.auth&&(s.push(t.auth.user),s.push(t.auth.passwd)),p.open.apply(p,s);for(i in t.headers)p.setRequestHeader(i,t.headers[i]);p.onprogress=function(e){e.lengthComputable&&u.trigger("progress",e.loaded/e.total)},p.onload=function(){var e=p.responseText;o&&clearTimeout(o),this.status>=200&&this.status<300&&("function"==typeof n&&(e=n(e)),u.trigger("success",e)),u.trigger(this.status,e),u.trigger("end",e)},p.onerror=function(e){o&&clearTimeout(o),u.trigger("error",e,arguments)},m&&(o=setTimeout(function(){u.trigger("timeout",{type:"timeout",expiredAfter:m},p,arguments),p.abort()},m)),p.send(h)},jsonp:function(n){var r,o=this,a=document.querySelector("head"),s=!0!==t.sync,c=t.jsonPaddingName||"callback",u=t.jsonPadding||"_padd"+(new Date).getTime()+Math.floor(1e4*Math.random()),l={};if(e[u])throw new Error("Padding "+u+" already exists. It must be unique.");/^ajajsonp_/.test(u)||(u="ajajsonp_"+u),window[u]=function(e){o.trigger("success",e),a.removeChild(r),window[u]=void 0},l[c]=u,n=i(n,l),r=document.createElement("script"),r.async=s,r.src=n,r.onerror=function(){o.trigger("error",arguments),a.removeChild(r),window[u]=void 0},a.appendChild(r)},script:function(e){var n,r=this,i=document.querySelector("head")||document.querySelector("body"),o=!0!==t.sync;if(!i)throw new Error("Ok, wait a second, you want to load a script, but you don't have at least a head or body tag...");n=document.createElement("script"),n.async=o,n.src=e,n.onerror=function(){r.trigger("error",arguments),i.removeChild(n)},n.onload=function(){r.trigger("success",arguments)},i.appendChild(n)}},s=function(e,n,i,o){if(void 0!==n){if("function"==typeof i)try{n=i.call(r,n)}catch(t){throw new TypeError("Failed to set "+e+" : "+t.message)}return t[e]="function"==typeof o?o.call(this,n):n,this}return"undefined"===t[e]?null:t[e]},c=function(){return["delete","patch","post","put"].indexOf(t.method)>-1},u=function(){var e=t.url,n=void 0===t.cache||!!t.cache,r=t.queryString||"",o=t.data;return!1===n&&(r+="&ajabuster="+(new Date).getTime()),e=i(e,r),o&&!c()&&(e=i(e,o)),e};return o},r={bool:function(e){return!!e},string:function(e){if("string"!=typeof e)throw new TypeError("a string is expected, but "+e+" ["+typeof e+"] given");return e},positiveInteger:function(e){if(parseInt(e)!==e||e<=0)throw new TypeError("an integer is expected, but "+e+" ["+typeof e+"] given");return e},plainObject:function(e){if("object"!=typeof e||e.constructor!==Object)throw new TypeError("an object is expected, but "+e+" ["+typeof e+"] given");return e},type:function(t){if(t=this.string(t),e.indexOf(t.toLowerCase())<0)throw new TypeError("a type in ["+e.join(", ")+"] is expected, but "+t+" given");return t.toLowerCase()},method:function(e){if(e=this.string(e),t.indexOf(e.toLowerCase())<0)throw new TypeError("a method in ["+t.join(", ")+"] is expected, but "+e+" given");return e.toLowerCase()},queryString:function(e){var t={};return"string"==typeof e?e.replace("?","").split("&").forEach(function(e){var n=e.split("=");2===n.length&&(t[decodeURIComponent(n[0])]=decodeURIComponent(n[1]))}):t=e,this.plainObject(t)},selector:function(e){if("string"!=typeof e&&!(e instanceof HTMLElement))throw new TypeError("a selector or an HTMLElement is expected, "+e+" ["+typeof e+"] given");return e},func:function(e){if(e=this.string(e),!/^([a-zA-Z_])([a-zA-Z0-9_\-])+$/.test(e))throw new TypeError("a valid function name is expected, "+e+" ["+typeof e+"] given");return e}},i=function(e,t){var n;if(e=e||"",t)if(-1===e.indexOf("?")&&(e+="?"),"string"==typeof t)e+=t;else if("object"==typeof t)for(n in t)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(t[n]);return e};"function"==typeof define&&define.amd?define([],function(){return n}):"object"==typeof exports?module.exports=n:window.aja=window.aja||n}(),function(e){function t(e,t){return function(){e.apply(t,arguments)}}function n(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],c(e,t(i,this),t(o,this))}function r(e){var t=this;if(null===this._state)return void this._deferreds.push(e);l(function(){var n=t._state?e.onFulfilled:e.onRejected;if(null===n)return void(t._state?e.resolve:e.reject)(t._value);var r;try{r=n(t._value)}catch(t){return void e.reject(t)}e.resolve(r)})}function i(e){try{if(e===this)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void c(t(n,e),t(i,this),t(o,this))}this._state=!0,this._value=e,a.call(this)}catch(e){o.call(this,e)}}function o(e){this._state=!1,this._value=e,a.call(this)}function a(){for(var e=0,t=this._deferreds.length;e0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(s),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(s,s.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(T=x(T,t)),U.d("Initialized called with:",T),!e)return Promise.reject("Missing file module!");try{b=window.cordova.file.applicationStorageDirectory,_=window.cordova.file.cacheDirectory,S=window.cordova.file.tempDirectory,A=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",P=window.cordova.file.dataDirectory}catch(e){return U.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(b+="Documents/"),"android"==window.device.platform.toLowerCase()&&(S=_),O.SDK_DIR=b+"scripts/",O.SDK_RELATIVE_DIR="../../scripts/",O.GAMEOVER_RELATIVE_DIR="../../gameover_template/",O.GAMES_DIR=b+"games/",O.BASE_DIR=b,O.CACHE_DIR=_,O.TEMP_DIR=S,O.CORDOVAJS=A+"cordova.js",O.CORDOVA_PLUGINS_JS=A+"cordova_plugins.js",O.STARGATEJS=A+"js/stargate.js",O.DATA_DIR=P,O.GAMEOVER_DIR=O.BASE_DIR+"gameover_template/",O.WWW_DIR=A,U.i("cordova JS dir to include",O.CORDOVAJS),n.game._public.BASE_DIR=O.BASE_DIR,n.game._public.OFFLINE_INDEX=O.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(O.BASE_DIR,"games"),a=e.createDir(O.BASE_DIR,"scripts"),u=e.fileExists(O.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(j))}),l=e.fileExists(O.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return U.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(O.BASE_DIR+"gameover_template"),e.dirExists(O.SDK_DIR+"plugins"),e.fileExists(O.SDK_DIR+"cordova.js"),e.fileExists(O.SDK_DIR+"cordova_plugins.js"),e.fileExists(O.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(O.WWW_DIR+"gameover_template",O.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(O.WWW_DIR+"plugins",O.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(O.CORDOVAJS,O.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(O.CORDOVA_PLUGINS_JS,O.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(O.WWW_DIR+"js/gamesFixes.js",O.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=D(T.sdk_url,{v:t.getTime()});return""===T.sdk_url||void 0===T.sdk_url||null===T.sdk_url?(U.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(O.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(U.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,O.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(O.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return U.d("Serialized dom",r),r}).then(function(t){return U.d("Write dom:",r,t),e.write(r,t)})}function g(e){return new RegExp(/.*\.html?$/i).test(e)}function m(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=O.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return U.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function w(){return U.i("readUserJson",O.BASE_DIR+"user.json"),e.readFileAsJSON(O.BASE_DIR+"user.json")}function v(e){return w().then(function(t){if(!t.ponyUrl)throw U.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];U.d("PONYVALUE",n);var r=D(T.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,U.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return U.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(O.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return U.d("writing offlineData.json",t),e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var b,_,S,A,P,I,E=t.Logger,D=t.composeApiString,R=t.jsonpRequest,x=t.extend,O={},T={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},k=!1,j={GaForGame:{},GamifiveInfo:{},queues:{}},C={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},U=new E("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"}) -;var n=e.requestFileSystem(1,w);return U.d("Get GameInfo, fly my minipony!"),n.then(function(e){return U.i("Space is ok, can download:",w,e),v(y)}).then(function(n){return U.d("Ga for game and gamifive info stored!",n),U.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,O.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),U.d("unzip:",t.id,O.TEMP_DIR+y),e._promiseZip(n.path,O.TEMP_DIR+y,r("unzip"))}).then(function(n){U.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,w=d*Math.pow(1024,f?p.MB:p.KB),y=t.id;return s.then(function(e){return U.d("Exists",e),e?(k=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(k=!0,i())})},r.prototype.play=function(t){U.d("Play",t);var n=O.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return g(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){U.d("Removing game",t);var n=e.dirExists(O.CACHE_DIR+t+".zip"),r=e.dirExists(O.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(U.d("Removed in cache",n[0]),r.push(e.removeFile(O.CACHE_DIR+t+".zip"))),n[1]&&(U.d("Removed",n[1]),r.push(e.removeDir(O.GAMES_DIR+t))),0===r.length&&U.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return k},r.prototype.abortDownload=function(){return this.isDownloading()?(U.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,k=!1),!0):(U.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return U.d("Get games list"),e.readDir(O.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=O.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(U.d("Read meta.json:",n),U.d("GAMEOVER_TEMPLATE path",O.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(O.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return U.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(O.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(O.GAMES_DIR).then(function(t){return U.d("All games deleted!",t),e.createDir(O.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){U.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){U.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(K.hasOwnProperty("webappsfixes")&&"object"==typeof K.webappsfixes){t=!0;for(var e in K.webappsfixes)if(K.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){m("[webappsFixes] applying fix: "+e);var r=n[e](K.webappsfixes[e]);r&&w("[webappsFixes] fix '"+e+"' failed: "+r)}else w("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(_()&&!e.platforms.ios)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(b()&&!e.platforms.android)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(m("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),m("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return w("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!K.statusbar)return;e=K.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},X=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(_()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){m("[share] Share completed? "+e.completed),m("[share] Shared to app: "+e.app),n(e)},a=function(e){w("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){m("[share] Facebook share completed, result: ",e),t(e)},i=function(e){w("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){m("[share] Twitter share completed, result: ",e),t(e)},i=function(e){w("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){m("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){w("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){m("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){m("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(m("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(w("[share] type not valid"),n("type not valid"))):(w("[share] missing parameter url"),n("missing parameter url")):(w("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return I?E?new Promise(function(t,n){X.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return I?E?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(X.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){w(e),n(e)})}):(w("[share] missing parameter url"),Promise.reject("missing parameter url")):(w("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(w("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var Y=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){h().then(function(e){f&&f.type&&"online"===f.type?(m("[push] going to url: ",e),A(e)):w("[push] i'm offline not going to url")}).catch(function(e){w("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var p=function(){var e=window.cordova.file.applicationStorageDirectory;return _()&&(e+="Documents/"),e},h=function(){return s.file.fileExists(p()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(p()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},g=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(p(),"SGpushUrl").then(function(e){return m("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){w("[push] error sg create SGpushUrl file",e)})},b=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();m("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,p=1732584193,f=-271733879,h=-1732584194,g=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function p(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function f(e){return unescape(encodeURIComponent(e))}function h(e){return l(f(e))}function g(e){return p(h(e))}function m(e,t){return d(f(e),f(t))}function w(e,t){return p(m(e,t))}function v(e,t,n){return t?n?m(t,e):w(t,e):n?h(e):g(e)}return v}(),ne=function(e){if(void 0===window.SpinnerDialog)return w("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},re=function(){return void 0===window.SpinnerDialog?w("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=ne,window.stopLoading=re,a.inAppPurchaseSubscription=function(e,t,n,r){return I?E?(H(!0),void 0!==r&&(oe.returnUrl=r),void 0!==n&&(oe.subscribeMethod=n),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0, +void 0===(r="[object Function]"===String(Object.prototype.toString.call(i))?i(e):"[object Function]"===String(Object.prototype.toString.call(i[e]))?i[e](e):i[e])||null===r)return a;if("[object Array]"===String(Object.prototype.toString.call(r))){for(t=0,n=r.length;t3?Object.keys(n).forEach(function(e){var n=e.match(/^([0-9])([0-9x])([0-9x])$/i);!(n&&n.length>3&&o[1]===n[1])||"x"!==n[2]&&o[2]!==n[2]||"x"!==n[3]&&o[3]!==n[3]||i(e,t)}):n[e]&&i(e,t)}return this},go:function(){var e=t.type||(t.into?"html":"json"),n=u();if("function"==typeof a[e])return a[e].call(this,n)}},a={json:function(e){var t=this;a._xhr.call(this,e,function(e){if(e)try{e=JSON.parse(e)}catch(e){return t.trigger("error",e),null}return e})},html:function(e){a._xhr.call(this,e,function(e){return t.into&&t.into.length&&[].forEach.call(t.into,function(t){t.innerHTML=e}),e})},_xhr:function(e,n){var r,i,o,a,s,u=this,l=t.method||"get",d=!0!==t.sync,p=new XMLHttpRequest,f=t.data,h=t.body,g=(t.headers,this.header("Content-Type")),m=t.timeout;if(!g&&f&&c()&&(this.header("Content-Type","application/x-www-form-urlencoded;charset=utf-8"),g=this.header("Content-Type")),f&&c())if("string"!=typeof h&&(h=""),g.indexOf("json")>-1)try{h=JSON.stringify(f)}catch(e){throw new TypeError("Unable to stringify body's content : "+e.name)}else{a=g&&g.indexOf("x-www-form-urlencoded")>1;for(r in f)h+=a?encodeURIComponent(r)+"="+encodeURIComponent(f[r])+"&":r+"="+f[r]+"\n\r"}s=[l,e,d],t.auth&&(s.push(t.auth.user),s.push(t.auth.passwd)),p.open.apply(p,s);for(i in t.headers)p.setRequestHeader(i,t.headers[i]);p.onprogress=function(e){e.lengthComputable&&u.trigger("progress",e.loaded/e.total)},p.onload=function(){var e=p.responseText;o&&clearTimeout(o),this.status>=200&&this.status<300&&("function"==typeof n&&(e=n(e)),u.trigger("success",e)),u.trigger(this.status,e),u.trigger("end",e)},p.onerror=function(e){o&&clearTimeout(o),u.trigger("error",e,arguments)},m&&(o=setTimeout(function(){u.trigger("timeout",{type:"timeout",expiredAfter:m},p,arguments),p.abort()},m)),p.send(h)},jsonp:function(n){var r,o=this,a=document.querySelector("head"),s=!0!==t.sync,c=t.jsonPaddingName||"callback",u=t.jsonPadding||"_padd"+(new Date).getTime()+Math.floor(1e4*Math.random()),l={};if(e[u])throw new Error("Padding "+u+" already exists. It must be unique.");/^ajajsonp_/.test(u)||(u="ajajsonp_"+u),window[u]=function(e){o.trigger("success",e),a.removeChild(r),window[u]=void 0},l[c]=u,n=i(n,l),r=document.createElement("script"),r.async=s,r.src=n,r.onerror=function(){o.trigger("error",arguments),a.removeChild(r),window[u]=void 0},a.appendChild(r)},script:function(e){var n,r=this,i=document.querySelector("head")||document.querySelector("body"),o=!0!==t.sync;if(!i)throw new Error("Ok, wait a second, you want to load a script, but you don't have at least a head or body tag...");n=document.createElement("script"),n.async=o,n.src=e,n.onerror=function(){r.trigger("error",arguments),i.removeChild(n)},n.onload=function(){r.trigger("success",arguments)},i.appendChild(n)}},s=function(e,n,i,o){if(void 0!==n){if("function"==typeof i)try{n=i.call(r,n)}catch(t){throw new TypeError("Failed to set "+e+" : "+t.message)}return t[e]="function"==typeof o?o.call(this,n):n,this}return"undefined"===t[e]?null:t[e]},c=function(){return["delete","patch","post","put"].indexOf(t.method)>-1},u=function(){var e=t.url,n=void 0===t.cache||!!t.cache,r=t.queryString||"",o=t.data;return!1===n&&(r+="&ajabuster="+(new Date).getTime()),e=i(e,r),o&&!c()&&(e=i(e,o)),e};return o},r={bool:function(e){return!!e},string:function(e){if("string"!=typeof e)throw new TypeError("a string is expected, but "+e+" ["+typeof e+"] given");return e},positiveInteger:function(e){if(parseInt(e)!==e||e<=0)throw new TypeError("an integer is expected, but "+e+" ["+typeof e+"] given");return e},plainObject:function(e){if("object"!=typeof e||e.constructor!==Object)throw new TypeError("an object is expected, but "+e+" ["+typeof e+"] given");return e},type:function(t){if(t=this.string(t),e.indexOf(t.toLowerCase())<0)throw new TypeError("a type in ["+e.join(", ")+"] is expected, but "+t+" given");return t.toLowerCase()},method:function(e){if(e=this.string(e),t.indexOf(e.toLowerCase())<0)throw new TypeError("a method in ["+t.join(", ")+"] is expected, but "+e+" given");return e.toLowerCase()},queryString:function(e){var t={};return"string"==typeof e?e.replace("?","").split("&").forEach(function(e){var n=e.split("=");2===n.length&&(t[decodeURIComponent(n[0])]=decodeURIComponent(n[1]))}):t=e,this.plainObject(t)},selector:function(e){if("string"!=typeof e&&!(e instanceof HTMLElement))throw new TypeError("a selector or an HTMLElement is expected, "+e+" ["+typeof e+"] given");return e},func:function(e){if(e=this.string(e),!/^([a-zA-Z_])([a-zA-Z0-9_\-])+$/.test(e))throw new TypeError("a valid function name is expected, "+e+" ["+typeof e+"] given");return e}},i=function(e,t){var n;if(e=e||"",t)if(-1===e.indexOf("?")&&(e+="?"),"string"==typeof t)e+=t;else if("object"==typeof t)for(n in t)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(t[n]);return e};"function"==typeof define&&define.amd?define([],function(){return n}):"object"==typeof exports?module.exports=n:window.aja=window.aja||n}(),function(e){function t(e,t){return function(){e.apply(t,arguments)}}function n(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],c(e,t(i,this),t(o,this))}function r(e){var t=this;if(null===this._state)return void this._deferreds.push(e);l(function(){var n=t._state?e.onFulfilled:e.onRejected;if(null===n)return void(t._state?e.resolve:e.reject)(t._value);var r;try{r=n(t._value)}catch(t){return void e.reject(t)}e.resolve(r)})}function i(e){try{if(e===this)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void c(t(n,e),t(i,this),t(o,this))}this._state=!0,this._value=e,a.call(this)}catch(e){o.call(this,e)}}function o(e){this._state=!1,this._value=e,a.call(this)}function a(){for(var e=0,t=this._deferreds.length;e0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(s),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(s,s.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(T=x(T,t)),U.d("Initialized called with:",T),!e)return Promise.reject("Missing file module!");try{b=window.cordova.file.applicationStorageDirectory,_=window.cordova.file.cacheDirectory,S=window.cordova.file.tempDirectory,A=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",P=window.cordova.file.dataDirectory}catch(e){return U.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(b+="Documents/"),"android"==window.device.platform.toLowerCase()&&(S=_),O.SDK_DIR=b+"scripts/",O.SDK_RELATIVE_DIR="../../scripts/",O.GAMEOVER_RELATIVE_DIR="../../gameover_template/",O.GAMES_DIR=b+"games/",O.BASE_DIR=b,O.CACHE_DIR=_,O.TEMP_DIR=S,O.CORDOVAJS=A+"cordova.js",O.CORDOVA_PLUGINS_JS=A+"cordova_plugins.js",O.STARGATEJS=A+"js/stargate.js",O.DATA_DIR=P,O.GAMEOVER_DIR=O.BASE_DIR+"gameover_template/",O.WWW_DIR=A,U.i("cordova JS dir to include",O.CORDOVAJS),n.game._public.BASE_DIR=O.BASE_DIR,n.game._public.OFFLINE_INDEX=O.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(O.BASE_DIR,"games"),a=e.createDir(O.BASE_DIR,"scripts"),u=e.fileExists(O.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(j))}),l=e.fileExists(O.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return U.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(O.BASE_DIR+"gameover_template"),e.dirExists(O.SDK_DIR+"plugins"),e.fileExists(O.SDK_DIR+"cordova.js"),e.fileExists(O.SDK_DIR+"cordova_plugins.js"),e.fileExists(O.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(O.WWW_DIR+"gameover_template",O.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(O.WWW_DIR+"plugins",O.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(O.CORDOVAJS,O.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(O.CORDOVA_PLUGINS_JS,O.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(O.WWW_DIR+"js/gamesFixes.js",O.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=D(T.sdk_url,{v:t.getTime()});return""===T.sdk_url||void 0===T.sdk_url||null===T.sdk_url?(U.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(O.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(U.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,O.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(O.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return U.d("Serialized dom",r),r}).then(function(t){return U.d("Write dom:",r,t),e.write(r,t)})}function g(e){return new RegExp(/.*\.html?$/i).test(e)}function m(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=O.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return U.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function w(){return U.i("readUserJson",O.BASE_DIR+"user.json"),e.readFileAsJSON(O.BASE_DIR+"user.json")}function v(e){return w().then(function(t){if(!t.ponyUrl)throw U.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];U.d("PONYVALUE",n);var r=D(T.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,U.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return U.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(O.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return U.d("writing offlineData.json",t),e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var b,_,S,A,P,I,E=t.Logger,D=t.composeApiString,R=t.jsonpRequest,x=t.extend,O={},T={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},k=!1,j={GaForGame:{},GamifiveInfo:{},queues:{}},C={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},U=new E("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"}) +;var n=e.requestFileSystem(1,w);return U.d("Get GameInfo, fly my minipony!"),n.then(function(e){return U.i("Space is ok, can download:",w,e),v(y)}).then(function(n){return U.d("Ga for game and gamifive info stored!",n),U.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,O.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),U.d("unzip:",t.id,O.TEMP_DIR+y),e._promiseZip(n.path,O.TEMP_DIR+y,r("unzip"))}).then(function(n){U.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,w=d*Math.pow(1024,f?p.MB:p.KB),y=t.id;return s.then(function(e){return U.d("Exists",e),e?(k=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(k=!0,i())})},r.prototype.play=function(t){U.d("Play",t);var n=O.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return g(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){U.d("Removing game",t);var n=e.dirExists(O.CACHE_DIR+t+".zip"),r=e.dirExists(O.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(U.d("Removed in cache",n[0]),r.push(e.removeFile(O.CACHE_DIR+t+".zip"))),n[1]&&(U.d("Removed",n[1]),r.push(e.removeDir(O.GAMES_DIR+t))),0===r.length&&U.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return k},r.prototype.abortDownload=function(){return this.isDownloading()?(U.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,k=!1),!0):(U.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return U.d("Get games list"),e.readDir(O.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=O.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(U.d("Read meta.json:",n),U.d("GAMEOVER_TEMPLATE path",O.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(O.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return U.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(O.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(O.GAMES_DIR).then(function(t){return U.d("All games deleted!",t),e.createDir(O.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){U.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){U.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(K.hasOwnProperty("webappsfixes")&&"object"==typeof K.webappsfixes){t=!0;for(var e in K.webappsfixes)if(K.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){m("[webappsFixes] applying fix: "+e);var r=n[e](K.webappsfixes[e]);r&&w("[webappsFixes] fix '"+e+"' failed: "+r)}else w("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(_()&&!e.platforms.ios)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(b()&&!e.platforms.android)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(m("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),m("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return w("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!K.statusbar)return;e=K.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},X=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(_()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){m("[share] Share completed? "+e.completed),m("[share] Shared to app: "+e.app),n(e)},a=function(e){w("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){m("[share] Facebook share completed, result: ",e),t(e)},i=function(e){w("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){m("[share] Twitter share completed, result: ",e),t(e)},i=function(e){w("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){m("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){w("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){m("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){m("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(m("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(w("[share] type not valid"),n("type not valid"))):(w("[share] missing parameter url"),n("missing parameter url")):(w("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return I?E?new Promise(function(t,n){X.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return I?E?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(X.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){w(e),n(e)})}):(w("[share] missing parameter url"),Promise.reject("missing parameter url")):(w("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(w("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var Y=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){h().then(function(e){f&&f.type&&"online"===f.type?(m("[push] going to url: ",e),A(e)):w("[push] i'm offline not going to url")}).catch(function(e){w("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var p=function(){var e=window.cordova.file.applicationStorageDirectory;return _()&&(e+="Documents/"),e},h=function(){return s.file.fileExists(p()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(p()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},g=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(p(),"SGpushUrl").then(function(e){return m("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){w("[push] error sg create SGpushUrl file",e)})},b=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();m("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,p=1732584193,f=-271733879,h=-1732584194,g=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function p(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function f(e){return unescape(encodeURIComponent(e))}function h(e){return l(f(e))}function g(e){return p(h(e))}function m(e,t){return d(f(e),f(t))}function w(e,t){return p(m(e,t))}function v(e,t,n){return t?n?m(t,e):w(t,e):n?h(e):g(e)}return v}(),ne=function(e){if(void 0===window.SpinnerDialog)return w("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},re=function(){return void 0===window.SpinnerDialog?w("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=ne,window.stopLoading=re,a.inAppPurchaseSubscription=function(e,t,n,r){return I?E?(H(!0),void 0!==r&&(oe.returnUrl=r),void 0!==n&&(oe.subscribeMethod=n),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0, oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(),window.store.order(oe.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.inAppRestore=function(e,t,n,r){return I?E?(void 0!==n&&(oe.subscribeMethod=n),void 0!==r&&(oe.returnUrl=r),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0,void oe.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},a.inAppProductInfo=function(e){if(e.productId||(e.productId=oe.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return w("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!I)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!E)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(oe.subscribeMethod=e.subscriptionUrl,oe.requestedListingProductId=e.productId,oe.callbackListingSuccess=e.callbackListingSuccess,oe.callbackPurchaseSuccess=e.callbackPurchaseSuccess,oe.callbackListingError=e.callbackError,oe.inappProductInfoCalled=!0,oe.productsInfo[e.productId])try{oe.callbackListingSuccess(oe.productsInfo[e.productId])}catch(e){w("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(!0),!0)};var ie=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(b()?n=e.productsIdAndroid:_()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,m("[IAPlight] getProducts ok",e),e}).catch(function(e){w("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(m("[IAPlight] subscribe ok",t),_())return e.getActiveSubscriptionsInfo().then(function(e){if(m("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(b()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return w("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw w("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){m("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),m(JSON.stringify(e)),m(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){m("IAP> Purchase approved."),m(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){m("subscription verified ",e)},onStoreReady:function(){m("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(m("[IAP] > Product Owned."),!e.transaction.id&&_())return w("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),_()&&window.localStorage.setItem("transaction_id",e.transaction.id),b()){var t=e.transaction.purchaseToken+"|"+O+"|"+oe.id;m("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||oe.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(m("[IAP] appStoreReceipt: "+t.appStoreReceipt),oe.createUser(e,t.appStoreReceipt)):m("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){H(!1),oe.callbackError({iap_cancelled:1,return_url:oe.returnUrl}),m("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){m("[IAP] ORDER APPROVED "+oe.id),e.finish()},error:function(e){H(!1),w("[IAP] error: "+e),oe.callbackError({iap_error:1,return_url:oe.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(m("[IAP] createUser start "),!oe.inappProductInfoCalled&&!oe.inappPurchaseCalled)return oe.lastCreateUserProduct=e,void(oe.lastCreateUserToken=t);if(!oe.subscribeMethod)return void w("[IAP] createUser configuration error: missing api url.");var n=oe.getRandomEmail(),r=1;b()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=oe.subscribeMethod,o={paymethod:oe.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:oe.returnUrl,inapp_pwd:oe.getPassword(t),hybrid:1};oe.lastCreateuserUrl=i,oe.lastCreateuserData=o;var a=function(e){if(oe.createUserAttempt<=oe.maxCreateUserAttempt)w("[IAP] createUser failed "+oe.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{w("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:oe.returnUrl};H(!1),oe.inappPurchaseCalled?oe.callbackError(t):oe.inappProductInfoCalled&&oe.callbackListingError(t)}},s=function(e){m("[IAP] createUser success ",e);try{e.device_id=y.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),H(!1),oe.callbackSuccess(e),oe.inappPurchaseCalled?oe.callbackSuccess(e):oe.inappProductInfoCalled&&oe.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){oe.createUserAttempt=oe.createUserAttempt+1,m("[IAP] createUser attempt: "+oe.createUserAttempt+" with timeout: "+c+"sec."),m("[IAP] POST createUser: "+oe.lastCreateuserUrl+" params: "+JSON.stringify(oe.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(oe.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(oe.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){m("[IAP] createUser end"),H(!1)}).go(),c+=5},10)};oe.createUserAttempt=0,u()}},ae=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return w("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return w("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});m("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){w("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return w("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});m("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){w("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(w("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(w("[globalization] getLocaleName: not initialized!"),!1)},e}();a.facebookLogin=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){m("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){w("Got FB login error:",e),n({error:e})})},a.facebookShare=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){w("Got FB share error:",e),n({error:e})})};var se=function(){deltadna.registerPushCallback(ue)},ce=function(e){w("[DeltaDNA] error: "+e)},ue=function(e){return b()&&e.payload&&e.payload.url&&!e.foreground?A(e.payload.url):_()&&e.url?A(e.url):void 0},le=function(){var e={},t={},n=function(n){m("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(w("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(w("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&m("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return w("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),de=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return w("[appsflyer] missing cordova plugin");if(void 0===K.appsflyer_devkey)return w("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:K.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(_()){if(void 0===K.appstore_appid)return w("[appsflyer] missing manifest configuration: appstore_appid");n.appId=K.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}ee.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();a.setConversionDataCallback=function(e){de.setCallback(e)};var pe=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return m("[analytics] callback not set!");try{e(t)}catch(e){w("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();a.setAnalyticsCallback=function(e){pe.setCallback(e)};var fe={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(fe.DefaultOptions=e),AdMob&&(fe.AdMobSupport=!0,fe.initAdMob(e,t,n)),MoPub&&(fe.MoPubSupport=!0),!0},isAdMobSupported:function(){return fe.AdMobSupport},isMoPubSupported:function(){return fe.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=fe.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=fe.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=fe.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?fe.AdSize.LEADERBOARD:t>=468&&e>=60?fe.AdSize.BANNER:t>=320&&e>=50?fe.AdSize.BANNER:void 0}};return a.game=s.game._public,a.file=s.file,a.AdManager=s.AdManager,a}); \ No newline at end of file diff --git a/package.json b/package.json index a8fad7c..7e09b9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stargatejs-apps", - "version": "0.13.3", + "version": "0.13.4", "description": "StargateJS for HTML5 apps", "main": "dist/stargate.js", "scripts": { From d0c09593a3c8b2329a527f77c2bb1240e5c223cc Mon Sep 17 00:00:00 2001 From: Mirco Cipriani Date: Wed, 12 Jul 2017 12:54:25 +0200 Subject: [PATCH 09/13] publish procedure updated with cleaning of dist and pushing after building to automate more the process --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7e09b9f..3d45a56 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,9 @@ "description": "StargateJS for HTML5 apps", "main": "dist/stargate.js", "scripts": { - "preversion": "npm test", + "preversion": "git checkout dist/ && npm test", "upload": "scp -r dist/*.js super@192.168.124.3:/dadanet2/wl2/webstore_apps/js/webstore_apps/stargate/v4", - "postversion": "git push --tags && npm publish", + "postversion": "git push && git push --tags && npm publish", "version": "gulp build && git add dist/", "clean": "rm -r gh-pages", "docs": "rm -rf gh-pages/* && node bin/generate_docs", From 60af51e45db0f72730a3895f35896458ea7e9923 Mon Sep 17 00:00:00 2001 From: Mirco Cipriani Date: Wed, 12 Jul 2017 12:55:02 +0200 Subject: [PATCH 10/13] initialize local push only if requested on manifest --- src/stargate.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/stargate.js b/src/stargate.js index 983c5ad..5f6db19 100644 --- a/src/stargate.js +++ b/src/stargate.js @@ -417,7 +417,13 @@ var onPluginReady = function (resolve) { codepush.initialize(); - push.initialize(); + if (hasFeature('localpush')) { + push.initialize() + .catch(function(e) { + err("LocalPush initialization error: "+e, e); + }); + } + var modulePromises = []; From 54fa3fded5fe776e80d7e3548d17bd3bfc58fe48 Mon Sep 17 00:00:00 2001 From: Mirco Cipriani Date: Wed, 12 Jul 2017 12:57:23 +0200 Subject: [PATCH 11/13] 0.13.5 --- dist/bower/stargate.js | 10 ++++++++-- dist/bower/stargate.min.js | 6 +++--- dist/stargate.js | 10 ++++++++-- dist/stargate.min.js | 4 ++-- package.json | 2 +- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/dist/bower/stargate.js b/dist/bower/stargate.js index b090385..1035a98 100644 --- a/dist/bower/stargate.js +++ b/dist/bower/stargate.js @@ -18,7 +18,7 @@ } }(this, function () { // Public interface - var stargatePackageVersion = "0.13.4"; + var stargatePackageVersion = "0.13.5"; var stargatePublic = {}; var stargateModules = {}; @@ -3253,7 +3253,13 @@ var onPluginReady = function (resolve) { codepush.initialize(); - push.initialize(); + if (hasFeature('localpush')) { + push.initialize() + .catch(function(e) { + err("LocalPush initialization error: "+e, e); + }); + } + var modulePromises = []; diff --git a/dist/bower/stargate.min.js b/dist/bower/stargate.min.js index 9822648..5d3c589 100644 --- a/dist/bower/stargate.min.js +++ b/dist/bower/stargate.min.js @@ -1,9 +1,9 @@ /*! * StargateJS Apps - * v0.13.4 + * v0.13.5 * Copyright 2015 DMobileLab. http://buongiorno.com/ * See LICENSE in this repository for license information */ !function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.Stargate=t()}(this,function(){function e(e){p.type=e.type,p.networkState=navigator.connection.type,"function"==typeof f&&f(p)}function t(){document.addEventListener("offline",e,!1),document.addEventListener("online",e,!1)}function n(){p.networkState=navigator.connection.type,"none"===navigator.connection.type?p.type="offline":p.type="online"}function r(e){if("android"==window.device.platform.toLowerCase())window.navigator.app.loadUrl(e);else if("ios"==window.device.platform.toLowerCase()&&-1!==e.indexOf("file:///")){var t=e.split("?")[0];h("Without qs",t),window.resolveLocalFileSystemURL(t,function(e){var t=e.toInternalURL()+"?hybrid=1";h("Redirect to",t),window.location.href=t},m)}else window.location.href=e}function i(){var e=window.cordova.file.applicationDirectory+"www/manifest.json";return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)}).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})}).then(function(e){var t="";try{t=window.JSON.parse(e)}catch(e){return Promise.reject(e)}return Promise.resolve(t)}).catch(function(e){console.error("getManifestWithCordovaFilePlugin() error:"+e,e)})}function o(){return window.hostedwebapp?new Promise(function(e,t){window.hostedwebapp.getManifest(function(t){e(t)},function(e){m(e),t(new Error(e))})}):window.cordova.file?i():(m("getManifest() no available reading mechanism!"),Promise.resolve({}))}var a={},s={};!function(e){function t(e,n,r){this.level=t.levels[e.toUpperCase()],this.styles=r||{background:"white",color:"black"},this.tag="%c "+n+" ",this.isstaging="1"==="IS_STAGING = 1".slice(-1),this.styleString="background:"+this.styles.background+";color:"+this.styles.color+";";var i=function(){if(arguments.length<1)return"";for(var e=Array.prototype.slice.call(arguments[0]),t="",n=0;n0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(s),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(s,s.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(L=O(L,t)),j.d("Initialized called with:",L),!e)return Promise.reject("Missing file module!");try{S=window.cordova.file.applicationStorageDirectory,b=window.cordova.file.cacheDirectory,A=window.cordova.file.tempDirectory,P=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",_=window.cordova.file.dataDirectory}catch(e){return j.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(S+="Documents/"),"android"==window.device.platform.toLowerCase()&&(A=b),k.SDK_DIR=S+"scripts/",k.SDK_RELATIVE_DIR="../../scripts/",k.GAMEOVER_RELATIVE_DIR="../../gameover_template/",k.GAMES_DIR=S+"games/",k.BASE_DIR=S,k.CACHE_DIR=b,k.TEMP_DIR=A,k.CORDOVAJS=P+"cordova.js",k.CORDOVA_PLUGINS_JS=P+"cordova_plugins.js",k.STARGATEJS=P+"js/stargate.js",k.DATA_DIR=_,k.GAMEOVER_DIR=k.BASE_DIR+"gameover_template/",k.WWW_DIR=P,j.i("cordova JS dir to include",k.CORDOVAJS),n.game._public.BASE_DIR=k.BASE_DIR,n.game._public.OFFLINE_INDEX=k.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(k.BASE_DIR,"games"),a=e.createDir(k.BASE_DIR,"scripts"),u=e.fileExists(k.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(C))}),l=e.fileExists(k.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return j.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(k.BASE_DIR+"gameover_template"),e.dirExists(k.SDK_DIR+"plugins"),e.fileExists(k.SDK_DIR+"cordova.js"),e.fileExists(k.SDK_DIR+"cordova_plugins.js"),e.fileExists(k.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(k.WWW_DIR+"gameover_template",k.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(k.WWW_DIR+"plugins",k.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(k.CORDOVAJS,k.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(k.CORDOVA_PLUGINS_JS,k.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(k.WWW_DIR+"js/gamesFixes.js",k.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=E(L.sdk_url,{v:t.getTime()});return""===L.sdk_url||void 0===L.sdk_url||null===L.sdk_url?(j.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(k.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(j.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,k.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(k.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return j.d("Serialized dom",r),r}).then(function(t){return j.d("Write dom:",r,t),e.write(r,t)})}function w(e){return new RegExp(/.*\.html?$/i).test(e)}function h(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=k.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return j.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function m(){return j.i("readUserJson",k.BASE_DIR+"user.json"),e.readFileAsJSON(k.BASE_DIR+"user.json")}function v(e){return m().then(function(t){if(!t.ponyUrl)throw j.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];j.d("PONYVALUE",n);var r=E(L.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,j.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return j.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(k.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return j.d("writing offlineData.json",t),e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var S,b,A,P,_,I,D=t.Logger,E=t.composeApiString,R=t.jsonpRequest,O=t.extend,k={},L={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},T=!1,C={GaForGame:{},GamifiveInfo:{},queues:{}},N={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},j=new D("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,m);return j.d("Get GameInfo, fly my minipony!"),n.then(function(e){return j.i("Space is ok, can download:",m,e),v(y)}).then(function(n){return j.d("Ga for game and gamifive info stored!",n),j.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,k.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),j.d("unzip:",t.id,k.TEMP_DIR+y),e._promiseZip(n.path,k.TEMP_DIR+y,r("unzip"))}).then(function(n){j.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,m=d*Math.pow(1024,p?f.MB:f.KB),y=t.id;return s.then(function(e){return j.d("Exists",e),e?(T=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(T=!0,i())})},r.prototype.play=function(t){j.d("Play",t);var n=k.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return w(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){j.d("Removing game",t);var n=e.dirExists(k.CACHE_DIR+t+".zip"),r=e.dirExists(k.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(j.d("Removed in cache",n[0]),r.push(e.removeFile(k.CACHE_DIR+t+".zip"))),n[1]&&(j.d("Removed",n[1]),r.push(e.removeDir(k.GAMES_DIR+t))),0===r.length&&j.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return T},r.prototype.abortDownload=function(){return this.isDownloading()?(j.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,T=!1),!0):(j.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return j.d("Get games list"),e.readDir(k.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=k.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(j.d("Read meta.json:",n),j.d("GAMEOVER_TEMPLATE path",k.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(k.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return j.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(k.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(k.GAMES_DIR).then(function(t){return j.d("All games deleted!",t),e.createDir(k.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(L.bundle_games.length>0){j.d("Games bundle in configuration",L.bundle_games);var t,n=L.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){j.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(W.hasOwnProperty("webappsfixes")&&"object"==typeof W.webappsfixes){t=!0;for(var e in W.webappsfixes)if(W.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){h("[webappsFixes] applying fix: "+e);var r=n[e](W.webappsfixes[e]);r&&m("[webappsFixes] fix '"+e+"' failed: "+r)}else m("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(b()&&!e.platforms.ios)return void h("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(S()&&!e.platforms.android)return void h("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(h("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),h("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return m("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!W.statusbar)return;e=W.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},Q=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(b()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){h("[share] Share completed? "+e.completed),h("[share] Shared to app: "+e.app),n(e)},a=function(e){m("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){h("[share] Facebook share completed, result: ",e),t(e)},i=function(e){m("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){h("[share] Twitter share completed, result: ",e),t(e)},i=function(e){m("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){h("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){m("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){h("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){h("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(h("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(m("[share] type not valid"),n("type not valid"))):(m("[share] missing parameter url"),n("missing parameter url")):(m("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return I?D?new Promise(function(t,n){Q.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return I?D?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Q.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){m(e),n(e)})}):(m("[share] missing parameter url"),Promise.reject("missing parameter url")):(m("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(m("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var $=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){g().then(function(e){p&&p.type&&"online"===p.type?(h("[push] going to url: ",e),P(e)):m("[push] i'm offline not going to url")}).catch(function(e){m("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var f=function(){var e=window.cordova.file.applicationStorageDirectory;return b()&&(e+="Documents/"),e},g=function(){return s.file.fileExists(f()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(f()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},w=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(f(),"SGpushUrl").then(function(e){return h("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){m("[push] error sg create SGpushUrl file",e)})},S=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();h("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,f=1732584193,p=-271733879,g=-1732584194,w=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function f(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function p(e){return unescape(encodeURIComponent(e))}function g(e){return l(p(e))}function w(e){return f(g(e))}function h(e,t){return d(p(e),p(t))}function m(e,t){return f(h(e,t))}function v(e,t,n){return t?n?h(t,e):m(t,e):n?g(e):w(e)}return v}(),ne=function(e){if(void 0===window.SpinnerDialog)return m("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},re=function(){return void 0===window.SpinnerDialog?m("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=ne,window.stopLoading=re,a.inAppPurchaseSubscription=function(e,t,n,r){return I?D?(J(!0),void 0!==r&&(oe.returnUrl=r),void 0!==n&&(oe.subscribeMethod=n),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0,oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(),window.store.order(oe.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.inAppRestore=function(e,t,n,r){return I?D?(void 0!==n&&(oe.subscribeMethod=n),void 0!==r&&(oe.returnUrl=r),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0,void oe.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},a.inAppProductInfo=function(e){if(e.productId||(e.productId=oe.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return m("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!I)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!D)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(oe.subscribeMethod=e.subscriptionUrl,oe.requestedListingProductId=e.productId,oe.callbackListingSuccess=e.callbackListingSuccess,oe.callbackPurchaseSuccess=e.callbackPurchaseSuccess,oe.callbackListingError=e.callbackError,oe.inappProductInfoCalled=!0,oe.productsInfo[e.productId])try{oe.callbackListingSuccess(oe.productsInfo[e.productId])}catch(e){m("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(!0),!0)};var ie=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(S()?n=e.productsIdAndroid:b()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,h("[IAPlight] getProducts ok",e),e}).catch(function(e){m("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(h("[IAPlight] subscribe ok",t),b())return e.getActiveSubscriptionsInfo().then(function(e){if(h("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(S()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return m("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw m("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){h("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),h(JSON.stringify(e)),h(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){h("IAP> Purchase approved."),h(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){h("subscription verified ",e)},onStoreReady:function(){h("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(h("[IAP] > Product Owned."),!e.transaction.id&&b())return m("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),b()&&window.localStorage.setItem("transaction_id",e.transaction.id),S()){var t=e.transaction.purchaseToken+"|"+k+"|"+oe.id;h("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||oe.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(h("[IAP] appStoreReceipt: "+t.appStoreReceipt),oe.createUser(e,t.appStoreReceipt)):h("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){J(!1),oe.callbackError({iap_cancelled:1,return_url:oe.returnUrl}),h("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){h("[IAP] ORDER APPROVED "+oe.id),e.finish()},error:function(e){J(!1),m("[IAP] error: "+e),oe.callbackError({iap_error:1,return_url:oe.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(h("[IAP] createUser start "),!oe.inappProductInfoCalled&&!oe.inappPurchaseCalled)return oe.lastCreateUserProduct=e,void(oe.lastCreateUserToken=t);if(!oe.subscribeMethod)return void m("[IAP] createUser configuration error: missing api url.");var n=oe.getRandomEmail(),r=1;S()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=oe.subscribeMethod,o={paymethod:oe.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:oe.returnUrl,inapp_pwd:oe.getPassword(t),hybrid:1};oe.lastCreateuserUrl=i,oe.lastCreateuserData=o;var a=function(e){if(oe.createUserAttempt<=oe.maxCreateUserAttempt)m("[IAP] createUser failed "+oe.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{m("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:oe.returnUrl};J(!1),oe.inappPurchaseCalled?oe.callbackError(t):oe.inappProductInfoCalled&&oe.callbackListingError(t)}},s=function(e){h("[IAP] createUser success ",e);try{e.device_id=y.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),J(!1),oe.callbackSuccess(e),oe.inappPurchaseCalled?oe.callbackSuccess(e):oe.inappProductInfoCalled&&oe.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ -oe.createUserAttempt=oe.createUserAttempt+1,h("[IAP] createUser attempt: "+oe.createUserAttempt+" with timeout: "+c+"sec."),h("[IAP] POST createUser: "+oe.lastCreateuserUrl+" params: "+JSON.stringify(oe.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(oe.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(oe.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){h("[IAP] createUser end"),J(!1)}).go(),c+=5},10)};oe.createUserAttempt=0,u()}},ae=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return m("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return m("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});h("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){m("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return m("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});h("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){m("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(m("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(m("[globalization] getLocaleName: not initialized!"),!1)},e}();a.facebookLogin=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){h("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){m("Got FB login error:",e),n({error:e})})},a.facebookShare=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){m("Got FB share error:",e),n({error:e})})};var se=function(){deltadna.registerPushCallback(ue)},ce=function(e){m("[DeltaDNA] error: "+e)},ue=function(e){return S()&&e.payload&&e.payload.url&&!e.foreground?P(e.payload.url):b()&&e.url?P(e.url):void 0},le=function(){var e={},t={},n=function(n){h("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(m("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(m("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&h("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return m("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),de=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return m("[appsflyer] missing cordova plugin");if(void 0===W.appsflyer_devkey)return m("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:W.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(b()){if(void 0===W.appstore_appid)return m("[appsflyer] missing manifest configuration: appstore_appid");n.appId=W.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}ee.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();a.setConversionDataCallback=function(e){de.setCallback(e)};var fe=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return h("[analytics] callback not set!");try{e(t)}catch(e){m("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();a.setAnalyticsCallback=function(e){fe.setCallback(e)};var pe={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(pe.DefaultOptions=e),AdMob&&(pe.AdMobSupport=!0,pe.initAdMob(e,t,n)),MoPub&&(pe.MoPubSupport=!0),!0},isAdMobSupported:function(){return pe.AdMobSupport},isMoPubSupported:function(){return pe.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=pe.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=pe.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=pe.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?pe.AdSize.LEADERBOARD:t>=468&&e>=60?pe.AdSize.BANNER:t>=320&&e>=50?pe.AdSize.BANNER:void 0}};return a.game=s.game._public,a.file=s.file,a.AdManager=s.AdManager,a}); \ No newline at end of file +e.modules_conf&&("object"!=typeof e.modules_conf?m("initialize() configurations.modules_conf is not an object"):j=e.modules_conf),e.country&&("mfp"in C?C.mfp.country=e.country:C.mfp={country:e.country}),_?(h("initialize() starting up, configuration: ",C),E=r,d=new Promise(function(e,t){var n=function(){V(e,t),document.removeEventListener("deviceready",n,!1)};document.addEventListener("deviceready",n,!1)}),I=!0,d):(h("version 0.13.5 running outside hybrid "),r&&r(_),d=Promise.resolve(_),I=!0,d)))},a.isInitialized=function(){return I},a.isOpen=function(){return D},a.isHybrid=function(){return K()},a.openUrl=function(e){return I?D?window.cordova&&window.cordova.InAppBrowser&&window.cordova.InAppBrowser.open?(h("[openUrl] opening: "+e),window.open(e,"_system"),!0):(m("Missing cordova plugin InAppBrowser"),!1):(m("Stargate closed, wait for Stargate.initialize to complete!"),!1):m("Stargate not initialized, call Stargate.initialize first!")},a.googleLogin=function(e,t){if(!I)return t("Stargate not initialized, call Stargate.initialize first!");m("unimplemented"),t("unimplemented")};var f,p={type:"unknown",networkState:"unknown"};a.addListener=function(e,t){"connectionchange"==e&&"function"==typeof t&&(h("onConnectionChange registered"),f=t)},a.checkConnection=function(){var e=arguments.length<=0||void 0===arguments[0]?function(){}:arguments[0],t=arguments.length<=1||void 0===arguments[1]?function(){}:arguments[1];return I?D?void 0===navigator.connection||"function"!=typeof navigator.connection.getInfo?(t("Missing cordova plugin"),console.warn("Cordova Network Information module missing"),!1):(e(p),p):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.getDeviceID=function(e,t){return I?D?void e({deviceID:y.uuid}):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):t("Stargate not initialized, call Stargate.initialize first!")},a.goToLocalIndex=function(){if("undefined"!==window.cordova.file.applicationDirectory){r(window.cordova.file.applicationDirectory+"www/index.html"+"?hybrid=1")}else m("Missing cordova-plugin-file. Install it with: cordova plugin add cordova-plugin-file")},a.goToWebIndex=function(){var e=a.conf.getWebappStartUrl()+"";h("Redirect to",e),r(e)},a.getVersion=function(){return"0.13.5"},a.getAppInformation=function(){return U},a.getAvailableFeatures=function(){return X()};var g="2",w=function(){for(var e=Array.prototype.slice.call(arguments),t="",n=0;n-1},Q=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(b()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){h("[share] Share completed? "+e.completed),h("[share] Shared to app: "+e.app),n(e)},a=function(e){m("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){h("[share] Facebook share completed, result: ",e),t(e)},i=function(e){m("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){h("[share] Twitter share completed, result: ",e),t(e)},i=function(e){m("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){h("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){m("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){h("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){h("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(h("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(m("[share] type not valid"),n("type not valid"))):(m("[share] missing parameter url"),n("missing parameter url")):(m("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return I?D?new Promise(function(t,n){Q.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return I?D?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Q.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){m(e),n(e)})}):(m("[share] missing parameter url"),Promise.reject("missing parameter url")):(m("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(m("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var $=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){g().then(function(e){p&&p.type&&"online"===p.type?(h("[push] going to url: ",e),P(e)):m("[push] i'm offline not going to url")}).catch(function(e){m("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var f=function(){var e=window.cordova.file.applicationStorageDirectory;return b()&&(e+="Documents/"),e},g=function(){return s.file.fileExists(f()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(f()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},w=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(f(),"SGpushUrl").then(function(e){return h("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){m("[push] error sg create SGpushUrl file",e)})},S=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();h("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,f=1732584193,p=-271733879,g=-1732584194,w=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function f(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function p(e){return unescape(encodeURIComponent(e))}function g(e){return l(p(e))}function w(e){return f(g(e))}function h(e,t){return d(p(e),p(t))}function m(e,t){return f(h(e,t))}function v(e,t,n){return t?n?h(t,e):m(t,e):n?g(e):w(e)}return v}(),ne=function(e){if(void 0===window.SpinnerDialog)return m("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},re=function(){return void 0===window.SpinnerDialog?m("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=ne,window.stopLoading=re,a.inAppPurchaseSubscription=function(e,t,n,r){return I?D?(J(!0),void 0!==r&&(oe.returnUrl=r),void 0!==n&&(oe.subscribeMethod=n),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0,oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(),window.store.order(oe.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.inAppRestore=function(e,t,n,r){return I?D?(void 0!==n&&(oe.subscribeMethod=n),void 0!==r&&(oe.returnUrl=r),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0,void oe.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},a.inAppProductInfo=function(e){if(e.productId||(e.productId=oe.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return m("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!I)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!D)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(oe.subscribeMethod=e.subscriptionUrl,oe.requestedListingProductId=e.productId,oe.callbackListingSuccess=e.callbackListingSuccess,oe.callbackPurchaseSuccess=e.callbackPurchaseSuccess,oe.callbackListingError=e.callbackError,oe.inappProductInfoCalled=!0,oe.productsInfo[e.productId])try{oe.callbackListingSuccess(oe.productsInfo[e.productId])}catch(e){m("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(!0),!0)};var ie=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(S()?n=e.productsIdAndroid:b()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,h("[IAPlight] getProducts ok",e),e}).catch(function(e){m("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(h("[IAPlight] subscribe ok",t),b())return e.getActiveSubscriptionsInfo().then(function(e){if(h("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(S()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return m("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw m("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){h("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),h(JSON.stringify(e)),h(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){h("IAP> Purchase approved."),h(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){h("subscription verified ",e)},onStoreReady:function(){h("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(h("[IAP] > Product Owned."),!e.transaction.id&&b())return m("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),b()&&window.localStorage.setItem("transaction_id",e.transaction.id),S()){var t=e.transaction.purchaseToken+"|"+k+"|"+oe.id;h("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||oe.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(h("[IAP] appStoreReceipt: "+t.appStoreReceipt),oe.createUser(e,t.appStoreReceipt)):h("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){J(!1),oe.callbackError({iap_cancelled:1,return_url:oe.returnUrl}),h("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){h("[IAP] ORDER APPROVED "+oe.id),e.finish()},error:function(e){J(!1),m("[IAP] error: "+e),oe.callbackError({iap_error:1,return_url:oe.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(h("[IAP] createUser start "),!oe.inappProductInfoCalled&&!oe.inappPurchaseCalled)return oe.lastCreateUserProduct=e,void(oe.lastCreateUserToken=t);if(!oe.subscribeMethod)return void m("[IAP] createUser configuration error: missing api url.");var n=oe.getRandomEmail(),r=1;S()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=oe.subscribeMethod,o={paymethod:oe.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:oe.returnUrl,inapp_pwd:oe.getPassword(t),hybrid:1};oe.lastCreateuserUrl=i,oe.lastCreateuserData=o;var a=function(e){if(oe.createUserAttempt<=oe.maxCreateUserAttempt)m("[IAP] createUser failed "+oe.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{m("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:oe.returnUrl};J(!1),oe.inappPurchaseCalled?oe.callbackError(t):oe.inappProductInfoCalled&&oe.callbackListingError(t)}},s=function(e){h("[IAP] createUser success ",e);try{e.device_id=y.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),J(!1),oe.callbackSuccess(e),oe.inappPurchaseCalled?oe.callbackSuccess(e):oe.inappProductInfoCalled&&oe.callbackPurchaseSuccess(e) +}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){oe.createUserAttempt=oe.createUserAttempt+1,h("[IAP] createUser attempt: "+oe.createUserAttempt+" with timeout: "+c+"sec."),h("[IAP] POST createUser: "+oe.lastCreateuserUrl+" params: "+JSON.stringify(oe.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(oe.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(oe.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){h("[IAP] createUser end"),J(!1)}).go(),c+=5},10)};oe.createUserAttempt=0,u()}},ae=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return m("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return m("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});h("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){m("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return m("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});h("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){m("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(m("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(m("[globalization] getLocaleName: not initialized!"),!1)},e}();a.facebookLogin=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){h("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){m("Got FB login error:",e),n({error:e})})},a.facebookShare=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){m("Got FB share error:",e),n({error:e})})};var se=function(){deltadna.registerPushCallback(ue)},ce=function(e){m("[DeltaDNA] error: "+e)},ue=function(e){return S()&&e.payload&&e.payload.url&&!e.foreground?P(e.payload.url):b()&&e.url?P(e.url):void 0},le=function(){var e={},t={},n=function(n){h("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(m("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(m("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&h("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return m("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),de=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return m("[appsflyer] missing cordova plugin");if(void 0===W.appsflyer_devkey)return m("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:W.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(b()){if(void 0===W.appstore_appid)return m("[appsflyer] missing manifest configuration: appstore_appid");n.appId=W.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}ee.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();a.setConversionDataCallback=function(e){de.setCallback(e)};var fe=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return h("[analytics] callback not set!");try{e(t)}catch(e){m("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();a.setAnalyticsCallback=function(e){fe.setCallback(e)};var pe={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(pe.DefaultOptions=e),AdMob&&(pe.AdMobSupport=!0,pe.initAdMob(e,t,n)),MoPub&&(pe.MoPubSupport=!0),!0},isAdMobSupported:function(){return pe.AdMobSupport},isMoPubSupported:function(){return pe.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=pe.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=pe.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=pe.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=pe.getUserAgent();e||pe.isObjEmpty(pe.DefaultOptions)||(e=pe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?pe.AdSize.LEADERBOARD:t>=468&&e>=60?pe.AdSize.BANNER:t>=320&&e>=50?pe.AdSize.BANNER:void 0}};return a.game=s.game._public,a.file=s.file,a.AdManager=s.AdManager,a}); \ No newline at end of file diff --git a/dist/stargate.js b/dist/stargate.js index 7dd9414..09f29c4 100644 --- a/dist/stargate.js +++ b/dist/stargate.js @@ -3935,7 +3935,7 @@ } }(this, function () { // Public interface - var stargatePackageVersion = "0.13.4"; + var stargatePackageVersion = "0.13.5"; var stargatePublic = {}; var stargateModules = {}; @@ -7170,7 +7170,13 @@ var onPluginReady = function (resolve) { codepush.initialize(); - push.initialize(); + if (hasFeature('localpush')) { + push.initialize() + .catch(function(e) { + err("LocalPush initialization error: "+e, e); + }); + } + var modulePromises = []; diff --git a/dist/stargate.min.js b/dist/stargate.min.js index 0fb0f71..8542575 100644 --- a/dist/stargate.min.js +++ b/dist/stargate.min.js @@ -1,10 +1,10 @@ /*! * StargateJS Apps - * v0.13.4 + * v0.13.5 * Copyright 2015 DMobileLab. http://buongiorno.com/ * See LICENSE in this repository for license information */ !function(e,t){"use strict";"object"==typeof exports?module.exports=t(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"==typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],t):e.URI=t(e.punycode,e.IPv6,e.SecondLevelDomains,e)}(this,function(e,t,n,r){"use strict";function i(e,t){var n=arguments.length>=1,r=arguments.length>=2;if(!(this instanceof i))return n?r?new i(e,t):new i(e):new i;if(void 0===e){if(n)throw new TypeError("undefined is not a valid argument for URI");e="undefined"!=typeof location?location.href+"":""}return this.href(e),void 0!==t?this.absoluteTo(t):this}function o(e){return e.replace(/([.*+?^=!:()|[\]\/\\])/g,"\\$1")}function a(e){return void 0===e?"Undefined":String(Object.prototype.toString.call(e)).slice(8,-1)}function s(e){return"Array"===a(e)}function c(e,t){var n,r,i={};if("RegExp"===a(t))i=null;else if(s(t))for(n=0,r=t.length;n]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,i.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?«»“”„‘’]+$/},i.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},i.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/,i.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"},i.getDomAttribute=function(e){if(e&&e.nodeName){var t=e.nodeName.toLowerCase();if("input"!==t||"image"===e.type)return i.domAttributes[t]}},i.encode=f,i.decode=decodeURIComponent,i.iso8859=function(){i.encode=escape,i.decode=unescape},i.unicode=function(){i.encode=f,i.decode=decodeURIComponent},i.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/gi,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}},i.encodeQuery=function(e,t){var n=i.encode(e+"");return void 0===t&&(t=i.escapeQuerySpace),t?n.replace(/%20/g,"+"):n},i.decodeQuery=function(e,t){e+="",void 0===t&&(t=i.escapeQuerySpace);try{return i.decode(t?e.replace(/\+/g,"%20"):e)}catch(t){return e}};var y,b={encode:"encode",decode:"decode"},_=function(e,t){return function(n){try{return i[t](n+"").replace(i.characters[e][t].expression,function(n){return i.characters[e][t].map[n]})}catch(e){return n}}};for(y in b)i[y+"PathSegment"]=_("pathname",b[y]),i[y+"UrnPathSegment"]=_("urnpath",b[y]);var S=function(e,t,n){return function(r){var o;o=n?function(e){return i[t](i[n](e))}:i[t];for(var a=(r+"").split(e),s=0,c=a.length;s-1&&(t.fragment=e.substring(n+1)||null,e=e.substring(0,n)),n=e.indexOf("?"),n>-1&&(t.query=e.substring(n+1)||null,e=e.substring(0,n)),"//"===e.substring(0,2)?(t.protocol=null,e=e.substring(2),e=i.parseAuthority(e,t)):(n=e.indexOf(":"))>-1&&(t.protocol=e.substring(0,n)||null,t.protocol&&!t.protocol.match(i.protocol_expression)?t.protocol=void 0:"//"===e.substring(n+1,n+3)?(e=e.substring(n+3),e=i.parseAuthority(e,t)):(e=e.substring(n+1),t.urn=!0)),t.path=e,t},i.parseHost=function(e,t){e=e.replace(/\\/g,"/");var n,r,i=e.indexOf("/");if(-1===i&&(i=e.length),"["===e.charAt(0))n=e.indexOf("]"),t.hostname=e.substring(1,n)||null,t.port=e.substring(n+2,i)||null,"/"===t.port&&(t.port=null);else{var o=e.indexOf(":"),a=e.indexOf("/"),s=e.indexOf(":",o+1);-1!==s&&(-1===a||s-1?r:e.length-1);return o>-1&&(-1===r||o3?Object.keys(n).forEach(function(e){var n=e.match(/^([0-9])([0-9x])([0-9x])$/i);!(n&&n.length>3&&o[1]===n[1])||"x"!==n[2]&&o[2]!==n[2]||"x"!==n[3]&&o[3]!==n[3]||i(e,t)}):n[e]&&i(e,t)}return this},go:function(){var e=t.type||(t.into?"html":"json"),n=u();if("function"==typeof a[e])return a[e].call(this,n)}},a={json:function(e){var t=this;a._xhr.call(this,e,function(e){if(e)try{e=JSON.parse(e)}catch(e){return t.trigger("error",e),null}return e})},html:function(e){a._xhr.call(this,e,function(e){return t.into&&t.into.length&&[].forEach.call(t.into,function(t){t.innerHTML=e}),e})},_xhr:function(e,n){var r,i,o,a,s,u=this,l=t.method||"get",d=!0!==t.sync,p=new XMLHttpRequest,f=t.data,h=t.body,g=(t.headers,this.header("Content-Type")),m=t.timeout;if(!g&&f&&c()&&(this.header("Content-Type","application/x-www-form-urlencoded;charset=utf-8"),g=this.header("Content-Type")),f&&c())if("string"!=typeof h&&(h=""),g.indexOf("json")>-1)try{h=JSON.stringify(f)}catch(e){throw new TypeError("Unable to stringify body's content : "+e.name)}else{a=g&&g.indexOf("x-www-form-urlencoded")>1;for(r in f)h+=a?encodeURIComponent(r)+"="+encodeURIComponent(f[r])+"&":r+"="+f[r]+"\n\r"}s=[l,e,d],t.auth&&(s.push(t.auth.user),s.push(t.auth.passwd)),p.open.apply(p,s);for(i in t.headers)p.setRequestHeader(i,t.headers[i]);p.onprogress=function(e){e.lengthComputable&&u.trigger("progress",e.loaded/e.total)},p.onload=function(){var e=p.responseText;o&&clearTimeout(o),this.status>=200&&this.status<300&&("function"==typeof n&&(e=n(e)),u.trigger("success",e)),u.trigger(this.status,e),u.trigger("end",e)},p.onerror=function(e){o&&clearTimeout(o),u.trigger("error",e,arguments)},m&&(o=setTimeout(function(){u.trigger("timeout",{type:"timeout",expiredAfter:m},p,arguments),p.abort()},m)),p.send(h)},jsonp:function(n){var r,o=this,a=document.querySelector("head"),s=!0!==t.sync,c=t.jsonPaddingName||"callback",u=t.jsonPadding||"_padd"+(new Date).getTime()+Math.floor(1e4*Math.random()),l={};if(e[u])throw new Error("Padding "+u+" already exists. It must be unique.");/^ajajsonp_/.test(u)||(u="ajajsonp_"+u),window[u]=function(e){o.trigger("success",e),a.removeChild(r),window[u]=void 0},l[c]=u,n=i(n,l),r=document.createElement("script"),r.async=s,r.src=n,r.onerror=function(){o.trigger("error",arguments),a.removeChild(r),window[u]=void 0},a.appendChild(r)},script:function(e){var n,r=this,i=document.querySelector("head")||document.querySelector("body"),o=!0!==t.sync;if(!i)throw new Error("Ok, wait a second, you want to load a script, but you don't have at least a head or body tag...");n=document.createElement("script"),n.async=o,n.src=e,n.onerror=function(){r.trigger("error",arguments),i.removeChild(n)},n.onload=function(){r.trigger("success",arguments)},i.appendChild(n)}},s=function(e,n,i,o){if(void 0!==n){if("function"==typeof i)try{n=i.call(r,n)}catch(t){throw new TypeError("Failed to set "+e+" : "+t.message)}return t[e]="function"==typeof o?o.call(this,n):n,this}return"undefined"===t[e]?null:t[e]},c=function(){return["delete","patch","post","put"].indexOf(t.method)>-1},u=function(){var e=t.url,n=void 0===t.cache||!!t.cache,r=t.queryString||"",o=t.data;return!1===n&&(r+="&ajabuster="+(new Date).getTime()),e=i(e,r),o&&!c()&&(e=i(e,o)),e};return o},r={bool:function(e){return!!e},string:function(e){if("string"!=typeof e)throw new TypeError("a string is expected, but "+e+" ["+typeof e+"] given");return e},positiveInteger:function(e){if(parseInt(e)!==e||e<=0)throw new TypeError("an integer is expected, but "+e+" ["+typeof e+"] given");return e},plainObject:function(e){if("object"!=typeof e||e.constructor!==Object)throw new TypeError("an object is expected, but "+e+" ["+typeof e+"] given");return e},type:function(t){if(t=this.string(t),e.indexOf(t.toLowerCase())<0)throw new TypeError("a type in ["+e.join(", ")+"] is expected, but "+t+" given");return t.toLowerCase()},method:function(e){if(e=this.string(e),t.indexOf(e.toLowerCase())<0)throw new TypeError("a method in ["+t.join(", ")+"] is expected, but "+e+" given");return e.toLowerCase()},queryString:function(e){var t={};return"string"==typeof e?e.replace("?","").split("&").forEach(function(e){var n=e.split("=");2===n.length&&(t[decodeURIComponent(n[0])]=decodeURIComponent(n[1]))}):t=e,this.plainObject(t)},selector:function(e){if("string"!=typeof e&&!(e instanceof HTMLElement))throw new TypeError("a selector or an HTMLElement is expected, "+e+" ["+typeof e+"] given");return e},func:function(e){if(e=this.string(e),!/^([a-zA-Z_])([a-zA-Z0-9_\-])+$/.test(e))throw new TypeError("a valid function name is expected, "+e+" ["+typeof e+"] given");return e}},i=function(e,t){var n;if(e=e||"",t)if(-1===e.indexOf("?")&&(e+="?"),"string"==typeof t)e+=t;else if("object"==typeof t)for(n in t)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(t[n]);return e};"function"==typeof define&&define.amd?define([],function(){return n}):"object"==typeof exports?module.exports=n:window.aja=window.aja||n}(),function(e){function t(e,t){return function(){e.apply(t,arguments)}}function n(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],c(e,t(i,this),t(o,this))}function r(e){var t=this;if(null===this._state)return void this._deferreds.push(e);l(function(){var n=t._state?e.onFulfilled:e.onRejected;if(null===n)return void(t._state?e.resolve:e.reject)(t._value);var r;try{r=n(t._value)}catch(t){return void e.reject(t)}e.resolve(r)})}function i(e){try{if(e===this)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void c(t(n,e),t(i,this),t(o,this))}this._state=!0,this._value=e,a.call(this)}catch(e){o.call(this,e)}}function o(e){this._state=!1,this._value=e,a.call(this)}function a(){for(var e=0,t=this._deferreds.length;e0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(s),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(s,s.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(T=x(T,t)),U.d("Initialized called with:",T),!e)return Promise.reject("Missing file module!");try{b=window.cordova.file.applicationStorageDirectory,_=window.cordova.file.cacheDirectory,S=window.cordova.file.tempDirectory,A=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",P=window.cordova.file.dataDirectory}catch(e){return U.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(b+="Documents/"),"android"==window.device.platform.toLowerCase()&&(S=_),O.SDK_DIR=b+"scripts/",O.SDK_RELATIVE_DIR="../../scripts/",O.GAMEOVER_RELATIVE_DIR="../../gameover_template/",O.GAMES_DIR=b+"games/",O.BASE_DIR=b,O.CACHE_DIR=_,O.TEMP_DIR=S,O.CORDOVAJS=A+"cordova.js",O.CORDOVA_PLUGINS_JS=A+"cordova_plugins.js",O.STARGATEJS=A+"js/stargate.js",O.DATA_DIR=P,O.GAMEOVER_DIR=O.BASE_DIR+"gameover_template/",O.WWW_DIR=A,U.i("cordova JS dir to include",O.CORDOVAJS),n.game._public.BASE_DIR=O.BASE_DIR,n.game._public.OFFLINE_INDEX=O.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(O.BASE_DIR,"games"),a=e.createDir(O.BASE_DIR,"scripts"),u=e.fileExists(O.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(j))}),l=e.fileExists(O.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return U.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(O.BASE_DIR+"gameover_template"),e.dirExists(O.SDK_DIR+"plugins"),e.fileExists(O.SDK_DIR+"cordova.js"),e.fileExists(O.SDK_DIR+"cordova_plugins.js"),e.fileExists(O.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(O.WWW_DIR+"gameover_template",O.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(O.WWW_DIR+"plugins",O.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(O.CORDOVAJS,O.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(O.CORDOVA_PLUGINS_JS,O.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(O.WWW_DIR+"js/gamesFixes.js",O.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=D(T.sdk_url,{v:t.getTime()});return""===T.sdk_url||void 0===T.sdk_url||null===T.sdk_url?(U.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(O.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(U.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,O.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(O.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return U.d("Serialized dom",r),r}).then(function(t){return U.d("Write dom:",r,t),e.write(r,t)})}function g(e){return new RegExp(/.*\.html?$/i).test(e)}function m(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=O.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return U.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function w(){return U.i("readUserJson",O.BASE_DIR+"user.json"),e.readFileAsJSON(O.BASE_DIR+"user.json")}function v(e){return w().then(function(t){if(!t.ponyUrl)throw U.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];U.d("PONYVALUE",n);var r=D(T.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,U.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return U.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(O.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return U.d("writing offlineData.json",t),e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var b,_,S,A,P,I,E=t.Logger,D=t.composeApiString,R=t.jsonpRequest,x=t.extend,O={},T={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},k=!1,j={GaForGame:{},GamifiveInfo:{},queues:{}},C={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},U=new E("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"}) -;var n=e.requestFileSystem(1,w);return U.d("Get GameInfo, fly my minipony!"),n.then(function(e){return U.i("Space is ok, can download:",w,e),v(y)}).then(function(n){return U.d("Ga for game and gamifive info stored!",n),U.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,O.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),U.d("unzip:",t.id,O.TEMP_DIR+y),e._promiseZip(n.path,O.TEMP_DIR+y,r("unzip"))}).then(function(n){U.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,w=d*Math.pow(1024,f?p.MB:p.KB),y=t.id;return s.then(function(e){return U.d("Exists",e),e?(k=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(k=!0,i())})},r.prototype.play=function(t){U.d("Play",t);var n=O.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return g(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){U.d("Removing game",t);var n=e.dirExists(O.CACHE_DIR+t+".zip"),r=e.dirExists(O.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(U.d("Removed in cache",n[0]),r.push(e.removeFile(O.CACHE_DIR+t+".zip"))),n[1]&&(U.d("Removed",n[1]),r.push(e.removeDir(O.GAMES_DIR+t))),0===r.length&&U.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return k},r.prototype.abortDownload=function(){return this.isDownloading()?(U.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,k=!1),!0):(U.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return U.d("Get games list"),e.readDir(O.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=O.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(U.d("Read meta.json:",n),U.d("GAMEOVER_TEMPLATE path",O.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(O.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return U.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(O.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(O.GAMES_DIR).then(function(t){return U.d("All games deleted!",t),e.createDir(O.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){U.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){U.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(K.hasOwnProperty("webappsfixes")&&"object"==typeof K.webappsfixes){t=!0;for(var e in K.webappsfixes)if(K.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){m("[webappsFixes] applying fix: "+e);var r=n[e](K.webappsfixes[e]);r&&w("[webappsFixes] fix '"+e+"' failed: "+r)}else w("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(_()&&!e.platforms.ios)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(b()&&!e.platforms.android)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(m("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),m("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return w("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!K.statusbar)return;e=K.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},X=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(_()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){m("[share] Share completed? "+e.completed),m("[share] Shared to app: "+e.app),n(e)},a=function(e){w("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){m("[share] Facebook share completed, result: ",e),t(e)},i=function(e){w("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){m("[share] Twitter share completed, result: ",e),t(e)},i=function(e){w("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){m("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){w("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){m("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){m("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(m("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(w("[share] type not valid"),n("type not valid"))):(w("[share] missing parameter url"),n("missing parameter url")):(w("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return I?E?new Promise(function(t,n){X.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return I?E?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(X.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){w(e),n(e)})}):(w("[share] missing parameter url"),Promise.reject("missing parameter url")):(w("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(w("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var Y=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){h().then(function(e){f&&f.type&&"online"===f.type?(m("[push] going to url: ",e),A(e)):w("[push] i'm offline not going to url")}).catch(function(e){w("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var p=function(){var e=window.cordova.file.applicationStorageDirectory;return _()&&(e+="Documents/"),e},h=function(){return s.file.fileExists(p()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(p()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},g=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(p(),"SGpushUrl").then(function(e){return m("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){w("[push] error sg create SGpushUrl file",e)})},b=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();m("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,p=1732584193,f=-271733879,h=-1732584194,g=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function p(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function f(e){return unescape(encodeURIComponent(e))}function h(e){return l(f(e))}function g(e){return p(h(e))}function m(e,t){return d(f(e),f(t))}function w(e,t){return p(m(e,t))}function v(e,t,n){return t?n?m(t,e):w(t,e):n?h(e):g(e)}return v}(),ne=function(e){if(void 0===window.SpinnerDialog)return w("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},re=function(){return void 0===window.SpinnerDialog?w("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=ne,window.stopLoading=re,a.inAppPurchaseSubscription=function(e,t,n,r){return I?E?(H(!0),void 0!==r&&(oe.returnUrl=r),void 0!==n&&(oe.subscribeMethod=n),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0, +;var n=e.requestFileSystem(1,w);return U.d("Get GameInfo, fly my minipony!"),n.then(function(e){return U.i("Space is ok, can download:",w,e),v(y)}).then(function(n){return U.d("Ga for game and gamifive info stored!",n),U.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,O.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),U.d("unzip:",t.id,O.TEMP_DIR+y),e._promiseZip(n.path,O.TEMP_DIR+y,r("unzip"))}).then(function(n){U.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,w=d*Math.pow(1024,f?p.MB:p.KB),y=t.id;return s.then(function(e){return U.d("Exists",e),e?(k=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(k=!0,i())})},r.prototype.play=function(t){U.d("Play",t);var n=O.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return g(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){U.d("Removing game",t);var n=e.dirExists(O.CACHE_DIR+t+".zip"),r=e.dirExists(O.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(U.d("Removed in cache",n[0]),r.push(e.removeFile(O.CACHE_DIR+t+".zip"))),n[1]&&(U.d("Removed",n[1]),r.push(e.removeDir(O.GAMES_DIR+t))),0===r.length&&U.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return k},r.prototype.abortDownload=function(){return this.isDownloading()?(U.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,k=!1),!0):(U.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return U.d("Get games list"),e.readDir(O.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=O.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(U.d("Read meta.json:",n),U.d("GAMEOVER_TEMPLATE path",O.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(O.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return U.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(O.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(O.GAMES_DIR).then(function(t){return U.d("All games deleted!",t),e.createDir(O.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(T.bundle_games.length>0){U.d("Games bundle in configuration",T.bundle_games);var t,n=T.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){U.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(K.hasOwnProperty("webappsfixes")&&"object"==typeof K.webappsfixes){t=!0;for(var e in K.webappsfixes)if(K.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){m("[webappsFixes] applying fix: "+e);var r=n[e](K.webappsfixes[e]);r&&w("[webappsFixes] fix '"+e+"' failed: "+r)}else w("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(_()&&!e.platforms.ios)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(b()&&!e.platforms.android)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(m("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),m("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return w("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!K.statusbar)return;e=K.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},X=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(_()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){m("[share] Share completed? "+e.completed),m("[share] Shared to app: "+e.app),n(e)},a=function(e){w("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){m("[share] Facebook share completed, result: ",e),t(e)},i=function(e){w("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){m("[share] Twitter share completed, result: ",e),t(e)},i=function(e){w("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){m("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){w("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){m("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){m("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(m("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(w("[share] type not valid"),n("type not valid"))):(w("[share] missing parameter url"),n("missing parameter url")):(w("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return I?E?new Promise(function(t,n){X.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return I?E?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(X.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){w(e),n(e)})}):(w("[share] missing parameter url"),Promise.reject("missing parameter url")):(w("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(w("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var Y=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){h().then(function(e){f&&f.type&&"online"===f.type?(m("[push] going to url: ",e),A(e)):w("[push] i'm offline not going to url")}).catch(function(e){w("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var p=function(){var e=window.cordova.file.applicationStorageDirectory;return _()&&(e+="Documents/"),e},h=function(){return s.file.fileExists(p()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(p()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},g=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(p(),"SGpushUrl").then(function(e){return m("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){w("[push] error sg create SGpushUrl file",e)})},b=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();m("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,p=1732584193,f=-271733879,h=-1732584194,g=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function p(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function f(e){return unescape(encodeURIComponent(e))}function h(e){return l(f(e))}function g(e){return p(h(e))}function m(e,t){return d(f(e),f(t))}function w(e,t){return p(m(e,t))}function v(e,t,n){return t?n?m(t,e):w(t,e):n?h(e):g(e)}return v}(),ne=function(e){if(void 0===window.SpinnerDialog)return w("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},re=function(){return void 0===window.SpinnerDialog?w("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=ne,window.stopLoading=re,a.inAppPurchaseSubscription=function(e,t,n,r){return I?E?(H(!0),void 0!==r&&(oe.returnUrl=r),void 0!==n&&(oe.subscribeMethod=n),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0, oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(),window.store.order(oe.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.inAppRestore=function(e,t,n,r){return I?E?(void 0!==n&&(oe.subscribeMethod=n),void 0!==r&&(oe.returnUrl=r),oe.callbackSuccess=e,oe.callbackError=t,oe.inappPurchaseCalled=!0,void oe.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},a.inAppProductInfo=function(e){if(e.productId||(e.productId=oe.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return w("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!I)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!E)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(oe.subscribeMethod=e.subscriptionUrl,oe.requestedListingProductId=e.productId,oe.callbackListingSuccess=e.callbackListingSuccess,oe.callbackPurchaseSuccess=e.callbackPurchaseSuccess,oe.callbackListingError=e.callbackError,oe.inappProductInfoCalled=!0,oe.productsInfo[e.productId])try{oe.callbackListingSuccess(oe.productsInfo[e.productId])}catch(e){w("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return oe.lastCreateUserProduct&&oe.lastCreateUserToken?(oe.createUser(oe.lastCreateUserProduct,oe.lastCreateUserToken),!0):(oe.doRefresh(!0),!0)};var ie=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(b()?n=e.productsIdAndroid:_()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,m("[IAPlight] getProducts ok",e),e}).catch(function(e){w("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(m("[IAPlight] subscribe ok",t),_())return e.getActiveSubscriptionsInfo().then(function(e){if(m("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(b()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return w("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw w("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){m("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),m(JSON.stringify(e)),m(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){m("IAP> Purchase approved."),m(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){m("subscription verified ",e)},onStoreReady:function(){m("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(m("[IAP] > Product Owned."),!e.transaction.id&&_())return w("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),_()&&window.localStorage.setItem("transaction_id",e.transaction.id),b()){var t=e.transaction.purchaseToken+"|"+O+"|"+oe.id;m("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||oe.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(m("[IAP] appStoreReceipt: "+t.appStoreReceipt),oe.createUser(e,t.appStoreReceipt)):m("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){H(!1),oe.callbackError({iap_cancelled:1,return_url:oe.returnUrl}),m("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){m("[IAP] ORDER APPROVED "+oe.id),e.finish()},error:function(e){H(!1),w("[IAP] error: "+e),oe.callbackError({iap_error:1,return_url:oe.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(m("[IAP] createUser start "),!oe.inappProductInfoCalled&&!oe.inappPurchaseCalled)return oe.lastCreateUserProduct=e,void(oe.lastCreateUserToken=t);if(!oe.subscribeMethod)return void w("[IAP] createUser configuration error: missing api url.");var n=oe.getRandomEmail(),r=1;b()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=oe.subscribeMethod,o={paymethod:oe.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:oe.returnUrl,inapp_pwd:oe.getPassword(t),hybrid:1};oe.lastCreateuserUrl=i,oe.lastCreateuserData=o;var a=function(e){if(oe.createUserAttempt<=oe.maxCreateUserAttempt)w("[IAP] createUser failed "+oe.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{w("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:oe.returnUrl};H(!1),oe.inappPurchaseCalled?oe.callbackError(t):oe.inappProductInfoCalled&&oe.callbackListingError(t)}},s=function(e){m("[IAP] createUser success ",e);try{e.device_id=y.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),H(!1),oe.callbackSuccess(e),oe.inappPurchaseCalled?oe.callbackSuccess(e):oe.inappProductInfoCalled&&oe.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){oe.createUserAttempt=oe.createUserAttempt+1,m("[IAP] createUser attempt: "+oe.createUserAttempt+" with timeout: "+c+"sec."),m("[IAP] POST createUser: "+oe.lastCreateuserUrl+" params: "+JSON.stringify(oe.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(oe.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(oe.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){m("[IAP] createUser end"),H(!1)}).go(),c+=5},10)};oe.createUserAttempt=0,u()}},ae=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return w("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return w("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});m("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){w("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return w("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});m("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){w("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(w("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(w("[globalization] getLocaleName: not initialized!"),!1)},e}();a.facebookLogin=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){m("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){w("Got FB login error:",e),n({error:e})})},a.facebookShare=function(e,t,n){if(!I)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){w("Got FB share error:",e),n({error:e})})};var se=function(){deltadna.registerPushCallback(ue)},ce=function(e){w("[DeltaDNA] error: "+e)},ue=function(e){return b()&&e.payload&&e.payload.url&&!e.foreground?A(e.payload.url):_()&&e.url?A(e.url):void 0},le=function(){var e={},t={},n=function(n){m("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(w("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(w("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&m("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return w("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),de=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return w("[appsflyer] missing cordova plugin");if(void 0===K.appsflyer_devkey)return w("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:K.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(_()){if(void 0===K.appstore_appid)return w("[appsflyer] missing manifest configuration: appstore_appid");n.appId=K.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}ee.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();a.setConversionDataCallback=function(e){de.setCallback(e)};var pe=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return m("[analytics] callback not set!");try{e(t)}catch(e){w("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();a.setAnalyticsCallback=function(e){pe.setCallback(e)};var fe={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(fe.DefaultOptions=e),AdMob&&(fe.AdMobSupport=!0,fe.initAdMob(e,t,n)),MoPub&&(fe.MoPubSupport=!0),!0},isAdMobSupported:function(){return fe.AdMobSupport},isMoPubSupported:function(){return fe.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=fe.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=fe.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=fe.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=fe.getUserAgent();e||fe.isObjEmpty(fe.DefaultOptions)||(e=fe.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?fe.AdSize.LEADERBOARD:t>=468&&e>=60?fe.AdSize.BANNER:t>=320&&e>=50?fe.AdSize.BANNER:void 0}};return a.game=s.game._public,a.file=s.file,a.AdManager=s.AdManager,a}); \ No newline at end of file diff --git a/package.json b/package.json index 3d45a56..a5dd909 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stargatejs-apps", - "version": "0.13.4", + "version": "0.13.5", "description": "StargateJS for HTML5 apps", "main": "dist/stargate.js", "scripts": { From b63af3d50552cf7f16d53d2b5493ca5c1a0b006c Mon Sep 17 00:00:00 2001 From: Mirco Cipriani Date: Thu, 3 Aug 2017 11:36:27 +0200 Subject: [PATCH 12/13] check loacalstorage support --- src/stargate.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/stargate.js b/src/stargate.js index 58d2548..07de0c1 100644 --- a/src/stargate.js +++ b/src/stargate.js @@ -655,7 +655,7 @@ var _isHybridEnvironment = function(location) { return true; } - if (window.localStorage.getItem('hybrid')) { + if (hasLocalStorage && window.localStorage.getItem('hybrid')) { return true; } @@ -668,6 +668,17 @@ var _isHybridEnvironment = function(location) { return false; }; +var hasLocalStorage = function () { + var isLocalStorageSupported = false;     + try {       + window.localStorage.setItem('newton-test', 'pippo');       + isLocalStorageSupported = window.localStorage.getItem('newton-test') === 'pippo'; + return isLocalStorageSupported;     + } catch (e) { + return isLocalStorageSupported; + } +}; + var setBusy = function(value) { if (value) { startLoading(); From ba9295beb1b3f45495d71c1ba3362026f3717b0b Mon Sep 17 00:00:00 2001 From: Mirco Cipriani Date: Thu, 3 Aug 2017 11:38:05 +0200 Subject: [PATCH 13/13] 0.13.6 --- dist/bower/stargate.js | 15 +++++++++++++-- dist/bower/stargate.min.js | 8 ++++---- dist/stargate.js | 15 +++++++++++++-- dist/stargate.min.js | 6 +++--- package.json | 2 +- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/dist/bower/stargate.js b/dist/bower/stargate.js index 25f70a3..15d0c08 100644 --- a/dist/bower/stargate.js +++ b/dist/bower/stargate.js @@ -18,7 +18,7 @@ } }(this, function () { // Public interface - var stargatePackageVersion = "0.13.5"; + var stargatePackageVersion = "0.13.6"; var stargatePublic = {}; var stargateModules = {}; @@ -3491,7 +3491,7 @@ var _isHybridEnvironment = function(location) { return true; } - if (window.localStorage.getItem('hybrid')) { + if (hasLocalStorage && window.localStorage.getItem('hybrid')) { return true; } @@ -3504,6 +3504,17 @@ var _isHybridEnvironment = function(location) { return false; }; +var hasLocalStorage = function () { + var isLocalStorageSupported = false;     + try {       + window.localStorage.setItem('newton-test', 'pippo');       + isLocalStorageSupported = window.localStorage.getItem('newton-test') === 'pippo'; + return isLocalStorageSupported;     + } catch (e) { + return isLocalStorageSupported; + } +}; + var setBusy = function(value) { if (value) { startLoading(); diff --git a/dist/bower/stargate.min.js b/dist/bower/stargate.min.js index 7f4dbd1..7266eb5 100644 --- a/dist/bower/stargate.min.js +++ b/dist/bower/stargate.min.js @@ -1,9 +1,9 @@ /*! * StargateJS Apps - * v0.13.5 + * v0.13.6 * Copyright 2015 DMobileLab. http://buongiorno.com/ * See LICENSE in this repository for license information */ -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.Stargate=t()}(this,function(){function e(e){p.type=e.type,p.networkState=navigator.connection.type,"function"==typeof f&&f(p)}function t(){document.addEventListener("offline",e,!1),document.addEventListener("online",e,!1)}function n(){p.networkState=navigator.connection.type,"none"===navigator.connection.type?p.type="offline":p.type="online"}function r(e){if("android"==window.device.platform.toLowerCase())window.navigator.app.loadUrl(e);else if("ios"==window.device.platform.toLowerCase()&&-1!==e.indexOf("file:///")){var t=e.split("?")[0];h("Without qs",t),window.resolveLocalFileSystemURL(t,function(e){var t=e.toInternalURL()+"?hybrid=1";h("Redirect to",t),window.location.href=t},m)}else window.location.href=e}function i(){var e=window.cordova.file.applicationDirectory+"www/manifest.json";return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)}).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})}).then(function(e){var t="";try{t=window.JSON.parse(e)}catch(e){return Promise.reject(e)}return Promise.resolve(t)}).catch(function(e){console.error("getManifestWithCordovaFilePlugin() error:"+e,e)})}function o(){return window.hostedwebapp?new Promise(function(e,t){window.hostedwebapp.getManifest(function(t){e(t)},function(e){m(e),t(new Error(e))})}):window.cordova.file?i():(m("getManifest() no available reading mechanism!"),Promise.resolve({}))}var a={},s={};!function(e){function t(e,n,r){this.level=t.levels[e.toUpperCase()],this.styles=r||{background:"white",color:"black"},this.tag="%c "+n+" ",this.isstaging="1"==="IS_STAGING = 1".slice(-1),this.styleString="background:"+this.styles.background+";color:"+this.styles.color+";";var i=function(){if(arguments.length<1)return"";for(var e=Array.prototype.slice.call(arguments[0]),t="",n=0;n0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(s),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(s,s.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(C=O(C,t)),j.d("Initialized called with:",C),!e)return Promise.reject("Missing file module!");try{S=window.cordova.file.applicationStorageDirectory,b=window.cordova.file.cacheDirectory,A=window.cordova.file.tempDirectory,P=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",_=window.cordova.file.dataDirectory}catch(e){return j.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(S+="Documents/"),"android"==window.device.platform.toLowerCase()&&(A=b),k.SDK_DIR=S+"scripts/",k.SDK_RELATIVE_DIR="../../scripts/",k.GAMEOVER_RELATIVE_DIR="../../gameover_template/",k.GAMES_DIR=S+"games/",k.BASE_DIR=S,k.CACHE_DIR=b,k.TEMP_DIR=A,k.CORDOVAJS=P+"cordova.js",k.CORDOVA_PLUGINS_JS=P+"cordova_plugins.js",k.STARGATEJS=P+"js/stargate.js",k.DATA_DIR=_,k.GAMEOVER_DIR=k.BASE_DIR+"gameover_template/",k.WWW_DIR=P,j.i("cordova JS dir to include",k.CORDOVAJS),n.game._public.BASE_DIR=k.BASE_DIR,n.game._public.OFFLINE_INDEX=k.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(k.BASE_DIR,"games"),a=e.createDir(k.BASE_DIR,"scripts"),u=e.fileExists(k.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(L))}),l=e.fileExists(k.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return j.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(k.BASE_DIR+"gameover_template"),e.dirExists(k.SDK_DIR+"plugins"),e.fileExists(k.SDK_DIR+"cordova.js"),e.fileExists(k.SDK_DIR+"cordova_plugins.js"),e.fileExists(k.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(k.WWW_DIR+"gameover_template",k.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(k.WWW_DIR+"plugins",k.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(k.CORDOVAJS,k.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(k.CORDOVA_PLUGINS_JS,k.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(k.WWW_DIR+"js/gamesFixes.js",k.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=D(C.sdk_url,{v:t.getTime()});return""===C.sdk_url||void 0===C.sdk_url||null===C.sdk_url?(j.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(k.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(j.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,k.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(k.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return j.d("Serialized dom",r),r}).then(function(t){return j.d("Write dom:",r,t),e.write(r,t)})}function w(e){return new RegExp(/.*\.html?$/i).test(e)}function h(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=k.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return j.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function m(){return j.i("readUserJson",k.BASE_DIR+"user.json"),e.readFileAsJSON(k.BASE_DIR+"user.json")}function v(e){return m().then(function(t){if(!t.ponyUrl)throw j.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];j.d("PONYVALUE",n);var r=D(C.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,j.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return j.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(k.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return j.d("writing offlineData.json",t),e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var S,b,A,P,_,I,E=t.Logger,D=t.composeApiString,R=t.jsonpRequest,O=t.extend,k={},C={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},T=!1,L={GaForGame:{},GamifiveInfo:{},queues:{}},N={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},j=new E("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,m);return j.d("Get GameInfo, fly my minipony!"),n.then(function(e){return j.i("Space is ok, can download:",m,e),v(y)}).then(function(n){return j.d("Ga for game and gamifive info stored!",n),j.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,k.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),j.d("unzip:",t.id,k.TEMP_DIR+y),e._promiseZip(n.path,k.TEMP_DIR+y,r("unzip"))}).then(function(n){j.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,m=d*Math.pow(1024,p?f.MB:f.KB),y=t.id;return s.then(function(e){return j.d("Exists",e),e?(T=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(T=!0,i())})},r.prototype.play=function(t){j.d("Play",t);var n=k.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return w(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){j.d("Removing game",t);var n=e.dirExists(k.CACHE_DIR+t+".zip"),r=e.dirExists(k.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(j.d("Removed in cache",n[0]),r.push(e.removeFile(k.CACHE_DIR+t+".zip"))),n[1]&&(j.d("Removed",n[1]),r.push(e.removeDir(k.GAMES_DIR+t))),0===r.length&&j.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return T},r.prototype.abortDownload=function(){return this.isDownloading()?(j.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,T=!1),!0):(j.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return j.d("Get games list"),e.readDir(k.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=k.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(j.d("Read meta.json:",n),j.d("GAMEOVER_TEMPLATE path",k.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(k.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return j.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(k.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(k.GAMES_DIR).then(function(t){return j.d("All games deleted!",t),e.createDir(k.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(C.bundle_games.length>0){j.d("Games bundle in configuration",C.bundle_games);var t,n=C.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){j.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(H.hasOwnProperty("webappsfixes")&&"object"==typeof H.webappsfixes){t=!0;for(var e in H.webappsfixes)if(H.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){h("[webappsFixes] applying fix: "+e);var r=n[e](H.webappsfixes[e]);r&&m("[webappsFixes] fix '"+e+"' failed: "+r)}else m("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(b()&&!e.platforms.ios)return void h("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(S()&&!e.platforms.android)return void h("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(h("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),h("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return m("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!H.statusbar)return;e=H.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},$=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(b()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){h("[share] Share completed? "+e.completed),h("[share] Shared to app: "+e.app),n(e)},a=function(e){m("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){h("[share] Facebook share completed, result: ",e),t(e)},i=function(e){m("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){h("[share] Twitter share completed, result: ",e),t(e)},i=function(e){m("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){h("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){m("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){h("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){h("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(h("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(m("[share] type not valid"),n("type not valid"))):(m("[share] missing parameter url"),n("missing parameter url")):(m("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return E?D?new Promise(function(t,n){$.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return E?D?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push($.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){m(e),n(e)})}):(m("[share] missing parameter url"),Promise.reject("missing parameter url")):(m("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(m("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var ee=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){g().then(function(e){p&&p.type&&"online"===p.type?(h("[push] going to url: ",e),_(e)):m("[push] i'm offline not going to url")}).catch(function(e){m("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var f=function(){var e=window.cordova.file.applicationStorageDirectory;return b()&&(e+="Documents/"),e},g=function(){return s.file.fileExists(f()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(f()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},w=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(f(),"SGpushUrl").then(function(e){return h("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){m("[push] error sg create SGpushUrl file",e)})},S=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();h("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,f=1732584193,p=-271733879,g=-1732584194,w=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function f(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function p(e){return unescape(encodeURIComponent(e))}function g(e){return l(p(e))}function w(e){return f(g(e))}function h(e,t){return d(p(e),p(t))}function m(e,t){return f(h(e,t))}function v(e,t,n){return t?n?h(t,e):m(t,e):n?g(e):w(e)}return v}(),re=function(e){if(void 0===window.SpinnerDialog)return m("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},ie=function(){return void 0===window.SpinnerDialog?m("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=re,window.stopLoading=ie,a.inAppPurchaseSubscription=function(e,t,n,r){return E?D?(W(!0),void 0!==r&&(ae.returnUrl=r),void 0!==n&&(ae.subscribeMethod=n),ae.callbackSuccess=e,ae.callbackError=t,ae.inappPurchaseCalled=!0,ae.lastCreateUserProduct&&ae.lastCreateUserToken?(ae.createUser(ae.lastCreateUserProduct,ae.lastCreateUserToken),!0):(ae.doRefresh(),window.store.order(ae.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.inAppRestore=function(e,t,n,r){return E?D?(void 0!==n&&(ae.subscribeMethod=n),void 0!==r&&(ae.returnUrl=r),ae.callbackSuccess=e,ae.callbackError=t,ae.inappPurchaseCalled=!0,void ae.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},a.inAppProductInfo=function(e){if(e.productId||(e.productId=ae.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return m("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!E)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!D)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(ae.subscribeMethod=e.subscriptionUrl,ae.requestedListingProductId=e.productId,ae.callbackListingSuccess=e.callbackListingSuccess,ae.callbackPurchaseSuccess=e.callbackPurchaseSuccess,ae.callbackListingError=e.callbackError,ae.inappProductInfoCalled=!0,ae.productsInfo[e.productId])try{ae.callbackListingSuccess(ae.productsInfo[e.productId])}catch(e){m("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return ae.lastCreateUserProduct&&ae.lastCreateUserToken?(ae.createUser(ae.lastCreateUserProduct,ae.lastCreateUserToken),!0):(ae.doRefresh(!0),!0)};var oe=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(S()?n=e.productsIdAndroid:b()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,h("[IAPlight] getProducts ok",e),e}).catch(function(e){m("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(h("[IAPlight] subscribe ok",t),b())return e.getActiveSubscriptionsInfo().then(function(e){if(h("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(S()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return m("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw m("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){h("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),h(JSON.stringify(e)),h(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){h("IAP> Purchase approved."),h(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){h("subscription verified ",e)},onStoreReady:function(){h("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(h("[IAP] > Product Owned."),!e.transaction.id&&b())return m("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),b()&&window.localStorage.setItem("transaction_id",e.transaction.id),S()){var t=e.transaction.purchaseToken+"|"+C+"|"+ae.id;h("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||ae.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(h("[IAP] appStoreReceipt: "+t.appStoreReceipt),ae.createUser(e,t.appStoreReceipt)):h("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){W(!1),ae.callbackError({iap_cancelled:1,return_url:ae.returnUrl}),h("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){h("[IAP] ORDER APPROVED "+ae.id),e.finish()},error:function(e){W(!1),m("[IAP] error: "+e),ae.callbackError({iap_error:1,return_url:ae.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(h("[IAP] createUser start "),!ae.inappProductInfoCalled&&!ae.inappPurchaseCalled)return ae.lastCreateUserProduct=e,void(ae.lastCreateUserToken=t);if(!ae.subscribeMethod)return void m("[IAP] createUser configuration error: missing api url.");var n=ae.getRandomEmail(),r=1 -;S()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=ae.subscribeMethod,o={paymethod:ae.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:ae.returnUrl,inapp_pwd:ae.getPassword(t),hybrid:1};ae.lastCreateuserUrl=i,ae.lastCreateuserData=o;var a=function(e){if(ae.createUserAttempt<=ae.maxCreateUserAttempt)m("[IAP] createUser failed "+ae.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{m("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:ae.returnUrl};W(!1),ae.inappPurchaseCalled?ae.callbackError(t):ae.inappProductInfoCalled&&ae.callbackListingError(t)}},s=function(e){h("[IAP] createUser success ",e);try{e.device_id=y.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),W(!1),ae.callbackSuccess(e),ae.inappPurchaseCalled?ae.callbackSuccess(e):ae.inappProductInfoCalled&&ae.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ae.createUserAttempt=ae.createUserAttempt+1,h("[IAP] createUser attempt: "+ae.createUserAttempt+" with timeout: "+c+"sec."),h("[IAP] POST createUser: "+ae.lastCreateuserUrl+" params: "+JSON.stringify(ae.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(ae.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(ae.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){h("[IAP] createUser end"),W(!1)}).go(),c+=5},10)};ae.createUserAttempt=0,u()}},se=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return m("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return m("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});h("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){m("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return m("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});h("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){m("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(m("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(m("[globalization] getLocaleName: not initialized!"),!1)},e}();a.facebookLogin=function(e,t,n){if(!E)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){h("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){m("Got FB login error:",e),n({error:e})})},a.facebookShare=function(e,t,n){if(!E)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){m("Got FB share error:",e),n({error:e})})};var ce=function(){deltadna.registerPushCallback(le)},ue=function(e){m("[DeltaDNA] error: "+e)},le=function(e){return S()&&e.payload&&e.payload.url&&!e.foreground?_(e.payload.url):b()&&e.url?_(e.url):void 0},de=function(){var e={},t={},n=function(n){h("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(m("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(m("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&h("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return m("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),fe=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return m("[appsflyer] missing cordova plugin");if(void 0===H.appsflyer_devkey)return m("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:H.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(b()){if(void 0===H.appstore_appid)return m("[appsflyer] missing manifest configuration: appstore_appid");n.appId=H.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}te.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();a.setConversionDataCallback=function(e){fe.setCallback(e)};var pe=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return h("[analytics] callback not set!");try{e(t)}catch(e){m("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();a.setAnalyticsCallback=function(e){pe.setCallback(e)};var ge={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(ge.DefaultOptions=e),AdMob&&(ge.AdMobSupport=!0,ge.initAdMob(e,t,n)),MoPub&&(ge.MoPubSupport=!0),!0},isAdMobSupported:function(){return ge.AdMobSupport},isMoPubSupported:function(){return ge.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=ge.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=ge.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=ge.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?ge.AdSize.LEADERBOARD:t>=468&&e>=60?ge.AdSize.BANNER:t>=320&&e>=50?ge.AdSize.BANNER:void 0}};return a.game=s.game._public,a.file=s.file,a.AdManager=s.AdManager,a}); \ No newline at end of file +!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.Stargate=t()}(this,function(){function e(e){p.type=e.type,p.networkState=navigator.connection.type,"function"==typeof f&&f(p)}function t(){document.addEventListener("offline",e,!1),document.addEventListener("online",e,!1)}function n(){p.networkState=navigator.connection.type,"none"===navigator.connection.type?p.type="offline":p.type="online"}function r(e){if("android"==window.device.platform.toLowerCase())window.navigator.app.loadUrl(e);else if("ios"==window.device.platform.toLowerCase()&&-1!==e.indexOf("file:///")){var t=e.split("?")[0];h("Without qs",t),window.resolveLocalFileSystemURL(t,function(e){var t=e.toInternalURL()+"?hybrid=1";h("Redirect to",t),window.location.href=t},m)}else window.location.href=e}function i(){var e=window.cordova.file.applicationDirectory+"www/manifest.json";return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)}).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})}).then(function(e){var t="";try{t=window.JSON.parse(e)}catch(e){return Promise.reject(e)}return Promise.resolve(t)}).catch(function(e){console.error("getManifestWithCordovaFilePlugin() error:"+e,e)})}function o(){return window.hostedwebapp?new Promise(function(e,t){window.hostedwebapp.getManifest(function(t){e(t)},function(e){m(e),t(new Error(e))})}):window.cordova.file?i():(m("getManifest() no available reading mechanism!"),Promise.resolve({}))}var a={},s={};!function(e){function t(e,n,r){this.level=t.levels[e.toUpperCase()],this.styles=r||{background:"white",color:"black"},this.tag="%c "+n+" ",this.isstaging="1"==="IS_STAGING = 1".slice(-1),this.styleString="background:"+this.styles.background+";color:"+this.styles.color+";";var i=function(){if(arguments.length<1)return"";for(var e=Array.prototype.slice.call(arguments[0]),t="",n=0;n0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(s),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(s,s.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(C=O(C,t)),j.d("Initialized called with:",C),!e)return Promise.reject("Missing file module!");try{S=window.cordova.file.applicationStorageDirectory,b=window.cordova.file.cacheDirectory,A=window.cordova.file.tempDirectory,P=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",_=window.cordova.file.dataDirectory}catch(e){return j.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(S+="Documents/"),"android"==window.device.platform.toLowerCase()&&(A=b),k.SDK_DIR=S+"scripts/",k.SDK_RELATIVE_DIR="../../scripts/",k.GAMEOVER_RELATIVE_DIR="../../gameover_template/",k.GAMES_DIR=S+"games/",k.BASE_DIR=S,k.CACHE_DIR=b,k.TEMP_DIR=A,k.CORDOVAJS=P+"cordova.js",k.CORDOVA_PLUGINS_JS=P+"cordova_plugins.js",k.STARGATEJS=P+"js/stargate.js",k.DATA_DIR=_,k.GAMEOVER_DIR=k.BASE_DIR+"gameover_template/",k.WWW_DIR=P,j.i("cordova JS dir to include",k.CORDOVAJS),n.game._public.BASE_DIR=k.BASE_DIR,n.game._public.OFFLINE_INDEX=k.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(k.BASE_DIR,"games"),a=e.createDir(k.BASE_DIR,"scripts"),u=e.fileExists(k.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(L))}),l=e.fileExists(k.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(k.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return j.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(k.BASE_DIR+"gameover_template"),e.dirExists(k.SDK_DIR+"plugins"),e.fileExists(k.SDK_DIR+"cordova.js"),e.fileExists(k.SDK_DIR+"cordova_plugins.js"),e.fileExists(k.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(k.WWW_DIR+"gameover_template",k.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(k.WWW_DIR+"plugins",k.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(k.CORDOVAJS,k.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(k.CORDOVA_PLUGINS_JS,k.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(k.WWW_DIR+"js/gamesFixes.js",k.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=D(C.sdk_url,{v:t.getTime()});return""===C.sdk_url||void 0===C.sdk_url||null===C.sdk_url?(j.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(k.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(j.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,k.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(k.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return j.d("Serialized dom",r),r}).then(function(t){return j.d("Write dom:",r,t),e.write(r,t)})}function w(e){return new RegExp(/.*\.html?$/i).test(e)}function h(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=k.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return j.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function m(){return j.i("readUserJson",k.BASE_DIR+"user.json"),e.readFileAsJSON(k.BASE_DIR+"user.json")}function v(e){return m().then(function(t){if(!t.ponyUrl)throw j.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];j.d("PONYVALUE",n);var r=D(C.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,j.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return j.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(k.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return j.d("writing offlineData.json",t),e.write(k.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var S,b,A,P,_,I,E=t.Logger,D=t.composeApiString,R=t.jsonpRequest,O=t.extend,k={},C={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},T=!1,L={GaForGame:{},GamifiveInfo:{},queues:{}},N={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},j=new E("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"});var n=e.requestFileSystem(1,m);return j.d("Get GameInfo, fly my minipony!"),n.then(function(e){return j.i("Space is ok, can download:",m,e),v(y)}).then(function(n){return j.d("Ga for game and gamifive info stored!",n),j.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,k.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),j.d("unzip:",t.id,k.TEMP_DIR+y),e._promiseZip(n.path,k.TEMP_DIR+y,r("unzip"))}).then(function(n){j.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,m=d*Math.pow(1024,p?f.MB:f.KB),y=t.id;return s.then(function(e){return j.d("Exists",e),e?(T=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(T=!0,i())})},r.prototype.play=function(t){j.d("Play",t);var n=k.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return w(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){j.d("Removing game",t);var n=e.dirExists(k.CACHE_DIR+t+".zip"),r=e.dirExists(k.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(j.d("Removed in cache",n[0]),r.push(e.removeFile(k.CACHE_DIR+t+".zip"))),n[1]&&(j.d("Removed",n[1]),r.push(e.removeDir(k.GAMES_DIR+t))),0===r.length&&j.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return T},r.prototype.abortDownload=function(){return this.isDownloading()?(j.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,T=!1),!0):(j.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return j.d("Get games list"),e.readDir(k.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=k.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(j.d("Read meta.json:",n),j.d("GAMEOVER_TEMPLATE path",k.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(k.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return j.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(k.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(k.GAMES_DIR).then(function(t){return j.d("All games deleted!",t),e.createDir(k.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(C.bundle_games.length>0){j.d("Games bundle in configuration",C.bundle_games);var t,n=C.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){j.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(Y.hasOwnProperty("webappsfixes")&&"object"==typeof Y.webappsfixes){t=!0;for(var e in Y.webappsfixes)if(Y.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){h("[webappsFixes] applying fix: "+e);var r=n[e](Y.webappsfixes[e]);r&&m("[webappsFixes] fix '"+e+"' failed: "+r)}else m("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(b()&&!e.platforms.ios)return void h("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(S()&&!e.platforms.android)return void h("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(h("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),h("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return m("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!Y.statusbar)return;e=Y.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},ee=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(b()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){h("[share] Share completed? "+e.completed),h("[share] Shared to app: "+e.app),n(e)},a=function(e){m("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){h("[share] Facebook share completed, result: ",e),t(e)},i=function(e){m("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){h("[share] Twitter share completed, result: ",e),t(e)},i=function(e){m("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){h("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){m("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){h("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){h("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(h("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(m("[share] type not valid"),n("type not valid"))):(m("[share] missing parameter url"),n("missing parameter url")):(m("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return E?D?new Promise(function(t,n){ee.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return E?D?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(ee.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){m(e),n(e)})}):(m("[share] missing parameter url"),Promise.reject("missing parameter url")):(m("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(m("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var te=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){g().then(function(e){p&&p.type&&"online"===p.type?(h("[push] going to url: ",e),_(e)):m("[push] i'm offline not going to url")}).catch(function(e){m("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var f=function(){var e=window.cordova.file.applicationStorageDirectory;return b()&&(e+="Documents/"),e},g=function(){return s.file.fileExists(f()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(f()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},w=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(f(),"SGpushUrl").then(function(e){return h("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){m("[push] error sg create SGpushUrl file",e)})},S=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();h("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,f=1732584193,p=-271733879,g=-1732584194,w=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function f(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function p(e){return unescape(encodeURIComponent(e))}function g(e){return l(p(e))}function w(e){return f(g(e))}function h(e,t){return d(p(e),p(t))}function m(e,t){return f(h(e,t))}function v(e,t,n){return t?n?h(t,e):m(t,e):n?g(e):w(e)}return v}(),ie=function(e){if(void 0===window.SpinnerDialog)return m("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},oe=function(){return void 0===window.SpinnerDialog?m("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=ie,window.stopLoading=oe,a.inAppPurchaseSubscription=function(e,t,n,r){return E?D?(H(!0),void 0!==r&&(se.returnUrl=r),void 0!==n&&(se.subscribeMethod=n),se.callbackSuccess=e,se.callbackError=t,se.inappPurchaseCalled=!0,se.lastCreateUserProduct&&se.lastCreateUserToken?(se.createUser(se.lastCreateUserProduct,se.lastCreateUserToken),!0):(se.doRefresh(),window.store.order(se.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.inAppRestore=function(e,t,n,r){return E?D?(void 0!==n&&(se.subscribeMethod=n),void 0!==r&&(se.returnUrl=r),se.callbackSuccess=e,se.callbackError=t,se.inappPurchaseCalled=!0,void se.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},a.inAppProductInfo=function(e){if(e.productId||(e.productId=se.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return m("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!E)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!D)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(se.subscribeMethod=e.subscriptionUrl,se.requestedListingProductId=e.productId,se.callbackListingSuccess=e.callbackListingSuccess,se.callbackPurchaseSuccess=e.callbackPurchaseSuccess,se.callbackListingError=e.callbackError,se.inappProductInfoCalled=!0,se.productsInfo[e.productId])try{se.callbackListingSuccess(se.productsInfo[e.productId])}catch(e){m("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return se.lastCreateUserProduct&&se.lastCreateUserToken?(se.createUser(se.lastCreateUserProduct,se.lastCreateUserToken),!0):(se.doRefresh(!0),!0)};var ae=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(S()?n=e.productsIdAndroid:b()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,h("[IAPlight] getProducts ok",e),e}).catch(function(e){m("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(h("[IAPlight] subscribe ok",t),b())return e.getActiveSubscriptionsInfo().then(function(e){if(h("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(S()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return m("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw m("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){h("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),h(JSON.stringify(e)),h(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){h("IAP> Purchase approved."),h(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){h("subscription verified ",e)},onStoreReady:function(){h("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(h("[IAP] > Product Owned."),!e.transaction.id&&b())return m("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),b()&&window.localStorage.setItem("transaction_id",e.transaction.id),S()){var t=e.transaction.purchaseToken+"|"+C+"|"+se.id;h("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||se.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(h("[IAP] appStoreReceipt: "+t.appStoreReceipt),se.createUser(e,t.appStoreReceipt)):h("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){H(!1),se.callbackError({iap_cancelled:1,return_url:se.returnUrl}),h("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){h("[IAP] ORDER APPROVED "+se.id),e.finish()},error:function(e){H(!1),m("[IAP] error: "+e),se.callbackError({iap_error:1,return_url:se.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(h("[IAP] createUser start "),!se.inappProductInfoCalled&&!se.inappPurchaseCalled)return se.lastCreateUserProduct=e,void(se.lastCreateUserToken=t) +;if(!se.subscribeMethod)return void m("[IAP] createUser configuration error: missing api url.");var n=se.getRandomEmail(),r=1;S()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=se.subscribeMethod,o={paymethod:se.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:se.returnUrl,inapp_pwd:se.getPassword(t),hybrid:1};se.lastCreateuserUrl=i,se.lastCreateuserData=o;var a=function(e){if(se.createUserAttempt<=se.maxCreateUserAttempt)m("[IAP] createUser failed "+se.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{m("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:se.returnUrl};H(!1),se.inappPurchaseCalled?se.callbackError(t):se.inappProductInfoCalled&&se.callbackListingError(t)}},s=function(e){h("[IAP] createUser success ",e);try{e.device_id=y.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),H(!1),se.callbackSuccess(e),se.inappPurchaseCalled?se.callbackSuccess(e):se.inappProductInfoCalled&&se.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){se.createUserAttempt=se.createUserAttempt+1,h("[IAP] createUser attempt: "+se.createUserAttempt+" with timeout: "+c+"sec."),h("[IAP] POST createUser: "+se.lastCreateuserUrl+" params: "+JSON.stringify(se.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(se.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(se.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){h("[IAP] createUser end"),H(!1)}).go(),c+=5},10)};se.createUserAttempt=0,u()}},ce=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return m("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return m("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});h("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){m("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return m("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});h("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){m("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(m("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(m("[globalization] getLocaleName: not initialized!"),!1)},e}();a.facebookLogin=function(e,t,n){if(!E)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){h("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){m("Got FB login error:",e),n({error:e})})},a.facebookShare=function(e,t,n){if(!E)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){m("Got FB share error:",e),n({error:e})})};var ue=function(){deltadna.registerPushCallback(de)},le=function(e){m("[DeltaDNA] error: "+e)},de=function(e){return S()&&e.payload&&e.payload.url&&!e.foreground?_(e.payload.url):b()&&e.url?_(e.url):void 0},fe=function(){var e={},t={},n=function(n){h("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(m("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(m("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&h("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return m("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),pe=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return m("[appsflyer] missing cordova plugin");if(void 0===Y.appsflyer_devkey)return m("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:Y.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(b()){if(void 0===Y.appstore_appid)return m("[appsflyer] missing manifest configuration: appstore_appid");n.appId=Y.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}ne.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();a.setConversionDataCallback=function(e){pe.setCallback(e)};var ge=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return h("[analytics] callback not set!");try{e(t)}catch(e){m("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();a.setAnalyticsCallback=function(e){ge.setCallback(e)};var we={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(we.DefaultOptions=e),AdMob&&(we.AdMobSupport=!0,we.initAdMob(e,t,n)),MoPub&&(we.MoPubSupport=!0),!0},isAdMobSupported:function(){return we.AdMobSupport},isMoPubSupported:function(){return we.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=we.getUserAgent();e||we.isObjEmpty(we.DefaultOptions)||(e=we.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=we.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=we.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=we.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=we.getUserAgent();e||we.isObjEmpty(we.DefaultOptions)||(e=we.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=we.getUserAgent();e||we.isObjEmpty(we.DefaultOptions)||(e=we.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=we.getUserAgent();e||we.isObjEmpty(we.DefaultOptions)||(e=we.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=we.getUserAgent();e||we.isObjEmpty(we.DefaultOptions)||(e=we.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=we.getUserAgent();e||we.isObjEmpty(we.DefaultOptions)||(e=we.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=we.getUserAgent();e||we.isObjEmpty(we.DefaultOptions)||(e=we.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?we.AdSize.LEADERBOARD:t>=468&&e>=60?we.AdSize.BANNER:t>=320&&e>=50?we.AdSize.BANNER:void 0}};return a.game=s.game._public,a.file=s.file,a.AdManager=s.AdManager,a}); \ No newline at end of file diff --git a/dist/stargate.js b/dist/stargate.js index c9002cc..be71313 100644 --- a/dist/stargate.js +++ b/dist/stargate.js @@ -3935,7 +3935,7 @@ } }(this, function () { // Public interface - var stargatePackageVersion = "0.13.5"; + var stargatePackageVersion = "0.13.6"; var stargatePublic = {}; var stargateModules = {}; @@ -7408,7 +7408,7 @@ var _isHybridEnvironment = function(location) { return true; } - if (window.localStorage.getItem('hybrid')) { + if (hasLocalStorage && window.localStorage.getItem('hybrid')) { return true; } @@ -7421,6 +7421,17 @@ var _isHybridEnvironment = function(location) { return false; }; +var hasLocalStorage = function () { + var isLocalStorageSupported = false;     + try {       + window.localStorage.setItem('newton-test', 'pippo');       + isLocalStorageSupported = window.localStorage.getItem('newton-test') === 'pippo'; + return isLocalStorageSupported;     + } catch (e) { + return isLocalStorageSupported; + } +}; + var setBusy = function(value) { if (value) { startLoading(); diff --git a/dist/stargate.min.js b/dist/stargate.min.js index 1698a40..2b065d3 100644 --- a/dist/stargate.min.js +++ b/dist/stargate.min.js @@ -1,10 +1,10 @@ /*! * StargateJS Apps - * v0.13.5 + * v0.13.6 * Copyright 2015 DMobileLab. http://buongiorno.com/ * See LICENSE in this repository for license information */ !function(e,t){"use strict";"object"==typeof exports?module.exports=t(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"==typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],t):e.URI=t(e.punycode,e.IPv6,e.SecondLevelDomains,e)}(this,function(e,t,n,r){"use strict";function i(e,t){var n=arguments.length>=1,r=arguments.length>=2;if(!(this instanceof i))return n?r?new i(e,t):new i(e):new i;if(void 0===e){if(n)throw new TypeError("undefined is not a valid argument for URI");e="undefined"!=typeof location?location.href+"":""}return this.href(e),void 0!==t?this.absoluteTo(t):this}function o(e){return e.replace(/([.*+?^=!:()|[\]\/\\])/g,"\\$1")}function a(e){return void 0===e?"Undefined":String(Object.prototype.toString.call(e)).slice(8,-1)}function s(e){return"Array"===a(e)}function c(e,t){var n,r,i={};if("RegExp"===a(t))i=null;else if(s(t))for(n=0,r=t.length;n]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,i.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?«»“”„‘’]+$/},i.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},i.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/,i.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"},i.getDomAttribute=function(e){if(e&&e.nodeName){var t=e.nodeName.toLowerCase();if("input"!==t||"image"===e.type)return i.domAttributes[t]}},i.encode=f,i.decode=decodeURIComponent,i.iso8859=function(){i.encode=escape,i.decode=unescape},i.unicode=function(){i.encode=f,i.decode=decodeURIComponent},i.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/gi,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}},i.encodeQuery=function(e,t){var n=i.encode(e+"");return void 0===t&&(t=i.escapeQuerySpace),t?n.replace(/%20/g,"+"):n},i.decodeQuery=function(e,t){e+="",void 0===t&&(t=i.escapeQuerySpace);try{return i.decode(t?e.replace(/\+/g,"%20"):e)}catch(t){return e}};var y,b={encode:"encode",decode:"decode"},_=function(e,t){return function(n){try{return i[t](n+"").replace(i.characters[e][t].expression,function(n){return i.characters[e][t].map[n]})}catch(e){return n}}};for(y in b)i[y+"PathSegment"]=_("pathname",b[y]),i[y+"UrnPathSegment"]=_("urnpath",b[y]);var S=function(e,t,n){return function(r){var o;o=n?function(e){return i[t](i[n](e))}:i[t];for(var a=(r+"").split(e),s=0,c=a.length;s-1&&(t.fragment=e.substring(n+1)||null,e=e.substring(0,n)),n=e.indexOf("?"),n>-1&&(t.query=e.substring(n+1)||null,e=e.substring(0,n)),"//"===e.substring(0,2)?(t.protocol=null,e=e.substring(2),e=i.parseAuthority(e,t)):(n=e.indexOf(":"))>-1&&(t.protocol=e.substring(0,n)||null,t.protocol&&!t.protocol.match(i.protocol_expression)?t.protocol=void 0:"//"===e.substring(n+1,n+3)?(e=e.substring(n+3),e=i.parseAuthority(e,t)):(e=e.substring(n+1),t.urn=!0)),t.path=e,t},i.parseHost=function(e,t){e=e.replace(/\\/g,"/");var n,r,i=e.indexOf("/");if(-1===i&&(i=e.length),"["===e.charAt(0))n=e.indexOf("]"),t.hostname=e.substring(1,n)||null,t.port=e.substring(n+2,i)||null,"/"===t.port&&(t.port=null);else{var o=e.indexOf(":"),a=e.indexOf("/"),s=e.indexOf(":",o+1);-1!==s&&(-1===a||s-1?r:e.length-1);return o>-1&&(-1===r||o3?Object.keys(n).forEach(function(e){var n=e.match(/^([0-9])([0-9x])([0-9x])$/i);!(n&&n.length>3&&o[1]===n[1])||"x"!==n[2]&&o[2]!==n[2]||"x"!==n[3]&&o[3]!==n[3]||i(e,t)}):n[e]&&i(e,t)}return this},go:function(){var e=t.type||(t.into?"html":"json"),n=u();if("function"==typeof a[e])return a[e].call(this,n)}},a={json:function(e){var t=this;a._xhr.call(this,e,function(e){if(e)try{e=JSON.parse(e)}catch(e){return t.trigger("error",e),null}return e})},html:function(e){a._xhr.call(this,e,function(e){return t.into&&t.into.length&&[].forEach.call(t.into,function(t){t.innerHTML=e}),e})},_xhr:function(e,n){var r,i,o,a,s,u=this,l=t.method||"get",d=!0!==t.sync,p=new XMLHttpRequest,f=t.data,h=t.body,g=(t.headers,this.header("Content-Type")),m=t.timeout;if(!g&&f&&c()&&(this.header("Content-Type","application/x-www-form-urlencoded;charset=utf-8"),g=this.header("Content-Type")),f&&c())if("string"!=typeof h&&(h=""),g.indexOf("json")>-1)try{h=JSON.stringify(f)}catch(e){throw new TypeError("Unable to stringify body's content : "+e.name)}else{a=g&&g.indexOf("x-www-form-urlencoded")>1;for(r in f)h+=a?encodeURIComponent(r)+"="+encodeURIComponent(f[r])+"&":r+"="+f[r]+"\n\r"}s=[l,e,d],t.auth&&(s.push(t.auth.user),s.push(t.auth.passwd)),p.open.apply(p,s);for(i in t.headers)p.setRequestHeader(i,t.headers[i]);p.onprogress=function(e){e.lengthComputable&&u.trigger("progress",e.loaded/e.total)},p.onload=function(){var e=p.responseText;o&&clearTimeout(o),this.status>=200&&this.status<300&&("function"==typeof n&&(e=n(e)),u.trigger("success",e)),u.trigger(this.status,e),u.trigger("end",e)},p.onerror=function(e){o&&clearTimeout(o),u.trigger("error",e,arguments)},m&&(o=setTimeout(function(){u.trigger("timeout",{type:"timeout",expiredAfter:m},p,arguments),p.abort()},m)),p.send(h)},jsonp:function(n){var r,o=this,a=document.querySelector("head"),s=!0!==t.sync,c=t.jsonPaddingName||"callback",u=t.jsonPadding||"_padd"+(new Date).getTime()+Math.floor(1e4*Math.random()),l={};if(e[u])throw new Error("Padding "+u+" already exists. It must be unique.");/^ajajsonp_/.test(u)||(u="ajajsonp_"+u),window[u]=function(e){o.trigger("success",e),a.removeChild(r),window[u]=void 0},l[c]=u,n=i(n,l),r=document.createElement("script"),r.async=s,r.src=n,r.onerror=function(){o.trigger("error",arguments),a.removeChild(r),window[u]=void 0},a.appendChild(r)},script:function(e){var n,r=this,i=document.querySelector("head")||document.querySelector("body"),o=!0!==t.sync;if(!i)throw new Error("Ok, wait a second, you want to load a script, but you don't have at least a head or body tag...");n=document.createElement("script"),n.async=o,n.src=e,n.onerror=function(){r.trigger("error",arguments),i.removeChild(n)},n.onload=function(){r.trigger("success",arguments)},i.appendChild(n)}},s=function(e,n,i,o){if(void 0!==n){if("function"==typeof i)try{n=i.call(r,n)}catch(t){throw new TypeError("Failed to set "+e+" : "+t.message)}return t[e]="function"==typeof o?o.call(this,n):n,this}return"undefined"===t[e]?null:t[e]},c=function(){return["delete","patch","post","put"].indexOf(t.method)>-1},u=function(){var e=t.url,n=void 0===t.cache||!!t.cache,r=t.queryString||"",o=t.data;return!1===n&&(r+="&ajabuster="+(new Date).getTime()),e=i(e,r),o&&!c()&&(e=i(e,o)),e};return o},r={bool:function(e){return!!e},string:function(e){if("string"!=typeof e)throw new TypeError("a string is expected, but "+e+" ["+typeof e+"] given");return e},positiveInteger:function(e){if(parseInt(e)!==e||e<=0)throw new TypeError("an integer is expected, but "+e+" ["+typeof e+"] given");return e},plainObject:function(e){if("object"!=typeof e||e.constructor!==Object)throw new TypeError("an object is expected, but "+e+" ["+typeof e+"] given");return e},type:function(t){if(t=this.string(t),e.indexOf(t.toLowerCase())<0)throw new TypeError("a type in ["+e.join(", ")+"] is expected, but "+t+" given");return t.toLowerCase()},method:function(e){if(e=this.string(e),t.indexOf(e.toLowerCase())<0)throw new TypeError("a method in ["+t.join(", ")+"] is expected, but "+e+" given");return e.toLowerCase()},queryString:function(e){var t={};return"string"==typeof e?e.replace("?","").split("&").forEach(function(e){var n=e.split("=");2===n.length&&(t[decodeURIComponent(n[0])]=decodeURIComponent(n[1]))}):t=e,this.plainObject(t)},selector:function(e){if("string"!=typeof e&&!(e instanceof HTMLElement))throw new TypeError("a selector or an HTMLElement is expected, "+e+" ["+typeof e+"] given");return e},func:function(e){if(e=this.string(e),!/^([a-zA-Z_])([a-zA-Z0-9_\-])+$/.test(e))throw new TypeError("a valid function name is expected, "+e+" ["+typeof e+"] given");return e}},i=function(e,t){var n;if(e=e||"",t)if(-1===e.indexOf("?")&&(e+="?"),"string"==typeof t)e+=t;else if("object"==typeof t)for(n in t)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(t[n]);return e};"function"==typeof define&&define.amd?define([],function(){return n}):"object"==typeof exports?module.exports=n:window.aja=window.aja||n}(),function(e){function t(e,t){return function(){e.apply(t,arguments)}}function n(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],c(e,t(i,this),t(o,this))}function r(e){var t=this;if(null===this._state)return void this._deferreds.push(e);l(function(){var n=t._state?e.onFulfilled:e.onRejected;if(null===n)return void(t._state?e.resolve:e.reject)(t._value);var r;try{r=n(t._value)}catch(t){return void e.reject(t)}e.resolve(r)})}function i(e){try{if(e===this)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void c(t(n,e),t(i,this),t(o,this))}this._state=!0,this._value=e,a.call(this)}catch(e){o.call(this,e)}}function o(e){this._state=!1,this._value=e,a.call(this)}function a(){for(var e=0,t=this._deferreds.length;e0&&(n=n.substring(0,n.length-1)),e+n}function i(e){e=encodeURI(e);var t="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),n="responseType"in t;t.open("GET",e,!0),n&&(t.responseType="json");var r=new Promise(function(e,r){t.onreadystatechange=function(){if(4===t.readyState)try{var i=n?t.response:JSON.parse(t.responseText);e(i)}catch(e){r(e)}}});return t.setRequestHeader("Content-type","application/json; charset=UTF-8"),t.send(),r}function o(e){var t=this;if(t.timeout=3e3,t.called=!1,window.document){var n=Date.now();t.scriptTag=window.document.createElement("script"),e+="&callback=window.__jsonpHandler_"+n,t.scriptTag.src=e,t.scriptTag.type="text/javascript",t.scriptTag.async=!0,t.prom=new Promise(function(e,r){var i="__jsonpHandler_"+n;window[i]=function(n){t.called=!0,e(n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i]},setTimeout(function(){t.called||(r("Timeout jsonp request "+n),t.scriptTag.parentElement.removeChild(t.scriptTag),delete window[i])},t.timeout)}),window.document.getElementsByTagName("head")[0].appendChild(t.scriptTag)}}function a(e,t){var n=t||function(){};return new Promise(function(t,r){function i(){var n;switch(e.responseType){case"blob":n=new Blob([this.response],{type:e.mimeType||"image/jpeg"});break;case"arraybuffer":n=this.response;break;default:n=this.response,t(n)}}var o=new XMLHttpRequest;o.open("GET",e.url,!0),o.responseType=e.responseType||"blob",e.withCredentials&&(o.withCredentials=e.withCredentials);var a=r,s=r;o.addEventListener("progress",n,!1),o.addEventListener("load",i,!1),o.addEventListener("error",s,!1),o.addEventListener("abort",a,!1),o.send(null)})}function s(e,t){var n=Object.prototype.toString.apply({});if(e.toString()!==n||t.toString()!==n)throw new Error("Cannot merge different type");var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);for(var o in t)t.hasOwnProperty(i)&&(r[o]=t[o]);return r}function c(e){return{}.toString.call(e).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}function u(e){e=e.slice(0),e=decodeURIComponent(e);var t=e.split("?")[1];return t?t.split("&").reduce(function(e,t){var n=t.split("="),r=n[0],i=n[1];return e[r]=i,e},{}):{}}t.levels={ALL:5,ERROR:4,WARN:3,INFO:2,DEBUG:1,OFF:0},t.prototype.e=function(){0!==this.level&&this.level>=t.levels.ERROR&&this.__e(arguments)},t.prototype.i=function(){0!==this.level&&this.level>=t.levels.WARN&&this.__i(arguments)},t.prototype.w=function(){0!==this.level&&this.level>=t.levels.INFO&&this.__w(arguments)},t.prototype.d=function(){0!==this.level&&this.level>=t.levels.DEBUG&&this.__d(arguments)},t.prototype.setLevel=function(e){this.level=t.levels[e]};var l={Iterator:n,Logger:t,composeApiString:r,getJSON:i,jsonpRequest:o,getImageRaw:a,extend:s,getType:c,dequerify:u};e?e.Utils=l:window.Utils=l}(s),function(e,t){function n(e){var t=e.map(function(e){return{fullPath:e.fullPath,path:e.toURL(),internalURL:e.toInternalURL(),isFile:e.isFile,isDirectory:e.isDirectory}});return 1==t.length?t[0]:t}var r={},i=new t.Logger("ALL","[File - module]");r.LOG=i,window.requestFileSystem=window.requestFileSystem||window.webkitRequestFileSystem,r.ERROR_MAP={1:"NOT_FOUND_ERR",2:"SECURITY_ERR",3:"ABORT_ERR",4:"NOT_READABLE_ERR",5:"ENCODING_ERR",6:"NO_MODIFICATION_ALLOWED_ERR",7:"INVALID_STATE_ERR",8:"SYNTAX_ERR",9:"INVALID_MODIFICATION_ERR",10:"QUOTA_EXCEEDED_ERR",11:"TYPE_MISMATCH_ERR",12:"PATH_EXISTS_ERR"},r.currentFileTransfer=null,r.resolveFS=function(e){return new Promise(function(t,n){window.resolveLocalFileSystemURL(e,t,n)})},r.appendToFile=function(e,t,i,o){return i=void 0!==arguments[2]&&arguments[2],o=void 0===arguments[3]?"text/plain":arguments[3],r.resolveFS(e).then(function(e){return new Promise(function(r,a){e.createWriter(function(s){i||s.seek(s.length);var c;c=t instanceof Blob?t:new Blob([t],{type:o}),s.write(c),s.onerror=a,s.onabort=a,s.onwriteend=function(){r(n([e]))}},a)})})},r.readFileAsHTML=function(e){return r.readFile(e).then(function(e){return(new window.DOMParser).parseFromString(e,"text/html")})},r.readFileAsJSON=function(e){return r.readFile(e).then(function(e){try{return Promise.resolve(window.JSON.parse(e))}catch(e){return Promise.reject(e)}})},r.removeFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.remove(function(e){t(null===e||"OK"===e)},n)})})},r.removeDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.removeRecursively(function(e){t(null===e||"OK"===e)},n)})})},r._promiseZip=function(e,t,n){return i.d("PROMISEZIP:",arguments),new Promise(function(r,i){window.zip.unzip(e,t,function(e){0===e?r(!0):i(e)},n)})},r.download=function(e,t,i,o){var a=this;this.ft=new window.FileTransfer,this.ft.onprogress=o,r.currentFileTransfer=a.ft,a.promise=new Promise(function(r,o){a.ft.download(window.encodeURI(e),t+i,function(e){r(n([e])),a.ft=null},function(e){o(e),a.ft=null},!0)})},r.createDir=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getDirectory(t,{create:!0},function(e){r(n([e]))},i)})})},r.fileExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isFile)},function(e){t(1!==e.code)})})},r.dirExists=function(e){return new Promise(function(t){window.resolveLocalFileSystemURL(e,function(e){t(e.isDirectory)},function(e){t(1!=e.code)})})},r.requestFileSystem=function(e,t){return new Promise(function(n,r){window.requestFileSystem(e,t,n,r)})},r.readDir=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,r){e.createReader().readEntries(function(e){i.d("readDir:",e),t(n(e))},r)})})},r.readFile=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.file(function(e){var r=new FileReader;r.onerror=n,r.onabort=n,r.onloadend=function(){var e=this.result;t(e)},r.readAsText(e)})})})},r.createFile=function(e,t){return r.resolveFS(e).then(function(e){return new Promise(function(r,i){e.getFile(t,{create:!0},function(e){r(n([e]))},i)})})},r.write=function(e,t){return r.fileExists(e).then(function(n){if(!n){var i=e.split("/"),o=i.slice(0,i.length-1).join("/"),a=i[i.length-1];return r.createFile(o,a).then(function(e){return r.appendToFile(e.path,t,!0)})}return r.appendToFile(e,t,!0)})},r.moveDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return i.d("moveDir:",o,n),Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("moveDir: resolved entries",e),new Promise(function(t,r){e[0].moveTo(e[1],n,t,r)})})},r.copyFile=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(e){return i.d("copyFileTo",e),new Promise(function(t,r){e[0].copyTo(e[1],n,t,r)})})},r.copyDir=function(e,t){var n=t.substring(t.lastIndexOf("/")+1),o=t.replace(n,"");return Promise.all([r.resolveFS(e),r.resolveFS(o)]).then(function(r){return i.d("copyDir",e,"in",t),new Promise(function(e,t){r[0].copyTo(r[1],n,e,t)})})},r.getMetadata=function(e){return r.resolveFS(e).then(function(e){return new Promise(function(t,n){e.getMetadata(t,n)})})},e?e.file=r:window.file=r}(s,s.Utils),function(e,t,n){"use strict";function r(){}function i(t){if(t&&(C=x(C,t)),U.d("Initialized called with:",C),!e)return Promise.reject("Missing file module!");try{b=window.cordova.file.applicationStorageDirectory,_=window.cordova.file.cacheDirectory,S=window.cordova.file.tempDirectory,A=window.cordova.file.applicationDirectory+"www/",I=window.cordova.file.applicationDirectory+"www/js/stargate.js",P=window.cordova.file.dataDirectory}catch(e){return U.e(e),Promise.reject(e)}"ios"==window.device.platform.toLowerCase()&&(b+="Documents/"),"android"==window.device.platform.toLowerCase()&&(S=_),O.SDK_DIR=b+"scripts/",O.SDK_RELATIVE_DIR="../../scripts/",O.GAMEOVER_RELATIVE_DIR="../../gameover_template/",O.GAMES_DIR=b+"games/",O.BASE_DIR=b,O.CACHE_DIR=_,O.TEMP_DIR=S,O.CORDOVAJS=A+"cordova.js",O.CORDOVA_PLUGINS_JS=A+"cordova_plugins.js",O.STARGATEJS=A+"js/stargate.js",O.DATA_DIR=P,O.GAMEOVER_DIR=O.BASE_DIR+"gameover_template/",O.WWW_DIR=A,U.i("cordova JS dir to include",O.CORDOVAJS),n.game._public.BASE_DIR=O.BASE_DIR,n.game._public.OFFLINE_INDEX=O.WWW_DIR+"index.html";var r={"0000":{"0000":{data:{},UpdatedAt:new Date(0)}}},i=e.createDir(O.BASE_DIR,"games"),a=e.createDir(O.BASE_DIR,"scripts"),u=e.fileExists(O.BASE_DIR+"offlineData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(k))}),l=e.fileExists(O.BASE_DIR+"userData.json").then(function(t){return t?Promise.resolve():e.write(O.BASE_DIR+"userData.json",JSON.stringify(r))});return Promise.all([i,a,u,l]).then(function(e){return U.d("GamesDir, ScriptsDir, offlineData.json, userData.json created",e),o()}).then(s).then(c)}function o(){return Promise.all([e.dirExists(O.BASE_DIR+"gameover_template"),e.dirExists(O.SDK_DIR+"plugins"),e.fileExists(O.SDK_DIR+"cordova.js"),e.fileExists(O.SDK_DIR+"cordova_plugins.js"),e.fileExists(O.SDK_DIR+"gamesFixes.js")]).then(function(t){var n=[];return t[0]||n.push(e.copyDir(O.WWW_DIR+"gameover_template",O.BASE_DIR+"gameover_template")),t[1]||n.push(e.copyDir(O.WWW_DIR+"plugins",O.SDK_DIR+"plugins")),t[2]||n.push(e.copyFile(O.CORDOVAJS,O.SDK_DIR+"cordova.js")),t[3]||n.push(e.copyFile(O.CORDOVA_PLUGINS_JS,O.SDK_DIR+"cordova_plugins.js")),t[4]||n.push(e.copyFile(O.WWW_DIR+"js/gamesFixes.js",O.SDK_DIR+"gamesFixes.js")),Promise.all(n)})}function a(e,t){return new Promise(function(n,r){var i=new XMLHttpRequest;i.open("HEAD",e,!0),i.addEventListener("error",r,!1),i.addEventListener("abort",r,!1),i.addEventListener("loadend",function(){n(i.getResponseHeader(t))}),i.send(null)})}function s(){var t=new Date,n=D(C.sdk_url,{v:t.getTime()});return""===C.sdk_url||void 0===C.sdk_url||null===C.sdk_url?(U.d("sdk_url is not a valid one"),Promise.resolve("sdk_url is not a valid one")):e.fileExists(O.SDK_DIR+"gfsdk.min.js").then(function(t){var r=[];return t||(U.d("isSdkDownloaded",t,"get SDK",n),r.push(new e.download(n,O.SDK_DIR,"gfsdk.min.js").promise)),Promise.all(r)}).then(function(){return Promise.all([a(n,"Last-Modified"),e.getMetadata(O.SDK_DIR+"gfsdk.min.js")])}).then(function(t){var r=t[1],i=t[0],o=[],a=new Date(r.modificationTime),s=new Date(i);return a=0;r--)if(-1!==n[r].innerHTML.indexOf("function open")){t.push(n[r]);break}for(var i=0;i"+e.documentElement.innerHTML+"";return U.d("Serialized dom",r),r}).then(function(t){return U.d("Write dom:",r,t),e.write(r,t)})}function g(e){return new RegExp(/.*\.html?$/i).test(e)}function m(n){var r=n.url.replace("[WSIZE]",n.size.width).replace("[HSIZE]",n.size.height).split("?")[0],i=O.GAMES_DIR+n.gameId,o=n.type+"_"+n.size.width+"x"+n.size.height+("_"+n.size.ratio||"")+".jpeg";return U.d("request Image to",r,"coverImageUrl",o,"imagesFolder",i),"xhr"===n.method?Promise.all([e.createFile(i,o),t.getImageRaw({url:r})]).then(function(t){var n=t[0],r=t[1];return e.appendToFile(n.path,r,!0,"image/jpeg")}):new e.download(r,i,o,function(){}).promise}function w(){return U.i("readUserJson",O.BASE_DIR+"user.json"),e.readFileAsJSON(O.BASE_DIR+"user.json")}function v(e){return w().then(function(t){if(!t.ponyUrl)throw U.w("ponyUrl in user check undefined!",t.ponyUrl),new Error("Not premium user");var n=t.ponyUrl.split("&_PONY=")[1];U.d("PONYVALUE",n);var r=D(C.gamifive_info_api,{content_id:e,format:"jsonp"});return r+=t.ponyUrl,U.d("Call game_info api: ",r),new R(r).prom}).then(function(t){if(403===t.status||200!==t.status)throw new Error("Error retrieving game_info",t);return U.d("Save game_Info: ","OK"),y({content_id:e,gamifive_info:t.game_info})})}function y(t){return e.readFileAsJSON(O.BASE_DIR+"offlineData.json").then(function(e){return e.GamifiveInfo[t.content_id]=t.gamifive_info,e}).then(function(t){return U.d("writing offlineData.json",t),e.write(O.BASE_DIR+"offlineData.json",JSON.stringify(t))})}var b,_,S,A,P,I,E=t.Logger,D=t.composeApiString,R=t.jsonpRequest,x=t.extend,O={},C={sdk_url:"",dixie_url:"",api:"",ga_for_game_url:"",gamifive_info_api:"",bundle_games:[]},T=!1,k={GaForGame:{},GamifiveInfo:{},queues:{}},j={content_id:"",formats:"html5applications",sort:"-born_date",category:"b940b384ff0565b06dde433e05dc3c93",publisher:"",size:6,offset:0,label:"",label_slug:"",access_type:"",real_customer_id:"xx_gameasy",lang:"en",use_cs_id:"",white_label:"xx_gameasy",main_domain:"http://www2.gameasy.com/ww",fw:"gameasy",vh:"ww.gameasy.com",check_compatibility_header:0},U=new E("ALL","[Game - module]",{background:"black",color:"#5aa73a"});r.prototype.download=function(t,n){function r(e){return function(t){var n=Math.round(t.loaded/t.total*100);c({percentage:n,type:e})}}function i(){u({type:"download"}) -;var n=e.requestFileSystem(1,w);return U.d("Get GameInfo, fly my minipony!"),n.then(function(e){return U.i("Space is ok, can download:",w,e),v(y)}).then(function(n){return U.d("Ga for game and gamifive info stored!",n),U.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,O.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),U.d("unzip:",t.id,O.TEMP_DIR+y),e._promiseZip(n.path,O.TEMP_DIR+y,r("unzip"))}).then(function(n){U.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,w=d*Math.pow(1024,f?p.MB:p.KB),y=t.id;return s.then(function(e){return U.d("Exists",e),e?(T=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(T=!0,i())})},r.prototype.play=function(t){U.d("Play",t);var n=O.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return g(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){U.d("Removing game",t);var n=e.dirExists(O.CACHE_DIR+t+".zip"),r=e.dirExists(O.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(U.d("Removed in cache",n[0]),r.push(e.removeFile(O.CACHE_DIR+t+".zip"))),n[1]&&(U.d("Removed",n[1]),r.push(e.removeDir(O.GAMES_DIR+t))),0===r.length&&U.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return T},r.prototype.abortDownload=function(){return this.isDownloading()?(U.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,T=!1),!0):(U.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return U.d("Get games list"),e.readDir(O.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=O.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(U.d("Read meta.json:",n),U.d("GAMEOVER_TEMPLATE path",O.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(O.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return U.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(O.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(O.GAMES_DIR).then(function(t){return U.d("All games deleted!",t),e.createDir(O.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(C.bundle_games.length>0){U.d("Games bundle in configuration",C.bundle_games);var t,n=C.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){U.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(J.hasOwnProperty("webappsfixes")&&"object"==typeof J.webappsfixes){t=!0;for(var e in J.webappsfixes)if(J.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){m("[webappsFixes] applying fix: "+e);var r=n[e](J.webappsfixes[e]);r&&w("[webappsFixes] fix '"+e+"' failed: "+r)}else w("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(_()&&!e.platforms.ios)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(b()&&!e.platforms.android)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(m("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),m("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return w("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!J.statusbar)return;e=J.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},Y=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(_()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){m("[share] Share completed? "+e.completed),m("[share] Shared to app: "+e.app),n(e)},a=function(e){w("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){m("[share] Facebook share completed, result: ",e),t(e)},i=function(e){w("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){m("[share] Twitter share completed, result: ",e),t(e)},i=function(e){w("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){m("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){w("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){m("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){m("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(m("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(w("[share] type not valid"),n("type not valid"))):(w("[share] missing parameter url"),n("missing parameter url")):(w("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return E?D?new Promise(function(t,n){Y.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return E?D?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(Y.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){w(e),n(e)})}):(w("[share] missing parameter url"),Promise.reject("missing parameter url")):(w("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(w("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var ee=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){h().then(function(e){f&&f.type&&"online"===f.type?(m("[push] going to url: ",e),P(e)):w("[push] i'm offline not going to url")}).catch(function(e){w("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var p=function(){var e=window.cordova.file.applicationStorageDirectory;return _()&&(e+="Documents/"),e},h=function(){return s.file.fileExists(p()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(p()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},g=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(p(),"SGpushUrl").then(function(e){return m("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){w("[push] error sg create SGpushUrl file",e)})},b=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();m("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,p=1732584193,f=-271733879,h=-1732584194,g=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length), -c(s(a.concat(r),640))}function p(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function f(e){return unescape(encodeURIComponent(e))}function h(e){return l(f(e))}function g(e){return p(h(e))}function m(e,t){return d(f(e),f(t))}function w(e,t){return p(m(e,t))}function v(e,t,n){return t?n?m(t,e):w(t,e):n?h(e):g(e)}return v}(),re=function(e){if(void 0===window.SpinnerDialog)return w("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},ie=function(){return void 0===window.SpinnerDialog?w("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=re,window.stopLoading=ie,a.inAppPurchaseSubscription=function(e,t,n,r){return E?D?(K(!0),void 0!==r&&(ae.returnUrl=r),void 0!==n&&(ae.subscribeMethod=n),ae.callbackSuccess=e,ae.callbackError=t,ae.inappPurchaseCalled=!0,ae.lastCreateUserProduct&&ae.lastCreateUserToken?(ae.createUser(ae.lastCreateUserProduct,ae.lastCreateUserToken),!0):(ae.doRefresh(),window.store.order(ae.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.inAppRestore=function(e,t,n,r){return E?D?(void 0!==n&&(ae.subscribeMethod=n),void 0!==r&&(ae.returnUrl=r),ae.callbackSuccess=e,ae.callbackError=t,ae.inappPurchaseCalled=!0,void ae.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},a.inAppProductInfo=function(e){if(e.productId||(e.productId=ae.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return w("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!E)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!D)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(ae.subscribeMethod=e.subscriptionUrl,ae.requestedListingProductId=e.productId,ae.callbackListingSuccess=e.callbackListingSuccess,ae.callbackPurchaseSuccess=e.callbackPurchaseSuccess,ae.callbackListingError=e.callbackError,ae.inappProductInfoCalled=!0,ae.productsInfo[e.productId])try{ae.callbackListingSuccess(ae.productsInfo[e.productId])}catch(e){w("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return ae.lastCreateUserProduct&&ae.lastCreateUserToken?(ae.createUser(ae.lastCreateUserProduct,ae.lastCreateUserToken),!0):(ae.doRefresh(!0),!0)};var oe=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(b()?n=e.productsIdAndroid:_()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,m("[IAPlight] getProducts ok",e),e}).catch(function(e){w("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(m("[IAPlight] subscribe ok",t),_())return e.getActiveSubscriptionsInfo().then(function(e){if(m("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(b()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return w("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw w("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){m("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),m(JSON.stringify(e)),m(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){m("IAP> Purchase approved."),m(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){m("subscription verified ",e)},onStoreReady:function(){m("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(m("[IAP] > Product Owned."),!e.transaction.id&&_())return w("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),_()&&window.localStorage.setItem("transaction_id",e.transaction.id),b()){var t=e.transaction.purchaseToken+"|"+C+"|"+ae.id;m("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||ae.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(m("[IAP] appStoreReceipt: "+t.appStoreReceipt),ae.createUser(e,t.appStoreReceipt)):m("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){K(!1),ae.callbackError({iap_cancelled:1,return_url:ae.returnUrl}),m("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){m("[IAP] ORDER APPROVED "+ae.id),e.finish()},error:function(e){K(!1),w("[IAP] error: "+e),ae.callbackError({iap_error:1,return_url:ae.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(m("[IAP] createUser start "),!ae.inappProductInfoCalled&&!ae.inappPurchaseCalled)return ae.lastCreateUserProduct=e,void(ae.lastCreateUserToken=t);if(!ae.subscribeMethod)return void w("[IAP] createUser configuration error: missing api url.");var n=ae.getRandomEmail(),r=1;b()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=ae.subscribeMethod,o={paymethod:ae.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:ae.returnUrl,inapp_pwd:ae.getPassword(t),hybrid:1};ae.lastCreateuserUrl=i,ae.lastCreateuserData=o;var a=function(e){if(ae.createUserAttempt<=ae.maxCreateUserAttempt)w("[IAP] createUser failed "+ae.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{w("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:ae.returnUrl};K(!1),ae.inappPurchaseCalled?ae.callbackError(t):ae.inappProductInfoCalled&&ae.callbackListingError(t)}},s=function(e){m("[IAP] createUser success ",e);try{e.device_id=y.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),K(!1),ae.callbackSuccess(e),ae.inappPurchaseCalled?ae.callbackSuccess(e):ae.inappProductInfoCalled&&ae.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){ae.createUserAttempt=ae.createUserAttempt+1,m("[IAP] createUser attempt: "+ae.createUserAttempt+" with timeout: "+c+"sec."),m("[IAP] POST createUser: "+ae.lastCreateuserUrl+" params: "+JSON.stringify(ae.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(ae.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(ae.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){m("[IAP] createUser end"),K(!1)}).go(),c+=5},10)};ae.createUserAttempt=0,u()}},se=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return w("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return w("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});m("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){w("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return w("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});m("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){w("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(w("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(w("[globalization] getLocaleName: not initialized!"),!1)},e}();a.facebookLogin=function(e,t,n){if(!E)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){m("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){w("Got FB login error:",e),n({error:e})})},a.facebookShare=function(e,t,n){if(!E)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){w("Got FB share error:",e),n({error:e})})};var ce=function(){deltadna.registerPushCallback(le)},ue=function(e){w("[DeltaDNA] error: "+e)},le=function(e){return b()&&e.payload&&e.payload.url&&!e.foreground?P(e.payload.url):_()&&e.url?P(e.url):void 0},de=function(){var e={},t={},n=function(n){m("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(w("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(w("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&m("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return w("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),pe=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return w("[appsflyer] missing cordova plugin");if(void 0===J.appsflyer_devkey)return w("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:J.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(_()){if(void 0===J.appstore_appid)return w("[appsflyer] missing manifest configuration: appstore_appid");n.appId=J.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}te.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();a.setConversionDataCallback=function(e){pe.setCallback(e)};var fe=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return m("[analytics] callback not set!");try{e(t)}catch(e){w("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();a.setAnalyticsCallback=function(e){fe.setCallback(e)};var he={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(he.DefaultOptions=e),AdMob&&(he.AdMobSupport=!0,he.initAdMob(e,t,n)),MoPub&&(he.MoPubSupport=!0),!0},isAdMobSupported:function(){return he.AdMobSupport},isMoPubSupported:function(){return he.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=he.getUserAgent();e||he.isObjEmpty(he.DefaultOptions)||(e=he.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=he.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=he.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=he.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=he.getUserAgent();e||he.isObjEmpty(he.DefaultOptions)||(e=he.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=he.getUserAgent();e||he.isObjEmpty(he.DefaultOptions)||(e=he.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=he.getUserAgent();e||he.isObjEmpty(he.DefaultOptions)||(e=he.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=he.getUserAgent();e||he.isObjEmpty(he.DefaultOptions)||(e=he.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=he.getUserAgent();e||he.isObjEmpty(he.DefaultOptions)||(e=he.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=he.getUserAgent();e||he.isObjEmpty(he.DefaultOptions)||(e=he.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?he.AdSize.LEADERBOARD:t>=468&&e>=60?he.AdSize.BANNER:t>=320&&e>=50?he.AdSize.BANNER:void 0}};return a.game=s.game._public,a.file=s.file,a.AdManager=s.AdManager,a}); \ No newline at end of file +;var n=e.requestFileSystem(1,w);return U.d("Get GameInfo, fly my minipony!"),n.then(function(e){return U.i("Space is ok, can download:",w,e),v(y)}).then(function(n){return U.d("Ga for game and gamifive info stored!",n),U.d("Start Download:",t.id,t.response_api_dld.binary_url),new e.download(t.response_api_dld.binary_url,O.TEMP_DIR,y+".zip",r("download")).promise}).then(function(n){return u({type:"unzip"}),U.d("unzip:",t.id,O.TEMP_DIR+y),e._promiseZip(n.path,O.TEMP_DIR+y,r("unzip"))}).then(function(n){U.d("Unzip ended",n),l({type:"unzip"});var r=t.response_api_dld.url_download,i=r.substring(r.lastIndexOf("game"),r.length).split("/"),o=r.split("/"),a=o.slice(o.lastIndexOf("game"),o.length);i=[];for(var s=0;s-1,w=d*Math.pow(1024,f?p.MB:p.KB),y=t.id;return s.then(function(e){return U.d("Exists",e),e?(T=!1,Promise.reject({12:"AlreadyExists",gameID:t.id})):(T=!0,i())})},r.prototype.play=function(t){U.d("Play",t);var n=O.GAMES_DIR+t;return e.readDir(n).then(function(e){return e.filter(function(e){return g(e.path)})}).then(function(e){u(e[0],!1)})},r.prototype.remove=function(t){U.d("Removing game",t);var n=e.dirExists(O.CACHE_DIR+t+".zip"),r=e.dirExists(O.GAMES_DIR+t);return Promise.all([n,r]).then(function(n){var r=[];return n[0]&&(U.d("Removed in cache",n[0]),r.push(e.removeFile(O.CACHE_DIR+t+".zip"))),n[1]&&(U.d("Removed",n[1]),r.push(e.removeDir(O.GAMES_DIR+t))),0===r.length&&U.i("Nothing to remove",r),r})},r.prototype.isDownloading=function(){return T},r.prototype.abortDownload=function(){return this.isDownloading()?(U.d("Abort last download"),e.currentFileTransfer&&(e.currentFileTransfer.abort(),e.currentFileTransfer=null,T=!1),!0):(U.w("There's not a download operation to abort"),!1)},r.prototype.list=function(){return U.d("Get games list"),e.readDir(O.GAMES_DIR).then(function(e){return(Array.isArray(e)?e:[e]).filter(function(e){if(e.isDirectory)return e})}).then(function(t){var n=t.map(function(t){return e.readFileAsJSON(t.path+"meta.json")});return Promise.all(n).then(function(e){return e})})},r.prototype.buildGameOver=function(t){var n=O.GAMES_DIR+t.content_id+"/meta.json";return t.hasOwnProperty("content_id")?(U.d("Read meta.json:",n),U.d("GAMEOVER_TEMPLATE path",O.GAMEOVER_DIR+"gameover.html"),Promise.all([e.readFileAsJSON(n),e.readFile(O.GAMEOVER_DIR+"gameover.html")]).then(function(e){var n=e[1],r=e[0];return U.i("Meta JSON:",r),n.replace("{{score}}",t.score).replace("{{game_title}}",r.title).replace("{{game_title}}",r.title).replace("{{url_share}}",r.url_share).replace("{{url_cover}}",r.images.cover.ratio_1)})):Promise.reject("Missing content_id key!")},r.prototype.isGameDownloaded=function(t){return e.dirExists(O.GAMES_DIR+t)},r.prototype.removeAll=function(){return e.removeDir(O.GAMES_DIR).then(function(t){return U.d("All games deleted!",t),e.createDir(O.BASE_DIR,"games")})},r.prototype.getBundleGameObjects=function(){var e=this;if(C.bundle_games.length>0){U.d("Games bundle in configuration",C.bundle_games);var t,n=C.bundle_games.map(function(t){return e.isGameDownloaded(t)}),r=Promise.all(n).then(function(e){U.d("alreadyDownloaded",e);for(var t=0;t-1&&this.events[e].splice(n,1)}},e.EventBus=t}(s),function(e){function t(e,t,n,r,i){return function(){if("function"==typeof e&&(e=e.call(null)),e)return t.apply(n||null,arguments);switch(r=r||"NoMessage",i){case"warn":console.warn(r);break;case"error":console.error(r);break;case"info":console.info(r);break;default:console.log(r)}}}e.Decorators={requireCondition:t}}(s),function(e,t,n){function r(){this.LOG=new e.Logger("OFF","ADMANAGER")}function i(e,t){return e.some(function(e){return t===e})}function o(){return"undefined"!==window.admob}/(android)/i.test(navigator.userAgent)||/(ipod|iphone|ipad)/i.test(navigator.userAgent);var a,s=["ios","android"];r.prototype.initialize=function(t){return a=window.device.platform.toLowerCase(),i(s,a)?(this.AD_TYPE=window.admob.AD_TYPE,this.AD_SIZE=window.admob.AD_SIZE,this.LOG=new e.Logger("all","[AdManager]"),this.LOG.i("initialize admob with",a,t[a]),this.setOptions(t[a]),Promise.resolve("OK")):Promise.reject([a,"Unsupported"].join(" "))},r.prototype.createBanner=function(t){this.LOG.i("createBanner");var n=this;return t=e.extend(n.options,t||{}),new Promise(function(e,n){window.admob.createBannerView(t,e,n)})},r.prototype.removeBanner=function(){return window.admob.destroyBannerView(),Promise.resolve("OK")},r.prototype.showBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!0,e,t)})},r.prototype.showBannerAtGivenXY=function(){this.LOG.d("NotImplemented")},r.prototype.showBannerAtSelectedPosition=function(){this.LOG.d("NotImplemented")},r.prototype.hideBanner=function(){return new Promise(function(e,t){window.admob.showBannerAd(!1,e,t)})},r.prototype.prepareInterstitial=function(t){var n=this;return new Promise(function(r,i){window.admob.requestInterstitialAd(e.extend(n.options,t||{}),r,i)})},r.prototype.showInterstitial=function(){return new Promise(function(e,t){window.admob.showInterstitialAd(e,t)})},r.prototype.registerAdEvents=function(e){this.LOG.d("NotImplemented",e)},r.prototype.setOptions=function(e){this.options=e||{},window.admob.setOptions(e||{})};for(var c in r.prototype)r.prototype.hasOwnProperty(c)&&(r.prototype[c]=t.requireCondition(o,r.prototype[c],r.prototype,"try cordova plugin add cordova-admob:plugin not installed","warn"));n.AdManager=new r}(s.Utils,s.Decorators,s);var c=function(){var e={},t=!1;e.init=function(){if(W.hasOwnProperty("webappsfixes")&&"object"==typeof W.webappsfixes){t=!0;for(var e in W.webappsfixes)if(W.webappsfixes.hasOwnProperty(e))if(n.hasOwnProperty(e)&&"function"==typeof n[e]){m("[webappsFixes] applying fix: "+e);var r=n[e](W.webappsfixes[e]);r&&w("[webappsFixes] fix '"+e+"' failed: "+r)}else w("[webappsFixes] fix implementation not found for: "+e)}return t};var n={};return n.gamifiveSearchBox=function(e){if(!window.cordova||!window.cordova.plugins||!window.cordova.plugins.Keyboard)return"missing ionic-plugin-keyboard";if(e.platforms){if(_()&&!e.platforms.ios)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on iOS");if(b()&&!e.platforms.android)return void m("[webappsFixes] [gamifiveSearchBox] fix disabled on Android")}return window.addEventListener("native.keyboardshow",function(){setTimeout(function(){0===document.querySelectorAll("input:focus").length&&(m("[webappsFixes] [gamifiveSearchBox] keyboard show on null input: hiding"),cordova.plugins.Keyboard.close())},1)},!1),m("[webappsFixes] [gamifiveSearchBox] listening on event native.keyboardshow"),""},e}();s.statusbar=function(){var e={};return e.initialize=function(e){if(void 0===window.StatusBar)return w("[StatusBar] missing cordova plugin");if(!e||e.constructor!==Object||0===Object.keys(e).length){if(!W.statusbar)return;e=W.statusbar}if(void 0!==e.hideOnUrlPattern&&e.hideOnUrlPattern.constructor===Array){for(var t=document.location.href,n=!1,r=0;r-1},ee=function(){var e={},t=function(e){var t=["message","subject","files","chooserTitle"],n={url:e.url};return t.forEach(function(t){t in e&&(n[t]=e[t])}),n},n=function(e){if(_()){if("facebook"===e)return"com.apple.social.facebook";if("twitter"===e)return"com.apple.social.twitter"}return e},r=function(e,n,r){var i=t(e),o=function(e){m("[share] Share completed? "+e.completed),m("[share] Shared to app: "+e.app),n(e)},a=function(e){w("[share] Sharing failed with message: "+e),r(e)};window.plugins.socialsharing.shareWithOptions(i,o,a)},i=function(e,t,n){var r=function(e){m("[share] Facebook share completed, result: ",e),t(e)},i=function(e){w("[share] Facebook sharing failed with message: "+e),n(e)};window.plugins.socialsharing.shareViaFacebook("",null,e.url,r,i)},o=function(e,t,n){var r=function(e){m("[share] Twitter share completed, result: ",e),t(e)},i=function(e){w("[share] Twitter sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaTwitter(o,null,e.url,r,i)},a=function(e,t,n){var r=function(e){m("[share] Whatsapp share completed, result: ",e),t(e)},i=function(e){w("[share] Whatsapp sharing failed with message: "+e),n(e)},o="";"message"in e&&(o=e.message),window.plugins.socialsharing.shareViaWhatsApp(o,null,e.url,r,i)};return e.canShareVia=function(e,t){var r=n(e);return new Promise(function(n){window.plugins.socialsharing.canShareVia(r,null,null,null,t,function(t){m("[share] canShareVia "+e+" ("+r+") result true: ",t),n({network:e,available:!0})},function(t){m("[share] canShareVia "+e+" ("+r+") result false: ",t),n({network:e,available:!1})})})},e.socialShare=function(e,t,n){return"object"!=typeof e&&(e={},v("[share] parameter options must be object!")),e.type||(e.type="chooser"),window.plugins&&window.plugins.socialsharing?e.url?(m("[share] Sharing url: "+e.url+" on: "+e.type,e),"chooser"==e.type?r(e,t,n):"facebook"==e.type?i(e,t,n):"twitter"==e.type?o(e,t,n):"whatsapp"==e.type?a(e,t,n):(w("[share] type not valid"),n("type not valid"))):(w("[share] missing parameter url"),n("missing parameter url")):(w("[share] missing cordova plugin"),n("missing cordova plugin"))},e}();a.socialShare=function(e){return E?D?new Promise(function(t,n){ee.socialShare(e,t,n)}):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")},a.socialShareAvailable=function(e){return E?D?window.plugins&&window.plugins.socialsharing?e.socials&&"object"==typeof e.socials?e.url?new Promise(function(t,n){var r=[];["facebook","whatsapp","twitter","instagram"].forEach(function(t){e.socials[t]&&r.push(ee.canShareVia(t,e.url))}),Promise.all(r).then(function(e){var n={};e.forEach(function(e){n[e.network]=e.available}),t(n)},function(e){w(e),n(e)})}):(w("[share] missing parameter url"),Promise.reject("missing parameter url")):(w("[share] missing object parameter socials"),Promise.reject("missing object parameter socials")):(w("[share] missing cordova plugin"),Promise.reject("missing cordova plugin")):Promise.reject("Stargate closed, wait for Stargate.initialize to complete!"):Promise.reject("Stargate not initialized, call Stargate.initialize first!")};var te=function(){var e=["fc5413366b9d3f40","188b6b1d46296303"],t={},n=null,r=function(){h().then(function(e){f&&f.type&&"online"===f.type?(m("[push] going to url: ",e),P(e)):w("[push] i'm offline not going to url")}).catch(function(e){w("[push] error reading url: "+e)})},i=function(){return window.cordova&&window.cordova.plugins&&window.cordova.plugins.notification&&window.cordova.plugins.notification.local},o=[],a=!1,c=!1,l=function(){c||i()&&(c=!0,window.cordova.plugins.notification.local.on("click",function(e){a?r():o.push(e)}))},d=function(){if(window.cordova){var e=window.cordova.require("cordova/channel");2===e.onPluginsReady.state?l():e.onPluginsReady.subscribe(function(){l()})}};d();var p=function(){var e=window.cordova.file.applicationStorageDirectory;return _()&&(e+="Documents/"),e},h=function(){return s.file.fileExists(p()+"SGpushUrl").then(function(e){return e?s.file.readFileAsJSON(p()+"SGpushUrl").then(function(e){return e.url}):Promise.reject("file not found")})},g=function(e){var t={url:u(e,{source:"localpush"})};return s.file.createFile(p(),"SGpushUrl").then(function(e){return m("[push] writing offline data",t,"in: ",e.path),s.file.write(e.path,JSON.stringify(t))}).catch(function(e){w("[push] error sg create SGpushUrl file",e)})},b=function(){var t=y.uuid;return e.indexOf(t)>-1};t.initialize=function(){return i()?null!==n?n:n=new Promise(function(e){for(c||d();o.length>0;){var t=o.pop();m("[push] processing queued event: ",t),r()}a=!0,e()}):Promise.reject(" not available, missing cordova plugin.")},t.setScheduledNotify=function(e){if(null===n)return Promise.reject("Not initialized");if("object"!=typeof e)return Promise.reject("[push] params must be an object");for(var t=["title","text","date","deeplink"],r=0;r>16)+(t>>16)+(n>>16)<<16|65535&n}function t(e,t){return e<>>32-t}function n(n,r,i,o,a,s){return e(t(e(e(r,n),e(o,s)),a),i)}function r(e,t,r,i,o,a,s){return n(t&r|~t&i,e,t,o,a,s)}function i(e,t,r,i,o,a,s){return n(t&i|r&~i,e,t,o,a,s)}function o(e,t,r,i,o,a,s){return n(t^r^i,e,t,o,a,s)}function a(e,t,r,i,o,a,s){return n(r^(t|~i),e,t,o,a,s)}function s(t,n){t[n>>5]|=128<>>9<<4)]=n;var s,c,u,l,d,p=1732584193,f=-271733879,h=-1732584194,g=271733878;for(s=0;s>5]>>>t%32&255);return n}function u(e){var t,n=[];for(n[(e.length>>2)-1]=void 0,t=0;t>5]|=(255&e.charCodeAt(t/8))<16&&(i=s(i,8*e.length)),n=0;n<16;n+=1)o[n]=909522486^i[n],a[n]=1549556828^i[n];return r=s(o.concat(u(t)),512+8*t.length),c(s(a.concat(r),640))}function p(e){var t,n,r="0123456789abcdef",i="";for(n=0;n>>4&15)+r.charAt(15&t);return i}function f(e){return unescape(encodeURIComponent(e))}function h(e){return l(f(e))}function g(e){return p(h(e))}function m(e,t){return d(f(e),f(t))}function w(e,t){return p(m(e,t))}function v(e,t,n){return t?n?m(t,e):w(t,e):n?h(e):g(e)}return v}(),ie=function(e){if(void 0===window.SpinnerDialog)return w("startLoading(): SpinnerDialog cordova plugin missing!");"object"!=typeof e&&(e={});var t=null;return e.hasOwnProperty("message")&&(t=e.message),window.SpinnerDialog.show(null,t),!0},oe=function(){return void 0===window.SpinnerDialog?w("startLoading(): SpinnerDialog cordova plugin missing!"):(window.SpinnerDialog.hide(),!0)};window.startLoading=ie,window.stopLoading=oe,a.inAppPurchaseSubscription=function(e,t,n,r){return E?D?(J(!0),void 0!==r&&(se.returnUrl=r),void 0!==n&&(se.subscribeMethod=n),se.callbackSuccess=e,se.callbackError=t,se.inappPurchaseCalled=!0,se.lastCreateUserProduct&&se.lastCreateUserToken?(se.createUser(se.lastCreateUserProduct,se.lastCreateUserToken),!0):(se.doRefresh(),window.store.order(se.id),!0)):(t("Stargate closed, wait for Stargate.initialize to complete!"),!1):(t("Stargate not initialized, call Stargate.initialize first!"),!1)},a.inAppRestore=function(e,t,n,r){return E?D?(void 0!==n&&(se.subscribeMethod=n),void 0!==r&&(se.returnUrl=r),se.callbackSuccess=e,se.callbackError=t,se.inappPurchaseCalled=!0,void se.doRefresh(!0)):t("Stargate closed, wait for Stargate.initialize to complete!"):t("Stargate not initialized, call Stargate.initialize first!")},a.inAppProductInfo=function(e){if(e.productId||(e.productId=se.id),"function"!=typeof e.callbackListingSuccess&&(e.callbackListingSuccess=function(){}),"function"!=typeof e.callbackPurchaseSuccess&&(e.callbackPurchaseSuccess=function(){}),"function"!=typeof e.callbackError&&(e.callbackError=function(){}),!e.subscriptionUrl)return w("[IAP] inAppProductInfo(): options.subscriptionUrl invalid"),!1;if(!E)return e.callbackError("Stargate not initialized, call Stargate.initialize first!"),!1;if(!D)return e.callbackError("Stargate closed, wait for Stargate.initialize to complete!"),!1;if(se.subscribeMethod=e.subscriptionUrl,se.requestedListingProductId=e.productId,se.callbackListingSuccess=e.callbackListingSuccess,se.callbackPurchaseSuccess=e.callbackPurchaseSuccess,se.callbackListingError=e.callbackError,se.inappProductInfoCalled=!0,se.productsInfo[e.productId])try{se.callbackListingSuccess(se.productsInfo[e.productId])}catch(e){w("[IAP] inAppProductInfo(): error on callbackListingSuccess!")}return se.lastCreateUserProduct&&se.lastCreateUserToken?(se.createUser(se.lastCreateUserProduct,se.lastCreateUserToken),!0):(se.doRefresh(!0),!0)};var ae=function(){var e={},t=null,n=[],r=[];e.initialize=function(e){return window.inAppPurchase?null!==t?t:((e.productsIdAndroid||e.productsIdIos)&&(b()?n=e.productsIdAndroid:_()&&(n=e.productsIdIos)),n?n&&n.constructor!==Array?Promise.reject("parameter error, productsId(Android|Ios) must be an array"):0===n.length?Promise.reject("parameter error, productsId(Android|Ios) must contains at least a productid"):t=window.inAppPurchase.getProducts(n).then(function(e){return r=e,m("[IAPlight] getProducts ok",e),e}).catch(function(e){w("[IAPlight] getProducts KO",e)}):Promise.reject("missing parameter productsId(Android|Ios)")):Promise.reject("inAppPurchase not available, missing cordova plugin.")},e.subscribe=function(n){if(null===t)return Promise.reject("Not initialized");var r=function(){return window.inAppPurchase.subscribe(n).then(function(t){if(m("[IAPlight] subscribe ok",t),_())return e.getActiveSubscriptionsInfo().then(function(e){if(m("resIos:"+JSON.stringify(e)),!(n in e))throw new Error("Subscription information incomplete!"+n);var t=e[n];return{productId:t.productId,transactionId:t.transactionIdentifier,purchaseDate:t.purchaseDate,purchaseTime:(+new Date(t.purchaseDate).getTime()/1e3).toFixed(0)}});if(b()){var r=JSON.parse(t.receipt);return Promise.resolve({productId:r.productId,transactionId:t.transactionId,purchaseDate:new Date(1e3*r.purchaseTime).toISOString(),purchaseTime:r.purchaseTime+""})}return w("[IAPlight] subscribe() unsupported platform!"),Promise.reject("Unsupported platform!")}).catch(function(e){throw w("[IAPlight] subscribe KO: "+e,e),e})};return t.then(r)},e.getExpireDate=function(e){if(null===t)return Promise.reject("Not initialized");var n=function(){return window.inAppPurchase.getReceiptBundle().then(function(t){m("[IAPlight] getExpireDate getReceiptBundle ok",t);var n={};return t.inAppPurchases&&t.inAppPurchases.constructor===Array&&t.inAppPurchases.forEach(function(t){if(t.productId==e){if(!n.subscriptionExpirationDate)return void(n=t);if(new Date(n.subscriptionExpirationDate) Product updated."),m(JSON.stringify(e)),m(e.owned?"[IAP] Subscribed!":"[IAP] Not Subscribed")},onPurchaseApproved:function(e){m("IAP> Purchase approved."),m(JSON.stringify(e)),e.finish()},onPurchaseVerified:function(e){m("subscription verified ",e)},onStoreReady:function(){m("\\o/ STORE READY \\o/")},onProductOwned:function(e){if(m("[IAP] > Product Owned."),!e.transaction.id&&_())return w("[IAP] > no transaction id"),!1;if(window.localStorage.setItem("product",e),_()&&window.localStorage.setItem("transaction_id",e.transaction.id),b()){var t=e.transaction.purchaseToken+"|"+C+"|"+se.id;m("[IAP] Purchase Token: "+t),window.localStorage.getItem("user_account")||se.createUser(e,t)}else window.storekit.loadReceipts(function(t){window.localStorage.getItem("user_account")||(t.appStoreReceipt?(m("[IAP] appStoreReceipt: "+t.appStoreReceipt),se.createUser(e,t.appStoreReceipt)):m("[IAP] appStoreReceipt empty, ignoring request"))})},onCancelledProduct:function(e){J(!1),se.callbackError({iap_cancelled:1,return_url:se.returnUrl}),m("[IAP] > Purchase cancelled ##################################",e)},onOrderApproved:function(e){m("[IAP] ORDER APPROVED "+se.id),e.finish()},error:function(e){J(!1),w("[IAP] error: "+e),se.callbackError({iap_error:1,return_url:se.returnUrl})},getRandomEmail:function(){return"fake"+Math.floor(9e3*Math.random()+1e3).toString()+Date.now()+"@example.com"},createUser:function(e,t){if(m("[IAP] createUser start "),!se.inappProductInfoCalled&&!se.inappPurchaseCalled)return se.lastCreateUserProduct=e,void(se.lastCreateUserToken=t);if(!se.subscribeMethod)return void w("[IAP] createUser configuration error: missing api url.");var n=se.getRandomEmail(),r=1;b()&&window.localStorage.getItem("googleAccount")&&(n=window.localStorage.getItem("googleAccount"),r=0),window.localStorage.setItem("user_account",n);var i=se.subscribeMethod,o={paymethod:se.paymethod,user_account:n,email_is_fake:r,purchase_token:t,return_url:se.returnUrl,inapp_pwd:se.getPassword(t),hybrid:1};se.lastCreateuserUrl=i,se.lastCreateuserData=o;var a=function(e){if(se.createUserAttempt<=se.maxCreateUserAttempt)w("[IAP] createUser failed "+se.createUserAttempt+" times, trying again... last error: "+JSON.stringify(e)),u();else{w("[IAP] createUser onCreateError: removing user_account"),window.localStorage.removeItem("user_account");var t={iap_error:"1",return_url:se.returnUrl};J(!1),se.inappPurchaseCalled?se.callbackError(t):se.inappProductInfoCalled&&se.callbackListingError(t)}},s=function(e){m("[IAP] createUser success ",e);try{e.device_id=y.uuid,window.localStorage.getItem("transaction_id")&&(e.transaction_id=window.localStorage.getItem("transaction_id")),J(!1),se.callbackSuccess(e),se.inappPurchaseCalled?se.callbackSuccess(e):se.inappProductInfoCalled&&se.callbackPurchaseSuccess(e)}catch(e){a(e)}},c=10,u=function(){setTimeout(function(){se.createUserAttempt=se.createUserAttempt+1,m("[IAP] createUser attempt: "+se.createUserAttempt+" with timeout: "+c+"sec."),m("[IAP] POST createUser: "+se.lastCreateuserUrl+" params: "+JSON.stringify(se.lastCreateuserData)+" timeout: "+1e3*c),window.aja().method("POST").url(se.lastCreateuserUrl).cache(!1).timeout(1e3*c).data(se.lastCreateuserData).on("success",function(e){s(e)}).on("error",function(e){a(e)}).on("4xx",function(e){a(e)}).on("5xx",function(e){a(e)}).on("timeout",function(){a("timeout")}).on("end",function(){m("[IAP] createUser end"),J(!1)}).go(),c+=5},10)};se.createUserAttempt=0,u()}},ce=function(){var e={},t={},n={},r=!1;return e.initialize=function(){if("object"!=typeof window.navigator||"object"!=typeof window.navigator.globalization)return w("[globalization] missing cordova plugin!"),!1;var e=new Promise(function(e){navigator.globalization.getPreferredLanguage(function(n){if("object"!=typeof n)return w("[globalization] initialize getPreferredLanguage result error: invalid type",n),void e({error:"invalid type"});m("[globalization] initialize getPreferredLanguage result ok: ",n),t=n,e(n)},function(t){w("[globalization] initialize getPreferredLanguage result error: ",t),e({error:t})})}),i=new Promise(function(e){navigator.globalization.getLocaleName(function(t){if("object"!=typeof t)return w("[globalization] initialize getLocaleName result error: invalid type",t),void e({error:"invalid type"});m("[globalization] initialize getLocaleName result ok: ",t),n=t,e(t)},function(t){w("[globalization] initialize getLocaleName result error: ",t),e({error:t})})});return Promise.all([e,i]).then(function(e){return r=!0,e})},e.getPreferredLanguage=function(){return r?t:(w("[globalization] getPreferredLanguage: not initialized!"),!1)},e.getLocaleName=function(){return r?n:(w("[globalization] getLocaleName: not initialized!"),!1)},e}();a.facebookLogin=function(e,t,n){if(!E)return n("Stargate not initialized, call Stargate.initialize first!");facebookConnectPlugin.login(e.split(","),function(e){m("[facebook] got userdata: ",e),facebookConnectPlugin.getAccessToken(function(e){t({accessToken:e})},function(e){n({error:e})})},function(e){w("Got FB login error:",e),n({error:e})})},a.facebookShare=function(e,t,n){if(!E)return n("Stargate not initialized, call Stargate.initialize first!");var r={method:"share",href:e};facebookConnectPlugin.showDialog(r,function(e){t({message:e})},function(e){w("Got FB share error:",e),n({error:e})})};var ue=function(){deltadna.registerPushCallback(de)},le=function(e){w("[DeltaDNA] error: "+e)},de=function(e){return b()&&e.payload&&e.payload.url&&!e.foreground?P(e.payload.url):_()&&e.url?P(e.url):void 0},pe=function(){var e={},t={},n=function(n){m("[CodePush] syncStatus: "+e.syncStatus[n]),t[n]&&Array===t[n].constructor&&t[n].forEach(function(e){e(n)})};e.syncStatus={0:"UP_TO_DATE",1:"UPDATE_INSTALLED",2:"UPDATE_IGNORED",3:"ERROR",4:"IN_PROGRESS",5:"CHECKING_FOR_UPDATE",6:"AWAITING_USER_ACTION",7:"DOWNLOADING_PACKAGE",8:"INSTALLING_UPDATE",AWAITING_USER_ACTION:6,CHECKING_FOR_UPDATE:5,DOWNLOADING_PACKAGE:7,ERROR:3,INSTALLING_UPDATE:8,IN_PROGRESS:4,UPDATE_IGNORED:2,UPDATE_INSTALLED:1,UP_TO_DATE:0},e.registerForNotification=function(e,n){return e?"function"!=typeof n?(w("[CodePush] registerForNotification: callback is not a function"),!1):(t[e]||(t[e]=[]),t[e].push(n),!0):(w("[CodePush] registerForNotification: undefined status requested"),!1)};var r=function(e){e&&m("[CodePush] Downloading "+e.receivedBytes+" of "+e.totalBytes)};return e.initialize=function(){if(void 0===window.codePush)return w("[CodePush] missing cordova plugin!"),!1;e.syncStatus=window.SyncStatus,window.codePush.sync(n,null,r)},e}(),fe=function(){var e,t={};return t.init=function(t){if(!window.plugins||!window.plugins.appsFlyer)return w("[appsflyer] missing cordova plugin");if(void 0===W.appsflyer_devkey)return w("[appsflyer] missing manifest configuration: appsflyer_devkey");var n={devKey:W.appsflyer_devkey,isDebug:!1,onInstallConversionDataListener:!0};if(_()){if(void 0===W.appstore_appid)return w("[appsflyer] missing manifest configuration: appstore_appid");n.appId=W.appstore_appid}var r=function(n){if("function"!=typeof e)return console.log("[Stargate] [appsflyer] callback not set!");if(window.localStorage.getItem("appsflyerSetSessionDone"))return e(null),!0;try{"string"==typeof n&&(n=JSON.parse(n)),n.type&&"onInstallConversionDataLoaded"==n.type&&n.data&&(n=n.data),e(n),console.log("[Stargate] [appsflyer] parameters sent to webapp callback: "+JSON.stringify(n))}catch(e){console.error("[Stargate] [appsflyer] callback error: "+e,e)}if(console.log("[Stargate] [appsflyer] configuration:",t),!window.localStorage.getItem("appsflyerSetSessionDone")&&t.autologin){var r="af_sub1";t.fieldPony&&(r=t.fieldPony);var i="";if(t.fieldReturnUrl&&(i=t.fieldReturnUrl),window.localStorage.setItem("appsflyerSetSessionDone",1),"object"==typeof n&&n[r]){var o=null;return i&&n[i]&&(o=n[i]),void window.setTimeout(function(){if(console.log("[Stargate] [appsflyer] perform autologin"),t.cbOnAfOkPreSession&&"function"==typeof t.cbOnAfOkPreSession){(0,t.cbOnAfOkPreSession)()}ne.setSession(n[r],o)},100)}}if(t.cbOnAfEmptySession&&"function"==typeof t.cbOnAfEmptySession){(0,t.cbOnAfEmptySession)()}},i=function(e){console.error("[Stargate] [appsflyer] plugin error: "+e,e)};window.plugins.appsFlyer.initSdk(n,r,i)},t.setCallback=function(t){e=t},t}();a.setConversionDataCallback=function(e){fe.setCallback(e)};var he=function(){var e,t={};return t.track=function(t){if("function"!=typeof e)return m("[analytics] callback not set!");try{e(t)}catch(e){w("[analytics] callback error: "+e,e)}},t.setCallback=function(t){e=t},t}();a.setAnalyticsCallback=function(e){he.setCallback(e)};var ge={AdMobSupport:!1,MoPubSupport:!1,AdPosition:{NO_CHANGE:0,TOP_LEFT:1,TOP_CENTER:2,TOP_RIGHT:3,LEFT:4,CENTER:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM_CENTER:8,BOTTOM_RIGHT:9,POS_XY:10},AdSize:{SMART_BANNER:"SMART_BANNER",BANNER:"BANNER",MEDIUM_RECTANGLE:"MEDIUM_RECTANGLE",FULL_BANNER:"FULL_BANNER",LEADERBOARD:"LEADERBOARD",SKYSCRAPER:"SKYSCRAPER"},DefaultOptions:null,initialize:function(e,t,n){return e&&(ge.DefaultOptions=e),AdMob&&(ge.AdMobSupport=!0,ge.initAdMob(e,t,n)),MoPub&&(ge.MoPubSupport=!0),!0},isAdMobSupported:function(){return ge.AdMobSupport},isMoPubSupported:function(){return ge.MoPubSupport},getUserAgent:function(){return/(android)/i.test(navigator.userAgent)?"android":/(ipod|iphone|ipad)/i.test(navigator.userAgent)?"ios":"other"},initAdMob:function(e,t,n){var r={adSize:"BANNER",position:8,bgColor:"black",isTesting:!1,autoShow:!0};AdMob.setOptions(r,t,n)},registerAdEvents:function(e){document.addEventListener("onAdFailLoad",e),document.addEventListener("onAdLoaded",e),document.addEventListener("onAdPresent",e),document.addEventListener("onAdLeaveApp",e),document.addEventListener("onAdDismiss",e)},manageAdEvents:function(e){console.log("error: "+e.error+", reason: "+e.reason+", adNetwork:"+e.adNetwork+", adType:"+e.adType+", adEvent:"+e.adEvent)},createBanner:function(e,t,n){var r={},i=[],o=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){if("default"==e.device||e.device==o){var i=ge.getAdSize().toLowerCase();e.overlap&&(r.overlap=e.overlap),e.offsetTopBar&&(r.offsetTopBar=e.offsetTopBar),r.adSize=ge.getAdSize(),i&&(r.adId=e[i]),e.position&&(r.position=ge.AdPosition[e.position]),e.width&&(r.width=e.width),e.height&&(r.height=e.height),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?(e.width&&e.height&&(r.adSize="CUSTOM"),AdMob.createBanner(r,t,n)):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.createBanner(r,t,n)}})},showBannerAtSelectedPosition:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBanner(e.position):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBanner(e.position))})},showBannerAtGivenXY:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showBannerAtXY(e.x,e.y):"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showBannerAtXY(e.x,e.y))})},hideBanner:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.hideBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.hideBanner())})},removeBanner:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.removeBanner():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.removeBanner())})},prepareInterstitial:function(e,t,n){var r={},i=[],o=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?i=e:i.push(e),i.forEach(function(e){"default"!=e.device&&e.device!=o||(e.interstitial&&(r.adId=e.interstitial),e.autoShow&&(r.autoShow=e.autoShow),"admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.prepareInterstitial(r):"mopub"==e.network.toLowerCase()&&MoPub.prepareInterstitial(r,t,n))})},showInterstitial:function(e){var t=[],n=ge.getUserAgent();e||ge.isObjEmpty(ge.DefaultOptions)||(e=ge.DefaultOptions),Array.isArray(e)?t=e:t.push(e),t.forEach(function(e){"default"!=e.device&&e.device!=n||("admob"==e.network.toLowerCase()||"dfp"==e.network.toLowerCase()?AdMob.showInterstitial():"mopub"==e.network.toLowerCase().toLowerCase()&&MoPub.showInterstitial())})},isObjEmpty:function(e){return 0===Object.keys(e).length},getAdSize:function(){var e=screen.height,t=screen.width;return t>=728&&e>=90?ge.AdSize.LEADERBOARD:t>=468&&e>=60?ge.AdSize.BANNER:t>=320&&e>=50?ge.AdSize.BANNER:void 0}};return a.game=s.game._public,a.file=s.file,a.AdManager=s.AdManager,a}); \ No newline at end of file diff --git a/package.json b/package.json index a5dd909..c006209 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stargatejs-apps", - "version": "0.13.5", + "version": "0.13.6", "description": "StargateJS for HTML5 apps", "main": "dist/stargate.js", "scripts": {