1 |
efrain |
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 |
/**
|
|
|
25 |
* DOM Selectors.
|
|
|
26 |
* @type {{URL_VALUE: string}}
|
|
|
27 |
*/
|
|
|
28 |
const SELECTORS = {
|
|
|
29 |
URL_VALUE: '[id^="lti_tool_endpoint_url_"]',
|
|
|
30 |
};
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Focus handler for the registration URL field, enabling auto select of text on click.
|
|
|
34 |
*
|
|
|
35 |
* @param {Event} event a click event.
|
|
|
36 |
*/
|
|
|
37 |
const focusURLHandler = (event) => {
|
|
|
38 |
const triggerElement = event.target.closest(SELECTORS.URL_VALUE);
|
|
|
39 |
if (triggerElement === null) {
|
|
|
40 |
return;
|
|
|
41 |
}
|
|
|
42 |
event.preventDefault();
|
|
|
43 |
|
|
|
44 |
triggerElement.select();
|
|
|
45 |
};
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Initialise the tool registration page, attaching handlers, etc.
|
|
|
49 |
*/
|
|
|
50 |
export const init = () => {
|
|
|
51 |
// Event delegation supporting the select on focus behaviour (with text selection permitted on subsequent clicks).
|
|
|
52 |
document.addEventListener('focusin', focusURLHandler);
|
|
|
53 |
};
|