diff --git a/README.md b/README.md deleted file mode 100644 index fc9fd69..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# JS_Advanced \ No newline at end of file diff --git a/css/normalize.css b/css/normalize.css new file mode 100644 index 0000000..192eb9c --- /dev/null +++ b/css/normalize.css @@ -0,0 +1,349 @@ +/*! 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/css/style.css b/css/style.css new file mode 100644 index 0000000..008f02f --- /dev/null +++ b/css/style.css @@ -0,0 +1,198 @@ +body{ + font-family: 'SF Pro Display', sans-serif; +} +header{ + display: flex; + background-color: #2f2a2d; + justify-content: space-between; + color: #fafafa; + padding: 30px 80px; +} +button:focus{ + 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 {*/ +/*display: flex;*/ +/*justify-content: space-between;*/ +/*flex-wrap: wrap;*/ +/*padding: 40px 80px;*/ +/*}*/ +.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 +} +.cart{ + display: flex; + position: relative; +} +.cart-block{ + box-shadow: 0 0 5px rgba(0, 0, 0, 0.62); + border-radius: 5px; + box-sizing: border-box; + right: 0; + top: 130%; + position: absolute; + background-color: white; + padding: 20px; + color: black; + width: 300px; +} + +.invisible{ + display: none; +} +.cart-block:before{ + content: ''; + width: 0; + height: 0; + position: absolute; + top: -10px; + right: 35px; + border-left: 10px solid transparent; + border-right: 10px solid transparent; + border-bottom: 10px solid white; +} + +.buy-btn, .del-btn{ + margin-top: 5px; + background-color: #2f2a2d; + padding: 5px 15px; + border: 1px solid transparent; + color: #fafafa; + border-radius: 5px; + transition: all ease-in-out .4s; + cursor: pointer; +} +.buy-btn:hover, .del-btn:hover{ + background-color: #fafafa; + color: #2f2a2d; + border: 1px solid #2f2a2d; +} +.cart-item { + display: flex; + justify-content: space-between; +} +.cart-item:not(:last-child){ + margin-bottom: 20px; +} +.product-bio{ + display: flex; +} +.cart-item img{ + align-self: flex-start; + margin-right: 15px; +} +.product-single-price{ + color: #474747; + font-size: 0.5em; +} +.product-price{ + margin-left: 30px; +} +.product-desc{ + max-width: 150px; +} +.product-quantity { + margin-top: 15px; + font-size: 0.75em; +} +.right-block{ + text-align: right; +} +.btn-search { + background-color: transparent; + border: none; + color: #fafafa; + font-size: 1.2em; + position: absolute; + bottom: 5px; + right: 0; +} +.search-form{ + position: relative; + margin-right: 50px; + display: inline-block; +} +.search-field:focus{ + outline: none; +} +.search-field { + box-sizing: border-box; + width: 200px; + color: #fafafa; + padding: 10px; + background-color: transparent; + border: none; + border-bottom: 2px solid #fafafa; +} +.error-msg { + padding: 30px 20px; + background-color: red; + color: white; + position: relative; +} +.error-block { + background-color: rgba(0,0,0, .5); + justify-content: center; + display: flex; + position: absolute; + top: 0; + width: 100%; + height: 100%; + align-items: center; +} +.close-btn { + font-size: 1.5em; + top: -40px; + position: absolute; + right: 0; + background: none; + border: none; + color: white; + font-weight: bold; +} diff --git a/getProducts.json b/getProducts.json new file mode 100644 index 0000000..f541d81 --- /dev/null +++ b/getProducts.json @@ -0,0 +1,12 @@ +[ + { + "id_product": 124, + "product_name": "Keyboard", + "price": 1600 + }, + { + "id_product": 457, + "product_name": "Gamepad", + "price": 3000 + } +] \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..4286a2b --- /dev/null +++ b/index.html @@ -0,0 +1,31 @@ + + + + + Интернет-магазин + + + + +
+
+ +
+ + +
+
+
+ + +
+
+ + + + + + + + + diff --git a/js/CartComp.js b/js/CartComp.js new file mode 100644 index 0000000..03b50b4 --- /dev/null +++ b/js/CartComp.js @@ -0,0 +1,82 @@ +Vue.component('cart', { + data(){ + return { + imgCart: 'https://placehold.it/50x100', + cartUrl: '/getBasket.json', + cartItems: [], + showCart: false, + } + }, + methods: { + addProduct(product){ + this.$parent.getJson(`${API}/addToBasket.json`) + .then(data => { + if(data.result === 1){ + let find = this.cartItems.find(el => el.id_product === product.id_product); + if(find){ + find.quantity++; + } else { + let prod = Object.assign({quantity: 1}, product); + this.cartItems.push(prod) + } + } else { + alert('Error'); + } + }) + }, + remove(item) { + this.$parent.getJson(`${API}/deleteFromBasket.json`) + .then(data => { + if(data.result === 1) { + if(item.quantity>1){ + item.quantity--; + } else { + this.cartItems.splice(this.cartItems.indexOf(item), 1) + } + } + }) + }, + }, + mounted(){ + this.$parent.getJson(`${API + this.cartUrl}`) + .then(data => { + for(let el of data.contents){ + this.cartItems.push(el); + } + }); + }, + template: ` +
+ +
+

Корзина пуста

+ + +
+
` +}); + +Vue.component('cart-item', { + props: ['cartItem', 'img'], + template: ` +
+
+ Some image +
+

{{cartItem.product_name}}

+

Количество: {{cartItem.quantity}}

+

{{cartItem.price}}₽ за шт.

+
+
+
+

{{cartItem.quantity*cartItem.price}}

+ +
+
+ ` +}); diff --git a/js/ErrorComp.js b/js/ErrorComp.js new file mode 100644 index 0000000..7fef048 --- /dev/null +++ b/js/ErrorComp.js @@ -0,0 +1,25 @@ +Vue.component('error', { + data(){ + return { + text: '' + } + }, + methods: { + setError(error){ + this.text = error + } + }, + computed: { + isVisible(){ + return this.text !== '' + } + }, + template: ` +
+

+ + {{ text }} +

+
+ ` +}); diff --git a/js/FilterComp.js b/js/FilterComp.js new file mode 100644 index 0000000..c9347ff --- /dev/null +++ b/js/FilterComp.js @@ -0,0 +1,15 @@ +Vue.component('filter-el', { + data(){ + return { + userSearch: '' + } + }, + template: ` +
+ + +
+ ` +}); diff --git a/js/ProducComp.js b/js/ProducComp.js new file mode 100644 index 0000000..50c71f1 --- /dev/null +++ b/js/ProducComp.js @@ -0,0 +1,56 @@ +Vue.component('products', { + data(){ + return { + catalogUrl: '/catalogData.json', + products: [], + filtered: [], + imgCatalog: 'https://placehold.it/200x150', + } + }, + methods: { + filter(value){ + let regexp = new RegExp(value, 'i'); + this.filtered = this.products.filter(el => regexp.test(el.product_name)); + } + }, + mounted(){ + this.$parent.getJson(`${API + this.catalogUrl}`) + .then(data => { + for(let el of data){ + this.products.push(el); + this.filtered.push(el); + } + }); + }, + template: ` +
+ +
+ ` +}); +Vue.component('product', { + props: ['product', 'img'], + data() { + return { + /** + * Создали ссылку на API нашей корзины. Т.к. все компоненты у нас регистрируются в корневом экземпляре Vue, + * то мы легко можем получить доступ к ним используя свойство $root. + * $parent можно использовать для доступа к родительскому экземпляру из дочернего. + */ + cartAPI: this.$root.$refs.cart, + }; + }, + + template: ` +
+ Some img +
+

{{product.product_name}}

+

{{product.price}}₽

+ + + +
+
+ ` +}); diff --git a/js/main.js b/js/main.js new file mode 100644 index 0000000..f851830 --- /dev/null +++ b/js/main.js @@ -0,0 +1,18 @@ +const API = 'https://raw.githubusercontent.com/GeekBrainsTutorial/online-store-api/master/responses'; + +const app = new Vue({ + el: '#app', + methods: { + getJson(url){ + return fetch(url) + .then(result => result.json()) + .catch(error => { + this.$refs.error.setError(error); + }) + }, + }, + mounted() { + console.log(this); + } +}); +