Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add paste images #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion tags/images-slider.tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
var tag = this;
tag.readImageFiles = readImageFiles;
tag.readImageFile = readImageFile;
tag.pasteImage = pasteImage;
tag.slideleft = slideleft;
tag.slideright = slideright;
tag.deleteThumbnail = deleteThumbnail;
Expand Down Expand Up @@ -82,13 +83,23 @@
e.stopPropagation();
}
})

document.addEventListener('paste', e => {

clipdata = e.clipboardData || window.clipboardData;
pasteImage(clipdata);
e.preventDefault();
e.stopPropagation();
})

});

this.on('updated', () => {
//$("#thumbnail_0").click(); as this triggers before images are uploaded it cuase issue. Load it with an interval
})

function readImageFiles(e) {
function readImageFiles(e) {
console.log(this);
var input = e.srcElement || e.target;
if (input.files && input.files[0]) {
for (i = 0; i < input.files.length; i++) {
Expand All @@ -105,6 +116,7 @@
if (f.type.startsWith("image")) {
var reader = new FileReader();
reader.onload = e => {
console.log(e);
var imgData = {
name: f.name,
src: e.target.result
Expand Down Expand Up @@ -136,6 +148,27 @@
img.src = imgFileSrc;
}

function pasteImage(clipboardData) {
console.log("pasteImage:" + clipboardData);
console.log(this);
if (!clipboardData.items) {
return false;
}

[].forEach.call(clipboardData.items, item => {
if (item.type.match(/^image\//)) {
try {
let pastePath = item.getAsFile();
console.log(pastePath);
tag.readImageFile(pastePath);
}
catch (error) {
console.log('pasteError', error);
}
}
});
}

this.sliding = false;
this.sliderMove = "80px";
function slideleft(e) {
Expand Down