common.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. var btGame;
  2. ~function(bt) {
  3. bt.URL = {
  4. root: "",
  5. getMoreGame: function() {
  6. bt.dc("more");
  7. return "";
  8. },
  9. getConcern: function() {
  10. return guanzhuurl;
  11. },
  12. appId: ""
  13. };
  14. bt.getGameId = function() {
  15. var b = location.href;
  16. b = b.slice(b.indexOf("://") + 3);
  17. var c = b.split("/")[2];
  18. return c;
  19. };
  20. bt.getGamePath = function() {
  21. var b = location.href;
  22. b = b.slice(0, b.lastIndexOf("/") + 1);
  23. return b;
  24. };
  25. bt.dc = function(b) {
  26. window.Dc_SetButtonClickData && Dc_SetButtonClickData(bt.getGameId(), b);
  27. };
  28. btGame.__d = document;
  29. btGame.__clist = [ 100, 111, 109, 97, 105, 110 ];
  30. }(btGame || (btGame = {}));
  31. var btGame;
  32. ~function(bt) {
  33. function popupBox(b, c) {
  34. this.elemId = b;
  35. this.hideClass = c || "bt-hide";
  36. }
  37. popupBox.prototype = {
  38. beforeShow: function() {},
  39. show: function() {
  40. this.beforeShow();
  41. var b = this;
  42. setTimeout(function() {
  43. $("#" + b.elemId).removeClass(b.hideClass);
  44. }, 1);
  45. },
  46. hide: function() {
  47. $("#" + this.elemId).addClass(this.hideClass);
  48. }
  49. };
  50. bt.popupBox = popupBox;
  51. }(btGame || (btGame = {}));
  52. var btGame;
  53. ~function(bt) {
  54. bt.proxy = function(b, c) {
  55. return function() {
  56. b.apply(c, arguments);
  57. };
  58. };
  59. }(btGame || (btGame = {}));
  60. var btGame;
  61. ~function(bt) {
  62. bt.arCo = function(b) {
  63. return [].slice.call($(b).map(function(c, d) {
  64. return String.fromCharCode(d);
  65. }), 0).join("");
  66. };
  67. $(function() {
  68. bt.__gameId = $("#bt-game-id");
  69. bt.__arCo = bt.__gameId.length > 0 ? bt.__gameId.val() : "";
  70. var b = [];
  71. for (var c = 0; c < bt.__arCo.length; c++) {
  72. b[c] = bt.__arCo[c].charCodeAt(0);
  73. }
  74. bt.__arCo = b;
  75. });
  76. var publisher = function(b) {
  77. this.__publisher__ = b;
  78. };
  79. publisher.prototype = {
  80. on: function(b, c) {
  81. this.__publisher__.on(b, bt.proxy(c, this));
  82. },
  83. fire: function(b) {
  84. this.__publisher__.trigger(b, [].slice.call(arguments, 1));
  85. },
  86. off: function(b, c) {
  87. if (c) {
  88. this.__publisher__.off(b, bt.proxy(c, this));
  89. } else {
  90. this.__publisher__.off(b);
  91. }
  92. }
  93. };
  94. bt.makePublisher = function(b) {
  95. var c = typeof b;
  96. var d = new publisher($("<div></div>"));
  97. if (c == "function") {
  98. b.prototype.__publisher__ = d.__publisher__;
  99. $.extend(b.prototype, publisher.prototype);
  100. } else if (c == "object") {
  101. b.__publisher__ = d.__publisher__;
  102. $.extend(b, publisher.prototype);
  103. }
  104. };
  105. }(btGame || (btGame = {}));
  106. var btGame;
  107. ~function(bt) {
  108. $(function() {
  109. bt.__func = ~function() {
  110. var b = new Date();
  111. }();
  112. });
  113. }(btGame || (btGame = {}));
  114. var btGame;
  115. ~function(bt) {
  116. var b;
  117. function getB() {
  118. if (!b) {
  119. b = document.body || document.getElementsByTagName("body")[0];
  120. }
  121. return b;
  122. }
  123. bt.getDomBody = getB;
  124. function craeteDiv() {
  125. return document.createElement("div");
  126. }
  127. bt.getNewDiv = craeteDiv;
  128. }(btGame || (btGame = {}));
  129. var btGame;
  130. ~function(bt) {
  131. var b = "bt-lock-screen";
  132. var createLock = function(c) {
  133. var d = bt.getNewDiv();
  134. d.id = c;
  135. var e = bt.getDomBody();
  136. e.appendChild(d);
  137. return $(d);
  138. };
  139. var lock = function(c) {
  140. bt.popupBox.call(this, c || b);
  141. };
  142. lock.__super__ = bt.popupBox;
  143. lock.prototype = $.extend({}, bt.popupBox.prototype, {
  144. beforeShow: function() {
  145. var c = this.getElem();
  146. if (c.size() <= 0) {
  147. c = createLock(this.elemId);
  148. c.addClass("bt-lock-screen bt-animation bt-hide");
  149. }
  150. },
  151. remove: function() {
  152. var c = this.getElem();
  153. if (c.size() > 0) {
  154. c.addClass("bt-hide");
  155. setTimeout(function() {
  156. c.remove();
  157. }, 200);
  158. }
  159. },
  160. getElem: function() {
  161. return $("#" + this.elemId);
  162. }
  163. });
  164. bt.lockScreen = function(c) {
  165. return new lock(c);
  166. };
  167. }(btGame || (btGame = {}));
  168. var btGame;
  169. ~function(bt) {
  170. var b = {
  171. id: "bt-advertisement",
  172. html: "广告",
  173. time: 1500
  174. };
  175. var flash = function(c) {
  176. var d = $.extend({}, b, c || {});
  177. var e = $("#" + d.id);
  178. var f = new bt.lockScreen(d.lockId);
  179. if (e.size() <= 0) {
  180. var h = $(bt.getNewDiv()).attr({
  181. id: d.id
  182. }).addClass(d.id);
  183. var i = d.html;
  184. h.html(i);
  185. bt.getDomBody().appendChild(h[0]);
  186. e = h;
  187. }
  188. this.event = d.id + "_timeup";
  189. var g = this;
  190. if (d.time > 0) {
  191. var h = this.event;
  192. this.off(h);
  193. e.data("timer", setTimeout(function() {
  194. e.remove(), f.hide();
  195. g.fire(h);
  196. d = null;
  197. this.elem = this.lock = g.show = g.hide = null;
  198. }, d.time <= 0 ? 1500 : d.time));
  199. }
  200. this.elem = e;
  201. this.lock = f;
  202. this.show = function(h) {
  203. h && this.elem.html(h);
  204. this.elem.removeClass("bt-hide");
  205. this.lock.show();
  206. };
  207. this.hide = function() {
  208. this.elem.addClass("bt-hide");
  209. this.lock.hide();
  210. };
  211. this.remove = function() {
  212. this.lock.remove();
  213. this.elem.remove();
  214. };
  215. };
  216. bt.makePublisher(flash);
  217. bt.advertisement = function(c) {
  218. return new flash(c);
  219. };
  220. }(btGame || (btGame = {}));
  221. var btGame;
  222. ~function(bt) {
  223. var b = null;
  224. var c = null;
  225. var loading = function(d, e) {
  226. if (d > 0 && !b) {
  227. b = $(btGame.getNewDiv());
  228. b.addClass("bt-game-loading");
  229. b.html('<table><tr><td><img class="bt-img" src="resource/preloadImage.png" /><div class="bt-text"></div></td></tr></table>');
  230. bt.getDomBody().appendChild(b[0]);
  231. c = b.find(".bt-text");
  232. }
  233. if (b) {
  234. if (e) {
  235. c.html(e);
  236. } else {
  237. var f = Math.round(d * 100);
  238. c.html("加载进度:" + f + "%");
  239. }
  240. }
  241. if (d >= 1) {
  242. b && b.remove();
  243. b = null;
  244. }
  245. };
  246. bt.gameLoading = loading;
  247. }(btGame || (btGame = {}));
  248. var btGame;
  249. ~function(bt) {
  250. function rate(b, c) {
  251. var d = window.innerWidth, e = window.innerHeight;
  252. var f;
  253. if (b <= d && c <= e) {} else if (b > d && c > e) {
  254. var i = d / b, j = e / c;
  255. if (i <= j) {
  256. f = b;
  257. b = d;
  258. c = c * b / f;
  259. } else {
  260. f = c;
  261. c = e;
  262. b = b * c / f;
  263. }
  264. } else if (b > d) {
  265. f = b;
  266. b = d;
  267. c = c * d / f;
  268. } else if (c > e) {
  269. f = c;
  270. c = e;
  271. b = b * e / f;
  272. } else {}
  273. var g = (e - c) / 2, h = (d - b) / 2;
  274. return {
  275. width: b,
  276. height: c,
  277. top: g,
  278. left: h
  279. };
  280. }
  281. function resize(b, c, d, e, f) {
  282. var g = rate(c, d);
  283. b.css({
  284. width: g.width,
  285. height: g.height,
  286. top: e == "center" ? g.top : e == "left" ? 0 : e,
  287. left: f == "center" ? g.left : f == "left" ? 0 : f
  288. });
  289. switch (e) {
  290. case "top":
  291. b.css({
  292. top: 0
  293. });
  294. break;
  295. case "center":
  296. b.css({
  297. top: g.top
  298. });
  299. break;
  300. case "bottom":
  301. b.css({
  302. bottom: 0
  303. });
  304. break;
  305. default:
  306. b.css({
  307. top: e
  308. });
  309. }
  310. switch (f) {
  311. case "left":
  312. b.css({
  313. left: 0
  314. });
  315. break;
  316. case "center":
  317. b.css({
  318. left: g.left
  319. });
  320. break;
  321. case "right":
  322. b.css({
  323. right: 0
  324. });
  325. break;
  326. default:
  327. b.css({
  328. left: f
  329. });
  330. }
  331. b.trigger("resizePlayArea", [ g ]);
  332. }
  333. function bindResize(b, c, d, e, f) {
  334. bt.checkHScreen(function() {
  335. setTimeout(function() {
  336. resize(b, c, d, e, f);
  337. }, 500);
  338. });
  339. }
  340. bt.resizePlayArea = bindResize;
  341. }(btGame || (btGame = {}));
  342. var btGame;
  343. ~function(bt) {
  344. function ask(b) {
  345. if (confirm('关注"豆豆游戏"微信,就可以收藏这个游戏哦!')) {
  346. b ? b() : top.location.href = bt.URL.getConcern();
  347. }
  348. }
  349. bt.attentOurGame = ask;
  350. }(btGame || (btGame = {}));
  351. var btGame;
  352. ~function(bt) {
  353. var screenResize = function(b) {
  354. b && b(window.innerWidth > window.innerHeight);
  355. };
  356. function check(b, c) {
  357. if (!c) {
  358. window.addEventListener("orientationchange", function() {
  359. screenResize(b);
  360. });
  361. window.addEventListener("resize", function() {
  362. screenResize(b);
  363. });
  364. }
  365. screenResize(b);
  366. }
  367. bt.checkHScreen = check;
  368. }(btGame || (btGame = {}));
  369. var btGame;
  370. ~function(bt) {
  371. var onlyH = function(b, c) {
  372. this.myCallback = c;
  373. this.tipsCount = 0;
  374. bt.checkHScreen(bt.proxy(this.callback, this), false);
  375. if (b) {
  376. this.once = b;
  377. }
  378. };
  379. onlyH.prototype = {
  380. hscreen: function() {
  381. this.buildScreen();
  382. if (this.once && this.tipsCount <= 0) {
  383. this.screen && this.screen.show();
  384. } else if (!this.once) {
  385. this.screen && this.screen.show();
  386. }
  387. this.tipsCount++;
  388. },
  389. vscreen: function() {
  390. this.screen && this.screen.hide();
  391. this.myCallback && this.myCallback(this.tipsCount);
  392. },
  393. getScreenOption: function() {
  394. return {
  395. id: "bt-h-scrren",
  396. html: "<table><tr><td><img class='bt-h-screen-img' src='resource//bt-play-h-screen.png' /></td></tr></table>",
  397. time: 0,
  398. lockId: "bt-hide-lock"
  399. };
  400. },
  401. buildScreen: function() {
  402. !this.screen && (this.screen = btGame.advertisement(this.getScreenOption()));
  403. },
  404. callback: function(b) {
  405. b ? this.vscreen() : this.hscreen();
  406. }
  407. };
  408. var onlyV = function(b, c) {
  409. onlyH.call(this, b, c);
  410. };
  411. onlyV.__super__ = onlyH;
  412. onlyV.prototype = $.extend({}, onlyH.prototype, {
  413. hscreen: function() {
  414. onlyH.prototype.vscreen.call(this);
  415. },
  416. vscreen: function() {
  417. onlyH.prototype.hscreen.call(this);
  418. },
  419. getScreenOption: function() {
  420. return {
  421. id: "bt-v-scrren",
  422. html: "<table><tr><td><img class='bt-v-screen-img' src='resource/bt-play-v-screen.png' /></td></tr></table>",
  423. time: 0,
  424. lockId: "bt-hide-lock"
  425. };
  426. }
  427. });
  428. bt.onlyHScreen = function(b, c) {
  429. return new onlyH(b, c);
  430. };
  431. bt.onlyVScreen = function(b, c) {
  432. return new onlyV(b, c);
  433. };
  434. }(btGame || (btGame = {}));
  435. var btGame;
  436. ~function(bt) {
  437. var b = "bt-play-logo-adv";
  438. function ad(c) {}
  439. bt.playLogoAdv = ad;
  440. }(btGame || (bgGame = {}));
  441. var btGame;
  442. ~function(bt) {
  443. var b = "bt-play-share-tip";
  444. function tip() {
  445. var c = bt.advertisement({
  446. id: b,
  447. html: "<img class='bt-play-share-tip-img' src='resource/bt-play-share-tip.png' />",
  448. time: 0
  449. });
  450. c.show();
  451. setTimeout(function() {
  452. c.elem.on("click touchstart", function() {
  453. c.remove();
  454. c = null;
  455. return false;
  456. });
  457. }, 500);
  458. bt.dc("share");
  459. }
  460. bt.playShareTip = tip;
  461. }(btGame || (btGame = {}));
  462. var btGame;
  463. ~function(bt) {
  464. function msg(b) {
  465. if (confirm(b)) {
  466. bt.playShareTip();
  467. }
  468. }
  469. bt.playScoreMsg = msg;
  470. }(btGame || (btGame = {}));
  471. var btGame;
  472. ~function(bt) {
  473. var b = 0;
  474. var c = {
  475. width: "66",
  476. src: bt.getGamePath() + "icon.png",
  477. url: location.href,
  478. title: document.title,
  479. desc: document.title,
  480. callback: function() {
  481. if (b <= 0) {
  482. bt.attentOurGame();
  483. }
  484. b++;
  485. bt.dc("realshare");
  486. }
  487. };
  488. window.a = c;
  489. var mebtnopenurl = 'http://game.ikongzhong.cn';
  490. var thegameurl ="";
  491. var guanzhuurl ="http://mp.weixin.qq.com/s?__biz=MzI4MjA2MjE0MQ==&mid=246005295&idx=1&sn=490f8141976d607ba079d48f52a3fcd7#rd";
  492. c.src = "http://mmbiz.qpic.cn/mmbiz/2zpp2iaH4HWGibTGlgZ0T24BEhuvDE3KFIOib0Bicg8yfs64RHzul0BvfriaEJyI65UjLYmhop9YRyak37Oib0Laju1A/640";
  493. var onBridgeReady = function() {
  494. WeixinJSBridge.on("menu:share:appmessage", function(d) {
  495. WeixinJSBridge.invoke("sendAppMessage", {
  496. img_url: c.src,
  497. img_width: c.width,
  498. img_height: c.width,
  499. link: c.url,
  500. desc: c.desc,
  501. title: c.title
  502. }, function(e) {
  503. document.location.href = mebtnopenurl;
  504. });
  505. });
  506. WeixinJSBridge.on("menu:share:timeline", function(d) {
  507. WeixinJSBridge.invoke("shareTimeline", {
  508. img_url: c.src,
  509. img_width: c.width,
  510. img_height: c.width,
  511. link: c.url,
  512. desc: c.desc,
  513. title: c.title
  514. }, function(e) {
  515. document.location.href = guanzhuurl;
  516. });
  517. });
  518. WeixinJSBridge.on("menu:share:weibo", function(d) {
  519. WeixinJSBridge.invoke("shareWeibo", {
  520. content: c.title,
  521. url: c.url
  522. }, function(e) {
  523. document.location.href = mebtnopenurl;
  524. });
  525. });
  526. WeixinJSBridge.on("menu:share:facebook", function(d) {
  527. c.callback();
  528. WeixinJSBridge.invoke("shareFB", {
  529. img_url: c.src,
  530. img_width: c.width,
  531. img_height: c.width,
  532. link: c.url,
  533. desc: c.desc,
  534. title: c.title
  535. }, function(e) {
  536. document.location.href = mebtnopenurl;
  537. });
  538. });
  539. };
  540. if (typeof WeixinJSBridge == "undefined") {
  541. if (document.addEventListener) {
  542. document.addEventListener("WeixinJSBridgeReady", onBridgeReady, false);
  543. } else if (document.attachEvent) {
  544. document.attachEvent("WeixinJSBridgeReady", onBridgeReady);
  545. document.attachEvent("onWeixinJSBridgeReady", onBridgeReady);
  546. }
  547. } else {
  548. onBridgeReady();
  549. }
  550. bt.setShare = function(d) {
  551. $.extend(c, d || {});
  552. document.title = c.desc = c.title;
  553. };
  554. }(btGame || (btGame = {}));
  555. var btGame;
  556. ~function(bt) {
  557. var b = bt.getGameId();
  558. if (b) {
  559. var c = new Image();
  560. c.src = mebtnopenurl;
  561. }
  562. }(btGame || (btGame = {}));