course/format/amd/src/local/courseindex/drawer.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. * Course index drawer wrap.
  17. *
  18. * This component is mostly used to ensure all subcomponents find a parent
  19. * compoment with a reactive instance defined.
  20. *
  21. * @module core_courseformat/local/courseindex/drawer
  22. * @class core_courseformat/local/courseindex/drawer
  23. * @copyright 2021 Ferran Recio <ferran@moodle.com>
  24. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25. */
  26. import {BaseComponent} from 'core/reactive';
  27. import {getCurrentCourseEditor} from 'core_courseformat/courseeditor';
  28. export default class Component extends BaseComponent {
  29. /**
  30. * Constructor hook.
  31. */
  32. create() {
  33. // Optional component name for debugging.
  34. this.name = 'courseindex-drawer';
  35. }
  36. /**
  37. * Static method to create a component instance form the mustache template.
  38. *
  39. * @param {element|string} target the DOM main element or its ID
  40. * @param {object} selectors optional css selector overrides
  41. * @return {Component}
  42. */
  43. static init(target, selectors) {
  44. return new this({
  45. element: document.getElementById(target),
  46. reactive: getCurrentCourseEditor(),
  47. selectors,
  48. });
  49. }
  50. }