qipa_app.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. if (void 0 == QIPA_DEBUG) var QIPA_DEBUG = !1;
  2. if (void 0 == GID) var GID = "qipa";
  3. if (void 0 == APP_API_URL) var APP_API_URL = /localhost/.test(location.host) ? "http://localhost:8000/": "http://wx.qipagame.com/app/";
  4. if (void 0 == APP_LIST_URL) var APP_LIST_URL = "http://1251002861.cdn.myqcloud.com/1251002861/index.html";
  5. if (void 0 == APP_FOLLOW_URL) var APP_FOLLOW_URL = "http://mp.weixin.qq.com/s?__biz=MzI4MjA2MjE0MQ==&mid=246005295&idx=1&sn=490f8141976d607ba079d48f52a3fcd7#rd";
  6. if (void 0 == ENABLE_SHARE) var ENABLE_SHARE = !0;
  7. if (void 0 == ENABLE_LB) var ENABLE_LB = !0;
  8. var APP_DEPLOYMENT = "WX",
  9. IS_IOS = navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? !0 : !1,
  10. IS_ANDROID = -1 < navigator.userAgent.indexOf("Android"),
  11. KEY_MY_ID = "myid",
  12. KEY_FOLLOWED = "flw",
  13. KEY_BEST_SUFFIX = ":best";
  14. function qipaLog() {
  15. QIPA_DEBUG && console.log(arguments)
  16. }
  17. qipaShare = {
  18. title: GID,
  19. desc: GID,
  20. link: document.URL,
  21. imgUrl: location.origin + location.pathname.replace("index.html", "") + "img/ico_large.png"
  22. };
  23. (function(a, f) {
  24. var c = APP_API_URL + "social/",
  25. d = location.search ? location.search + "&callback=?": "?callback=?",
  26. g = GID + KEY_BEST_SUFFIX;
  27. a.myPid = function() {
  28. return a.storage.get(KEY_MY_ID)
  29. };
  30. a.isFollowed = function() {
  31. return a.storage.get(KEY_FOLLOWED)
  32. };
  33. a.updateLoginInfo = function(b, e) {
  34. qipaLog("updateLoginInfo");
  35. qipaLog("pid: " + b);
  36. qipaLog("followed: " + e);
  37. b && b != a.storage.get(KEY_MY_ID) && a.storage.set(KEY_MY_ID, b);
  38. b && b != a.storage.get(KEY_FOLLOWED) && a.storage.set(KEY_FOLLOWED, e)
  39. };
  40. a.onNewScore = function(b) {
  41. ENABLE_LB && (b > a.best && (newRecord = !0, b > a.best && (a.best = b, a.storage.set(g, a.best))), b > SCORE_LIMIT && a.uploadScore(b))
  42. };
  43. a.storage = a.storage || {};
  44. a.storage.get = function(b) {
  45. try {
  46. if (b in localStorage) return localStorage[b]
  47. } catch(a) {}
  48. return $.cookie(b)
  49. };
  50. a.storage.set = function(b, a) {
  51. try {
  52. return localStorage[b] = a,
  53. !0
  54. } catch(c) {}
  55. $.cookie(b, a, {
  56. expires: 365
  57. });
  58. return ! 0
  59. };
  60. a.score = 0;
  61. a.best = a.storage.get(g) || 0;
  62. a.newRecord = !1;
  63. a.newscore_wxoauth = function(b) {
  64. b = APP_API_URL + "wxoauth/newscore/" + GID + "/?score=" + b + "&callback=?";
  65. qipaLog(b);
  66. $.getJSON(b).done(function(b) {
  67. "wxoauth_needed" == b.error ? qipaLog("upload score failed. wxoauth_needed.") : a.updateLoginInfo(b.pid, b.subscribed)
  68. })
  69. };
  70. a.uploadScore = function(b) {
  71. b = APP_API_URL + "newscore/" + GID + "/" + b + "/?callback=?";
  72. qipaLog(b);
  73. $.getJSON(b).done(function(b) {
  74. qipaLog(b);
  75. "wxoauth_needed" == b.error ? qipaLog("upload score failed. wxoauth_needed.") : a.updateLoginInfo(b.pid, b.subscribed)
  76. })
  77. };
  78. a.startOAuth = function() {
  79. qipaLog(APP_API_URL + "wxoauth_start");
  80. window.open(APP_API_URL + "wxoauth_start")
  81. };
  82. a.leaderboard = function(b, a, c) {
  83. qipaLog(APP_API_URL + "leaderboard/" + a + "/" + c + "?callback=?");
  84. $.getJSON(APP_API_URL + "leaderboard/" + a + "/" + c + "?callback=?", b)
  85. };
  86. a.onGameInit = function() {};
  87. a.onGameStarted = function() {
  88. qipaStage.showFollowAnim(!1)
  89. };
  90. a.onGameOver = function() {
  91. qipaStage.showFollowAnim(!0)
  92. };
  93. a.social = a.social || {};
  94. a.social.chongzhi = function(b) {
  95. qipaLog(c + "chongzhi" + d);
  96. $.getJSON(c + "chongzhi" + d, b)
  97. };
  98. a.social.startOAuth = function(b) {
  99. b = encodeURIComponent(b);
  100. qipaLog(c + "wxoauth_start/?ret=" + b);
  101. window.open(c + "wxoauth_start/?ret=" + b)
  102. };
  103. a.social.viewMe = function(b) {
  104. qipaLog(c + "me" + d);
  105. $.getJSON(c + "me" + d, b)
  106. };
  107. a.social.viewPlayer = function(b, a) {
  108. qipaLog(c + "view" + d + "&pid=" + a);
  109. $.getJSON(c + "view" + d + "&pid=" + a, b)
  110. };
  111. a.social.searchPlayer = function(b, a) {
  112. qipaLog(c + "search" + d + "&qstr=" + encodeURIComponent(a));
  113. $.getJSON(c + "search" + d + "&qstr=" + encodeURIComponent(a), b)
  114. };
  115. a.social.friendList = function(b) {
  116. qipaLog(c + "frdlist" + d);
  117. $.getJSON(c + "frdlist" + d, b)
  118. };
  119. a.social.mywall = function(b) {
  120. qipaLog(c + "mywall" + d);
  121. $.getJSON(c + "mywall" + d, b)
  122. };
  123. a.social.peerwall = function(b, a) {
  124. qipaLog(c + "wall" + d + "&pid=" + a);
  125. $.getJSON(c + "wall" + d + "&pid=" + a, b)
  126. };
  127. a.social.conversation = function(b, a) {
  128. qipaLog(c + "conversation" + d + "&pid=" + a);
  129. $.getJSON(c + "conversation" + d + "&pid=" + a, b)
  130. };
  131. a.social.wallAdd = function(a, e, h) {
  132. qipaLog(c + "walladd" + d + "&pid=" + h);
  133. $.getJSON(c + "walladd" + d + "&pid=" + h + "&msg=" + encodeURIComponent(e), a)
  134. };
  135. a.social.wallDel = function(a, e) {
  136. qipaLog(c + "walldel" + d + "&msgid=" + e);
  137. $.getJSON(c + "walldel" + d + "&msgid=" + e, a)
  138. };
  139. a.social.friendDel = function(a, e) {
  140. qipaLog(c + "frddel" + d + "&pid=" + e);
  141. $.getJSON(c + "frddel" + d + "&pid=" + e, a)
  142. };
  143. a.social.friendAdd = function(a, e) {
  144. qipaLog(c + "frdadd" + d + "&pid=" + e);
  145. $.getJSON(c + "frdadd" + d + "&pid=" + e, a)
  146. };
  147. a.social.friendBlack = function(a, e) {
  148. qipaLog(c + "frdblack" + d + "&pid=" + e);
  149. $.getJSON(c + "frdblack" + d + "&pid=" + e, a)
  150. };
  151. a.leaderboard = function(a, c, d) {
  152. qipaLog(APP_API_URL + "leaderboard/" + c + "/" + d + "?callback=?");
  153. $.getJSON(APP_API_URL + "leaderboard/" + c + "/" + d + "?callback=?", a)
  154. }
  155. })(window.qipaApp = window.qipaApp || {});
  156. function qipaUi_showPopup(a) {
  157. qipaLog("showPopup url: " + a);
  158. window.scroll(0, 0);
  159. var f = document.body.scrollWidth,
  160. c = document.body.scrollHeight;
  161. void 0 == window.popup && (window.popup = $('<iframe id="popup" class="app-popup">'), $("body").append(window.popup));
  162. window.popup.attr("src", a);
  163. window.popup.css({
  164. width: f,
  165. height: c
  166. }).fadeIn()
  167. };