OOP Navigation Bar
by manototh
HTML
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>OOP Navigation Bar</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/foundation-sites@6.7.4/dist/css/foundation.min.css" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/foundation-sites@6.7.4/dist/js/foundation.min.js" crossorigin="anonymous"></script>
</head>
<body>
<div id="navbar"></div>
</body>
</html>
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var _a;
var NavBarParentItem = /** @class */ (function () {
function NavBarParentItem() {
}
NavBarParentItem.prototype.RenderChildItems = function (navBarItems) {
var _this = this;
var renderedChildItems = [];
navBarItems.forEach(function (navBarItem) {
if (navBarItem.GetParent() === _this) {
renderedChildItems.push(navBarItem.Render(navBarItems));
}
});
return renderedChildItems;
};
return NavBarParentItem;
}());
var NavBarItem = /** @class */ (function (_super) {
__extends(NavBarItem, _super);
function NavBarItem(parent, text) {
var _this = _super.call(this) || this;
_this.parent = parent;
_this.text = text;
return _this;
}
NavBarItem.prototype.GetParent = function () {
return this.parent;
};
NavBarItem.prototype.CreateElement = function (elementType) {
var element = document.createElement(elementType);
return element;
};
NavBarItem.prototype.CreateAnchorElement = function () {
return this.CreateElement('a');
};
NavBarItem.prototype.ConfigureAnchor = function (anchor, text) {
...