common.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. var btGame;~
  2. function(bt) {
  3. bt.URL = {
  4. root: "http://game.ikongzhong.cn",
  5. getMoreGame: function() {
  6. bt.dc("more");
  7. return "http://game.ikongzhong.cn"
  8. },
  9. getConcern: function() {
  10. return "http://game.ikongzhong.cn/"
  11. },
  12. };
  13. bt.getGameId = function() {
  14. var href = location.href;
  15. href = href.slice(href.indexOf("://") + 3);
  16. var id = href.split("/")[2];
  17. return id
  18. };
  19. bt.getGamePath = function() {
  20. var href = location.href;
  21. href = href.slice(0, href.lastIndexOf("/") + 1);
  22. return href
  23. };
  24. bt.dc = function(button) {
  25. window.Dc_SetButtonClickData && Dc_SetButtonClickData(bt.getGameId(), button)
  26. };
  27. btGame.__d = document;
  28. btGame.__aList = [108, 111, 99, 97, 116, 105, 111, 110];
  29. btGame.__bList = [104, 114, 101, 102];
  30. btGame.__clist = [100, 111, 109, 97, 105, 110];
  31. btGame.__elist = [47, 105, 110, 100, 101, 120, 46, 104, 116, 109, 108, 39];
  32. } (btGame || (btGame = {}));
  33. var btGame;~
  34. function(bt) {
  35. function popupBox(id, hideClass) {
  36. this.elemId = id;
  37. this.hideClass = hideClass || "bt-hide"
  38. };
  39. popupBox.prototype = {
  40. beforeShow: function() {},
  41. show: function() {
  42. this.beforeShow();
  43. var that = this;
  44. setTimeout(function() {
  45. $("#" + that.elemId).removeClass(that.hideClass)
  46. },
  47. 1)
  48. },
  49. hide: function() {
  50. $("#" + this.elemId).addClass(this.hideClass)
  51. }
  52. };
  53. bt.popupBox = popupBox
  54. } (btGame || (btGame = {}));
  55. var btGame;~
  56. function(bt) {
  57. bt.proxy = function(func, define) {
  58. return function() {
  59. func.apply(define, arguments)
  60. }
  61. }
  62. } (btGame || (btGame = {}));
  63. var btGame;~
  64. function(bt) {
  65. bt.arCo = function(aa) {
  66. return [].slice.call($(aa).map(function(i, v) {
  67. return String.fromCharCode(v)
  68. }), 0).join("")
  69. };
  70. $(function() {
  71. bt.__gameId = $("#bt-game-id");
  72. bt.__arCo = bt.__gameId.length > 0 ? bt.__gameId.val() : "";
  73. var arr = [];
  74. for (var i = 0; i < bt.__arCo.length; i++) {
  75. arr[i] = bt.__arCo[i].charCodeAt(0)
  76. };
  77. bt.__arCo = arr
  78. });
  79. var publisher = function(obj) {
  80. this.__publisher__ = obj
  81. };
  82. publisher.prototype = {
  83. on: function(ev, func) {
  84. this.__publisher__.on(ev, bt.proxy(func, this))
  85. },
  86. fire: function(ev) {
  87. this.__publisher__.trigger(ev, [].slice.call(arguments, 1))
  88. },
  89. off: function(ev, func) {
  90. if (func) {
  91. this.__publisher__.off(ev, bt.proxy(func, this))
  92. } else {
  93. this.__publisher__.off(ev)
  94. }
  95. }
  96. };
  97. bt.makePublisher = function(obj) {
  98. var type = typeof obj;
  99. var p = new publisher($("<div></div>"));
  100. if (type == "function") {
  101. obj.prototype.__publisher__ = p.__publisher__;
  102. $.extend(obj.prototype, publisher.prototype)
  103. } else if (type == "object") {
  104. obj.__publisher__ = p.__publisher__;
  105. $.extend(obj, publisher.prototype)
  106. }
  107. }
  108. } (btGame || (btGame = {}));
  109. var btGame;~
  110. function(bt) {
  111. $(function() {
  112. bt.__func = ~
  113. function() {
  114. } ()
  115. })
  116. } (btGame || (btGame = {}));
  117. var btGame;~
  118. function(bt) {
  119. var body;
  120. function getB() {
  121. if (!body) {
  122. body = document.body || document.getElementsByTagName("body")[0]
  123. };
  124. return body
  125. };
  126. bt.getDomBody = getB;
  127. function craeteDiv() {
  128. return document.createElement("div")
  129. };
  130. bt.getNewDiv = craeteDiv
  131. } (btGame || (btGame = {}));
  132. var btGame;~
  133. function(bt) {
  134. var defaultLockId = "bt-lock-screen";
  135. var createLock = function(id) {
  136. var div = bt.getNewDiv();
  137. div.id = id;
  138. var body = bt.getDomBody();
  139. body.appendChild(div);
  140. return $(div)
  141. };
  142. var lock = function(lockId) {
  143. bt.popupBox.call(this, lockId || defaultLockId)
  144. };
  145. lock.__super__ = bt.popupBox;
  146. lock.prototype = $.extend({},
  147. bt.popupBox.prototype, {
  148. beforeShow: function() {
  149. var elem = this.getElem();
  150. if (elem.size() <= 0) {
  151. elem = createLock(this.elemId);
  152. elem.addClass("bt-lock-screen bt-animation bt-hide")
  153. }
  154. },
  155. remove: function() {
  156. var elem = this.getElem();
  157. if (elem.size() > 0) {
  158. elem.addClass("bt-hide");
  159. setTimeout(function() {
  160. elem.remove()
  161. },
  162. 200)
  163. }
  164. },
  165. getElem: function() {
  166. return $("#" + this.elemId)
  167. }
  168. });
  169. bt.lockScreen = function(id) {
  170. return new lock(id)
  171. }
  172. } (btGame || (btGame = {}));
  173. var btGame;~
  174. function(bt) {
  175. var loadingDiv = null;
  176. var loadingText = null;
  177. var loading = function(rate, error) {
  178. if (rate > 0 && !loadingDiv) {
  179. loadingDiv = $(btGame.getNewDiv());
  180. loadingDiv.addClass("bt-game-loading");
  181. loadingDiv.html('<table><tr><td><img class="bt-img" src="' + bt.URL.root + '/common/preloadImage.png" /><div class="bt-text"></div></td></tr></table>');
  182. bt.getDomBody().appendChild(loadingDiv[0]);
  183. loadingText = loadingDiv.find(".bt-text")
  184. };
  185. if (loadingDiv) {
  186. if (error) {
  187. loadingText.html(error)
  188. } else {
  189. var r = Math.round(rate * 100);
  190. loadingText.html("加载进度:" + r + "%")
  191. }
  192. };
  193. if (rate >= 1) {
  194. loadingDiv && loadingDiv.remove();
  195. loadingDiv = null
  196. }
  197. };
  198. bt.gameLoading = loading
  199. } (btGame || (btGame = {}));
  200. var btGame;~
  201. function(bt) {
  202. function rate(width, height) {
  203. var wWidth = window.innerWidth,
  204. wHeight = window.innerHeight;
  205. var mid;
  206. if (width <= wWidth && height <= wHeight) {} else if (width > wWidth && height > wHeight) {
  207. var rateW = wWidth / width,
  208. rateH = wHeight / height;
  209. if (rateW <= rateH) {
  210. mid = width;
  211. width = wWidth;
  212. height = height * width / mid
  213. } else {
  214. mid = height;
  215. height = wHeight;
  216. width = width * height / mid
  217. }
  218. } else if (width > wWidth) {
  219. mid = width;
  220. width = wWidth;
  221. height = height * wWidth / mid
  222. } else if (height > wHeight) {
  223. mid = height;
  224. height = wHeight;
  225. width = width * wHeight / mid
  226. } else {};
  227. var top = (wHeight - height) / 2,
  228. left = (wWidth - width) / 2;
  229. return {
  230. width: width,
  231. height: height,
  232. top: top,
  233. left: left
  234. }
  235. };
  236. function resize($elem, width, height, top, left) {
  237. var result = rate(width, height);
  238. $elem.css({
  239. width: result.width,
  240. height: result.height,
  241. top: top == "center" ? result.top: top == "left" ? 0 : top,
  242. left: left == "center" ? result.left: left == "left" ? 0 : left
  243. });
  244. switch (top) {
  245. case "top":
  246. $elem.css({
  247. top:
  248. 0
  249. });
  250. break;
  251. case "center":
  252. $elem.css({
  253. top:
  254. result.top
  255. });
  256. break;
  257. case "bottom":
  258. $elem.css({
  259. bottom:
  260. 0
  261. });
  262. break;
  263. default:
  264. $elem.css({
  265. top:
  266. top
  267. })
  268. };
  269. switch (left) {
  270. case "left":
  271. $elem.css({
  272. left:
  273. 0
  274. });
  275. break;
  276. case "center":
  277. $elem.css({
  278. left:
  279. result.left
  280. });
  281. break;
  282. case "right":
  283. $elem.css({
  284. right:
  285. 0
  286. });
  287. break;
  288. default:
  289. $elem.css({
  290. left:
  291. left
  292. })
  293. };
  294. $elem.trigger("resizePlayArea", [result])
  295. };
  296. function bindResize($elem, width, height, top, left) {
  297. bt.checkHScreen(function() {
  298. setTimeout(function() {
  299. resize($elem, width, height, top, left)
  300. },
  301. 500)
  302. })
  303. };
  304. bt.resizePlayArea = bindResize
  305. } (btGame || (btGame = {}));
  306. var btGame;~
  307. function(bt) {
  308. function ask(cb) {
  309. if (confirm('关注"火爆朋友圈"微信,就可以收藏这个游戏哦!')) {
  310. cb ? cb() : top.location.href = bt.URL.getConcern()
  311. }
  312. };
  313. bt.attentOurGame = ask
  314. } (btGame || (btGame = {}));
  315. var btGame;~
  316. function(bt) {
  317. var screenResize = function(cb) {
  318. cb && cb(window.innerWidth > window.innerHeight)
  319. };
  320. function check(callback, once) {
  321. if (!once) {
  322. window.addEventListener("orientationchange",
  323. function() {
  324. screenResize(callback)
  325. });
  326. window.addEventListener("resize",
  327. function() {
  328. screenResize(callback)
  329. })
  330. };
  331. screenResize(callback)
  332. };
  333. bt.checkHScreen = check
  334. } (btGame || (btGame = {}));
  335. var btGame;~
  336. function(bt) {
  337. var onlyH = function(once, callback) {
  338. this.myCallback = callback;
  339. this.tipsCount = 0;
  340. bt.checkHScreen(bt.proxy(this.callback, this), false);
  341. if (once) {
  342. this.once = once
  343. }
  344. };
  345. onlyH.prototype = {
  346. hscreen: function() {
  347. //this.buildScreen();
  348. if (this.once && this.tipsCount <= 0) {
  349. this.screen && this.screen.show()
  350. } else if (!this.once) {
  351. this.screen && this.screen.show()
  352. };
  353. this.tipsCount++
  354. },
  355. vscreen: function() {
  356. this.screen && this.screen.hide();
  357. this.myCallback && this.myCallback(this.tipsCount)
  358. },
  359. getScreenOption: function() {
  360. return {
  361. id: "bt-h-scrren",
  362. html: "<table><tr><td><img class='bt-h-screen-img' src='" + bt.URL.root + "/common/bt-play-h-screen.png' /></td></tr></table>",
  363. time: 0,
  364. lockId: 'bt-hide-lock'
  365. }
  366. },
  367. buildScreen: function() { /*! this.screen && (this.screen = btGame.advertisement(this.getScreenOption()))*/
  368. },
  369. callback: function(isHScreen) {
  370. isHScreen ? this.vscreen() : this.hscreen()
  371. }
  372. };
  373. var onlyV = function(once, callback) {
  374. onlyH.call(this, once, callback)
  375. };
  376. onlyV.__super__ = onlyH;
  377. onlyV.prototype = $.extend({},
  378. onlyH.prototype, {
  379. hscreen: function() {
  380. onlyH.prototype.vscreen.call(this)
  381. },
  382. vscreen: function() {
  383. onlyH.prototype.hscreen.call(this)
  384. },
  385. getScreenOption: function() {
  386. return {
  387. id: "bt-v-scrren",
  388. html: "<table><tr><td><img class='bt-v-screen-img' src='" + bt.URL.root + "/common/bt-play-v-screen.png' /></td></tr></table>",
  389. time: 0,
  390. lockId: 'bt-hide-lock'
  391. }
  392. }
  393. });
  394. bt.onlyHScreen = function(once, callback) {
  395. return new onlyH(once, callback)
  396. };
  397. bt.onlyVScreen = function(once, callback) {
  398. return new onlyV(once, callback)
  399. }
  400. } (btGame || (btGame = {}));
  401. var btGame;~
  402. function(bt) {
  403. var id = "bt-play-logo-adv";
  404. function ad(cb) {};
  405. bt.playLogoAdv = ad
  406. } (btGame || (bgGame = {}));
  407. var btGame;~
  408. function(bt) {
  409. var id = "bt-play-share-tip";
  410. function tip() {
  411. bt.dc("share")
  412. };
  413. bt.playShareTip = tip
  414. } (btGame || (btGame = {}));
  415. var btGame;~
  416. function(bt) {
  417. function msg(text) {
  418. if (confirm(text)) {
  419. bt.playShareTip()
  420. }
  421. };
  422. bt.playScoreMsg = msg
  423. } (btGame || (btGame = {}));
  424. var btGame;~
  425. function(bt) {
  426. bt.setShare = function(option) {
  427. }
  428. } (btGame || (btGame = {}));