From 89a2671d04fcba90938cf126fa82b40471056295 Mon Sep 17 00:00:00 2001 From: rein-d Date: Thu, 6 Dec 2018 11:55:56 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=20index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 0000000..c42f5f3 --- /dev/null +++ b/index.html @@ -0,0 +1,4 @@ +Урок 1 + + + \ No newline at end of file From fe640d827e8a74623b1d688ec4202caf1999a5bf Mon Sep 17 00:00:00 2001 From: rein-d Date: Thu, 6 Dec 2018 11:56:18 +0300 Subject: [PATCH 2/5] =?UTF-8?q?=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB?= =?UTF-8?q?=20JS-lesson1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JS/script.js | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 JS/script.js diff --git a/JS/script.js b/JS/script.js new file mode 100644 index 0000000..6115331 --- /dev/null +++ b/JS/script.js @@ -0,0 +1,67 @@ +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 = Object.create(Container.prototype); +Menu.prototype.constructor = Menu; +Menu.prototype.render = function () { + let result = '' + return result; + +}; + +Menu.prototype.remove = function ( i = 0 ) { + let elem = document.getElementById( this.id ), + item = document.getElementsByClassName( 'menu-item' ); + elem.removeChild( item[ i ] ); +}; + +function MenuItem(my_href, my_name) { + 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 '
  • ' + this.name + '
  • '; +}; + +let m_item1 = new MenuItem("/", "Главная"); +let m_item2 = new MenuItem("/catalog", "Каталог"); +let m_item3 = new MenuItem("/gallery", "Галерея"); +let m_items = {0: m_item1, 1: m_item2, 2: m_item3}; + +let menu = new Menu("my_menu", "menu_class", m_items); +menu.remove(); +document.write(menu.render()); + + From 2255c6a2ebe986f0ccc377655a9085d353c0b19b Mon Sep 17 00:00:00 2001 From: rein-d Date: Thu, 6 Dec 2018 14:34:45 +0300 Subject: [PATCH 3/5] =?UTF-8?q?=D0=A2=D0=B0=D0=BA=20=D0=B8=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B7=D0=BE=D0=B1=D1=80=D0=B0=D0=BB=D1=81=D1=8F?= =?UTF-8?q?=20=D0=BA=D0=B0=D0=BA=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D1=82?= =?UTF-8?q?=D1=8C,=20=D0=B2=D1=8B=D0=B4=D0=B0=D0=B5=D1=82=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BA=D0=B8=20Cannot=20set=20property=20'innerHTML?= =?UTF-8?q?'=20of=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JS/script.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/JS/script.js b/JS/script.js index 6115331..819a75a 100644 --- a/JS/script.js +++ b/JS/script.js @@ -10,7 +10,8 @@ Container.prototype.render = function () { }; Container.prototype.remove = function () { - delete this.htmlCode; + let elem = document.getElementById(this.id); + elem.parentNode.removeChild(elem); }; function Menu(my_id, my_class, my_items) { @@ -35,15 +36,9 @@ result += '' }; -Menu.prototype.remove = function ( i = 0 ) { - let elem = document.getElementById( this.id ), - item = document.getElementsByClassName( 'menu-item' ); - elem.removeChild( item[ i ] ); -}; - -function MenuItem(my_href, my_name) { +function MenuItem(my_href, my_name, my_id) { Container.call(this); - //this.id = my_id; + this.id = my_id; this.className = "menu-item"; this.href = my_href; this.name = my_name; @@ -55,13 +50,18 @@ MenuItem.prototype.render = function () { return '
  • ' + this.name + '
  • '; }; -let m_item1 = new MenuItem("/", "Главная"); -let m_item2 = new MenuItem("/catalog", "Каталог"); -let m_item3 = new MenuItem("/gallery", "Галерея"); +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", "menu_class", m_items); -menu.remove(); -document.write(menu.render()); +let menu = new Menu("my_menu", "My_class", m_items); + +window.onload = function () { + elem.innerHTML = menu.render(); + menu.remove(); +}; + + From f99a8aeb6c43609b7548c00bca7a20de98b55357 Mon Sep 17 00:00:00 2001 From: rein-d Date: Thu, 6 Dec 2018 21:03:14 +0300 Subject: [PATCH 4/5] update --- {JS => lesson1/JS}/script.js | 13 +++++++------ index.html => lesson1/index.html | 0 2 files changed, 7 insertions(+), 6 deletions(-) rename {JS => lesson1/JS}/script.js (90%) rename index.html => lesson1/index.html (100%) diff --git a/JS/script.js b/lesson1/JS/script.js similarity index 90% rename from JS/script.js rename to lesson1/JS/script.js index 819a75a..1b03c57 100644 --- a/JS/script.js +++ b/lesson1/JS/script.js @@ -10,8 +10,7 @@ Container.prototype.render = function () { }; Container.prototype.remove = function () { - let elem = document.getElementById(this.id); - elem.parentNode.removeChild(elem); + delete this.htmlCode; }; function Menu(my_id, my_class, my_items) { @@ -21,6 +20,11 @@ function Menu(my_id, my_class, my_items) { 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 () { @@ -57,10 +61,7 @@ let m_items = {0: m_item1, 1: m_item2, 2: m_item3}; let menu = new Menu("my_menu", "My_class", m_items); -window.onload = function () { - elem.innerHTML = menu.render(); - menu.remove(); -}; +document.write(menu.render()); diff --git a/index.html b/lesson1/index.html similarity index 100% rename from index.html rename to lesson1/index.html From 4ffc01e28a74d56ddce901754f4f79d5db795676 Mon Sep 17 00:00:00 2001 From: rein-d Date: Mon, 10 Dec 2018 15:40:04 +0300 Subject: [PATCH 5/5] update --- lesson2/JS/script.js | 131 +++++++++++++++++++++++++++++++++++++++++++ lesson2/index.html | 12 ++++ lesson2/menu.json | 19 +++++++ 3 files changed, 162 insertions(+) create mode 100644 lesson2/JS/script.js create mode 100644 lesson2/index.html create mode 100644 lesson2/menu.json diff --git a/lesson2/JS/script.js b/lesson2/JS/script.js new file mode 100644 index 0000000..8a90d91 --- /dev/null +++ b/lesson2/JS/script.js @@ -0,0 +1,131 @@ +function Container(){ + this.id = ""; + this.className = ""; + this.htmlCode = ""; + +}; + +Container.prototype.render = function () { + return this.htmlCode; +}; + +Container.prototype.remove = function () { + let elem = document.getElementById(this.id); + elem.parentNode.removeChild(elem); + console.log(elem); +}; + +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 = Object.create(Container.prototype); +Menu.prototype.constructor = Menu; +Menu.prototype.render = function () { + let result = '
      '; +for (let item in this.items) { + if(this.items[item] instanceof MenuItem){ + result += this.items[item].render(); + }; +}; + +result += '
    ' + return result; + +}; + +function MenuItem(my_id, my_href, my_name) { + 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 '
  • ' + this.name + '
  • '; +}; + + +function SubMenu (my_id, my_class, my_items){ + Container.call(this); + this.id = my_id; + this.className = my_class; + this.items = my_items; +} +SubMenu.prototype = Object.create(Container.prototype); +SubMenu.prototype.constructor =SubMenu; +SubMenu.prototype.render = function(){ + let result = '
      '; + for(let item in this.items){ + if(this.items[item] instanceof Menu){ + result +=this.items[item].render(); + result +='
    '; + } else { + console.log(this.items[item]); + for (let subitem in this.items[item]){ + console.log(this.items[item][subitem]); + result += this.items[item][subitem].render(); + } + } + } + result += ''; + return result; +}; + +/* +let m_item1 = new MenuItem("1", "/", "Главная"); +let m_item2 = new MenuItem("2", "/catalog", "Каталог"); +let m_item3 = new MenuItem("3", "/gallery", "Галерея"); +let m_items = {0: m_item1, 1: m_item2, 2: m_item3}; +*/ + +//let menu = new Menu("my_menu", "menu_class", m_items); +//let submenu = new SubMenu("menu_main", "sub_menu", [m_items,menu]); +//console.log(submenu); +// document.write(submenu.render()); + +function fillMenuContents(xhr) { + let m_items = {}; + + if (xhr.readyState ==4) { + if (xhr.status == 200) { + let items = JSON.parse(xhr.responseText); + + for (let currentitem of items.menu_items){ + m_items[currentitem.title] = new MenuItem(currentitem.id ,currentitem.href, currentitem.title); + } + + let menu = new Menu("my_menu", "My_class", m_items); + let submenu = new SubMenu("menu_main", "sub_menu", [m_items,menu]); + document.write(submenu.render()); + } + } else { + alert("ошибка выполнения запроса!"); + } +}; + + +let xhr; + +if (window.XMLHttpRequest) { + xhr = new XMLHttpRequest(); + if (window.overrideMimeType) { + xhr.overrideMimeType('application/json'); + } +} else if (window.ActiveXObject) { + xhr = new ActiveXObject('Microsoft.XMLHTTP'); +} + +if (!xhr) { + console.log("Невозможно создать запрос!"); +} + +xhr.onreadystatechange = function() { fillMenuContents(xhr); }; +xhr.ontimeout = function() {console.log("Превышего время ожидание запроса!");}; +xhr.open('GET', 'menu.json', true); +xhr.send(null); \ No newline at end of file diff --git a/lesson2/index.html b/lesson2/index.html new file mode 100644 index 0000000..a715855 --- /dev/null +++ b/lesson2/index.html @@ -0,0 +1,12 @@ + + + + + Урок 2. + + + + + + + \ No newline at end of file diff --git a/lesson2/menu.json b/lesson2/menu.json new file mode 100644 index 0000000..1a35010 --- /dev/null +++ b/lesson2/menu.json @@ -0,0 +1,19 @@ +{ + "menu_items": [ + { + "id": "1", + "href": "/", + "title": "Главная" + }, + { + "id": "2", + "href": "/catalogue", + "title": "Каталог" + }, + { + "id": "3", + "href": "/gallery", + "title": "Галлерея" + } + ] +} \ No newline at end of file