diff --git a/img/autumn.jpg b/src/assets/autumn.jpg similarity index 100% rename from img/autumn.jpg rename to src/assets/autumn.jpg diff --git a/img/golden_autumn.jpg b/src/assets/golden_autumn.jpg similarity index 100% rename from img/golden_autumn.jpg rename to src/assets/golden_autumn.jpg diff --git a/classes/blocks.js b/src/classes/blocks.js similarity index 81% rename from classes/blocks.js rename to src/classes/blocks.js index cc7f34b..5ec7bb9 100644 --- a/classes/blocks.js +++ b/src/classes/blocks.js @@ -1,4 +1,4 @@ -import { col, row } from '../src/utils.js' +import { col, row } from '../utils.js' export class Block { constructor(value, options) { @@ -54,8 +54,18 @@ export class ImageBlock extends Block { toHTML() { const { alt, styles } = this.options return row( - col(``), + col(``), styles ) } } + +export class CustomBlock extends Block { + constructor(value, options) { + super(value, options) + } + + toHTML() { + return row(this.value) + } +} diff --git a/src/classes/sidebar.js b/src/classes/sidebar.js new file mode 100644 index 0000000..2612265 --- /dev/null +++ b/src/classes/sidebar.js @@ -0,0 +1,57 @@ +import { + TitleBlock, + TextBlock, + TextColumnsBlock, + ImageBlock, + CustomBlock +} from './blocks' + +export class SideBar { + constructor(selector, update) { + this.$el = document.querySelector(selector) + this.update = update + + this.init() + } + + init() { + this.$el.addEventListener('submit', this.addBlock.bind(this)) + this.$el.innerHTML = this.template + } + + get template() { + return [block('text'), block('title')].join('') + } + + addBlock(event) { + event.preventDefault() + + const type = event.target.name + const value = event.target.value.value + const styles = event.target.styles.value + + const Constructor = type === 'text' ? TextBlock : TitleBlock + + const newBlock = new Constructor(value, { styles }) + this.update(newBlock) + + event.target.value.value = '' + event.target.styles.value = '' + } +} + +function block(type) { + return ` +
+