term_popup.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. function term_popup_init() {
  2. $(".term_link").each(function () {
  3. if ($(this).attr("init") != "1") {
  4. if ($(this).text().length > 0) {
  5. $(this).css("background", "unset");
  6. }
  7. let gid = $(this).attr("gid");
  8. if ($(this).offset().left < $(document.body).width() / 2) {
  9. //出现在左侧
  10. $(this).append(
  11. '<div term-popup="' +
  12. gid +
  13. '" class="guide_contence left" style="left: -5px;"></div>'
  14. );
  15. //$(".guide_contence:after").css("left", "0");
  16. } else {
  17. //出现在右侧
  18. $(this).append(
  19. '<div term-popup="' +
  20. gid +
  21. '" class="guide_contence right" style="right: -5px;"></div>'
  22. );
  23. //$(".guide_contence:after").css("right", "0");
  24. }
  25. $(this).attr("init", "1");
  26. }
  27. });
  28. $(".term_link").mouseenter(function (event) {
  29. let mouse_x=event.clientX - 20
  30. let mouse_y=event.clientY
  31. $(this).children(".guide_contence").first().css("left",mouse_x+"px")
  32. $(this).children(".guide_contence").first().css("top",mouse_y+"px")
  33. if ($(this).children(".guide_contence").first().html().length > 0) {
  34. return;
  35. }
  36. let gid = $(this).attr("gid");
  37. let id = "gid_" + gid;
  38. note_lookup_guid_json(gid);
  39. });
  40. }
  41. function note_lookup_guid_json(guid) {
  42. $.get(
  43. "../term/term.php",
  44. {
  45. op: "load_id",
  46. id: guid,
  47. format: "json",
  48. },
  49. function (data, status) {
  50. let html = "";
  51. if (status == "success") {
  52. try {
  53. let result = JSON.parse(data)[0];
  54. html = "<div class='term_block'>";
  55. html += "<h2>" + result.word + "</h2>";
  56. html += "<div class='meaning'>" + result.meaning + "</div>";
  57. html +=
  58. "<div class='term_note' status='1'>" +
  59. note_init(result.note) +
  60. "</div>";
  61. html += "<div class='term_popup_foot'>";
  62. html +=
  63. "<a href='../wiki/wiki.php?word=" +
  64. result.word +
  65. "' target='_blank'>更多</a>";
  66. html +=
  67. "<button onclick=\"term_edit_dlg_open('" +
  68. result.guid +
  69. "','','','',this)\">修改</button>";
  70. html += "</div>";
  71. html += "</div>";
  72. $("[term-popup='" + guid + "']").html(html);
  73. //note_refresh_new();
  74. } catch (e) {
  75. console.error("note_lookup_guid_json:" + e + " data:" + data);
  76. }
  77. }
  78. }
  79. );
  80. }