index.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. ! function($) {
  3. var dataUrl = "http://lolbox.duowan.com/new/api/index.php?_do=dealconfig/getchampiontalent&champion_id=";
  4. var errHtml = "天赋数据获取异常,请<a href=\"http://fankui.duowan.com/\" target=\"_blank\">反馈客服</a>!"
  5. function pageInit() {
  6. var championsId = getQueryString("championsId");
  7. if(!championsId){
  8. $("#errTips").show().html(errHtml);
  9. return ;
  10. }
  11. $.ajax({
  12. url: dataUrl + championsId,
  13. dataType: "jsonp",
  14. success: function(res) {
  15. if(res.status == 10402) {
  16. $("#errTips").show().html(errHtml);
  17. }else if(res.status == 10401) {
  18. $("#errTips").show().html(errHtml);
  19. }else {
  20. var data = res.talent_data,
  21. $con = $con = $("<div>");
  22. for( var i = 0; i < data.length; i++ ) {
  23. var temp = $("#contentTemp").html(),
  24. talent_con = drawCalculator(),
  25. talent_summaries = drawSummaries(),
  26. sHtml = temp.replace(/\{(.*)\}/g, function(arg1, arg2) {
  27. return data[i][$.trim(arg2)]
  28. }),
  29. $temp = $(sHtml);
  30. importMasteries(data[i], talent_con, talent_summaries, $temp, championsId);
  31. $temp
  32. .find(".tallent__head")
  33. .append(talent_summaries).end()
  34. .find(".tallent__con")
  35. .append(talent_con);
  36. $con.append($temp);
  37. }
  38. $("#talentListCon").append($con);
  39. scrollApi.reinitialise();
  40. }
  41. }
  42. })
  43. }
  44. function getQueryString(name) {
  45. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i"),
  46. r = window.location.search.substr(1).match(reg);
  47. if (r!=null) {
  48. return (r[2]);
  49. }
  50. return null;
  51. }
  52. var scrollDom, scrollApi;
  53. $(function() {
  54. $(document).on("click", ".btn_check", function() {
  55. var $this = $(this),
  56. lists = $this.parent().next();
  57. $this.toggleClass("btn_check_up");
  58. lists.toggleClass("show");
  59. $this.parents(".talentItem").toggleClass("active");
  60. scrollApi.reinitialise();
  61. if($(".talentItem.active").length > 0) {
  62. scrollApi.scrollToElement($this.parents(".talentItem"), true, 300);
  63. } else {
  64. $(".jspPane").css({
  65. top: 0
  66. })
  67. }
  68. }).on("click", ".btn_apply", function() {
  69. var timer, $this = $(this);
  70. $this.on("click", function(event) {
  71. event.stopPropagation()
  72. }), $("#submitTips").show(), timer = setTimeout(function() {
  73. $("#submitTips").hide(), $this.off("click")
  74. }, 4e3)
  75. });
  76. pageInit();
  77. scrollDom = $("#talentList").jScrollPane({
  78. mouseWheelSpeed: 20
  79. }), scrollApi = scrollDom.data("jsp")
  80. })
  81. }(jQuery, this);