From 33da8ad1e65c81ba498491f65ba1fa01cf90219a Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Thu, 14 Nov 2019 21:58:56 +0300 Subject: [PATCH] Added component Information --- dist/public/js/bundle.js | 16 ++++++++++++++-- dist/views/index.pug | 2 +- src/js/components/information.component.js | 20 ++++++++++++++++++++ src/js/core/component.js | 8 ++++++++ src/js/index.js | 5 ++++- 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/js/components/information.component.js diff --git a/dist/public/js/bundle.js b/dist/public/js/bundle.js index e411ea6..3c5c05e 100644 --- a/dist/public/js/bundle.js +++ b/dist/public/js/bundle.js @@ -3565,6 +3565,18 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ }), +/***/ "./src/js/components/information.component.js": +/*!****************************************************!*\ + !*** ./src/js/components/information.component.js ***! + \****************************************************/ +/*! exports provided: InformationComponent */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"InformationComponent\", function() { return InformationComponent; });\n/* harmony import */ var _core_component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/component */ \"./src/js/core/component.js\");\nfunction _typeof(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\n\nvar InformationComponent =\n/*#__PURE__*/\nfunction (_Component) {\n _inherits(InformationComponent, _Component);\n\n function InformationComponent(id) {\n _classCallCheck(this, InformationComponent);\n\n return _possibleConstructorReturn(this, _getPrototypeOf(InformationComponent).call(this, id));\n }\n\n _createClass(InformationComponent, [{\n key: \"init\",\n value: function init() {\n if (localStorage.getItem('visited')) {\n this.hide();\n }\n\n var btn = this.$el.querySelector('#information-close');\n btn.addEventListener('click', buttonHandler.bind(this));\n }\n }]);\n\n return InformationComponent;\n}(_core_component__WEBPACK_IMPORTED_MODULE_0__[\"Component\"]);\n\nfunction buttonHandler() {\n localStorage.setItem('visited', JSON.stringify(true));\n this.hide();\n}\n\n//# sourceURL=webpack:///./src/js/components/information.component.js?"); + +/***/ }), + /***/ "./src/js/core/component.js": /*!**********************************!*\ !*** ./src/js/core/component.js ***! @@ -3573,7 +3585,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Component\", function() { return Component; });\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nvar Component =\n/*#__PURE__*/\nfunction () {\n function Component(id) {\n _classCallCheck(this, Component);\n\n this.$el = document.getElementById(id);\n this.init();\n }\n\n _createClass(Component, [{\n key: \"init\",\n value: function init() {}\n }]);\n\n return Component;\n}();\n\n//# sourceURL=webpack:///./src/js/core/component.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Component\", function() { return Component; });\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nvar Component =\n/*#__PURE__*/\nfunction () {\n function Component(id) {\n _classCallCheck(this, Component);\n\n this.$el = document.getElementById(id);\n this.init();\n }\n\n _createClass(Component, [{\n key: \"init\",\n value: function init() {}\n }, {\n key: \"hide\",\n value: function hide() {\n this.$el.classList.add('hide');\n }\n }, {\n key: \"show\",\n value: function show() {\n this.$el.classList.remove('hide');\n }\n }]);\n\n return Component;\n}();\n\n//# sourceURL=webpack:///./src/js/core/component.js?"); /***/ }), @@ -3585,7 +3597,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _components_header_component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./components/header.component */ \"./src/js/components/header.component.js\");\n\nnew _components_header_component__WEBPACK_IMPORTED_MODULE_0__[\"HeaderComponent\"]('header');\n\n//# sourceURL=webpack:///./src/js/index.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _components_header_component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./components/header.component */ \"./src/js/components/header.component.js\");\n/* harmony import */ var _components_information_component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./components/information.component */ \"./src/js/components/information.component.js\");\n\n\nnew _components_header_component__WEBPACK_IMPORTED_MODULE_0__[\"HeaderComponent\"]('header');\nvar information = new _components_information_component__WEBPACK_IMPORTED_MODULE_1__[\"InformationComponent\"]('information');\n\n//# sourceURL=webpack:///./src/js/index.js?"); /***/ }), diff --git a/dist/views/index.pug b/dist/views/index.pug index 6227a4a..5fc1ad2 100644 --- a/dist/views/index.pug +++ b/dist/views/index.pug @@ -50,7 +50,7 @@ main.main-section | suscipit! | Minima. .information-close - button.waves-effect.btn.red Закрыть + button#information-close.waves-effect.btn.red Закрыть // Information Block END // Category Block diff --git a/src/js/components/information.component.js b/src/js/components/information.component.js new file mode 100644 index 0000000..9293505 --- /dev/null +++ b/src/js/components/information.component.js @@ -0,0 +1,20 @@ +import { Component } from "../core/component"; + +export class InformationComponent extends Component { + constructor(id) { + super(id); + } + + init() { + if (localStorage.getItem('visited')) { + this.hide(); + } + const btn = this.$el.querySelector('#information-close'); + btn.addEventListener('click', buttonHandler.bind(this)); + } +} + +function buttonHandler() { + localStorage.setItem('visited', JSON.stringify(true)); + this.hide(); +} \ No newline at end of file diff --git a/src/js/core/component.js b/src/js/core/component.js index fd07cdf..d8a13b5 100644 --- a/src/js/core/component.js +++ b/src/js/core/component.js @@ -5,4 +5,12 @@ export class Component { } init() {} + + hide() { + this.$el.classList.add('hide'); + } + + show() { + this.$el.classList.remove('hide') + } } \ No newline at end of file diff --git a/src/js/index.js b/src/js/index.js index 399d1e3..c66ea5b 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -1,3 +1,6 @@ import { HeaderComponent } from "./components/header.component"; +import { InformationComponent } from "./components/information.component"; -new HeaderComponent('header'); \ No newline at end of file +new HeaderComponent('header'); + +const information = new InformationComponent('information'); \ No newline at end of file