W10 fixes
This commit is contained in:
parent
c045c7b30d
commit
1d087064dd
4 changed files with 0 additions and 250 deletions
118
w10/app.js
118
w10/app.js
|
|
@ -1,118 +0,0 @@
|
||||||
/** @type {HTMLElement} */
|
|
||||||
let beforeImage = null;
|
|
||||||
|
|
||||||
/** @type {HTMLImageElement} */
|
|
||||||
let imageHolder = null;
|
|
||||||
|
|
||||||
/** @type {HTMLInputElement} */
|
|
||||||
let inputText = null;
|
|
||||||
|
|
||||||
/** @type {HTMLInputElement} */
|
|
||||||
let inputFontSize = null;
|
|
||||||
|
|
||||||
/** @type {HTMLInputElement} */
|
|
||||||
let inputColor = null;
|
|
||||||
|
|
||||||
/** @type {HTMLInputElement} */
|
|
||||||
let inputUnsplashID = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {Object} data
|
|
||||||
* @returns {String}
|
|
||||||
*/
|
|
||||||
const encodeQueryData = function (data) {
|
|
||||||
const ret = [];
|
|
||||||
for (let d in data) {
|
|
||||||
ret.push(encodeURIComponent(d) + "=" + encodeURIComponent(data[d]));
|
|
||||||
}
|
|
||||||
return ret.join("&");
|
|
||||||
}
|
|
||||||
|
|
||||||
const setCurrentWizardPage = function(callee) {
|
|
||||||
const current = parseInt(callee.getAttribute("wizardCurrent"));
|
|
||||||
const next = parseInt(callee.getAttribute("wizardNext"));
|
|
||||||
|
|
||||||
console.log(!inputText.validity.valid)
|
|
||||||
if (current === 1 && !inputText.validity.valid) {
|
|
||||||
inputText.reportValidity();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (current === 2 && (!inputFontSize.validity.valid || !inputColor.validity.valid)) {
|
|
||||||
if (!inputFontSize.validity.valid) {
|
|
||||||
inputFontSize.reportValidity();
|
|
||||||
}
|
|
||||||
if (!inputColor.validity.valid) {
|
|
||||||
inputColor.reportValidity();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (current === 3 && !inputUnsplashID.validity.valid) {
|
|
||||||
inputUnsplashID.reportValidity();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
document.querySelectorAll("[wizardPage]").forEach(page => {
|
|
||||||
const pageIdx = parseInt(page.getAttribute("wizardPage"));
|
|
||||||
page.hidden = pageIdx !== next;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (next === 4) {
|
|
||||||
loadImage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {String} text
|
|
||||||
* @param {Number} fontSize
|
|
||||||
* @param {Number} fontWeight
|
|
||||||
* @param {String} color
|
|
||||||
* @param {String?} backgroundImage
|
|
||||||
* @returns {String}
|
|
||||||
*/
|
|
||||||
const endpointTpl = (text, fontSize, color="#FFFFFF", backgroundImageId="random") => "https://img.bruzu.com/?" + encodeQueryData({
|
|
||||||
backgroundImage: `https://source.unsplash.com/${backgroundImageId}/500x500?hash=${Date.now()}`,
|
|
||||||
"a.text": text,
|
|
||||||
"a.color": color,
|
|
||||||
"a.fontFamily": "Poppins",
|
|
||||||
"a.fontSize": fontSize,
|
|
||||||
"a.width": 450,
|
|
||||||
});
|
|
||||||
|
|
||||||
const loadImage = async function () {
|
|
||||||
const text = inputText.value;
|
|
||||||
const fontSize = parseInt(inputFontSize.value);
|
|
||||||
const color = inputColor.value;
|
|
||||||
const backgroundImageId = inputUnsplashID.value;
|
|
||||||
|
|
||||||
const imageUri = endpointTpl(text, fontSize, color, backgroundImageId);
|
|
||||||
try {
|
|
||||||
const resp = await fetch(imageUri);
|
|
||||||
const imageBlob = await resp.blob();
|
|
||||||
const imageObjectURL = URL.createObjectURL(imageBlob);
|
|
||||||
|
|
||||||
beforeImage.hidden = true
|
|
||||||
imageHolder.children[0].src = imageObjectURL;
|
|
||||||
imageHolder.hidden = false;
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
alert(`Произошла ошибка: ${e}`);
|
|
||||||
location.reload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const init = function () {
|
|
||||||
beforeImage = document.getElementById("beforeImage");
|
|
||||||
imageHolder = document.getElementById("imageHolder");
|
|
||||||
inputText = document.getElementById("inputText");
|
|
||||||
inputFontSize = document.getElementById("inputFontSize");
|
|
||||||
inputColor = document.getElementById("inputColor");
|
|
||||||
inputUnsplashID = document.getElementById("inputUnsplashID");
|
|
||||||
|
|
||||||
document.querySelectorAll("[wizardNext]").forEach(e => e.addEventListener("click", setCurrentWizardPage.bind(window, e)))
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", init);
|
|
||||||
7
w10/assets/bootstrap.bundle.min.js
vendored
7
w10/assets/bootstrap.bundle.min.js
vendored
File diff suppressed because one or more lines are too long
7
w10/assets/bootstrap.min.css
vendored
7
w10/assets/bootstrap.min.css
vendored
File diff suppressed because one or more lines are too long
118
w10/index.html
118
w10/index.html
|
|
@ -1,118 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Картинкогенератор</title>
|
|
||||||
|
|
||||||
<link href="/assets/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<main>
|
|
||||||
<div class="container py-4">
|
|
||||||
<header class="pb-3 mb-4 border-bottom">
|
|
||||||
<a href="/" class="d-flex align-items-center text-dark text-decoration-none">
|
|
||||||
<span class="fs-4">Картинкогенератор</span>
|
|
||||||
</a>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<div wizardPage="1" class="row align-items-md-stretch">
|
|
||||||
<div class="col">
|
|
||||||
<div class="h-100 p-5 text-white bg-dark rounded-3">
|
|
||||||
<h2>Какой текст вы хотите нанести на картинку?</h2>
|
|
||||||
|
|
||||||
<div class="my-3">
|
|
||||||
<label for="inputText" class="form-label">Мой текст</label>
|
|
||||||
<input type="text" class="form-control" id="inputText" placeholder="Lorem ipsum dolor sit amet..." required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button class="btn btn-info" type="button" wizardCurrent="1" wizardNext="2">Дальше</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div wizardPage="2" class="row align-items-md-stretch" hidden>
|
|
||||||
<div class="col">
|
|
||||||
<div class="h-100 p-5 text-white bg-dark rounded-3">
|
|
||||||
<h2>Теперь давайте настроим внешний вид текста</h2>
|
|
||||||
|
|
||||||
<div class="mb-3 row">
|
|
||||||
<label for="inputFontSize" class="col-sm-2 col-form-label">Размер текста</label>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<input type="number" class="form-control" id="inputFontSize" value="40" placeholder="Размер текста" required>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3 row">
|
|
||||||
<label for="inputColor" class="col-sm-2 col-form-label">Цвет текста</label>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<input type="color" value="#FFFFFF" class="form-control h-100" id="inputColor" required>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row g-5">
|
|
||||||
<div class="col-auto">
|
|
||||||
<button class="btn btn-warning" type="button" wizardCurrent="2" wizardNext="1">Назад</button>
|
|
||||||
</div>
|
|
||||||
<div class="col-auto">
|
|
||||||
<button class="btn btn-info" type="button" wizardCurrent="2" wizardNext="3">Дальше</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div wizardPage="3" class="row align-items-md-stretch" hidden>
|
|
||||||
<div class="col">
|
|
||||||
<div class="h-100 p-5 text-white bg-dark rounded-3">
|
|
||||||
<h2>Добавим фоновое изображение?</h2>
|
|
||||||
<p>Вставьте в поле ниже идентификатор изображения с Unsplash. Можете оставить "random" для случайной кратинки.</p>
|
|
||||||
|
|
||||||
<div class="my-3">
|
|
||||||
<label for="inputUnsplashID" class="form-label">UnsplashID</label>
|
|
||||||
<input type="text" class="form-control" id="inputUnsplashID" value="random" placeholder="https://unsplash.com/photos/{UnsplashID}" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="row g-5">
|
|
||||||
<div class="col-auto">
|
|
||||||
<button class="btn btn-warning" type="button" wizardCurrent="3" wizardNext="2">Назад</button>
|
|
||||||
</div>
|
|
||||||
<div class="col-auto">
|
|
||||||
<button class="btn btn-success" type="button" wizardCurrent="3" wizardNext="4">Создать картинку!</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div wizardPage="4" class="row align-items-md-stretch" hidden>
|
|
||||||
<div class="col">
|
|
||||||
<div class="container-fluid py-5 text-center">
|
|
||||||
<div id="beforeImage">
|
|
||||||
<h1 class="display-5 fw-bold m-0">Секундочку...</h1>
|
|
||||||
<div class="spinner-border m-5" role="status">
|
|
||||||
<span class="visually-hidden">Loading...</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="imageHolder" hidden>
|
|
||||||
<img class="mb-2" src>
|
|
||||||
<div class="row g-5">
|
|
||||||
<button class="btn btn-success col" type="button" onclick="javascript:location.reload()">Создать новую картинку</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<footer class="pt-3 mt-4 text-muted border-top">
|
|
||||||
© 2022
|
|
||||||
</footer>
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
<script src="/assets/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
|
|
||||||
<script src="/app.js"></script>
|
|
||||||
</html>
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue