blocks/navigation/amd/src/navblock.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 navigation tree javascript.
  17. *
  18. * @module block_navigation/navblock
  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. /**
  25. * Initialise the navblock javascript for the specified block instance.
  26. *
  27. * @method
  28. * @param {Number} instanceId
  29. */
  30. export const init = instanceId => {
  31. const navTree = new Tree(".block_navigation .block_tree");
  32. const blockNode = document.querySelector(`[data-instance-id="${instanceId}"]`);
  33. /**
  34. * The method to call when then the navtree finishes expanding a group.
  35. *
  36. * @method finishExpandingGroup
  37. * @param {Object} item
  38. * @fires event:blockContentUpdated
  39. */
  40. navTree.finishExpandingGroup = item => {
  41. Tree.prototype.finishExpandingGroup.call(navTree, item);
  42. notifyBlockContentUpdated(blockNode);
  43. };
  44. /**
  45. * The method to call whe then the navtree collapses a group
  46. *
  47. * @method collapseGroup
  48. * @param {Object} item
  49. * @fires event:blockContentUpdated
  50. */
  51. navTree.collapseGroup = item => {
  52. Tree.prototype.collapseGroup.call(navTree, item);
  53. notifyBlockContentUpdated(blockNode);
  54. };
  55. };