index_pri.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. $(function () {
  2. /*
  3. fetchJSON("/api/tag/hot", {}, "get", function (ret) {
  4. if (ret.code === 0) {
  5. if (ret.data.length > 0) {
  6. var maxCount = ret.data.length > 6 ? 6 : ret.data.length;
  7. $("#hotTag").empty();
  8. $("#hotTag").html("热门关键字:");
  9. for (var i = 0; i < maxCount; i++) {
  10. $("#hotTag").append(
  11. $("<a>", {href: "list_index.html?q=" + ret.data[i].keyword, text: ret.data[i].keyword})
  12. );
  13. }
  14. }
  15. } else {
  16. console.log(ret.msg);
  17. }
  18. });
  19. */
  20. $("#search").on("click", function (e) {
  21. e.preventDefault();
  22. submitSearch($("#keyword"));
  23. });
  24. $("#keyword").on("keyup", function (e) {
  25. e.preventDefault();
  26. if (e.keyCode === 13) submitSearch($("#keyword"));
  27. });
  28. function submitSearch(control) {
  29. var inputValue = control.val().trim();
  30. if (inputValue === "" || inputValue.replace(/[-_—]/g, "") === "") {
  31. control.focus();
  32. return;
  33. }
  34. var keylist = encodeURIComponent(control.val().trim());
  35. window.location.href = "list_index.html?q=" + keylist;
  36. }
  37. /*
  38. fetchJSON("/api/tag/visit", {}, "get", function (ret) {
  39. if (ret.code === 0) {
  40. $("#visit").html(ret.data);
  41. }
  42. });
  43. */
  44. function relocationElement() {
  45. var baseLeft = $('#bk').position().left;
  46. var baseTop = $('#bk').position().top;
  47. $('#navbar').css('left', baseLeft + 120);
  48. $('#keyword').css('left', baseLeft + 790);
  49. $('#search').css('left', baseLeft + 1165);
  50. $('#tel').css('left', baseLeft + 540);
  51. $('#visit').css('left', baseLeft + 1160);
  52. }
  53. relocationElement();
  54. $(window).resize(function (e) {
  55. relocationElement();
  56. });
  57. });