Created
January 15, 2019 11:55
-
-
Save Sinozet/bf3fdca424d92bdabde5d9971d8874ec to your computer and use it in GitHub Desktop.
dwaLea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<li>Menu 1</li> | |
<li>Menu 2</li> | |
<li>Menu 3</li> | |
</ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Container() { | |
this.id = ""; | |
this.className = ""; | |
this.htmlCode = ""; | |
} | |
Container.prototype.render = function() { | |
return this.htmlCode; | |
}; | |
function Menu(myId, myClass, myItems) { | |
Container.call(this); | |
this.id = myId; | |
this.className = myClass; | |
this.items = myItems; | |
} | |
Menu.prototype = Object.create(Container.prototype); | |
Menu.prototype.constructor = Menu; | |
Menu.prototype.render = function() { | |
var menuList = ""; | |
for (var i in this.items) { | |
menuList += items[i].render(); | |
} | |
return "<ul>" + menuList + "</ul>"; | |
} | |
function MenuItem(myHref, myTitle) { | |
Container.call(this); | |
this.className = 'menu_class'; | |
this.href = myHref; | |
this.title = myTitle; | |
} | |
MenuItem.prototype = Object.create(Container.prototype); | |
MenuItem.prototype.constructor = MenuItem; | |
MenuItem.prototype.render = function() { | |
return "<li class='" + this.className + "'><a href='" + this.href + "'> - " + this.title + " - </a></li>"; | |
}; | |
var item1 = new MenuItem('/','Главная'); | |
var item2 = new MenuItem('/catalog','Каталог'); | |
var item3 = new MenuItem('/contacts','Контакты'); | |
var items = [item1, item2, item3]; | |
var menu = new Menu('my_menu', 'menu_class', items); | |
document.write(menu.render()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment