mirror of
https://github.com/sergeyyarkov/digital-store.git
synced 2026-10-11 10:19:15 +03:00
Component Notification
This commit is contained in:
parent
c0b5fbec56
commit
17b39b4a90
3
dist/public/css/media.css
vendored
3
dist/public/css/media.css
vendored
@ -97,6 +97,9 @@
|
|||||||
nav .nav-wrapper .brand-logo {
|
nav .nav-wrapper .brand-logo {
|
||||||
font-size: 17px;
|
font-size: 17px;
|
||||||
}
|
}
|
||||||
|
#notification {
|
||||||
|
right: 10px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 380px) {
|
@media (max-width: 380px) {
|
||||||
|
|||||||
7
dist/public/css/style.css
vendored
7
dist/public/css/style.css
vendored
@ -45,6 +45,13 @@ hr {
|
|||||||
|
|
||||||
/* Custom Styles */
|
/* Custom Styles */
|
||||||
|
|
||||||
|
#notification {
|
||||||
|
width: 300px;
|
||||||
|
position: fixed;
|
||||||
|
right: 30px;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
.block-title {
|
.block-title {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
16
dist/public/js/bundle.js
vendored
16
dist/public/js/bundle.js
vendored
File diff suppressed because one or more lines are too long
1
dist/views/index.pug
vendored
1
dist/views/index.pug
vendored
@ -6,6 +6,7 @@ include ./assets/templates/header.pug
|
|||||||
main.main-section
|
main.main-section
|
||||||
include ./assets/templates/modals/cart.pug
|
include ./assets/templates/modals/cart.pug
|
||||||
include ./assets/templates/modals/pay.pug
|
include ./assets/templates/modals/pay.pug
|
||||||
|
#notification
|
||||||
.container
|
.container
|
||||||
.row
|
.row
|
||||||
// Information Block
|
// Information Block
|
||||||
|
|||||||
@ -4,9 +4,10 @@ import { insertCount } from "../other/counter";
|
|||||||
import { renderItems } from "../templates/items.template";
|
import { renderItems } from "../templates/items.template";
|
||||||
|
|
||||||
export class ItemsComponent extends Component {
|
export class ItemsComponent extends Component {
|
||||||
constructor(id, {loader}) {
|
constructor(id, {loader}, {notification}) {
|
||||||
super(id);
|
super(id);
|
||||||
this.loader = loader;
|
this.loader = loader;
|
||||||
|
this.notification = notification;
|
||||||
this.$el ? this.roster = this.$el.querySelector('#roster') : false;
|
this.$el ? this.roster = this.$el.querySelector('#roster') : false;
|
||||||
if (localStorage.getItem('cart')) {
|
if (localStorage.getItem('cart')) {
|
||||||
this.cart = JSON.parse(localStorage.getItem('cart'));
|
this.cart = JSON.parse(localStorage.getItem('cart'));
|
||||||
@ -99,19 +100,21 @@ function renderObj(obj, context, target) {
|
|||||||
localStorage.setItem('cart', JSON.stringify(context.cart));
|
localStorage.setItem('cart', JSON.stringify(context.cart));
|
||||||
target.classList.add('orange');
|
target.classList.add('orange');
|
||||||
target.querySelector('i').innerHTML = 'close';
|
target.querySelector('i').innerHTML = 'close';
|
||||||
insertCount('counter', context.cart)
|
insertCount('counter', context.cart);
|
||||||
|
context.notification.notificate('Товар был успешно добавлен в корзину.', '#26A69A');
|
||||||
} else {
|
} else {
|
||||||
context.cart.splice(index, 1);
|
context.cart.splice(index, 1);
|
||||||
localStorage.setItem('cart', JSON.stringify(context.cart));
|
localStorage.setItem('cart', JSON.stringify(context.cart));
|
||||||
target.classList.remove('orange');
|
target.classList.remove('orange');
|
||||||
target.querySelector('i').innerHTML = 'shopping_cart';
|
target.querySelector('i').innerHTML = 'shopping_cart';
|
||||||
insertCount('counter', context.cart)
|
insertCount('counter', context.cart);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
context.cart.push(obj);
|
context.cart.push(obj);
|
||||||
localStorage.setItem('cart', JSON.stringify(context.cart));
|
localStorage.setItem('cart', JSON.stringify(context.cart));
|
||||||
target.classList.add('orange');
|
target.classList.add('orange');
|
||||||
target.querySelector('i').innerHTML = 'close';
|
target.querySelector('i').innerHTML = 'close';
|
||||||
insertCount('counter', context.cart)
|
insertCount('counter', context.cart);
|
||||||
|
context.notification.notificate('Товар был успешно добавлен в корзину.', '#26A69A');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
50
src/components/notification.component.js
Normal file
50
src/components/notification.component.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import { Component } from "../core/component";
|
||||||
|
|
||||||
|
export class NotificationComponent extends Component {
|
||||||
|
constructor(id) {
|
||||||
|
super(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
notificate(text, color) {
|
||||||
|
const card = document.createElement('div');
|
||||||
|
card.classList.add('card-panel');
|
||||||
|
card.style.backgroundColor = color;
|
||||||
|
card.innerHTML = `<span class="white-text">${text}</span>`;
|
||||||
|
this.$el.innerHTML += card.outerHTML;
|
||||||
|
this.removeNotificate();
|
||||||
|
}
|
||||||
|
|
||||||
|
removeNotificate() {
|
||||||
|
// Полифилл для IE ^9
|
||||||
|
(function() {
|
||||||
|
var arr = [window.Element, window.CharacterData, window.DocumentType];
|
||||||
|
var args = [];
|
||||||
|
|
||||||
|
arr.forEach(function (item) {
|
||||||
|
if (item) {
|
||||||
|
args.push(item.prototype);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
(function (arr) {
|
||||||
|
arr.forEach(function (item) {
|
||||||
|
if (item.hasOwnProperty('remove')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Object.defineProperty(item, 'remove', {
|
||||||
|
configurable: true,
|
||||||
|
enumerable: true,
|
||||||
|
writable: true,
|
||||||
|
value: function remove() {
|
||||||
|
this.parentNode.removeChild(this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})(args);
|
||||||
|
})();
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this.$el.querySelector('.card-panel').remove();
|
||||||
|
}, 2000)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,12 +7,14 @@ import { BreadcrumbComponent } from "./components/breadcrumb.component.js";
|
|||||||
import { FilterComponent } from "./components/filter.component.js";
|
import { FilterComponent } from "./components/filter.component.js";
|
||||||
import { CartModal } from "./modals/cart.modal.js";
|
import { CartModal } from "./modals/cart.modal.js";
|
||||||
import { PayModal } from "./modals/pay.modal.js";
|
import { PayModal } from "./modals/pay.modal.js";
|
||||||
|
import { NotificationComponent } from "./components/notification.component.js";
|
||||||
|
|
||||||
|
|
||||||
const header = new HeaderComponent('header');
|
const header = new HeaderComponent('header');
|
||||||
const loader = new LoaderComponent('loader');
|
const loader = new LoaderComponent('loader');
|
||||||
const information = new InformationComponent('information');
|
const information = new InformationComponent('information');
|
||||||
const items = new ItemsComponent('items', {loader});
|
const notification = new NotificationComponent('notification');
|
||||||
|
const items = new ItemsComponent('items', {loader}, {notification});
|
||||||
const filter = new FilterComponent('filter', {items});
|
const filter = new FilterComponent('filter', {items});
|
||||||
const category = new CategoryComponent('category', {items}, {filter});
|
const category = new CategoryComponent('category', {items}, {filter});
|
||||||
const breadcumb = new BreadcrumbComponent('breadcrumb');
|
const breadcumb = new BreadcrumbComponent('breadcrumb');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user