Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

added move left/right images #120 #125

Merged
merged 2 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ body.dark {
--field-borders: #222;
--primary-button-bg: #eee;
--primary-button-color: #111;
--delete-button-borders: #E76F7B;
--font-color-delete: #E76F7B;
--delete-button-borders: #e76f7b;
--font-color-delete: #e76f7b;
}
@font-face {
font-family: 'Hindi_Font';
Expand Down Expand Up @@ -441,9 +441,9 @@ input[type='file']::before {
}
}

/*To generate margin between download as pdf and delete button in small screens*/
/*To generate margin between download as pdf and delete button in small screens*/
@media (max-width: 430px) {
.delete-button {
margin-top: 10px;
}
}
}
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
gtag('config', 'UA-125454191-4');
</script>

<!-- Mobile Specific Metas -->
<!-- Mobile Specific Metas -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<!-- Basic -->
Expand Down Expand Up @@ -65,7 +65,7 @@

<title>Text to Handwriting</title>

<!-- Favicons -->
<!-- Favicons -->
<link
rel="apple-touch-icon"
sizes="180x180"
Expand All @@ -84,10 +84,10 @@
href="images/favicon-16x16.png"
/>

<!-- PWA Migration -->
<!-- PWA Migration -->
<link rel="manifest" href="./manifest.webmanifest" />

<!-- Load Fonts -->
<!-- Load Fonts -->
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Homemade+Apple|Roboto|Caveat|Liu+Jian+Mao+Cao&display=swap"
Expand Down
48 changes: 45 additions & 3 deletions js/generate-images.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { createPDF } from './utils/helpers.mjs';

const pageEl = document.querySelector('.page-a');
const outputImages = [];
let outputImages = [];

/**
* To generate image, we add styles to DIV and converts that HTML Element into Image.
Expand Down Expand Up @@ -102,8 +102,30 @@ export const deleteAll = () => {
outputImages.splice(0, outputImages.length);
renderOutput(outputImages);
document.querySelector('#output-header').textContent =
'Output' +
(outputImages.length ? ' ( ' + outputImages.length + ' )' : '');
'Output' + (outputImages.length ? ' ( ' + outputImages.length + ' )' : '');
};

const arrayMove = (arr, oldIndex, newIndex) => {
if (newIndex >= arr.length) {
let k = newIndex - arr.length + 1;
while (k--) {
arr.push(undefined);
}
}
arr.splice(newIndex, 0, arr.splice(oldIndex, 1)[0]);
return arr; // for testing
};

export const moveLeft = (index) => {
if (index === 0) return outputImages;
StTronn marked this conversation as resolved.
Show resolved Hide resolved
outputImages = arrayMove(outputImages, index, index - 1);
renderOutput(outputImages);
};

export const moveRight = (index) => {
if (index + 1 === outputImages.length) return outputImages;
outputImages = arrayMove(outputImages, index, index + 1);
renderOutput(outputImages);
};

/**
Expand Down Expand Up @@ -131,6 +153,26 @@ function setRemoveImageListeners() {
setRemoveImageListeners();
});
});

document.querySelectorAll('.move-left').forEach((leftButton) => {
leftButton.addEventListener('click', (e) => {
moveLeft(Number(e.target.dataset.index));
// Displaying no. of images on deletion
renderOutput(outputImages);
// When output changes, we have to set remove listeners again
setRemoveImageListeners();
});
});

document.querySelectorAll('.move-right').forEach((rightButton) => {
rightButton.addEventListener('click', (e) => {
moveRight(Number(e.target.dataset.index));
// Displaying no. of images on deletion
renderOutput(outputImages);
// When output changes, we have to set remove listeners again
setRemoveImageListeners();
});
});
}

/** Modifies image data to add contrast */
Expand Down
15 changes: 15 additions & 0 deletions js/utils/generate-utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ function renderOutput(outputImages) {
download
href="${outputImageCanvas.toDataURL('image/jpeg')}
">Download Image</a>
<br/>
<br/>
<button
class="button move-left"
data-index="${index}"
>
Move Left
</button>
<button
class="button move-right"
data-index="${index}"
>
Move Right
</button>
</div>
</div>
`
Expand Down
2 changes: 1 addition & 1 deletion js/utils/helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function formatText(event) {
}

function addPaperFromFile(file) {
var tmppath = URL.createObjectURL(file);
const tmppath = URL.createObjectURL(file);
pageEl.style.backgroundImage = `url(${tmppath})`;
}

Expand Down
Loading