page.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. (function (Misago) {
  2. 'use strict';
  3. Misago.Page = function(name, _) {
  4. var self = this;
  5. this.name = name;
  6. this.isFinalized = false;
  7. this._sections = [];
  8. var finalize = function() {
  9. if (!self.isFinalized) {
  10. self.isFinalized = true;
  11. var visible = [];
  12. self._sections.forEach(function (item) {
  13. if (!item.visibleIf || item.visibleIf(_)) {
  14. visible.push(item);
  15. }
  16. });
  17. self._sections = new Misago.OrderedList(visible).order(true);
  18. }
  19. };
  20. this.addSection = function(section) {
  21. if (this.isFinalized) {
  22. throw (this.name + " page was initialized already and no longer accepts new sections");
  23. }
  24. this._sections.push({
  25. key: section.link,
  26. item: section,
  27. after: section.after,
  28. before: section.before
  29. });
  30. };
  31. this.getSections = function() {
  32. finalize();
  33. return this._sections;
  34. };
  35. this.getDefaultLink = function() {
  36. finalize();
  37. return this._sections[0].link;
  38. };
  39. };
  40. }(Misago.prototype));