search.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. $(function() {
  2. var pageUrl = window.location.href.split("?")[0]; //当前页面的url
  3. var sn = encodeURIComponent(getURLParam("sn")) || "all";
  4. var pn = encodeURIComponent(getURLParam("pn")) || "YY直播";
  5. // var p = parseInt(getURLParam("p")) || 1;
  6. var Search = function() {
  7. this.pageUrl = pageUrl;
  8. // this.base = "http://lolbox.duowan.com/new/api/index.php?_do=inquiry/search";
  9. this.url = "http://api.lolbox.duowan.com/api/v2/player/search/?player_name_list=" + pn;
  10. // this.url = this.base + "&sn=" + sn + "&pn=" + pn + "&p=" + p;
  11. };
  12. Search.prototype = {
  13. constructor: Search,
  14. _getData: function() {
  15. var that = this;
  16. return $.ajax({
  17. url: this.url,
  18. type: "GET",
  19. dataType: "jsonp"
  20. });
  21. },
  22. init: function() {
  23. var that = this;
  24. $(".searchPn").html(getURLParam("pn"));
  25. $("#roleName").attr("href", "reparieLostPlayer.html?playerName=" + getURLParam("pn"));
  26. this._getData().done(function(data, status, xhr) {
  27. if (xhr && xhr.status && xhr.status) {
  28. if (xhr.status == "200") {
  29. $(".mod-tabs").show();
  30. $(".mod-tabs2").hide();
  31. that._render(data);
  32. setTimeout(function() {
  33. $(".main-wrap>ul").niceScroll({cursorcolor:"#D9D9D9",cursorwidth:"8",cursoropacitymin:1,cursorborder:'none'});
  34. }, 100);
  35. } else {
  36. $(".mod-tabs2").show();
  37. $(".mod-tabs").hide();
  38. }
  39. }
  40. }).fail(function() {});
  41. },
  42. _render: function(data) {
  43. var template = _.template($("#serversTemplate").html());
  44. $("#servers").html(template({
  45. data: data
  46. }));
  47. $("#scrollUl").niceScroll({
  48. cursorcolor: "#D9D9D9",
  49. cursorwidth: "8",
  50. cursoropacitymin: 1,
  51. cursorborder: 'none'
  52. });
  53. }
  54. };
  55. (new Search()).init();
  56. function getURLParam(name) {
  57. var value = location.search.match(new RegExp("[?&]" + name + "=([^&]*)(&?)", "i"));
  58. return value ? decodeURIComponent(value[1]) : value;
  59. }
  60. });