-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
68 lines (51 loc) · 1.57 KB
/
script.js
File metadata and controls
68 lines (51 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function Container(){
this.id = "";
this.className = "";
this.htmlCode = "";
};
Container.prototype.render = function () {
return this.htmlCode;
};
Container.prototype.remove = function () {
delete this.htmlCode;
};
function Menu(my_id, my_class, my_items) {
Container.call(this);
this.id = my_id;
this.className = my_class;
this.items = my_items;
};
Menu.prototype.remove = function ( i = 0 ) {
var elem = document.getElementById(this.id);
elem.parentNode.removeChild(elem);
};
Menu.prototype = Object.create(Container.prototype);
Menu.prototype.constructor = Menu;
Menu.prototype.render = function () {
let result = '<ul class="' + this.className + '" id="' + this.id + '">';
for (let item in this.items) {
if(this.items[item] instanceof MenuItem){
result += this.items[item].render();
};
};
result += '</ul>'
return result;
};
function MenuItem(my_href, my_name, my_id) {
Container.call(this);
this.id = my_id;
this.className = "menu-item";
this.href = my_href;
this.name = my_name;
};
MenuItem.prototype = Object.create(Container.prototype);
MenuItem.prototype.constructor = MenuItem;
MenuItem.prototype.render = function () {
return '<li class=' + this.className + '>' + this.name + '</li>';
};
let m_item1 = new MenuItem("/", "Главная", 1);
let m_item2 = new MenuItem("/catalog", "Каталог", 2);
let m_item3 = new MenuItem("/gallery", "Галерея", 3);
let m_items = {0: m_item1, 1: m_item2, 2: m_item3};
let menu = new Menu("my_menu", "My_class", m_items);
document.write(menu.render());