diff --git a/HW#1/project/css/style.css b/HW#1/project/css/style.css new file mode 100644 index 0000000..a3c4756 --- /dev/null +++ b/HW#1/project/css/style.css @@ -0,0 +1,47 @@ +*{ + margin: 0 auto; + padding: auto; + +} +body{ + background-color: #dedaeedd; +} +header{ + display: grid; + grid-template-rows: 1fr; + justify-content: flex-end; + background-color: #cccc; +} +.btn-cart{ + padding: 10px 50px; + background-color: #fff; +} +main{ + display: grid; + grid-template-columns: 1fr; +} +.products{ + display: grid; + grid-template-columns: 1fr 1fr; + grid-template-rows: 1fr; +} +.product-item{ + border: 1px solid black; + display: block; + width: 350px; + height: 200px; + margin: 5px; +} +.product-item h3{ + color: red; + font-size: 30px; + margin: 5px; +} +.product-item p{ + font-weight: 600; + font-size: 18px; + margin-left: 10px; +} +button{ + margin: 5px; +} \ No newline at end of file diff --git a/HW#1/project/index.html b/HW#1/project/index.html new file mode 100644 index 0000000..e6f0d11 --- /dev/null +++ b/HW#1/project/index.html @@ -0,0 +1,17 @@ + + + + + + Title + + +
+ +
+
+
+
+ + + \ No newline at end of file diff --git a/HW#1/project/js/main.js b/HW#1/project/js/main.js new file mode 100644 index 0000000..b76b60e --- /dev/null +++ b/HW#1/project/js/main.js @@ -0,0 +1,26 @@ +const data = [ + { title: 'Notebook', id: 1, price: 2000 }, + { title: 'Keyboard', id: 2, price: 200 }, + { title: 'Mouse', id: 3, price: 100 }, + { title: 'Gamepad', id: 4, price: 87 }, + { title: 'Новый Товар', id: 5 } +]; +const renderProduct = (title, id, price = 'Цена товара', img = "https://placehold.it//150x100") => { + return ` +
+ ${title} +
+

${title}

+

${price}

+ +
+
+ ` +}; + +const render = (products) => { + document.querySelector('.products').innerHTML = products.map(item => renderProduct(item.title, item.id, item.price)).join(''); +}; + +render(data); +console.log(data) \ No newline at end of file diff --git a/HW#3/.DS_Store b/HW#3/.DS_Store new file mode 100644 index 0000000..abe47a5 Binary files /dev/null and b/HW#3/.DS_Store differ diff --git a/HW#3/.idea/$CACHE_FILE$ b/HW#3/.idea/$CACHE_FILE$ new file mode 100644 index 0000000..6cb8985 --- /dev/null +++ b/HW#3/.idea/$CACHE_FILE$ @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HW#3/.idea/inspectionProfiles/profiles_settings.xml b/HW#3/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..0eefe32 --- /dev/null +++ b/HW#3/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/HW#3/.idea/jsLibraryMappings.xml b/HW#3/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..d23208f --- /dev/null +++ b/HW#3/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HW#3/.idea/lesson3_18.02.21.iml b/HW#3/.idea/lesson3_18.02.21.iml new file mode 100644 index 0000000..24643cc --- /dev/null +++ b/HW#3/.idea/lesson3_18.02.21.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/HW#3/.idea/misc.xml b/HW#3/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/HW#3/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/HW#3/.idea/modules.xml b/HW#3/.idea/modules.xml new file mode 100644 index 0000000..2fa1c2d --- /dev/null +++ b/HW#3/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HW#3/.idea/workspace.xml b/HW#3/.idea/workspace.xml new file mode 100644 index 0000000..0d8ff08 --- /dev/null +++ b/HW#3/.idea/workspace.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1613663214120 + + + + + + \ No newline at end of file diff --git a/HW#3/hamburger/.DS_Store b/HW#3/hamburger/.DS_Store new file mode 100644 index 0000000..031e2d2 Binary files /dev/null and b/HW#3/hamburger/.DS_Store differ diff --git a/HW#3/hamburger/burgerFactory.js b/HW#3/hamburger/burgerFactory.js new file mode 100644 index 0000000..513b3fa --- /dev/null +++ b/HW#3/hamburger/burgerFactory.js @@ -0,0 +1,98 @@ +class Param { + name = ''; + price = 0; + calories = 0; + + constructor(el) { + this.name = el.value; + ({price: this.price, cal: this.calories} = Burger.burgerParams[this.name]) + } +} + +class Burger { + static burgerParams = { + big: { + price: 100, + cal: 40 + }, + small: { + price: 50, + cal: 20 + }, + salad: { + price: 20, + cal: 5 + }, + cheese: { + price: 10, + cal: 20 + }, + potato: { + price: 15, + cal: 10 + }, + mayo: { + price: 20, + cal: 5 + }, + spices: { + price: 15, + cal: 0 + } + }; + + size = null; + add = null; + toppings = []; + + constructor(size, add, toppings) { + this.size = new Param(this._select(size)); + this.add = new Param(this._select(add)); + this.toppings = this._selectAll(toppings).map(el => new Param(el)); + } + + get price() { + return this._sum('price') + } + + get calories() { + return this._sum('calories') + } + + showSum(price, calories) { + document.querySelector(price).textContent = this.price; + document.querySelector(calories).textContent = this.calories; + } + + _select(name) { + return document.querySelector(`input[name="${name}"]:checked`); + } + + _selectAll(name) { + return [...document.querySelectorAll(`input[name="${name}"]:checked`)]; + } + + _sum(value) { + let result = this.size[value] + this.add[value]; + this.toppings.forEach(topping => result += topping[value]); + return result; + } +} + + + + + + + + + + + + + + + + + + diff --git a/HW#3/hamburger/burger_calc.html b/HW#3/hamburger/burger_calc.html new file mode 100644 index 0000000..85f7e46 --- /dev/null +++ b/HW#3/hamburger/burger_calc.html @@ -0,0 +1,69 @@ + + + + + Title + + +
+
+

Составь свой бургер.

+
+

Выберите размер бургера:

+ +
+ + +
+ +
+

Выберите начинку бургера:

+ +
+ +
+ +
+
+ +
+

Выберите доп. опцию:

+ +
+ +
+
+ +
Собрать бургер
+ +

Итоговая стоимость: 0
+ Кол-во калорий: 0

+
+
+ + + + + + + + + + + + + + + + + + + diff --git a/HW#3/lesson3.html b/HW#3/lesson3.html new file mode 100644 index 0000000..20c88cc --- /dev/null +++ b/HW#3/lesson3.html @@ -0,0 +1,175 @@ + + + + + Title + + + +
+ + + + + + \ No newline at end of file diff --git a/HW#3/project/.DS_Store b/HW#3/project/.DS_Store new file mode 100644 index 0000000..85b8569 Binary files /dev/null and b/HW#3/project/.DS_Store differ diff --git a/HW#3/project/css/normalize.css b/HW#3/project/css/normalize.css new file mode 100644 index 0000000..16e4c01 --- /dev/null +++ b/HW#3/project/css/normalize.css @@ -0,0 +1,348 @@ +/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */ + +/* Document + ========================================================================== */ + +/** + * 1. Correct the line height in all browsers. + * 2. Prevent adjustments of font size after orientation changes in iOS. + */ +html { + line-height: 1.15; /* 1 */ + -webkit-text-size-adjust: 100%; /* 2 */ +} + +/* Sections + ========================================================================== */ + +/** + * Remove the margin in all browsers. + */ + +body { + margin: 0; +} + +/** + * Render the `main` element consistently in IE. + */ + +main { + display: block; +} + +/** + * Correct the font size and margin on `h1` elements within `section` and + * `article` contexts in Chrome, Firefox, and Safari. + */ + +h1 { + font-size: 2em; + margin: 0.67em 0; +} + +/* Grouping content + ========================================================================== */ + +/** + * 1. Add the correct box sizing in Firefox. + * 2. Show the overflow in Edge and IE. + */ + +hr { + box-sizing: content-box; /* 1 */ + height: 0; /* 1 */ + overflow: visible; /* 2 */ +} + +/** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + +pre { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/* Text-level semantics + ========================================================================== */ + +/** + * Remove the gray background on active links in IE 10. + */ + +a { + background-color: transparent; +} + +/** + * 1. Remove the bottom border in Chrome 57- + * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari. + */ + +abbr[title] { + border-bottom: none; /* 1 */ + text-decoration: underline; /* 2 */ + text-decoration: underline dotted; /* 2 */ +} + +/** + * Add the correct font weight in Chrome, Edge, and Safari. + */ + +b, +strong { + font-weight: bolder; +} + +/** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + +code, +kbd, +samp { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/** + * Add the correct font size in all browsers. + */ + +small { + font-size: 80%; +} + +/** + * Prevent `sub` and `sup` elements from affecting the line height in + * all browsers. + */ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sub { + bottom: -0.25em; +} + +sup { + top: -0.5em; +} + +/* Embedded content + ========================================================================== */ + +/** + * Remove the border on images inside links in IE 10. + */ + +img { + border-style: none; +} + +/* Forms + ========================================================================== */ + +/** + * 1. Change the font styles in all browsers. + * 2. Remove the margin in Firefox and Safari. + */ + +button, +input, +optgroup, +select, +textarea { + font-family: inherit; /* 1 */ + font-size: 100%; /* 1 */ + line-height: 1.15; /* 1 */ + margin: 0; /* 2 */ +} + +/** + * Show the overflow in IE. + * 1. Show the overflow in Edge. + */ + +button, +input { /* 1 */ + overflow: visible; +} + +/** + * Remove the inheritance of text transform in Edge, Firefox, and IE. + * 1. Remove the inheritance of text transform in Firefox. + */ + +button, +select { /* 1 */ + text-transform: none; +} + +/** + * Correct the inability to style clickable types in iOS and Safari. + */ + +button, +[type="button"], +[type="reset"], +[type="submit"] { + -webkit-appearance: button; +} + +/** + * Remove the inner border and padding in Firefox. + */ + +button::-moz-focus-inner, +[type="button"]::-moz-focus-inner, +[type="reset"]::-moz-focus-inner, +[type="submit"]::-moz-focus-inner { + border-style: none; + padding: 0; +} + +/** + * Restore the focus styles unset by the previous rule. + */ + +button:-moz-focusring, +[type="button"]:-moz-focusring, +[type="reset"]:-moz-focusring, +[type="submit"]:-moz-focusring { + outline: 1px dotted ButtonText; +} + +/** + * Correct the padding in Firefox. + */ + +fieldset { + padding: 0.35em 0.75em 0.625em; +} + +/** + * 1. Correct the text wrapping in Edge and IE. + * 2. Correct the color inheritance from `fieldset` elements in IE. + * 3. Remove the padding so developers are not caught out when they zero out + * `fieldset` elements in all browsers. + */ + +legend { + box-sizing: border-box; /* 1 */ + color: inherit; /* 2 */ + display: table; /* 1 */ + max-width: 100%; /* 1 */ + padding: 0; /* 3 */ + white-space: normal; /* 1 */ +} + +/** + * Add the correct vertical alignment in Chrome, Firefox, and Opera. + */ + +progress { + vertical-align: baseline; +} + +/** + * Remove the default vertical scrollbar in IE 10+. + */ + +textarea { + overflow: auto; +} + +/** + * 1. Add the correct box sizing in IE 10. + * 2. Remove the padding in IE 10. + */ + +[type="checkbox"], +[type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ +} + +/** + * Correct the cursor style of increment and decrement buttons in Chrome. + */ + +[type="number"]::-webkit-inner-spin-button, +[type="number"]::-webkit-outer-spin-button { + height: auto; +} + +/** + * 1. Correct the odd appearance in Chrome and Safari. + * 2. Correct the outline style in Safari. + */ + +[type="search"] { + -webkit-appearance: textfield; /* 1 */ + outline-offset: -2px; /* 2 */ +} + +/** + * Remove the inner padding in Chrome and Safari on macOS. + */ + +[type="search"]::-webkit-search-decoration { + -webkit-appearance: none; +} + +/** + * 1. Correct the inability to style clickable types in iOS and Safari. + * 2. Change font properties to `inherit` in Safari. + */ + +::-webkit-file-upload-button { + -webkit-appearance: button; /* 1 */ + font: inherit; /* 2 */ +} + +/* Interactive + ========================================================================== */ + +/* + * Add the correct display in Edge, IE 10+, and Firefox. + */ + +details { + display: block; +} + +/* + * Add the correct display in all browsers. + */ + +summary { + display: list-item; +} + +/* Misc + ========================================================================== */ + +/** + * Add the correct display in IE 10+. + */ + +template { + display: none; +} + +/** + * Add the correct display in IE 10. + */ + +[hidden] { + display: none; +} diff --git a/HW#3/project/css/style.css b/HW#3/project/css/style.css new file mode 100644 index 0000000..9e463cb --- /dev/null +++ b/HW#3/project/css/style.css @@ -0,0 +1,87 @@ +body{ + font-family: 'SF Pro Display', sans-serif; +} +header{ + display: flex; + background-color: #2f2a2d; + justify-content: space-between; + color: #fafafa; + padding: 30px 80px; +} +button{ + outline: none; +} +.logo{ + + text-transform: uppercase; + font-weight: bold; +} +.btn-cart{ + background-color: #fafafa; + padding: 10px 20px; + border: 1px solid transparent; + color: #2f2a2d; + border-radius: 5px; + transition: all ease-in-out .4s; + cursor: pointer; +} +.btn-cart:hover{ + background-color: transparent; + border-color: #fafafa; + color: #fafafa; +} +.btn-cart, .logo{ + align-self: center; +} +.products{ + column-gap: 30px; + display: grid; + grid-template-columns: repeat(auto-fit, 200px); + grid-template-rows: 1fr; + padding: 40px 80px; + justify-content: space-between; +} +p { + margin: 0 0 5px 0; +} +.product-item{ + display: flex; + flex-direction: column; + width: 200px; + border-radius: 5px; + overflow: hidden; + margin: 20px 0; +} +img { + max-width: 100%; + height: auto +} +.desc { + border: 1px solid #c0c0c040; + padding: 15px +} +.buy-btn{ + margin-top: 5px; + background-color: #2f2a2d; + padding: 10px 20px; + border: 1px solid transparent; + color: #fafafa; + border-radius: 5px; + transition: all ease-in-out .4s; + cursor: pointer; +} +.buy-btn:hover{ + background-color: transparent; + border-color: #2f2a2d; + color: #2f2a2d; +} +.invisible{ + display: none; +} + +/* .side{ + color: #000; + display: block; + width: 900px; + height: 300px; +} */ diff --git a/HW#3/project/index.html b/HW#3/project/index.html new file mode 100644 index 0000000..f63ce07 --- /dev/null +++ b/HW#3/project/index.html @@ -0,0 +1,22 @@ + + + + + Store + + + + +
+ +
+ + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/HW#3/project/js/main.js b/HW#3/project/js/main.js new file mode 100644 index 0000000..70553e2 --- /dev/null +++ b/HW#3/project/js/main.js @@ -0,0 +1,237 @@ + + +let getRequest = url => { + return new Promise((resolve,reject) => { + let xhr = new XMLHttpRequest(); + xhr.open('GET', url, true); + xhr.onreadystatechange = () => { + if (xhr.readyState !== 4) { + return; + } + + if (xhr.status !== 200) { + reject('some error'); + return; + } + + resolve(xhr.responseText); + } + }); +}; +getRequest('tel.json').then(); + + +/////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////// + +class Item{ + product_name = ''; + price = 0; + id_product = 0; + img = ''; + rendered = false; + + constructor(product, img = 'https://placehold.it/200x150') { + ({ product_name: this.product_name, price: this.price, id_product: this.id } = product); + this.img = img; + } + + render() { + this.rendered = true; + return `
+ ${this.product_name} +
+

${this.product_name}

+

${this.price}

+ +
+
` + } + +} +class ProductItem extends Item{} +class CartItem extends Item{ + quantity = 0; + + constructor(product,img = 'https://placehold.it/50x100'){ + super(product,img); + this.quantity = product.quantity; + } + changeQuantity(count){ + this.quantity +=count; + this._updateItem(); + } + removeMarkup(){ + document.querySelector(`.cart-item[data-id = "${this.id_product}"]`).remove(); + } + render(){ + this.rendered = true; + return `
+ + Image +
+

${this.product_name}

+

Quantity: ${this.quantity}

+

$${this.price} each

+
+
+
+

$${this.quantity*this.price}

+ +
+ + ` + } + _updateItem(){ + const block = document.querySelector(`.cart-item[data-id = "${this.id_product}"]`); + block.querySelector(`.product-quantity`).textContent = `Quantity: ${this.quantity}` + block.querySelector(`.product-price`).textContent = `$${this.quantity*this.price}` + } +} +class List{ + static itemsMap ={ + Products: ProductItem, + Cart: CartItem + } + static API = `https://raw.githubusercontent.com/GeekBrainsTutorial/online-store-api/master/responses`; + + products = []; + container = null; + url ='' + + constructor(selector,url) { + this.container = document.querySelector(selector); + this.url = url + this._init() + } + getJson(url){ + return fetch(url ? url : `${List.API + this.url}`) + .then(result => result.json()) + } + handleData(data){ + for(let item of data){ + this.products.push(new List.itemsMap[this.constructor.name](item)) + } + this._render() + } + calcSum() { + return this.products.reduce((accum, item) => accum += item.price, 0); + } + getItem(id){ + return this.products.find(el => el.id_product === id) + } + _init(){} + _render(){ + for (let product of this.products) { + if (product.rendered) { + continue; + } + + this.container.insertAdjacentHTML('beforeend', product.render()) + } + } +} +/////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////// +class Products extends List{ + cart = null; + constructor(cart,container =".products",url = "/catalogData.json"){ + super(container,url) + this.cart = cart; + this.getJson() + .then(data => this.handleData(data)) + } + + _init() { + this.container.addEventListener('click',e =>{ + if(e.target.classList.contains('.buy-btn')){ + const id = +e.target.dataset.id; + this.cart.addProduct(this.getItem(id)) + } + }) + } + +} + +class Cart extends List{ + constructor(container = '.cart-block',url = '/getBasket.json'){ + super(container,url); + this.getJson() + .then(data => this.handleData(data.contents)) + } + addProduct(product){ + this.getJson(`${List.API}/addToBasket.json`) + .then(data =>{ + if(data.result){ + let find = this.products.find(el => el.id_product === product.id_product) + if(find){ + find.changeQuantity(1) + return + } + let prod = Object.assign({quantity:1},product) + this.handleData([prod]) + }else{ + console.log('error') + } + }) + } + removeProdoct(product){ + this.getJson(`${List.API}/deleteFromBasket.json`) + .then(data =>{ + if(data.result){ + if(product.quantity > 1){ + product.changeQuantity(-1) + return + } + this.products.splice(this.products.indexOf(product),1) + product.removeMarkup(); + }else{ + console.log('error') + } + }) + } + _init() { + this.container.addEventListener('click',e =>{ + if(e.target.classList.contains('.del-btn')){ + const id = +e.target.dataset.id; + this.removeProdoct(this.getItem(id)) + } + }); + document.querySelector(`.btn-cart`).addEventListener('click',()=>{ + this.container.classList.toggle('invisible') + }) + } +} +const cart = new Cart() +const list = new Products(cart) +/////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////// + + +//Все что смог сам реализовать. Не могу читать чужой код. Сразу становиться непонятно где что, кто что наследует и т.д. + + +// let Render = Boolean; +// Render = false; + +// function dropCart(){ +// aside = ''; +// reside = '
Корзина
' +// if(Render === false){ +// Render = true; +// document.querySelector('.btn-cart').insertAdjacentHTML('beforeend',aside); +// console.log(Render) +// return +// }else(Render === true) +// { +// Render = false; +// document.querySelector('.btn-cart').innerHTML = reside; +// console.log(Render) +// return +// } + +// } +/////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/HW#3/tel.json b/HW#3/tel.json new file mode 100644 index 0000000..e2d496d --- /dev/null +++ b/HW#3/tel.json @@ -0,0 +1,4 @@ +{ + "name": "John", + "tel": 234566 +} \ No newline at end of file