search.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. jQuery.cookie = function (name, value, options) {
  2. if (typeof value != 'undefined') { // name and value given, set cookie
  3. options = options || {};
  4. if (value === null) {
  5. value = '';
  6. options.expires = -1;
  7. }
  8. var expires = '';
  9. if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  10. var date;
  11. if (typeof options.expires == 'number') {
  12. date = new Date();
  13. date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  14. } else {
  15. date = options.expires;
  16. }
  17. expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
  18. }
  19. var path = options.path ? '; path=' + options.path : '';
  20. var domain = options.domain ? '; domain=' + options.domain : '';
  21. var secure = options.secure ? '; secure' : '';
  22. document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  23. } else { // only name given, get cookie
  24. var cookieValue = '';
  25. if (document.cookie && document.cookie != '') {
  26. var cookies = document.cookie.split(';');
  27. for (var i = 0; i < cookies.length; i++) {
  28. var cookie = jQuery.trim(cookies[i]);
  29. // Does this cookie string begin with the name we want?
  30. if (cookie.substring(0, name.length + 1) == (name + '=')) {
  31. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  32. break;
  33. }
  34. }
  35. }
  36. return cookieValue;
  37. }
  38. };
  39. $(function () {
  40. var pageUrl = window.location.href.split("?")[0]; //当前页面的url
  41. var sn = encodeURIComponent(getURLParam("sn")) || "all";
  42. var pn = encodeURIComponent(getURLParam("pn")) || "YY直播";
  43. // var p = parseInt(getURLParam("p")) || 1;
  44. var Search = function () {
  45. this.pageUrl = pageUrl;
  46. // this.base = "http://lolbox.duowan.com/new/api/index.php?_do=inquiry/search";
  47. this.url = 'http://api.lolbox.duowan.com/api/v3/player/search/?game_zone=' + sn + '&player_name_list=' + pn;
  48. // this.url = this.base + "&sn=" + sn + "&pn=" + pn + "&p=" + p;
  49. var boxUrlData = $.cookie("boxUrlData");
  50. var wsSecret = boxUrlData.split("&")[1];
  51. var ts = boxUrlData.split("&")[0];
  52. this.url += '&wsSecret=' + wsSecret + '&ts=' + ts;
  53. };
  54. Search.prototype = {
  55. constructor: Search,
  56. _getData: function () {
  57. var that = this;
  58. return $.ajax({
  59. url: this.url,
  60. type: "GET",
  61. dataType: "jsonp"
  62. });
  63. },
  64. init: function () {
  65. var that = this;
  66. $(".searchPn").text(getURLParam("pn"));
  67. $("#roleName").attr("href", "reparieLostPlayer.html?playerName=" + getURLParam("pn"));
  68. this._getData().done(function (data, status, xhr) {
  69. if (xhr && xhr.status && xhr.status) {
  70. if (xhr.status == "200") {
  71. $(".mod-tabs").show();
  72. $(".mod-tabs2").hide();
  73. that._render(data);
  74. setTimeout(function () {
  75. $(".main-wrap>ul").niceScroll({ cursorcolor: "#D9D9D9", cursorwidth: "8", cursoropacitymin: 1, cursorborder: 'none' });
  76. }, 100);
  77. } else {
  78. $(".mod-tabs2").show();
  79. $(".mod-tabs").hide();
  80. }
  81. }
  82. }).fail(function () { });
  83. },
  84. _render: function (data) {
  85. var template = _.template($("#serversTemplate").html());
  86. $("#servers").html(template({
  87. data: data
  88. }));
  89. $("#scrollUl").niceScroll({
  90. cursorcolor: "#D9D9D9",
  91. cursorwidth: "8",
  92. cursoropacitymin: 1,
  93. cursorborder: 'none'
  94. });
  95. }
  96. };
  97. (new Search()).init();
  98. function getURLParam(name) {
  99. var value = location.search.match(new RegExp("[?&]" + name + "=([^&]*)(&?)", "i"));
  100. return value ? decodeURIComponent(value[1]) : value;
  101. }
  102. });