enrol/lti/amd/src/tool_endpoints.js

  1. // This file is part of Moodle - http://moodle.org/
  2. //
  3. // Moodle is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // Moodle is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  15. /**
  16. * Module supporting the dynamic and manual registration URLs in the tool registration admin setting.
  17. *
  18. * @module enrol_lti/tool_endpoints
  19. * @copyright 2021 Jake Dallimore <jrhdallimore@gmail.com>
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. import 'core/copy_to_clipboard';
  23. /**
  24. * DOM Selectors.
  25. * @type {{URL_VALUE: string}}
  26. */
  27. const SELECTORS = {
  28. URL_VALUE: '[id^="lti_tool_endpoint_url_"]',
  29. };
  30. /**
  31. * Focus handler for the registration URL field, enabling auto select of text on click.
  32. *
  33. * @param {Event} event a click event.
  34. */
  35. const focusURLHandler = (event) => {
  36. const triggerElement = event.target.closest(SELECTORS.URL_VALUE);
  37. if (triggerElement === null) {
  38. return;
  39. }
  40. event.preventDefault();
  41. triggerElement.select();
  42. };
  43. /**
  44. * Initialise the tool registration page, attaching handlers, etc.
  45. */
  46. export const init = () => {
  47. // Event delegation supporting the select on focus behaviour (with text selection permitted on subsequent clicks).
  48. document.addEventListener('focusin', focusURLHandler);
  49. };