blocks/settings/amd/src/settingsblock.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. * Load the settings block tree javscript
  17. *
  18. * @module block_settings/settingsblock
  19. * @copyright 2015 John Okely <john@moodle.com>
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. import {notifyBlockContentUpdated} from 'core_block/events';
  23. import Tree from 'core/tree';
  24. export const init = (instanceId, siteAdminNodeId) => {
  25. const adminTree = new Tree(".block_settings .block_tree");
  26. const blockNode = document.querySelector(`[data-instance-id="${instanceId}"]`);
  27. if (siteAdminNodeId) {
  28. const siteAdminLink = adminTree.treeRoot.get(0).querySelector(`#${siteAdminNodeId} a`);
  29. const newContainer = document.createElement('span');
  30. newContainer.setAttribute('tabindex', '0');
  31. siteAdminLink.childNodes.forEach(node => newContainer.appendChild(node));
  32. siteAdminLink.replaceWith(newContainer);
  33. }
  34. /**
  35. * The method to call when then the navtree finishes expanding a group.
  36. *
  37. * @method finishExpandingGroup
  38. * @param {Object} item
  39. * @fires event:blockContentUpdated
  40. */
  41. adminTree.finishExpandingGroup = function(item) {
  42. Tree.prototype.finishExpandingGroup.call(adminTree, item);
  43. notifyBlockContentUpdated(blockNode);
  44. };
  45. /**
  46. * The method to call whe then the navtree collapses a group
  47. *
  48. * @method collapseGroup
  49. * @param {Object} item
  50. * @fires event:blockContentUpdated
  51. */
  52. adminTree.collapseGroup = function(item) {
  53. Tree.prototype.collapseGroup.call(adminTree, item);
  54. notifyBlockContentUpdated(blockNode);
  55. };
  56. };