Skip to content

Commit

Permalink
fix issue when save btn in hidden tools and call save method and
Browse files Browse the repository at this point in the history
  • Loading branch information
Yevhenii Korolikhin committed Apr 7, 2021
1 parent 786a5a3 commit ccf6b20
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 41 deletions.
67 changes: 35 additions & 32 deletions build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
</style>
</head>
<body>
<div id="holder">
<div id="app">
<!-- <div id="test-1"></div>
<div id="test-2"></div> -->
</div>
<div id="undefined"></div>
<div gg ></div>
<!--<div id="wrapper">
Expand Down Expand Up @@ -70,10 +72,10 @@
// }
// });

function saveTest() {
const u = window.p.imageSaver.asDataURL('image/png');
console.log('saved', u.length, u);
}
// function saveTest() {
// const u = window.p.imageSaver.asDataURL('image/png');
// console.log('saved', u.length, u);
// }

// window.p1 = Painterro({id: "test-1"}).show();

Expand All @@ -83,6 +85,7 @@
hideByEsc: true,
saveByEnter: true,
shadowScale: 1,
id: 'app',
// backplateImgUrl: 'https://images.pexels.com/photos/4386297/pexels-photo-4386297.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940',
// toolbarHeightPx: 50,
// buttonSizePx: 42,
Expand All @@ -92,7 +95,7 @@
onRedo: (e) => {console.log('onRedo e', e)},
//id: 'conatiner',
initText: 'Press <b>PrtScr</b>, <b>Ctrl+V</b> to paste screenshot.<br>Press <b>Ctrl+S</b> to save', // todo: different for os-es

hiddenTools: ['eraser', 'pixelize', 'rotate', 'settings', 'resize'],
//extraFonts: ['Open Sans'],
onBeforeClose: function (has, done) {
console.log('has unsaved: ', has);
Expand All @@ -111,7 +114,7 @@
console.log('saving', saver.getWidth(), saver.getHeight())
console.log('hasAlphaChannel', saver.hasAlphaChannel())
// console.log('Base64', saver.asDataURL())
done(true);
//done(true);
}
//toolbarPosition: 'top',
// fixMobilePageReloader: false,
Expand All @@ -127,31 +130,31 @@
// ctx.stroke();


document.onpaste = (event) => {
const { items } = event.clipboardData || event.originalEvent.clipboardData;
Array.from(items).forEach((item) => {
if (item.kind === 'file') {
if (!window.painterroOpenedInstance) {
// if painterro already opened - it will handle onpaste
const blob = item.getAsFile();
const reader = new FileReader();
reader.onload = (readerEvent) => {
window.painterroOpenedInstance = Painterro({
initText: 'Press <b>PrtScr</b>, <b>Ctrl+V</b> to paste screenshot.<br>Press <b>Ctrl+S</b> to save', // todo: different for os-es
onHide: () => {
window.painterroOpenedInstance = undefined;
},
saveHandler: (image, done) => {
console.log('Save it here', image.asDataURL()); // you could provide your save handler
done(true);
},
}).show(readerEvent.target.result, item.type);
};
reader.readAsDataURL(blob);
}
}
});
};
// document.onpaste = (event) => {
// const { items } = event.clipboardData || event.originalEvent.clipboardData;
// Array.from(items).forEach((item) => {
// if (item.kind === 'file') {
// if (!window.painterroOpenedInstance) {
// // if painterro already opened - it will handle onpaste
// const blob = item.getAsFile();
// const reader = new FileReader();
// reader.onload = (readerEvent) => {
// window.painterroOpenedInstance = Painterro({
// initText: 'Press <b>PrtScr</b>, <b>Ctrl+V</b> to paste screenshot.<br>Press <b>Ctrl+S</b> to save', // todo: different for os-es
// onHide: () => {
// window.painterroOpenedInstance = undefined;
// },
// saveHandler: (image, done) => {
// console.log('Save it here', image.asDataURL()); // you could provide your save handler
// done(true);
// },
// }).show(readerEvent.target.result, item.type);
// };
// reader.readAsDataURL(blob);
// }
// }
// });
// };


</script>
Expand Down
16 changes: 7 additions & 9 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,6 @@ class PainterroProc {
if (this.initText) this.wrapper.click();
this.save();
this.closeActiveTool();
this.close();
this.hide();
},
}, {
name: 'open',
Expand Down Expand Up @@ -551,9 +549,8 @@ class PainterroProc {
// this.iframe = this.baseEl.getElementsByTagName('iframe')[0];
// this.doc = this.iframe.contentDocument || this.iframe.contentWindow.document;
// this.doc.body.innerHTML = html;

this.saveBtn = this.doc.getElementById(this.toolByName.save.buttonId);
if (this.saveBtn) {
this.saveBtn = this.baseEl.querySelector(`#${this.toolByName.save.buttonId}`);
if (this.toolByName.save.buttonId && this.saveBtn) {
this.saveBtn.setAttribute('disabled', 'true');
}
this.body = this.doc.body;
Expand Down Expand Up @@ -744,12 +741,13 @@ class PainterroProc {
return this;
}
this.saving = true;
const btn = this.doc.getElementById(this.toolByName.save.buttonId);
const icon = this.doc.querySelector(`#${this.toolByName.save.buttonId} > i`);
if (btn) {
const btn = this.baseEl.querySelector(`#${this.toolByName.save.buttonId}`);
const icon = this.baseEl.querySelector(`#${this.toolByName.save.buttonId} > i`);
if (this.toolByName.save.buttonId && btn) {
btn.setAttribute('disabled', 'true');
this.hasUnsaved = false;
}
this.hasUnsaved = false;

if (icon) {
icon.className = 'ptro-icon ptro-icon-loading ptro-spinning';
}
Expand Down

0 comments on commit ccf6b20

Please sign in to comment.