var content, preview; var Printer = function () { this.init = function () { this.reset = document.querySelector('.js-reset'); this.delete = document.querySelector('.js-delete'); content = this.content = document.querySelector('.js-content'); // preview = this.preview = document.querySelector('#editor'); selfPrinter = this; this.reset.addEventListener('click', this.clear); // this.content.addEventListener('keypress', this.printPreview); // this.preview.addEventListener('keyup', this.divToTextbox); content.addEventListener("mouseup", this.contentResize); this.restoreContentHeight(); if (this.delete != null) { this.delete.addEventListener('click', this.confirmDelete); } document.querySelectorAll('.icon').forEach(function (e) { e.addEventListener('click', function () { document.querySelectorAll('.icon').forEach(function (e, i) { e.classList.remove('selected'); }); document.querySelector('#icon').value = this.title; this.classList.add('selected'); }); }) // this.commandCenter = document.querySelector('.icon.command.center'); // this.commandLeft = document.querySelector('.icon.command.left'); // this.commandRight = document.querySelector('.icon.command.right'); // this.commandBold = document.querySelector('.icon.command.bold'); // this.commandItalic = document.querySelector('.icon.command.italic'); // this.commandUnderline = document.querySelector('.icon.command.underline'); // this.commandCenter.addEventListener('click', function(){document.execCommand('justifyCenter', false);}); // this.commandLeft.addEventListener('click', function(){document.execCommand('justifyLeft', false);}); // this.commandRight.addEventListener('click', function(){document.execCommand('justifyRight', false);}); // this.commandBold.addEventListener('click', function(){document.execCommand('bold', false);}); // this.commandItalic.addEventListener('click', function(){document.execCommand('italic', false);}); // this.commandUnderline.addEventListener('click', function(){document.execCommand('underline', false);}); }; // this.printPreview = function(){ // preview.innerText = content.value; // }; this.restoreContentHeight = function () { if(!!localStorage.getItem('contentHeight')){ document.querySelector('.js-content').style.height = localStorage.getItem('contentHeight') } }; this.contentResize = function () { localStorage.setItem('contentHeight', this.style.height); }; this.divToTextbox = function () { content.value = preview.innerHTML; }; this.clear = function () { selfPrinter.content.innerHTML = ''; }; this.confirmDelete = function (e) { if (!confirm('Usunąć wpis?')) { e.preventDefault(); return false; } }; };