diff --git a/public/js/printer.js b/public/js/printer.js index 1ff62c1..80de9c7 100755 --- a/public/js/printer.js +++ b/public/js/printer.js @@ -1,4 +1,4 @@ -var content, preview; +var content, preview, selfPrinter; var Printer = function () { @@ -8,14 +8,11 @@ var Printer = function () { 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(); @@ -26,34 +23,24 @@ var Printer = function () { 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'); + selfPrinter.selectIcon(this.title); }); }) - // 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);}); }; + /** + * resetuje wybór ikony + */ + this.selectIcon = function(iconTitle){ + document.querySelectorAll('.icon').forEach(function (e, i) { + e.classList.remove('selected'); + }); + document.querySelector('#icon').value = iconTitle; + var selector = '.icon[title="' + iconTitle + '"]'; + document.querySelector(selector).classList.add('selected'); + }; - // this.printPreview = function(){ - // preview.innerText = content.value; - // }; this.restoreContentHeight = function () { if(!!localStorage.getItem('contentHeight')){ document.querySelector('.js-content').style.height = localStorage.getItem('contentHeight') @@ -70,6 +57,7 @@ var Printer = function () { this.clear = function () { selfPrinter.content.innerHTML = ''; + selfPrinter.selectIcon('empty'); }; this.confirmDelete = function (e) {