tph_sgext.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. // SilenGames HTML5 Extension
  2. // Author: Vitaliy Sidorov
  3. // Copyright: SilenGames 2014
  4. function sg_spil_ad() {
  5. try {
  6. if (sg_spilapi) {
  7. GameAPI.GameBreak.request(gml_Script_gmcallback_focusoff, gml_Script_gmcallback_focuson);
  8. }
  9. } catch(e) {
  10. gml_Script_gmcallback_focuson();
  11. };
  12. }
  13. function sg_spil_splash() {
  14. try {
  15. if (sg_spilapi_obj) {
  16. sg_spilapi_obj.Branding.displaySplashScreen(gml_Script_gmcallback_splashend);
  17. } else {
  18. gml_Script_gmcallback_splashend();
  19. }
  20. } catch(e) {
  21. gml_Script_gmcallback_splashend();
  22. };
  23. }
  24. function sg_fgl_ad() {
  25. try {
  26. fgl.showAd();
  27. } catch(e) {};
  28. }
  29. function sg_fgl_more_ok() {
  30. try {
  31. if (fgl.crossPromotionEnabled) {
  32. return true;
  33. } else {
  34. return false ;
  35. }
  36. } catch(e) {
  37. return false;
  38. };
  39. }
  40. function sg_fgl_more() {
  41. try {
  42. fgl.showMoreGames();
  43. } catch(e) {};
  44. }
  45. function sg_fgl_prem_ok() {
  46. try {
  47. if (fgl.unlockEnabled) {
  48. return true;
  49. } else {
  50. return false;
  51. }
  52. } catch(e) {
  53. return false;
  54. };
  55. }
  56. function sg_fgl_prem() {
  57. try {
  58. fgl.inApp.initiateUnlockFunction(
  59. function(){
  60. gml_Script_gmcallback_fgl_iap_ok();
  61. },
  62. function(){}
  63. );
  64. } catch(e) {};
  65. }
  66. function sg_fgl_isprem() {
  67. try {
  68. if (fgl.isPremium()) {
  69. return true;
  70. } else {
  71. return false;
  72. }
  73. } catch(e) {
  74. return false;
  75. };
  76. }
  77. function sg_fgl_spon_ok() {
  78. try {
  79. if (fgl.brandingEnabled) {
  80. return true;
  81. } else {
  82. return false;
  83. }
  84. } catch(e) {
  85. return false;
  86. };
  87. }
  88. function sg_fgl_spon_create() {
  89. try {
  90. if (window.sg_fgl_spon_obj == undefined) {
  91. sg_fgl_spon_obj = document.createElement('img');
  92. sg_fgl_spon_obj.src = fgl.getBrandingLogo();
  93. sg_fgl_spon_obj.onclick = fgl.handleBrandingClick;
  94. sg_fgl_spon_obj.setAttribute('style','display: none; position: absolute; left: 0px; top: 0px; width: 0px; height: 0px; z-index: 5; border: 0px');
  95. document.body.appendChild(sg_fgl_spon_obj);
  96. return true;
  97. } else {
  98. return false;
  99. }
  100. } catch(e) {
  101. return false;
  102. };
  103. }
  104. function sg_fgl_score_send(num) {
  105. try {
  106. fgl.submitScore(num);
  107. } catch(e) {};
  108. }
  109. function sg_fgl_score_show() {
  110. try {
  111. fgl.displayScoreboard();
  112. } catch(e) {};
  113. }
  114. function sg_lead_create() {
  115. try {
  116. if (window.adscreen == undefined) {
  117. adcont = undefined;
  118. adscreen = document.createElement("div");
  119. adscreen.id = "sg-ad-screen";
  120. adtext = document.createElement("div");
  121. adtext.id = "sg-ad-text";
  122. adtext.innerHTML = "Advertisment";
  123. adbut = document.createElement("img");
  124. adbut.id = "sg-ad-but";
  125. adbut.src = "icecream/adbut.png";
  126. adbut.onclick = gml_Script_gmcallback_adclose;
  127. adbut.width = "30";
  128. adbut.height = "30";
  129. adbut.border = "0";
  130. adbut.alt = "Close";
  131. adscreen.appendChild(adtext);
  132. adscreen.appendChild(adbut);
  133. document.body.insertBefore(adscreen, document.body.firstChild);
  134. }
  135. } catch(e) {};
  136. }
  137. function sg_lead_show(adid) {
  138. try {
  139. if (window.adscreen != undefined) {
  140. adscreen.setAttribute('style','display: block');
  141. if (window.adcont == undefined) {
  142. adcont = document.createElement("iframe");
  143. adcont.srcdoc = '<script type="text/javascript" src="http://ad.leadboltmobile.net/show_app_ad.js?section_id='+adid+'"></script>';
  144. adcont.id = "sg-ad-cont";
  145. adscreen.appendChild(adcont);
  146. }
  147. }
  148. } catch(e) {};
  149. }
  150. function sg_lead_close() {
  151. try {
  152. if (window.adscreen != undefined) {
  153. adscreen.setAttribute('style','display: none');
  154. if (window.adcont != undefined) {
  155. adscreen.removeChild(adcont);
  156. adcont = undefined;
  157. }
  158. }
  159. } catch(e) {};
  160. }
  161. function sg_clay_ad() {
  162. try {
  163. if (Clay.isReady) {
  164. var preroll = new Clay.Advertisement( { size: 'preroll', duration: 10000, allowSkip: true} );
  165. preroll.done();
  166. }
  167. } catch(e) {};
  168. }
  169. function sg_clay_score_send(num) {
  170. try {
  171. if (Clay.isReady) {
  172. ClayScore.post( { score: num , name: "Guest"} );
  173. }
  174. } catch(e) {};
  175. }
  176. function sg_clay_score_show() {
  177. try {
  178. if (Clay.isReady) {
  179. ClayScore.show( { showPersonal: true, best: true, filter: ['day', 'month', 'year'] } );
  180. }
  181. } catch(e) {};
  182. }
  183. function sg_clay_rate() {
  184. try {
  185. if (Clay.isReady) {
  186. Clay.Ratings();
  187. }
  188. } catch(e) {};
  189. }
  190. sg_clay_init_try = 5;
  191. function sg_clay_init(cross) {
  192. try {
  193. if (Clay.isReady) {
  194. ClayScore = new Clay.Leaderboard( { id: 4384, filter: ['day', 'month', 'year'] } );
  195. if (cross) {
  196. claycrossbar = document.createElement('div');
  197. claycrossbar.id = "sg-cross-bar";
  198. document.body.appendChild(claycrossbar);
  199. var crossopt = {
  200. position: {
  201. width: '100%',
  202. height: '80px',
  203. parent: 'sg-cross-bar',
  204. top: 0,
  205. right: 0,
  206. bottom: 0,
  207. left: 0,
  208. }
  209. };
  210. new Clay.Bar( crossopt );
  211. }
  212. } else {
  213. if (sg_clay_init_try > 0) {
  214. sg_clay_init_try-=1;
  215. setTimeout( function(){
  216. sg_clay_init(cross);
  217. },2000)
  218. }
  219. }
  220. } catch(e) {};
  221. }
  222. sg_guid = "";
  223. function sg_init(guid) {
  224. try {
  225. sg_guid = guid;
  226. if (window.loadingobj != undefined) {
  227. document.body.removeChild(loadingobj);
  228. }
  229. if (window.loadbarbackobj != undefined) {
  230. document.body.removeChild(loadbarbackobj);
  231. }
  232. if (window.loadintervalid != undefined) {
  233. clearInterval(loadintervalid);
  234. }
  235. if (window.loadingtextobj != undefined) {
  236. document.body.removeChild(loadingtextobj);
  237. }
  238. if (window.sg_spil_spon_obj != undefined) {
  239. sg_spil_spon_obj.setAttribute('style','display: none');
  240. }
  241. } catch(e) {};
  242. }
  243. function sg_canvas_resize(xpos, ypos, xsiz, ysiz) {
  244. canvasobj.setAttribute('style','position: absolute; left: '+xpos+'px; top: '+ypos+'px; width: '+xsiz+'px; height: '+ysiz+'px');
  245. }
  246. function sg_brand_set(type) {
  247. try {
  248. switch (type) {
  249. case "claycross": return claycrossbar;
  250. case "fgllogo": return sg_fgl_spon_obj;
  251. case "spillogo": return sg_spil_spon_obj;
  252. case "spilmore": return sg_spil_more_obj;
  253. case "spilcross": return sg_spil_cross_obj;
  254. default: return undefined;
  255. }
  256. } catch(e) {
  257. return undefined;
  258. };
  259. }
  260. function sg_brand_show(type,xpos,ypos,xsiz,ysiz) {
  261. try {
  262. var curobj = sg_brand_set(type);
  263. if (curobj != null && curobj != undefined) {
  264. if (type == "claycross") {
  265. curobj.setAttribute('style','display: block');
  266. } else {
  267. curobj.setAttribute('style','display: block; position: absolute; left: '+xpos+'px; top: '+ypos+'px; width:'+xsiz+'px; height:'+ysiz+'px; z-index: 5; border: 0px');
  268. }
  269. }
  270. } catch(e) {};
  271. }
  272. function sg_brand_hide(type) {
  273. try {
  274. var curobj = sg_brand_set(type);
  275. if (curobj != null && curobj != undefined) {
  276. curobj.setAttribute('style','display: none');
  277. }
  278. } catch(e) {};
  279. }
  280. sg_url_obj = [];
  281. sg_url_count = 0;
  282. function sg_url_add(url) {
  283. var oLink=document.createElement("a");
  284. oLink.setAttribute('href', url);
  285. oLink.setAttribute('target', '_blank');
  286. document.body.appendChild(oLink);
  287. var oDiv=document.createElement("div");
  288. oDiv.setAttribute('style','display: block; position: absolute; z-index: 5; border: 0px');
  289. oDiv.setAttribute("id", "sgurlobj"+sg_url_count);
  290. oDiv.style.left = "0px";
  291. oDiv.style.top = "0px";
  292. oDiv.style.width = "0px";
  293. oDiv.style.height = "0px";
  294. oDiv.style.cursor = "default";
  295. oDiv.style.backgroundColor = "rgba(0, 0, 0, 0)";
  296. oLink.appendChild(oDiv);
  297. sg_url_obj[sg_url_count] = oDiv;
  298. return sg_url_count++;
  299. }
  300. function sg_url_delete(num) {
  301. var obj = sg_url_obj[num];
  302. if (obj) {
  303. document.body.removeChild(obj.parentNode);
  304. sg_url_obj[num] = undefined;
  305. }
  306. }
  307. function sg_url_change(num, xpos, ypos, xsiz, ysiz) {
  308. var obj = sg_url_obj[num];
  309. if (obj) {
  310. obj.style.left = xpos + "px";
  311. obj.style.top = ypos + "px";
  312. obj.style.width = xsiz + "px";
  313. obj.style.height = ysiz + "px";
  314. }
  315. }
  316. function sg_get(url) {
  317. if (window.XMLHttpRequest) {
  318. xmlObject = new XMLHttpRequest();
  319. } else {
  320. xmlObject = new ActiveXObject("Microsoft.XMLHTTP");
  321. }
  322. xmlObject.open("GET",url,0);
  323. xmlObject.send(null);
  324. return xmlObject.responseText;
  325. }
  326. sg_focus = 1;
  327. sg_visible_event = "";
  328. try {
  329. if (typeof document.hidden !== "undefined") {
  330. sg_visible_event = "visibilitychange";
  331. } else if (typeof document.webkitHidden !== "undefined") {
  332. sg_visible_event = "webkitvisibilitychange";
  333. } else if (typeof document.msHidden !== "undefined") {
  334. sg_visible_event = "msvisibilitychange";
  335. } else if (typeof document.mozHidden !== "undefined") {
  336. sg_visible_event = "mozvisibilitychange";
  337. }
  338. } catch(e) {};
  339. if (sg_visible_event != "") {
  340. document.addEventListener(sg_visible_event, sg_get_visibility, false);
  341. }
  342. function sg_get_visibility() {
  343. try {
  344. if (sg_focus == 1) {
  345. sg_focus = 0;
  346. gml_Script_gmcallback_focusoff();
  347. } else {
  348. sg_focus = 1;
  349. gml_Script_gmcallback_focuson();
  350. }
  351. } catch(e) {};
  352. }
  353. function sg_get_language() {
  354. try {
  355. var lang = window.navigator.userLanguage || window.navigator.language;
  356. return lang.substring(0,2).toLowerCase();
  357. } catch(e) {
  358. return "en";
  359. };
  360. }
  361. sg_unlock_audio = null;
  362. sg_play_audio = null;
  363. sg_is_winphone = false;
  364. function sg_unlock_music(num, win) {
  365. sg_unlock_audio = document.getElementsByTagName('audio')[num];
  366. if (win) {
  367. sg_is_winphone = true;
  368. }
  369. }
  370. function sg_play_music() {
  371. try {
  372. if (sg_play_audio != null) {
  373. sg_stop_music();
  374. }
  375. sg_play_audio = sg_unlock_audio;
  376. sg_play_audio.loop = true;
  377. sg_play_audio.addEventListener("ended", sg_play_music, false);
  378. if (sg_is_winphone) {
  379. sg_play_audio.play();
  380. } else {
  381. window.addEventListener("touchend", sg_unlock_music_event, false);
  382. }
  383. } catch(e) {};
  384. }
  385. function sg_unlock_music_event() {
  386. try {
  387. sg_play_audio.play();
  388. window.removeEventListener("touchend", sg_unlock_music_event, false);
  389. } catch(e) {};
  390. }
  391. function sg_stop_music() {
  392. try {
  393. sg_play_audio.pause();
  394. sg_play_audio.removeEventListener("ended", sg_play_music, false);
  395. } catch(e) {};
  396. }
  397. function sg_unlock_webaudio() {
  398. try {
  399. window.addEventListener("touchstart", sg_unlock_webaudio_event, false);
  400. } catch(e) {};
  401. }
  402. function sg_unlock_webaudio_event(event) {
  403. try {
  404. var buffer = g_WebAudioContext.createBuffer(1, 1, 22050);
  405. var source = g_WebAudioContext.createBufferSource();
  406. source.buffer = buffer;
  407. source.connect(g_WebAudioContext.destination);
  408. source.noteOn(0);
  409. window.removeEventListener("touchstart", sg_unlock_webaudio_event, false);
  410. } catch(e) {};
  411. }
  412. function sg_no_bar() {
  413. if(!window.location.hash)
  414. {
  415. var divh = document.getElementById('gm4html5_div_id').style.height;
  416. if (divh < (window.outerHeight + 200))
  417. {
  418. document.getElementById('gm4html5_div_id').style.height = (window.outerHeight + 200) + 'px';
  419. }
  420. setTimeout ( function(){ window.scrollTo(0,1); },50);
  421. }
  422. }
  423. function test_browser_storage() {
  424. try {
  425. return 'localStorage' in window && window['localStorage'] !== null;
  426. } catch (e) {
  427. return false;
  428. }
  429. }
  430. sg_save_ok = test_browser_storage();
  431. function sg_save(name, numb) {
  432. try {
  433. var key = sg_guid + name;
  434. if (sg_save_ok) {
  435. window.localStorage.setItem(key, numb);
  436. } else {
  437. var date = new Date;
  438. date.setDate(date.getDate() + 999);
  439. document.cookie = key +"="+ numb +"; path=/; expires="+ date.toUTCString();
  440. }
  441. } catch(e) {};
  442. }
  443. function sg_load(name, def) {
  444. try {
  445. var key = sg_guid + name;
  446. if (sg_save_ok) {
  447. var done = window.localStorage.getItem(key);
  448. } else {
  449. var matches = document.cookie.match(new RegExp(
  450. "(?:^|; )" + key.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
  451. ))
  452. var done = matches ? decodeURIComponent(matches[1]) : undefined;
  453. }
  454. if (done!=null && done!="") {
  455. return parseInt(done);
  456. } else {
  457. return def;
  458. }
  459. } catch(e) {
  460. return def;
  461. };
  462. }
  463. function sg_orient(ok) {
  464. try {
  465. if (ok) {
  466. orientobj.setAttribute('style','display: block');
  467. } else {
  468. orientobj.setAttribute('style','display: none');
  469. }
  470. } catch(e) {};
  471. }
  472. function sg_test_orient() {
  473. try {
  474. if (!viewporter || !viewporter.ACTIVE) {
  475. alert(0)
  476. return false;
  477. } else {
  478. alert(1)
  479. return true;
  480. }
  481. } catch(e) {
  482. alert("not try")
  483. return true;
  484. };
  485. }
  486. sg_load_perc = 0;
  487. function sg_loadingbar(_graphics, _width, _height, _total, _current, _loadingscreen) {
  488. var room_width = splash_w;
  489. var room_height = splash_h;
  490. var ratio = (room_height/room_width);
  491. if (typeof(window.innerWidth)=='number') {
  492. browser_width = window.innerWidth;
  493. browser_height = window.innerHeight;
  494. } else if (document.documentElement&&document.documentElement.clientWidth) {
  495. browser_width = document.documentElement.clientWidth;
  496. browser_height = document.documentElement.clientHeight;
  497. } else if (document.body&&document.body.clientWidth) {
  498. browser_width = document.body.clientWidth;
  499. browser_height = document.body.clientHeight;
  500. }
  501. var multi = (browser_height / room_height);
  502. var new_width = (room_width * multi);
  503. var new_height = browser_height;
  504. if (new_width > browser_width) {
  505. multi = (browser_width / room_width);
  506. new_width = (room_width * multi);
  507. new_height = (room_height * multi);
  508. }
  509. var load_perc = _current/_total*100;
  510. if (load_perc < 100) {
  511. if (sg_load_perc < load_perc) {
  512. sg_load_perc+=1;
  513. }
  514. } else {
  515. sg_load_perc = 100;
  516. }
  517. var perc = bar_img_w/100*sg_load_perc;
  518. var bar_x = browser_width/2-new_width/2+bar_img_x*multi;
  519. var bar_y = browser_height/2-new_height/2+bar_img_y*multi;
  520. var bar_w = bar_img_w*multi;
  521. var bar_w2 = perc*multi;
  522. var bar_h = bar_img_h*multi;
  523. if (loadbarbackobj) {
  524. loadbarbackobj.setAttribute('style','left: '+bar_x+'px; top: '+bar_y+'px; width:'+bar_w+'px; height:'+bar_h+'px; background-size: '+(bar_img_w*multi)+'px');
  525. }
  526. if (loadbarobj) {
  527. loadbarobj.setAttribute('style','left: '+bar_x+'px; top: '+bar_y+'px; width:'+bar_w2+'px; height:'+bar_h+'px; background-size: '+(bar_img_w*multi)+'px');
  528. }
  529. }