search.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 pageSign = $.cookie("boxUrlData");
  50. this.url += '&wsSecret=' + pageSign;
  51. };
  52. Search.prototype = {
  53. constructor: Search,
  54. _getData: function() {
  55. var that = this;
  56. return $.ajax({
  57. url: this.url,
  58. type: "GET",
  59. dataType: "jsonp"
  60. });
  61. },
  62. init: function() {
  63. var that = this;
  64. $(".searchPn").html(getURLParam("pn"));
  65. $("#roleName").attr("href", "reparieLostPlayer.html?playerName=" + getURLParam("pn"));
  66. this._getData().done(function(data, status, xhr) {
  67. if (xhr && xhr.status && xhr.status) {
  68. if (xhr.status == "200") {
  69. $(".mod-tabs").show();
  70. $(".mod-tabs2").hide();
  71. that._render(data);
  72. setTimeout(function() {
  73. $(".main-wrap>ul").niceScroll({cursorcolor:"#D9D9D9",cursorwidth:"8",cursoropacitymin:1,cursorborder:'none'});
  74. }, 100);
  75. } else {
  76. $(".mod-tabs2").show();
  77. $(".mod-tabs").hide();
  78. }
  79. }
  80. }).fail(function() {});
  81. },
  82. _render: function(data) {
  83. var template = _.template($("#serversTemplate").html());
  84. $("#servers").html(template({
  85. data: data
  86. }));
  87. $("#scrollUl").niceScroll({
  88. cursorcolor: "#D9D9D9",
  89. cursorwidth: "8",
  90. cursoropacitymin: 1,
  91. cursorborder: 'none'
  92. });
  93. }
  94. };
  95. (new Search()).init();
  96. function getURLParam(name) {
  97. var value = location.search.match(new RegExp("[?&]" + name + "=([^&]*)(&?)", "i"));
  98. return value ? decodeURIComponent(value[1]) : value;
  99. }
  100. });