Compare commits
No commits in common. "2cc5437f21c1a4ce30e6231f5bfccacb30fe6409" and "4bfe32d0202f0530d8dc9f6b447b7c6aa73416d6" have entirely different histories.
2cc5437f21
...
4bfe32d020
@ -2,7 +2,6 @@ export class FileSelector {
|
|||||||
dropZones = [];
|
dropZones = [];
|
||||||
selectedFile = null;
|
selectedFile = null;
|
||||||
onFileSelected = null;
|
onFileSelected = null;
|
||||||
onFileRemoved = null;
|
|
||||||
|
|
||||||
constructor(mimeType) {
|
constructor(mimeType) {
|
||||||
this.mimeType = mimeType;
|
this.mimeType = mimeType;
|
||||||
@ -25,12 +24,6 @@ export class FileSelector {
|
|||||||
if (this.onFileSelected) this.onFileSelected(file);
|
if (this.onFileSelected) this.onFileSelected(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeFile() {
|
|
||||||
this.selectedFile = null;
|
|
||||||
|
|
||||||
if (this.onFileRemoved) this.onFileRemoved();
|
|
||||||
}
|
|
||||||
|
|
||||||
addInput(elem) {
|
addInput(elem) {
|
||||||
elem.oninput = () => {
|
elem.oninput = () => {
|
||||||
setTimeout(() => this.selectFile(elem.files[0]), 200);
|
setTimeout(() => this.selectFile(elem.files[0]), 200);
|
||||||
|
|||||||
@ -1,46 +0,0 @@
|
|||||||
export class UiManager {
|
|
||||||
TRANSITION_TIME = 300;
|
|
||||||
|
|
||||||
showSection(section) {
|
|
||||||
for (const section of document.getElementsByTagName("section")) {
|
|
||||||
this.hideElements(section);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.showElements(`#${section}-section`);
|
|
||||||
|
|
||||||
return new Promise(resolve => setTimeout(resolve, this.TRANSITION_TIME * 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
hideElements() {
|
|
||||||
for (const input of arguments) {
|
|
||||||
const elem = input instanceof Element ? input : document.querySelector(input);
|
|
||||||
|
|
||||||
if (getComputedStyle(elem).display === "none")
|
|
||||||
continue;
|
|
||||||
|
|
||||||
elem.style.opacity = "0";
|
|
||||||
elem.dataset.oldDisplay = getComputedStyle(elem).display;
|
|
||||||
|
|
||||||
setTimeout(() => elem.style.display = "none", this.TRANSITION_TIME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
showElements() {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
setTimeout(() => {
|
|
||||||
for (const input of arguments) {
|
|
||||||
const elem = input instanceof Element ? input : document.querySelector(input);
|
|
||||||
|
|
||||||
elem.style.opacity = "0";
|
|
||||||
|
|
||||||
elem.style.display = elem.dataset.oldDisplay || "block";
|
|
||||||
elem.dataset.oldDisplay = null;
|
|
||||||
|
|
||||||
setTimeout(() => elem.style.opacity = "1", 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve();
|
|
||||||
}, this.TRANSITION_TIME);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +1,8 @@
|
|||||||
import { UiManager } from "./UiManager.js";
|
|
||||||
import { Notifier } from "./Notifier.js";
|
import { Notifier } from "./Notifier.js";
|
||||||
import { ProgressBar } from "./ProgressBar.js";
|
import { ProgressBar } from "./ProgressBar.js";
|
||||||
import { VideoCompressor } from "./VideoCompressor.js";
|
import { VideoCompressor } from "./VideoCompressor.js";
|
||||||
import { FileSelector } from "./FileSelector.js";
|
import { FileSelector } from "./FileSelector.js";
|
||||||
|
|
||||||
const ui = new UiManager();
|
|
||||||
const notifier = new Notifier();
|
const notifier = new Notifier();
|
||||||
const progressBar = new ProgressBar();
|
const progressBar = new ProgressBar();
|
||||||
const videoCompressor = new VideoCompressor(progressBar);
|
const videoCompressor = new VideoCompressor(progressBar);
|
||||||
@ -17,29 +15,22 @@ fileSelector.onFileSelected = file => {
|
|||||||
document.getElementById("uploaded-video").src = URL.createObjectURL(file);
|
document.getElementById("uploaded-video").src = URL.createObjectURL(file);
|
||||||
document.getElementById("uploaded-video").load();
|
document.getElementById("uploaded-video").load();
|
||||||
|
|
||||||
ui.hideElements("#file-drop-area", "#file-input-spacing");
|
hideElements("#file-drop-area", "#file-input-spacing");
|
||||||
ui.showElements("#uploaded-video", "#remove-file");
|
showElements("#uploaded-video", "#change-file");
|
||||||
};
|
};
|
||||||
|
|
||||||
fileSelector.onFileRemoved = async () => {
|
|
||||||
ui.hideElements("#uploaded-video", "#remove-file");
|
|
||||||
await ui.showElements("#file-drop-area", "#file-input-spacing");
|
|
||||||
|
|
||||||
document.getElementById("uploaded-video").src = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById("remove-file").onclick = () => fileSelector.removeFile();
|
|
||||||
|
|
||||||
async function compress(filesize, filesizeUnit) {
|
async function compress(filesize, filesizeUnit) {
|
||||||
document.getElementById("uploaded-video").pause();
|
document.getElementById("uploaded-video").pause();
|
||||||
|
|
||||||
|
const sectionChangePromise = showSection("loading");
|
||||||
|
|
||||||
if (!fileSelector.selectedFile) {
|
if (!fileSelector.selectedFile) {
|
||||||
|
await sectionChangePromise; // Avoid changing sections at the same time
|
||||||
alert("Please select a file");
|
alert("Please select a file");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sectionChangePromise = ui.showSection("loading");
|
|
||||||
|
|
||||||
const videoLength = document.getElementById("uploaded-video").duration;
|
const videoLength = document.getElementById("uploaded-video").duration;
|
||||||
|
|
||||||
let targetFilesize;
|
let targetFilesize;
|
||||||
@ -55,7 +46,7 @@ async function compress(filesize, filesizeUnit) {
|
|||||||
await sectionChangePromise; // Avoid changing sections at the same time
|
await sectionChangePromise; // Avoid changing sections at the same time
|
||||||
alert(e.message);
|
alert(e.message);
|
||||||
|
|
||||||
ui.showSection("file-picker");
|
showSection("file-picker");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -90,7 +81,7 @@ async function compress(filesize, filesizeUnit) {
|
|||||||
document.getElementById("share").style.display = "none";
|
document.getElementById("share").style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.showSection("result");
|
showSection("result");
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("compress").onclick = async () => {
|
document.getElementById("compress").onclick = async () => {
|
||||||
@ -103,10 +94,13 @@ document.getElementById("compress").onclick = async () => {
|
|||||||
document.getElementById("cancel").onclick = () => {
|
document.getElementById("cancel").onclick = () => {
|
||||||
videoCompressor.stop();
|
videoCompressor.stop();
|
||||||
|
|
||||||
ui.showSection("file-picker");
|
showSection("file-picker");
|
||||||
};
|
};
|
||||||
|
|
||||||
document.getElementById("back").onclick = () => ui.showSection("file-picker");
|
|
||||||
|
document.getElementById("change-file").onclick = () => document.getElementById("file-input").click();
|
||||||
|
|
||||||
|
document.getElementById("back").onclick = () => showSection("file-picker");
|
||||||
|
|
||||||
window.onbeforeunload = event => {
|
window.onbeforeunload = event => {
|
||||||
if (videoCompressor.inProgress) event.preventDefault();
|
if (videoCompressor.inProgress) event.preventDefault();
|
||||||
|
|||||||
44
public/assets/scripts/ui.js
Normal file
44
public/assets/scripts/ui.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
const TRANSITION_TIME = 300;
|
||||||
|
|
||||||
|
function showSection(section) {
|
||||||
|
for (const section of document.getElementsByTagName("section")) {
|
||||||
|
hideElements(section);
|
||||||
|
}
|
||||||
|
|
||||||
|
showElements(`#${section}-section`);
|
||||||
|
|
||||||
|
return new Promise(resolve => setTimeout(resolve, TRANSITION_TIME * 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideElements() {
|
||||||
|
for (const input of arguments) {
|
||||||
|
const elem = input instanceof Element ? input : document.querySelector(input);
|
||||||
|
|
||||||
|
if (getComputedStyle(elem).display === "none")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
elem.style.opacity = "0";
|
||||||
|
elem.dataset.oldDisplay = getComputedStyle(elem).display;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
elem.style.display = "none";
|
||||||
|
}, TRANSITION_TIME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showElements() {
|
||||||
|
setTimeout(() => {
|
||||||
|
for (const input of arguments) {
|
||||||
|
const elem = input instanceof Element ? input : document.querySelector(input);
|
||||||
|
|
||||||
|
elem.style.opacity = "0";
|
||||||
|
|
||||||
|
elem.style.display = elem.dataset.oldDisplay || "block";
|
||||||
|
elem.dataset.oldDisplay = null;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
elem.style.opacity = "1";
|
||||||
|
}, 10);
|
||||||
|
}
|
||||||
|
}, TRANSITION_TIME);
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
#file-input, #remove-file {
|
#file-input, #change-file {
|
||||||
display: none;
|
display: none;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,8 +6,8 @@
|
|||||||
<meta name="description" content="Easily compress video files to a specific file size for uploading to various communication platforms that restrict upload size">
|
<meta name="description" content="Easily compress video files to a specific file size for uploading to various communication platforms that restrict upload size">
|
||||||
<title>Compact.Video - Compress videos online</title>
|
<title>Compact.Video - Compress videos online</title>
|
||||||
<script defer src="/assets/scripts/ffmpeg/package/dist/umd/ffmpeg.js"></script>
|
<script defer src="/assets/scripts/ffmpeg/package/dist/umd/ffmpeg.js"></script>
|
||||||
|
<script defer src="/assets/scripts/ui.js"></script>
|
||||||
<script defer type="module" src="/assets/scripts/main.js"></script>
|
<script defer type="module" src="/assets/scripts/main.js"></script>
|
||||||
<link rel="canonical" href="https://compact.video/">
|
|
||||||
<link rel="shortcut icon" href="/assets/images/icon.png">
|
<link rel="shortcut icon" href="/assets/images/icon.png">
|
||||||
<link rel="apple-touch-icon" href="/assets/images/icon.png">
|
<link rel="apple-touch-icon" href="/assets/images/icon.png">
|
||||||
<link rel="stylesheet" href="/assets/styles/main.css">
|
<link rel="stylesheet" href="/assets/styles/main.css">
|
||||||
@ -30,7 +30,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<video id="uploaded-video" controls autoplay></video>
|
<video id="uploaded-video" controls autoplay></video>
|
||||||
<button id="remove-file" class="simple">Remove video</button>
|
<button id="change-file" class="simple">Change video</button>
|
||||||
|
|
||||||
<input id="filesize" type="number" value="10" size="3" placeholder="#" style="margin-top: 1rem"><!--
|
<input id="filesize" type="number" value="10" size="3" placeholder="#" style="margin-top: 1rem"><!--
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user