ctl_utils.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. var s_iScaleFactor = 1;
  2. var s_bIsIphone = false;
  3. var s_oCanvasLeft;
  4. var s_oCanvasTop;
  5. var s_iOffsetX;
  6. var s_iOffsetY;
  7. var s_bFocus = true;
  8. /**
  9. * jQuery.browser.mobile (http://detectmobilebrowser.com/)
  10. * jQuery.browser.mobile will be true if the browser is a mobile device
  11. **/
  12. (function(a){(jQuery.browser=jQuery.browser||{}).mobile=/android|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(ad|hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|tablet|treo|up\.(browser|link)|vodafone|wap|webos|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))})(navigator.userAgent||navigator.vendor||window.opera);
  13. $(window).resize(function() {
  14. sizeHandler();
  15. });
  16. function trace(szMsg){
  17. console.log(szMsg);
  18. }
  19. function isMobile(){
  20. if(isIpad()){
  21. return true;
  22. }
  23. return jQuery.browser.mobile;
  24. }
  25. function isIpad() {
  26. var isIpad = navigator.userAgent.toLowerCase().indexOf('ipad') !== -1;
  27. if (!isIpad && navigator.userAgent.match(/Mac/) && navigator.maxTouchPoints && navigator.maxTouchPoints > 2) {
  28. return true;
  29. }
  30. return isIpad;
  31. }
  32. function isIOS() {
  33. var iDevices = [
  34. 'iPad Simulator',
  35. 'iPhone Simulator',
  36. 'iPod Simulator',
  37. 'iPad',
  38. 'iPhone',
  39. 'iPod'
  40. ];
  41. if (navigator.userAgent.toLowerCase().indexOf("iphone") !== -1){
  42. s_bIsIphone = true;
  43. return true;
  44. }
  45. while (iDevices.length) {
  46. if (navigator.platform === iDevices.pop()){
  47. s_bIsIphone = true;
  48. return true;
  49. }
  50. }
  51. s_bIsIphone = false;
  52. return false;
  53. }
  54. window.addEventListener("orientationchange", onOrientationChange );
  55. function onOrientationChange(){
  56. sizeHandler();
  57. }
  58. function getSize(Name) {
  59. var size;
  60. var name = Name.toLowerCase();
  61. var document = window.document;
  62. var documentElement = document.documentElement;
  63. if (window["inner" + Name] === undefined) {
  64. // IE6 & IE7 don't have window.innerWidth or innerHeight
  65. size = documentElement["client" + Name];
  66. }
  67. else if (window["inner" + Name] != documentElement["client" + Name]) {
  68. // WebKit doesn't include scrollbars while calculating viewport size so we have to get fancy
  69. // Insert markup to test if a media query will match document.doumentElement["client" + Name]
  70. var bodyElement = document.createElement("body");
  71. bodyElement.id = "vpw-test-b";
  72. bodyElement.style.cssText = "overflow:scroll";
  73. var divElement = document.createElement("div");
  74. divElement.id = "vpw-test-d";
  75. divElement.style.cssText = "position:absolute;top:-1000px";
  76. // Getting specific on the CSS selector so it won't get overridden easily
  77. divElement.innerHTML = "<style>@media(" + name + ":" + documentElement["client" + Name] + "px){body#vpw-test-b div#vpw-test-d{" + name + ":7px!important}}</style>";
  78. bodyElement.appendChild(divElement);
  79. documentElement.insertBefore(bodyElement, document.head);
  80. if (divElement["offset" + Name] == 7) {
  81. // Media query matches document.documentElement["client" + Name]
  82. size = documentElement["client" + Name];
  83. }
  84. else {
  85. // Media query didn't match, use window["inner" + Name]
  86. size = window["inner" + Name];
  87. }
  88. // Cleanup
  89. documentElement.removeChild(bodyElement);
  90. }
  91. else {
  92. // Default to use window["inner" + Name]
  93. size = window["inner" + Name];
  94. }
  95. return size;
  96. };function getIOSWindowHeight() {
  97. // Get zoom level of mobile Safari
  98. // Note, that such zoom detection might not work correctly in other browsers
  99. // We use width, instead of height, because there are no vertical toolbars :)
  100. var zoomLevel = document.documentElement.clientWidth / window.innerWidth;
  101. // window.innerHeight returns height of the visible area.
  102. // We multiply it by zoom and get out real height.
  103. return window.innerHeight * zoomLevel;
  104. };
  105. // You can also get height of the toolbars that are currently displayed
  106. function getHeightOfIOSToolbars() {
  107. var tH = (window.orientation === 0 ? screen.height : screen.width) - getIOSWindowHeight();
  108. return tH > 1 ? tH : 0;
  109. };
  110. //THIS FUNCTION MANAGES THE CANVAS SCALING TO FIT PROPORTIONALLY THE GAME TO THE CURRENT DEVICE RESOLUTION
  111. function sizeHandler() {
  112. window.scrollTo(0, 1);
  113. if (!$("#canvas")){
  114. return;
  115. }
  116. var h;
  117. if(platform.name !== null && platform.name.toLowerCase() === "safari"){
  118. h = getIOSWindowHeight();
  119. }else{
  120. h = getSize("Height");
  121. }
  122. var w = getSize("Width");
  123. if(s_bFocus){
  124. _checkOrientation(w,h);
  125. }
  126. var multiplier = s_iScaleFactor = Math.min((h / CANVAS_HEIGHT), (w / CANVAS_WIDTH));
  127. var destW = Math.round(CANVAS_WIDTH * multiplier);
  128. var destH = Math.round(CANVAS_HEIGHT * multiplier);
  129. var iAdd = 0;
  130. if (destH < h){
  131. iAdd = h-destH;
  132. destH += iAdd;
  133. destW += iAdd*(CANVAS_WIDTH/CANVAS_HEIGHT);
  134. }else if (destW < w){
  135. iAdd = w-destW;
  136. destW += iAdd;
  137. destH += iAdd*(CANVAS_HEIGHT/CANVAS_WIDTH);
  138. }
  139. var fOffsetY = ((h / 2) - (destH / 2));
  140. var fOffsetX = ((w / 2) - (destW / 2));
  141. var fGameInverseScaling = (CANVAS_WIDTH/destW);
  142. if( fOffsetX*fGameInverseScaling < -EDGEBOARD_X ||
  143. fOffsetY*fGameInverseScaling < -EDGEBOARD_Y ){
  144. multiplier = s_iScaleFactor = Math.min( h / (CANVAS_HEIGHT-(EDGEBOARD_Y*2)), w / (CANVAS_WIDTH-(EDGEBOARD_X*2)));
  145. destW = Math.round(CANVAS_WIDTH * multiplier);
  146. destH = Math.round(CANVAS_HEIGHT * multiplier);
  147. fOffsetY = ( h - destH ) / 2;
  148. fOffsetX = ( w - destW ) / 2;
  149. fGameInverseScaling = (CANVAS_WIDTH/destW);
  150. }
  151. s_iOffsetX = (-1*fOffsetX * fGameInverseScaling);
  152. s_iOffsetY = (-1*fOffsetY * fGameInverseScaling);
  153. if(fOffsetY >= 0 ){
  154. s_iOffsetY = 0;
  155. }
  156. if(fOffsetX >= 0 ){
  157. s_iOffsetX = 0;
  158. }
  159. if(s_oInterface !== null){
  160. s_oInterface.refreshButtonPos( s_iOffsetX,s_iOffsetY);
  161. }
  162. if(s_oMenu !== null){
  163. s_oMenu.refreshButtonPos( s_iOffsetX,s_iOffsetY);
  164. }
  165. if(s_bIsIphone){
  166. canvas = document.getElementById('canvas');
  167. s_oStage.canvas.width = destW*2;
  168. s_oStage.canvas.height = destH*2;
  169. canvas.style.width = destW+"px";
  170. canvas.style.height = destH+"px";
  171. var iScale = Math.min(destW / CANVAS_WIDTH, destH / CANVAS_HEIGHT);
  172. s_iScaleFactor = iScale*2;
  173. s_oStage.scaleX = s_oStage.scaleY = s_iScaleFactor;
  174. }else if(s_bMobile && isIOS() === false){
  175. $("#canvas").css("width",destW+"px");
  176. $("#canvas").css("height",destH+"px");
  177. }else{
  178. s_oStage.canvas.width = destW;
  179. s_oStage.canvas.height = destH;
  180. s_iScaleFactor = Math.min(destW / CANVAS_WIDTH, destH / CANVAS_HEIGHT);
  181. s_oStage.scaleX = s_oStage.scaleY = s_iScaleFactor;
  182. }
  183. if(fOffsetY < 0){
  184. $("#canvas").css("top",fOffsetY+"px");
  185. }else{
  186. // centered game
  187. fOffsetY = (h - destH)/2;
  188. $("#canvas").css("top",fOffsetY+"px");
  189. }
  190. $("#canvas").css("left",fOffsetX+"px");
  191. s_oCanvasLeft = $("#canvas").offset().left;
  192. s_oCanvasTop = $("#canvas").offset().top;
  193. fullscreenHandler();
  194. };
  195. function _checkOrientation(iWidth,iHeight){
  196. if(s_bMobile && ENABLE_CHECK_ORIENTATION){
  197. if( iWidth>iHeight ){
  198. if( $(".orientation-msg-container").attr("data-orientation") === "landscape" ){
  199. $(".orientation-msg-container").css("display","none");
  200. s_oMain.startUpdate();
  201. }else{
  202. $(".orientation-msg-container").css("display","block");
  203. s_oMain.stopUpdate();
  204. }
  205. }else{
  206. if( $(".orientation-msg-container").attr("data-orientation") === "portrait" ){
  207. $(".orientation-msg-container").css("display","none");
  208. s_oMain.startUpdate();
  209. }else{
  210. $(".orientation-msg-container").css("display","block");
  211. s_oMain.stopUpdate();
  212. }
  213. }
  214. }
  215. }
  216. function createBitmap(oSprite, iWidth, iHeight){
  217. var oBmp = new createjs.Bitmap(oSprite);
  218. var hitObject = new createjs.Shape();
  219. if (iWidth && iHeight){
  220. hitObject .graphics.beginFill("#fff").drawRect(0, 0, iWidth, iHeight);
  221. }else{
  222. hitObject .graphics.beginFill("#ff0").drawRect(0, 0, oSprite.width, oSprite.height);
  223. }
  224. oBmp.hitArea = hitObject;
  225. return oBmp;
  226. }
  227. function createSprite(oSpriteSheet, szState, iRegX,iRegY,iWidth, iHeight){
  228. if(szState !== null){
  229. var oRetSprite = new createjs.Sprite(oSpriteSheet, szState);
  230. }else{
  231. var oRetSprite = new createjs.Sprite(oSpriteSheet);
  232. }
  233. var hitObject = new createjs.Shape();
  234. hitObject .graphics.beginFill("#000000").drawRect(-iRegX, -iRegY, iWidth, iHeight);
  235. oRetSprite.hitArea = hitObject;
  236. return oRetSprite;
  237. }
  238. function randomFloatBetween(minValue,maxValue,precision){
  239. if(typeof(precision) === 'undefined'){
  240. precision = 2;
  241. }
  242. return parseFloat(Math.min(minValue + (Math.random() * (maxValue - minValue)),maxValue).toFixed(precision));
  243. }
  244. function shuffle(array) {
  245. var currentIndex = array.length
  246. , temporaryValue
  247. , randomIndex
  248. ;
  249. // While there remain elements to shuffle...
  250. while (0 !== currentIndex) {
  251. // Pick a remaining element...
  252. randomIndex = Math.floor(Math.random() * currentIndex);
  253. currentIndex -= 1;
  254. // And swap it with the current element.
  255. temporaryValue = array[currentIndex];
  256. array[currentIndex] = array[randomIndex];
  257. array[randomIndex] = temporaryValue;
  258. }
  259. return array;
  260. }
  261. function dotProductV2(v1,v2){
  262. return ( v1.x*v2.x+ v1.y*v2.y );
  263. }
  264. function distanceV2( v1, v2 ){
  265. return Math.sqrt( ( (v2.x-v1.x)*(v2.x-v1.x) ) + ( (v2.y-v1.y)*(v2.y-v1.y) ) );
  266. }
  267. function closestPointOnLine( vA, vB, vPoint ){
  268. var v1 = {x:vPoint.x,y:vPoint.y};
  269. v1.x -= vA.x;
  270. v1.y -= vA.y;
  271. var v2 = {x:vB.x,y:vB.y};
  272. v2.x -= vA.x;
  273. v2.y -= vA.y;
  274. var len = Math.sqrt( v2.x*v2.x+v2.y*v2.y );
  275. if (len > 0 ){
  276. v2.x/= len; v2.y/=len;
  277. }
  278. var t = dotProductV2(v2,v1);
  279. if ( t <= 0){
  280. return vA;
  281. }
  282. if ( t >= distanceV2(vA,vB) ){
  283. return vB;
  284. }
  285. v2.x *= t;
  286. v2.y *= t;
  287. v2.x += vA.x;
  288. v2.y += vA.y;
  289. return v2;
  290. }
  291. function toRadian( n ) {
  292. return ((n) * (Math.PI /180));
  293. }
  294. function toDegree( n ) {
  295. return ((n) * (180 / Math.PI));
  296. }
  297. function collideEdgeWithCircle( oSegmentPointA, oSegmentPointB,oCenter,iRadius ){
  298. var oPt = closestPointOnLine( oSegmentPointA, oSegmentPointB, oCenter );
  299. var iDist = distanceV2( oCenter, oPt );
  300. return (iRadius < iDist) ? false : true;
  301. }
  302. function rotateVector2D( iAngle, v ) {
  303. var iX = v.getX() * Math.cos( iAngle ) + v.getY() * Math.sin( iAngle );
  304. var iY = v.getX() * (-Math.sin( iAngle )) + v.getY() * Math.cos( iAngle );
  305. return new CVector2( iX, iY );
  306. }
  307. function getBounds(obj,iTolerance) {
  308. var bounds={x:Infinity,y:Infinity,width:0,height:0};
  309. if ( obj instanceof createjs.Container ) {
  310. bounds.x2 = -Infinity;
  311. bounds.y2 = -Infinity;
  312. var children = obj.children, l=children.length, cbounds, c;
  313. for ( c = 0; c < l; c++ ) {
  314. cbounds = getBounds(children[c],1);
  315. if ( cbounds.x < bounds.x ) bounds.x = cbounds.x;
  316. if ( cbounds.y < bounds.y ) bounds.y = cbounds.y;
  317. if ( cbounds.x + cbounds.width > bounds.x2 ) bounds.x2 = cbounds.x + cbounds.width;
  318. if ( cbounds.y + cbounds.height > bounds.y2 ) bounds.y2 = cbounds.y + cbounds.height;
  319. //if ( cbounds.x - bounds.x + cbounds.width > bounds.width ) bounds.width = cbounds.x - bounds.x + cbounds.width;
  320. //if ( cbounds.y - bounds.y + cbounds.height > bounds.height ) bounds.height = cbounds.y - bounds.y + cbounds.height;
  321. }
  322. if ( bounds.x == Infinity ) bounds.x = 0;
  323. if ( bounds.y == Infinity ) bounds.y = 0;
  324. if ( bounds.x2 == Infinity ) bounds.x2 = 0;
  325. if ( bounds.y2 == Infinity ) bounds.y2 = 0;
  326. bounds.width = bounds.x2 - bounds.x;
  327. bounds.height = bounds.y2 - bounds.y;
  328. delete bounds.x2;
  329. delete bounds.y2;
  330. } else {
  331. var gp,gp2,gp3,gp4,imgr={},sr;
  332. if ( obj instanceof createjs.Bitmap ) {
  333. sr = obj.sourceRect || obj.image;
  334. imgr.width = sr.width * iTolerance;
  335. imgr.height = sr.height * iTolerance;
  336. } else if ( obj instanceof createjs.Sprite ) {
  337. if ( obj.spriteSheet._frames && obj.spriteSheet._frames[obj.currentFrame] && obj.spriteSheet._frames[obj.currentFrame].image ) {
  338. var cframe = obj.spriteSheet.getFrame(obj.currentFrame);
  339. imgr.width = cframe.rect.width;
  340. imgr.height = cframe.rect.height;
  341. imgr.regX = cframe.regX;
  342. imgr.regY = cframe.regY;
  343. } else {
  344. bounds.x = obj.x || 0;
  345. bounds.y = obj.y || 0;
  346. }
  347. } else {
  348. bounds.x = obj.x || 0;
  349. bounds.y = obj.y || 0;
  350. }
  351. imgr.regX = imgr.regX || 0; imgr.width = imgr.width || 0;
  352. imgr.regY = imgr.regY || 0; imgr.height = imgr.height || 0;
  353. bounds.regX = imgr.regX;
  354. bounds.regY = imgr.regY;
  355. gp = obj.localToGlobal(0 -imgr.regX,0 -imgr.regY);
  356. gp2 = obj.localToGlobal(imgr.width-imgr.regX,imgr.height-imgr.regY);
  357. gp3 = obj.localToGlobal(imgr.width-imgr.regX,0 -imgr.regY);
  358. gp4 = obj.localToGlobal(0 -imgr.regX,imgr.height-imgr.regY);
  359. bounds.x = Math.min(Math.min(Math.min(gp.x,gp2.x),gp3.x),gp4.x);
  360. bounds.y = Math.min(Math.min(Math.min(gp.y,gp2.y),gp3.y),gp4.y);
  361. bounds.width = Math.max(Math.max(Math.max(gp.x,gp2.x),gp3.x),gp4.x) - bounds.x;
  362. bounds.height = Math.max(Math.max(Math.max(gp.y,gp2.y),gp3.y),gp4.y) - bounds.y;
  363. }
  364. return bounds;
  365. }
  366. function binarySearch(aArray, szValue,iLeft, iRight){
  367. if(iLeft > iRight)
  368. return -1;
  369. var iMiddle = Math.floor((iLeft + iRight) / 2);
  370. if(aArray[iMiddle].toLowerCase() === szValue.toLowerCase())
  371. return iMiddle;
  372. else if(aArray[iMiddle].toLowerCase() > szValue.toLowerCase())
  373. return binarySearch(aArray, szValue, iLeft,iMiddle - 1);
  374. else
  375. return binarySearch(aArray, szValue, iMiddle + 1,iRight);
  376. }
  377. function between(min, p, max){
  378. var bResult = false;
  379. if ( min < max ){
  380. if ( p > min && p < max ){
  381. bResult = true;
  382. }
  383. }
  384. if ( min > max ){
  385. if ( p > max && p < min){
  386. bResult = true;
  387. }
  388. }
  389. if ( p === min || p === max ){
  390. bResult = true;
  391. }
  392. return bResult;
  393. }
  394. function pointInRectangle( x, y, oRect){
  395. var bResult = false;
  396. var left = oRect.x;
  397. var top = oRect.y;
  398. var right = oRect.width;
  399. var bottom = oRect.height;
  400. if ( between(left,x,right) && between(top,y,bottom ) ){
  401. bResult = true;
  402. }
  403. return bResult;
  404. }
  405. function NoClickDelay(el) {
  406. this.element = el;
  407. if( window.Touch ) this.element.addEventListener('touchstart', this, false);
  408. }
  409. NoClickDelay.prototype = {
  410. handleEvent: function(e) {
  411. switch(e.type) {
  412. case 'touchstart': this.onTouchStart(e); break;
  413. case 'touchmove': this.onTouchMove(e); break;
  414. case 'touchend': this.onTouchEnd(e); break;
  415. }
  416. },
  417. onTouchStart: function(e) {
  418. e.preventDefault();
  419. this.moved = false;
  420. this.element.addEventListener('touchmove', this, false);
  421. this.element.addEventListener('touchend', this, false);
  422. },
  423. onTouchMove: function(e) {
  424. this.moved = true;
  425. },
  426. onTouchEnd: function(e) {
  427. this.element.removeEventListener('touchmove', this, false);
  428. this.element.removeEventListener('touchend', this, false);
  429. if( !this.moved ) {
  430. var theTarget = document.elementFromPoint(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
  431. if(theTarget.nodeType == 3) theTarget = theTarget.parentNode;
  432. var theEvent = document.createEvent('MouseEvents');
  433. theEvent.initEvent('click', true, true);
  434. theTarget.dispatchEvent(theEvent);
  435. }
  436. }
  437. };
  438. (function() {
  439. var hidden = "hidden";
  440. // Standards:
  441. if (hidden in document)
  442. document.addEventListener("visibilitychange", onchange);
  443. else if ((hidden = "mozHidden") in document)
  444. document.addEventListener("mozvisibilitychange", onchange);
  445. else if ((hidden = "webkitHidden") in document)
  446. document.addEventListener("webkitvisibilitychange", onchange);
  447. else if ((hidden = "msHidden") in document)
  448. document.addEventListener("msvisibilitychange", onchange);
  449. // IE 9 and lower:
  450. else if ('onfocusin' in document)
  451. document.onfocusin = document.onfocusout = onchange;
  452. // All others:
  453. else
  454. window.onpageshow = window.onpagehide
  455. = window.onfocus = window.onblur = onchange;
  456. function onchange (evt) {
  457. var v = 'visible', h = 'hidden',
  458. evtMap = {
  459. focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h
  460. };
  461. evt = evt || window.event;
  462. if (evt.type in evtMap){
  463. document.body.className = evtMap[evt.type];
  464. }else{
  465. document.body.className = this[hidden] ? "hidden" : "visible";
  466. if(document.body.className === "hidden"){
  467. s_oMain.stopUpdate();
  468. s_bFocus = false;
  469. }else{
  470. s_oMain.startUpdate();
  471. s_bFocus = true;
  472. }
  473. }
  474. }
  475. })();
  476. function playSound(szSound,iVolume,bLoop){
  477. if(DISABLE_SOUND_MOBILE === false || s_bMobile === false){
  478. s_aSounds[szSound].play();
  479. s_aSounds[szSound].volume(iVolume);
  480. s_aSounds[szSound].loop(bLoop);
  481. return s_aSounds[szSound];
  482. }
  483. return null;
  484. }
  485. function stopSound(szSound){
  486. if(DISABLE_SOUND_MOBILE === false || s_bMobile === false){
  487. s_aSounds[szSound].stop();
  488. }
  489. }
  490. function setVolume(szSound, iVolume){
  491. if(DISABLE_SOUND_MOBILE === false || s_bMobile === false){
  492. s_aSounds[szSound].volume(iVolume);
  493. }
  494. }
  495. function setMute(szSound, bMute){
  496. if(DISABLE_SOUND_MOBILE === false || s_bMobile === false){
  497. s_aSounds[szSound].mute(bMute);
  498. }
  499. }
  500. function ctlArcadeResume(){
  501. if(s_oMain !== null){
  502. s_oMain.startUpdate();
  503. }
  504. }
  505. function ctlArcadePause(){
  506. if(s_oMain !== null){
  507. s_oMain.stopUpdate();
  508. }
  509. }
  510. function getParamValue(paramName){
  511. var url = window.location.search.substring(1);
  512. var qArray = url.split('&');
  513. for (var i = 0; i < qArray.length; i++)
  514. {
  515. var pArr = qArray[i].split('=');
  516. if (pArr[0] == paramName)
  517. return pArr[1];
  518. }
  519. }
  520. function fullscreenHandler(){
  521. if (!ENABLE_FULLSCREEN || !screenfull.isEnabled){
  522. return;
  523. }
  524. s_bFullscreen = screenfull.isFullscreen;
  525. if (s_oInterface !== null){
  526. s_oInterface.resetFullscreenBut();
  527. }
  528. if (s_oMenu !== null){
  529. s_oMenu.resetFullscreenBut();
  530. }
  531. }
  532. if (screenfull.isEnabled) {
  533. screenfull.on('change', function(){
  534. s_bFullscreen = screenfull.isFullscreen;
  535. if (s_oInterface !== null){
  536. s_oInterface.resetFullscreenBut();
  537. }
  538. if (s_oMenu !== null){
  539. s_oMenu.resetFullscreenBut();
  540. }
  541. });
  542. }