controllers/comments_controller.js

  1. import { Controller } from "@hotwired/stimulus"
  2. /**
  3. * @class CommentsController
  4. * @classdesc Stimulus controller to initialise Commento to allow users to view and make comments.
  5. * @extends Controller
  6. */
  7. export default class extends Controller {
  8. /**
  9. * @property {Function} load - targets the button to load comments
  10. * @property {Function} commento - targets the div to initialise Commento
  11. * @memberof CommentsController
  12. * @static
  13. */
  14. static targets = [ "load", "commento" ]
  15. /**
  16. * Triggered by a click event.
  17. *
  18. * Hides the button for loading comments.
  19. *
  20. * Adds top margin to the Commneto block and initialises Commento
  21. *
  22. * @instance
  23. * @memberof CommentsController
  24. * @returns {void} N/A
  25. * */
  26. load() {
  27. this.loadTarget.style.display = "none"
  28. this.commentoTarget.classList.add("margin-top--xxl")
  29. window.commento.main()
  30. }
  31. }