matchList.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. var MAX_PAGE_NUM = 8;
  2. function getPlayerName() {
  3. return $("#playerName").text();
  4. }
  5. function getLOLBoxYYUID() {
  6. return getCookie('lolboxyyuid');
  7. }
  8. function getServerName() {
  9. return $("#serverName").text();
  10. }
  11. function getBoxServerName() {
  12. return getCookie('boxServerName');
  13. }
  14. function getBoxPlayerName() {
  15. return getCookie('boxPlayerName');
  16. }
  17. function getIsInMyFavorite() {
  18. return $.trim($("#isInMyFavorite").text());
  19. }
  20. function getCookie(cookieName) {
  21. var cookieString = document.cookie;
  22. var start = cookieString.indexOf(cookieName + '=');
  23. // 加上等号的原因是避免在某些 Cookie 的值里有
  24. // 与 cookieName 一样的字符串。
  25. if (start == -1) // 找不到
  26. return null;
  27. start += cookieName.length + 1;
  28. var end = cookieString.indexOf(';', start);
  29. if (end == -1)
  30. return cookieString.substring(start);
  31. return cookieString.substring(start, end);
  32. }
  33. function updateSideBarSelection(matchID) {
  34. $('.hover').removeClass('hover');
  35. $('#cli' + matchID).addClass('hover');
  36. }
  37. function highLightCurrentPlayer() {
  38. var pn = $("#playerName").text();
  39. $('div[class="team-name"] a').each(function() {
  40. var pnTemp = $.trim($(this).parent().find('img').attr('data-playername'));
  41. if (pn === pnTemp) {
  42. $(this).css('font-weight', 'bold');
  43. }
  44. });
  45. var boxPlayerName = getBoxPlayerName();
  46. $('div[class="team-name"]').each(function() {
  47. var pnTemp = $.trim($(this).find('img').attr('data-playername'));
  48. if (boxPlayerName === pnTemp) {
  49. $(this).parent().parent().addClass('current-player');
  50. }
  51. });
  52. }
  53. function loadMatchDetail(matchId, serverName, playerName) {
  54. updateSideBarSelection(matchId);
  55. $('#matchDetail').html('<img src="images/loading.gif" width="400" height="400">');
  56. var isFavoriteMatch = getIsInMyFavorite();
  57. $.ajax(
  58. {
  59. url: "http://lolbox.duowan.com/matchList/ajaxMatchDetail2.php",
  60. data: {matchId: matchId, serverName: serverName, playerName: playerName, favorate: isFavoriteMatch},
  61. cache: true,
  62. success: function (data, textStatus) {
  63. if (textStatus == 'success') {
  64. window.location.hash = matchId;
  65. /*
  66. 注意这里不要使用
  67. $('#matchDetail').html(data);
  68. 这个方法在 IE 6.0.2900.5512 080413-2111 多次调用后会导致 IE 崩溃。
  69. */
  70. if (data) {
  71. $('#matchDetail').get(0).innerHTML = data;
  72. }
  73. if (SnsShare) {
  74. SnsShare.init();
  75. }
  76. if (window.tipsWin) {
  77. tipsWin.tooltips.init();
  78. }
  79. addAnchorIconsToMatchList();
  80. prepareCertifiedLiveAnchorHover();
  81. highLightCurrentPlayer();
  82. setupACHShare();
  83. if (window.wan) {
  84. wan.init();
  85. }
  86. }
  87. },
  88. error: function () {
  89. $('#matchDetail').html('<p style="padding:50px">盒子未找到此场比赛的详情信息。</p>');
  90. $('.detailTip').html('');
  91. }
  92. });
  93. }
  94. function myFavorateMatches(action, timestamp) {
  95. var boxPlayerName = decodeURI(getCookie('boxPlayerName'));
  96. var boxServerName = decodeURI(getCookie('boxServerName'));
  97. //alert(action + boxServerName + boxPlayerName);
  98. $.ajax(
  99. {
  100. url: "http://lolbox.duowan.com/webApi.php",
  101. data: {serverName: boxServerName, playerName: boxPlayerName, action: action, timestamp: timestamp},
  102. cache: false,
  103. success: function (msg) {
  104. //alert(msg);
  105. if (msg == 1) {
  106. // location.reload();
  107. } else if (msg == -1) {
  108. alert('非法操作,请至少登陆一次游戏!');
  109. } else if (msg == -2) {
  110. alert('超过战绩收藏最大数24场!');
  111. } else if (msg == 0) {
  112. alert('收藏的比赛不存在');
  113. }
  114. },
  115. error: function () {
  116. }
  117. });
  118. }
  119. function getJiathisConifg(title, honourKey) {
  120. if (!title) return null;
  121. var boxPlayerName = getBoxPlayerName();
  122. if (boxPlayerName && boxPlayerName != '') {
  123. title = title.replace('我', '我(' + decodeURI(boxPlayerName) + ')');
  124. }
  125. var jiathis_config = {
  126. sm: "tsina,tqq,renren",
  127. url: document.location.toString(),
  128. title: "#无盒子 不开撸# " + title,
  129. summary: " ",
  130. data_track_clickback: true,
  131. appkey: {
  132. "tsina": "3629014272",
  133. "tqq": "801220649",
  134. "qzone": "100302822"
  135. },
  136. pic: 'http://img.lolbox.duowan.com/icon_' + honourKey + '_120x120.png',
  137. ralateuid: {
  138. "tsina": "2909042820"
  139. },
  140. evt: {
  141. "share": 'closeShare'
  142. }
  143. };
  144. return jiathis_config;
  145. }
  146. function screenshot() {
  147. $('.share').removeClass('hover');
  148. setTimeout(function () {
  149. var serverName = getServerName();
  150. var playerName = getPlayerName();
  151. window.location.href = 'lolboxphoto://' + serverName + '_' + playerName + '_玩家战绩';
  152. }, 200);
  153. }
  154. function setupShare() {
  155. $('.box .box-hd .btns-fast .share').hover(function () {
  156. var playerName = getBoxPlayerName() || getPlayerName();
  157. jiathis_config = {
  158. title: "#无盒子 不开撸# 我是" + decodeURIComponent(playerName) + ",我在使用LOL盒子。来看看我的比赛成绩吧!",
  159. appkey: {
  160. "tsina": "3629014272",
  161. "tqq": "801220649",
  162. "qzone": "100302822"
  163. },
  164. summary: " ",
  165. ralateuid: {
  166. "tsina": "2909042820"
  167. }
  168. };
  169. $(this).addClass('hover');
  170. }, function () {
  171. $(this).removeClass('hover');
  172. });
  173. }
  174. function StrRangeCompute(str) {
  175. var d = document.getElementById('__dvCompute');
  176. d.innerHTML = str;
  177. return { w: d.offsetWidth, h: d.offsetHeight };
  178. }
  179. function normalizePlayerName(playerName) {
  180. playerName = playerName.replace(/斗鱼TV/i, "");
  181. playerName = playerName.replace(/龙珠/i, "");
  182. playerName = playerName.replace(/战旗TV/i, "");
  183. var maxWidth = 96;
  184. var range = StrRangeCompute(playerName);
  185. if (range.w > maxWidth) {
  186. var p = playerName[0];
  187. for (var i = 1; i < playerName.length; i++) {
  188. var _range = StrRangeCompute(p + playerName[i]);
  189. if (_range.w > maxWidth)
  190. return p + '...';
  191. else
  192. p = p + playerName[i];
  193. }
  194. }
  195. return playerName;
  196. }
  197. function getMatchID() {
  198. var matchID = null;
  199. var fragment = window.location.hash;
  200. if (fragment) {
  201. matchID = fragment.replace(/^#/, '');
  202. } else {
  203. var idName = $('.recent-list li:first').attr('id');
  204. if (idName) {
  205. matchID = idName.replace(/^#/, '').replace(/^cli/, '');
  206. }
  207. }
  208. return matchID;
  209. }
  210. function setupInteractiveSideBar() {
  211. $('.recent-list li').click(function() {
  212. var matchID = $(this).attr('id').replace(/^cli/, '');
  213. loadMatchDetail(matchID, getServerName(), getPlayerName());
  214. });
  215. }
  216. function gotoSpecifyPage() {
  217. var newPageNum = parseInt($('.zj-cur').val());
  218. if (newPageNum > MAX_PAGE_NUM) {
  219. newPageNum = MAX_PAGE_NUM;
  220. }
  221. var isFavoriteMatch = getIsInMyFavorite();
  222. var url;
  223. var urlPrefix;
  224. if (isFavoriteMatch == '1') {
  225. urlPrefix = 'http://lolbox.duowan.com/favorateMatchList.php';
  226. } else {
  227. urlPrefix = 'http://lolbox.duowan.com/matchList.php';
  228. }
  229. url = urlPrefix + '?serverName=' + encodeURI(getServerName()) +
  230. '&playerName=' + encodeURI(getPlayerName()) +
  231. '&page=' + newPageNum;
  232. window.location = url;
  233. }
  234. function setupInteractivePagination() {
  235. $('.go-page').click(function() {
  236. gotoSpecifyPage();
  237. });
  238. $('.zj-page').keyup(function(event) {
  239. if (event.keyCode == 13) {
  240. gotoSpecifyPage();
  241. }
  242. });
  243. }
  244. window.gCachePlayerInfo = !window.gCachePlayerInfo ? {} : window.gCachePlayerInfo;
  245. tipsWin.tooltips.open = function (el) {
  246. tipsWin.tooltips.status = 1;
  247. $('#mod-tips-s1').show();
  248. var $this = $(el),
  249. _indent = parseInt($this.attr("data-indent")),
  250. userId = $this.attr("user-id"),
  251. gameZone = $this.attr("game-zone");
  252. if (!$("#data-layer .layer").get(_indent - 1)) {
  253. return;
  254. }
  255. /*定位浮层角标*/
  256. var pointY = $this.offset().top;
  257. $( '#mod-tips-s1 .arrow' ).css( 'top', (pointY-110 ) );
  258. /*获取浮层结构代码*/
  259. var _html = $("#data-layer .layer").eq(_indent - 1).html();
  260. this.html(_html);
  261. $.ajax({
  262. url: 'http://api.lolbox.duowan.com/api/v2/player/'+gameZone+'/'+userId+'/',
  263. dataType: 'jsonp'
  264. }).done(function(resp) {
  265. var data = resp && resp.player_list && resp.player_list[0];
  266. var tierRank = data.tier_rank, tierName;
  267. if (tierRank && tierRank['tier'] && tierRank['tier']['const'] > 0) {
  268. tierName = tierRank['tier']['name_cn'] + ' ' + tierRank['rank']['name'];
  269. } else {
  270. tierName = '-';
  271. }
  272. // var dpsTem='<div class="tip-level"><div class="ch_level level_'+chLevel+'"></div><p style="'+posClass+'">'+heroData.position+'</p></div><div class="tip-topright"><p><em class="zj-zdl zj-s"></em>' + data.player_zdl + '</p><p class="zj-blue">' + data.tier + ' ' + data.rank + '</p></div>';
  273. var dpsTem='<div class="tip-level"></div><div class="tip-topright"><p><em class="zj-zdl zj-s"></em>' + data.box_score + '</p><p class="zj-blue">' + tierName + '</p></div>';
  274. /*填写你的内容*/
  275. $('#mod-tips-s1').find(".tip-topright-wrap").html(dpsTem);
  276. });
  277. };
  278. function getURLParam(name) {
  279. var value = location.search.match(new RegExp("[?&]" + name + "=([^&]*)(&?)", "i"));
  280. return value ? decodeURIComponent(value[1]) : value;
  281. }
  282. function loadMatch() {
  283. var serverName = getServerName();
  284. var playerName = getPlayerName();
  285. var matchID = getMatchID();
  286. if (matchID && serverName && playerName) {
  287. loadMatchDetail(matchID, serverName, playerName);
  288. }
  289. }
  290. /*
  291. 分享 boxTitle “杀人如麻”之类荣誉,完整荣誉列表见 include/honourReds.php
  292. */
  293. function setupACHShare() {
  294. var currHonourReds = $.parseJSON($('#currentHonourReds').text());
  295. var AchShare = function (selector, title) {
  296. var _top = $(selector).offset().top + 26;
  297. var _top2 = $(selector).offset().top - 80;
  298. var _left = $(selector).offset().left - 20;
  299. var _title = title;
  300. var $share = $('.ach-share');
  301. var $text = $share.find('strong');
  302. var $arrow = $share.find('.arrow');
  303. if (_top < 280) {
  304. $share.show().css({'top': _top, 'left': _left});
  305. $text.text(_title);
  306. $arrow.removeClass('b').addClass('t');
  307. } else if (_top > 280) {
  308. $share.show().css({'top': _top2 + 20, 'left': _left});
  309. $text.text(_title);
  310. $arrow.removeClass('t').addClass('b');
  311. }
  312. };
  313. var boxPlayerName = getBoxPlayerName();
  314. window.achShareTimer = null;
  315. if (boxPlayerName) {
  316. $('*[data-playername="' + decodeURI(boxPlayerName) + '"]').parent().find('.zj-s').each(function() {
  317. $(this).mouseenter(function() {
  318. var honourKey = $(this).attr('data-honour-key');
  319. var honour = currHonourReds[honourKey];
  320. if (!honour) {
  321. $('.ach-share').hide();
  322. return;
  323. }
  324. $(this).attr('title', '');
  325. AchShare(this, honour.title);
  326. // jiathis_config = getJiathisConifg(honour.content, honourKey);
  327. });
  328. $(this).on('mouseleave', '', function(event) {
  329. achShareTimer = setTimeout(function() {
  330. $('.ach-share').hide();
  331. }, 300);
  332. event.preventDefault();
  333. });
  334. });
  335. $('.ach-share').mouseenter(function() {
  336. clearTimeout(achShareTimer);
  337. });
  338. $('.ach-share').mouseleave(function() {
  339. $(this).hide();
  340. });
  341. }
  342. }
  343. $(document).ready(function () {
  344. // setupShare();
  345. setupInteractiveSideBar();
  346. setupInteractivePagination();
  347. loadMatch();
  348. // 初始化10个英雄 tips 窗口
  349. tipsWin.tooltips.init();
  350. });