This repository has been archived on 2019-03-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
paper-pi/public/js/printer.js
kplaczek 46d32b2cec Merge branch 'issue-1'
# Conflicts:
#	public/js/printer.js
2018-04-04 22:10:28 +02:00

72 lines
1.9 KiB
JavaScript
Executable File

var content, preview, selfPrinter;
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');
selfPrinter = this;
this.reset.addEventListener('click', this.clear);
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 () {
selfPrinter.selectIcon(this.title);
});
})
};
/**
* 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.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 = '';
selfPrinter.selectIcon('empty');
};
this.confirmDelete = function (e) {
if (!confirm('Usunąć wpis?')) {
e.preventDefault();
return false;
}
};
};