mounts.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. (function (Misago) {
  2. 'use strict';
  3. var addMount = function(name) {
  4. if (this._mounts.indexOf(name) === -1) {
  5. this._mounts.push(name);
  6. }
  7. };
  8. Misago.addService('mounts', function(_) {
  9. // Default monts
  10. _._mounts = [
  11. 'alert-mount',
  12. 'auth-changed-message-mount',
  13. 'page-component',
  14. 'user-menu-mount',
  15. 'user-menu-compact-mount'
  16. ];
  17. // Function for including new mounts
  18. _.addMount = addMount;
  19. // List of active mounts, for debugging
  20. _.activeMounts = {};
  21. });
  22. Misago.addService('mount-components', {
  23. factory: function(_) {
  24. _._mounts.forEach(function(elementId) {
  25. var mount = document.getElementById(elementId);
  26. if (mount) {
  27. _.activeMounts[elementId] = mount.dataset.componentName;
  28. m.mount(mount, _.component(mount.dataset.componentName));
  29. }
  30. });
  31. },
  32. destroy: function(_) {
  33. _._mounts.forEach(function(elementId) {
  34. var mount = document.getElementById(elementId);
  35. if (mount && mount.hasChildNodes()) {
  36. m.mount(mount, null);
  37. }
  38. });
  39. }
  40. },
  41. {
  42. before: '_end'
  43. });
  44. }(Misago.prototype));