core.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. $(function () {
  2. // Flash
  3. if ($(".flash").length) {
  4. setTimeout(() => $(".flash").slideUp(() => $(".flash").remove()), 5000);
  5. }
  6. // Help popovers
  7. $(".hover-help").popover({ trigger: "hover", html: true });
  8. // Pressing '/' selects the search box.
  9. $("body").on("keypress", function (e) {
  10. if (e.keyCode === 47) {
  11. // The '/' key
  12. if (e.target.nodeName === "BODY") {
  13. e.preventDefault();
  14. return $agentNavigate.focus();
  15. }
  16. }
  17. });
  18. // Select2 Selects
  19. $(".select2").select2({ width: "resolve" });
  20. $(".select2-linked-tags").select2({
  21. width: "resolve",
  22. templateSelection: ({ id, text, element }) => {
  23. const a = document.createElement("a");
  24. a.href = `${element.closest("select").dataset.urlPrefix}/${id}/edit`;
  25. a.onClick = "Utils.select2TagClickHandler(event, this)";
  26. a.appendChild(document.createTextNode(text));
  27. return a;
  28. },
  29. });
  30. // Helper for selecting text when clicked
  31. $(".selectable-text").each(function () {
  32. return $(this).click(function () {
  33. const range = document.createRange();
  34. range.setStartBefore(this.firstChild);
  35. range.setEndAfter(this.lastChild);
  36. const sel = window.getSelection();
  37. sel.removeAllRanges();
  38. return sel.addRange(range);
  39. });
  40. });
  41. // Agent navbar dropdown
  42. return $(".navbar .dropdown.dropdown-hover").hover(
  43. function () {
  44. return $(this).addClass("open");
  45. },
  46. function () {
  47. return $(this).removeClass("open");
  48. }
  49. );
  50. });