term_popup.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. if ($(this).children(".guide_contence").first().html().length > 0) {
  30. return;
  31. }
  32. let gid = $(this).attr("gid");
  33. let id = "gid_" + gid;
  34. note_lookup_guid_json(gid);
  35. });
  36. }
  37. function note_lookup_guid_json(guid) {
  38. $.get(
  39. "../term/term.php",
  40. {
  41. op: "load_id",
  42. id: guid,
  43. format: "json",
  44. },
  45. function (data, status) {
  46. let html = "";
  47. if (status == "success") {
  48. try {
  49. let result = JSON.parse(data)[0];
  50. html = "<div class='term_block'>";
  51. html += "<h2>" + result.word + "</h2>";
  52. html += "<div class='meaning'>" + result.meaning + "</div>";
  53. html +=
  54. "<div class='term_note' status='1'>" +
  55. note_init(result.note) +
  56. "</div>";
  57. html += "<div class='term_popup_foot'>";
  58. html +=
  59. "<a href='../wiki/wiki.php?word=" +
  60. result.word +
  61. "' target='_blank'>更多</a>";
  62. html +=
  63. "<button onclick=\"term_edit_dlg_open('" +
  64. result.guid +
  65. "','','','',this)\">修改</button>";
  66. html += "</div>";
  67. html += "</div>";
  68. $("[term-popup='" + guid + "']").html(html);
  69. //note_refresh_new();
  70. } catch (e) {
  71. console.error("note_lookup_guid_json:" + e + " data:" + data);
  72. }
  73. }
  74. }
  75. );
  76. }