first commit
This commit is contained in:
61
public/js/printer.js
Executable file
61
public/js/printer.js
Executable file
@@ -0,0 +1,61 @@
|
||||
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);
|
||||
|
||||
if(this.delete != null){
|
||||
this.delete.addEventListener('click', this.confirmDelete);
|
||||
}
|
||||
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.divToTextbox = function(){
|
||||
content.value = preview.innerHTML;
|
||||
};
|
||||
|
||||
this.clear = function () {
|
||||
selfPrinter.content.innerHTML = '';
|
||||
};
|
||||
|
||||
this.confirmDelete = function (e) {
|
||||
if(!confirm('Usunąć wpis?')){
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user