script.js.下载 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * jQuery v1.9.1 included
  3. */
  4. !function (e, t, n) { function a() { var e = t.getElementsByTagName("script")[0], n = t.createElement("script"); n.type = "text/javascript", n.async = !0, n.src = "https://beacon-v2.helpscout.net", e.parentNode.insertBefore(n, e) } if (e.Beacon = n = function (t, n, a) { e.Beacon.readyQueue.push({ method: t, options: n, data: a }) }, n.readyQueue = [], "complete" === t.readyState) return a(); e.attachEvent ? e.attachEvent("onload", a) : e.addEventListener("load", a, !1) }(window, document, window.Beacon || function () { });
  5. $(document).ready(function() {
  6. // imtoken
  7. if (window.imTokenAgent) {
  8. $('body').addClass('imtoken')
  9. }
  10. // help scout
  11. window.Beacon('init', window.I18N.locale === "zh-cn" ? 'd8b2691c-875e-4db2-b3a9-f3ce3f7d3651' : '3ed06589-bbd3-4473-a502-9fd0d06a871e');
  12. // social share popups
  13. $(".share a").click(function(e) {
  14. e.preventDefault();
  15. window.open(this.href, "", "height = 500, width = 500");
  16. });
  17. // show form controls when the textarea receives focus or backbutton is used and value exists
  18. var $commentContainerTextarea = $(".comment-container textarea"),
  19. $commentContainerFormControls = $(".comment-form-controls, .comment-ccs");
  20. $commentContainerTextarea.one("focus", function() {
  21. $commentContainerFormControls.show();
  22. });
  23. if ($commentContainerTextarea.val() !== "") {
  24. $commentContainerFormControls.show();
  25. }
  26. // Expand Request comment form when Add to conversation is clicked
  27. var $showRequestCommentContainerTrigger = $(".request-container .comment-container .comment-show-container"),
  28. $requestCommentFields = $(".request-container .comment-container .comment-fields"),
  29. $requestCommentSubmit = $(".request-container .comment-container .request-submit-comment");
  30. $showRequestCommentContainerTrigger.on("click", function() {
  31. $showRequestCommentContainerTrigger.hide();
  32. $requestCommentFields.show();
  33. $requestCommentSubmit.show();
  34. $commentContainerTextarea.focus();
  35. });
  36. // Mark as solved button
  37. var $requestMarkAsSolvedButton = $(".request-container .mark-as-solved:not([data-disabled])"),
  38. $requestMarkAsSolvedCheckbox = $(".request-container .comment-container input[type=checkbox]"),
  39. $requestCommentSubmitButton = $(".request-container .comment-container input[type=submit]");
  40. $requestMarkAsSolvedButton.on("click", function () {
  41. $requestMarkAsSolvedCheckbox.attr("checked", true);
  42. $requestCommentSubmitButton.prop("disabled", true);
  43. $(this).attr("data-disabled", true).closest("form").submit();
  44. });
  45. // Change Mark as solved text according to whether comment is filled
  46. var $requestCommentTextarea = $(".request-container .comment-container textarea");
  47. $requestCommentTextarea.on("keyup", function() {
  48. if ($requestCommentTextarea.val() !== "") {
  49. $requestMarkAsSolvedButton.text($requestMarkAsSolvedButton.data("solve-and-submit-translation"));
  50. $requestCommentSubmitButton.prop("disabled", false);
  51. } else {
  52. $requestMarkAsSolvedButton.text($requestMarkAsSolvedButton.data("solve-translation"));
  53. $requestCommentSubmitButton.prop("disabled", true);
  54. }
  55. });
  56. // Disable submit button if textarea is empty
  57. if ($requestCommentTextarea.val() === "") {
  58. $requestCommentSubmitButton.prop("disabled", true);
  59. }
  60. // Submit requests filter form in the request list page
  61. $("#request-status-select, #request-organization-select")
  62. .on("change", function() {
  63. search();
  64. });
  65. // Submit requests filter form in the request list page
  66. $("#quick-search").on("keypress", function(e) {
  67. if (e.which === 13) {
  68. search();
  69. }
  70. });
  71. function search() {
  72. window.location.search = $.param({
  73. query: $("#quick-search").val(),
  74. status: $("#request-status-select").val(),
  75. organization_id: $("#request-organization-select").val()
  76. });
  77. }
  78. $(".header .icon-menu").on("click", function(e) {
  79. e.stopPropagation();
  80. var menu = document.getElementById("user-nav");
  81. var isExpanded = menu.getAttribute("aria-expanded") === "true";
  82. menu.setAttribute("aria-expanded", !isExpanded);
  83. });
  84. if ($("#user-nav").children().length === 0) {
  85. $(".header .icon-menu").hide();
  86. }
  87. // Submit organization form in the request page
  88. $("#request-organization select").on("change", function() {
  89. this.form.submit();
  90. });
  91. // Toggles expanded aria to collapsible elements
  92. $(".collapsible-nav, .collapsible-sidebar").on("click", function(e) {
  93. e.stopPropagation();
  94. var isExpanded = this.getAttribute("aria-expanded") === "true";
  95. this.setAttribute("aria-expanded", !isExpanded);
  96. });
  97. var _hmt = _hmt || [];
  98. var hm = document.createElement("script");
  99. hm.src = "https://hm.baidu.com/hm.js?3cd98d67bdd61e7f25984398bf0a3d34";
  100. var s = document.getElementsByTagName("script")[0];
  101. s.parentNode.insertBefore(hm, s);
  102. var fancyboxScript = document.createElement('script');
  103. fancyboxScript.src = "https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.js";
  104. document.head.appendChild(fancyboxScript);
  105. // 自动为文章内容中的所有图片添加 data-fancybox 属性
  106. $('.article-body img').each(function() {
  107. var imgSrc = $(this).attr('src');
  108. if (imgSrc) {
  109. $(this).wrap('<a href="' + imgSrc + '" data-fancybox="article-images" data-caption="' + $(this).attr('alt') + '"></a>');
  110. }
  111. });
  112. // 初始化 Fancybox, 并添加 Fancybox 的配置选项
  113. $('[data-fancybox]').fancybox({
  114. // infobar: false, // 隐藏图片上方的导航信息栏
  115. // buttons: ["zoom", "slideShow", "fullScreen", "close"], // 自定义按钮
  116. // loop: true, // 循环播放相册
  117. animationEffect: "zoom-in-out", // 过渡动画效果
  118. transitionEffect: "zoom-in-out", // 切换效果
  119. protect: true,
  120. easing: "ease-in",
  121. zoomEffect: false
  122. });
  123. });