forked from MarseyWorld/MarseyWorld
fix bug with pasting in /submit + dedup
parent
0073c2224f
commit
3a67c1647d
|
@ -1,40 +0,0 @@
|
||||||
const IMAGE_FORMATS = document.getElementById('IMAGE_FORMATS').value.split(',')
|
|
||||||
|
|
||||||
document.onpaste = function(event) {
|
|
||||||
files = structuredClone(event.clipboardData.files);
|
|
||||||
|
|
||||||
filename = files[0]
|
|
||||||
|
|
||||||
if (filename)
|
|
||||||
{
|
|
||||||
filename = filename.name.toLowerCase()
|
|
||||||
f=document.getElementById('file-upload');
|
|
||||||
f.files = files;
|
|
||||||
document.getElementById('filename-show').textContent = filename;
|
|
||||||
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
|
|
||||||
{
|
|
||||||
const fileReader = new FileReader();
|
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
|
||||||
fileReader.addEventListener("load", function () {
|
|
||||||
document.getElementById('image-preview').setAttribute('src', this.result);
|
|
||||||
document.getElementById('image-preview').classList.remove('d-none');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('file-upload').addEventListener('change', function(){
|
|
||||||
f=document.getElementById('file-upload');
|
|
||||||
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 20);
|
|
||||||
filename = f.files[0].name.toLowerCase()
|
|
||||||
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
|
|
||||||
{
|
|
||||||
const fileReader = new FileReader();
|
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
|
||||||
fileReader.addEventListener("load", function () {
|
|
||||||
document.getElementById('image-preview').setAttribute('src', this.result);
|
|
||||||
document.getElementById('image-preview').classList.remove('d-none');
|
|
||||||
});
|
|
||||||
document.getElementById('submit-asset').disabled = false;
|
|
||||||
}
|
|
||||||
})
|
|
|
@ -516,6 +516,38 @@ function handle_files(input, newfiles) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
file_upload = document.getElementById('file-upload');
|
||||||
|
|
||||||
|
if (file_upload) {
|
||||||
|
const IMAGE_FORMATS = document.getElementById('IMAGE_FORMATS').value.split(',')
|
||||||
|
|
||||||
|
function process_url_image() {
|
||||||
|
if (file_upload.files)
|
||||||
|
{
|
||||||
|
const filename = file_upload.files[0].name
|
||||||
|
document.getElementById('filename-show').textContent = filename.substr(0, 20);
|
||||||
|
if (IMAGE_FORMATS.some(s => filename.toLowerCase().endsWith(s)))
|
||||||
|
{
|
||||||
|
const fileReader = new FileReader();
|
||||||
|
fileReader.readAsDataURL(file_upload.files[0]);
|
||||||
|
fileReader.addEventListener("load", function () {
|
||||||
|
document.getElementById('image-preview').setAttribute('src', this.result);
|
||||||
|
document.getElementById('image-preview').classList.remove('d-none');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof checkForRequired === "function") {
|
||||||
|
document.getElementById('urlblock').classList.add('d-none');
|
||||||
|
checkForRequired();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.getElementById('submit-btn').disabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_upload.onchange = process_url_image
|
||||||
|
}
|
||||||
|
|
||||||
document.onpaste = function(event) {
|
document.onpaste = function(event) {
|
||||||
const files = structuredClone(event.clipboardData.files);
|
const files = structuredClone(event.clipboardData.files);
|
||||||
if (!files.length) return
|
if (!files.length) return
|
||||||
|
@ -523,32 +555,13 @@ document.onpaste = function(event) {
|
||||||
const focused = document.activeElement;
|
const focused = document.activeElement;
|
||||||
let input;
|
let input;
|
||||||
|
|
||||||
if (location.pathname.endsWith('/submit')) {
|
if (file_upload) {
|
||||||
if (focused) {
|
if (location.pathname.endsWith('/submit') && focused && focused.id == 'post-text') {
|
||||||
input = document.getElementById('file-upload-submit')
|
input = document.getElementById('file-upload-submit')
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
f=document.getElementById('file-upload');
|
file_upload.files = files;
|
||||||
f.files += files;
|
process_url_image();
|
||||||
|
|
||||||
if (f.files.length > 20)
|
|
||||||
{
|
|
||||||
alert("You can't upload more than 20 files at one time!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('filename-show').textContent = filename;
|
|
||||||
document.getElementById('urlblock').classList.add('d-none');
|
|
||||||
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
|
|
||||||
{
|
|
||||||
const fileReader = new FileReader();
|
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
|
||||||
fileReader.addEventListener("load", function () {document.getElementById('image-preview').setAttribute('src', this.result);});
|
|
||||||
}
|
|
||||||
document.getElementById('post-url').value = null;
|
|
||||||
localStorage.setItem("post-url", "")
|
|
||||||
document.getElementById('image-upload-block').classList.remove('d-none')
|
|
||||||
checkForRequired();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
const IMAGE_FORMATS = document.getElementById('IMAGE_FORMATS').value.split(',')
|
const submitButton = document.getElementById('submit')
|
||||||
const submitButton = document.getElementById('create_button')
|
|
||||||
|
|
||||||
document.getElementById('post-title').value = localStorage.getItem("post-title")
|
document.getElementById('post-title').value = localStorage.getItem("post-title")
|
||||||
document.getElementById('post-text').value = localStorage.getItem("post-text")
|
document.getElementById('post-text').value = localStorage.getItem("post-text")
|
||||||
|
@ -64,24 +63,6 @@ function hide_image() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
document.getElementById('file-upload').addEventListener('change', function(){
|
|
||||||
const f = document.getElementById('file-upload');
|
|
||||||
if (f.files)
|
|
||||||
{
|
|
||||||
document.getElementById('urlblock').classList.add('d-none');
|
|
||||||
const filename = f.files[0].name
|
|
||||||
document.getElementById('filename-show').textContent = filename.substr(0, 20);
|
|
||||||
if (IMAGE_FORMATS.some(s => filename.toLowerCase().endsWith(s)))
|
|
||||||
{
|
|
||||||
const fileReader = new FileReader();
|
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
|
||||||
fileReader.addEventListener("load", function () {document.getElementById('image-preview').setAttribute('src', this.result);});
|
|
||||||
}
|
|
||||||
checkForRequired();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const saved_values = ['post-title', 'post-text', 'post-url', 'sub']
|
const saved_values = ['post-title', 'post-text', 'post-url', 'sub']
|
||||||
|
|
||||||
function savetext() {
|
function savetext() {
|
||||||
|
|
|
@ -1,44 +1,3 @@
|
||||||
const IMAGE_FORMATS = document.getElementById('IMAGE_FORMATS').value.split(',')
|
|
||||||
|
|
||||||
document.onpaste = function(event) {
|
|
||||||
files = structuredClone(event.clipboardData.files);
|
|
||||||
|
|
||||||
filename = files[0]
|
|
||||||
|
|
||||||
if (filename)
|
|
||||||
{
|
|
||||||
filename = filename.name.toLowerCase()
|
|
||||||
f=document.getElementById('file-upload');
|
|
||||||
f.files = files;
|
|
||||||
document.getElementById('filename-show').textContent = filename;
|
|
||||||
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
|
|
||||||
{
|
|
||||||
const fileReader = new FileReader();
|
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
|
||||||
fileReader.addEventListener("load", function () {
|
|
||||||
document.getElementById('image-preview').setAttribute('src', this.result);
|
|
||||||
document.getElementById('image-preview').classList.remove('d-none');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('file-upload').addEventListener('change', function(){
|
|
||||||
f=document.getElementById('file-upload');
|
|
||||||
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 30);
|
|
||||||
filename = f.files[0].name.toLowerCase()
|
|
||||||
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
|
|
||||||
{
|
|
||||||
const fileReader = new FileReader();
|
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
|
||||||
fileReader.addEventListener("load", function () {
|
|
||||||
document.getElementById('image-preview').setAttribute('src', this.result);
|
|
||||||
document.getElementById('image-preview').classList.remove('d-none');
|
|
||||||
});
|
|
||||||
document.getElementById('submit-hat').disabled = false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function approve_hat(t, name) {
|
function approve_hat(t, name) {
|
||||||
postToast(t, `/admin/approve/hat/${name}`,
|
postToast(t, `/admin/approve/hat/${name}`,
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,44 +1,3 @@
|
||||||
const IMAGE_FORMATS = document.getElementById('IMAGE_FORMATS').value.split(',')
|
|
||||||
|
|
||||||
document.onpaste = function(event) {
|
|
||||||
files = structuredClone(event.clipboardData.files);
|
|
||||||
|
|
||||||
filename = files[0]
|
|
||||||
|
|
||||||
if (filename)
|
|
||||||
{
|
|
||||||
filename = filename.name.toLowerCase()
|
|
||||||
f=document.getElementById('file-upload');
|
|
||||||
f.files = files;
|
|
||||||
document.getElementById('filename-show').textContent = filename;
|
|
||||||
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
|
|
||||||
{
|
|
||||||
const fileReader = new FileReader();
|
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
|
||||||
fileReader.addEventListener("load", function () {
|
|
||||||
document.getElementById('image-preview').setAttribute('src', this.result);
|
|
||||||
document.getElementById('image-preview').classList.remove('d-none');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('file-upload').addEventListener('change', function(){
|
|
||||||
f=document.getElementById('file-upload');
|
|
||||||
document.getElementById('filename-show').textContent = document.getElementById('file-upload').files[0].name.substr(0, 30);
|
|
||||||
filename = f.files[0].name.toLowerCase()
|
|
||||||
if (IMAGE_FORMATS.some(s => filename.endsWith(s)))
|
|
||||||
{
|
|
||||||
const fileReader = new FileReader();
|
|
||||||
fileReader.readAsDataURL(f.files[0]);
|
|
||||||
fileReader.addEventListener("load", function () {
|
|
||||||
document.getElementById('image-preview').setAttribute('src', this.result);
|
|
||||||
document.getElementById('image-preview').classList.remove('d-none');
|
|
||||||
});
|
|
||||||
document.getElementById('submit-marsey').disabled = false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function approve_marsey(t, name) {
|
function approve_marsey(t, name) {
|
||||||
postToast(t, `/admin/approve/marsey/${name}`,
|
postToast(t, `/admin/approve/marsey/${name}`,
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="footer mt-4">
|
<div class="footer mt-4">
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<input id="update-asset" type="submit" data-nonce="{{g.nonce}}" data-onclick="disable(this)" class="btn btn-primary ml-auto" value="Update {{type}}">
|
<input id="submit-btn" type="submit" data-nonce="{{g.nonce}}" data-onclick="disable(this)" class="btn btn-primary ml-auto" value="Update {{type}}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -40,8 +40,5 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{macros.image_formats()}}
|
||||||
<input hidden id="IMAGE_FORMATS" value="{{IMAGE_FORMATS}}">
|
|
||||||
|
|
||||||
<script defer src="{{'js/admin/update_assets.js' | asset}}"></script>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<span class="text-danger text-small" style="vertical-align: sub;">{{error}}</span>
|
<span class="text-danger text-small" style="vertical-align: sub;">{{error}}</span>
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<button type="submit" class="btn btn-primary ml-auto" id="create_button" {% if cost > v.coins %}disabled{% endif %}>Create {{HOLE_NAME|capitalize}}</button>
|
<button type="submit" class="btn btn-primary ml-auto" {% if cost > v.coins %}disabled{% endif %}>Create {{HOLE_NAME|capitalize}}</button>
|
||||||
</div>
|
</div>
|
||||||
<p class="mt-2 mr-1" style="float: right"><b>Cost</b>: {{cost}} coins</p>
|
<p class="mt-2 mr-1" style="float: right"><b>Cost</b>: {{cost}} coins</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -101,7 +101,7 @@
|
||||||
<progress max="100"></progress>
|
<progress max="100"></progress>
|
||||||
<span></span>
|
<span></span>
|
||||||
</span>
|
</span>
|
||||||
<button type="submit" class="btn btn-primary" id="create_button" type="submit">Post</button>
|
<button type="submit" class="btn btn-primary" id="submit-btn" type="submit">Post</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -110,7 +110,7 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
<script defer src="{{'js/vendor/marked.js' | asset}}"></script>
|
<script defer src="{{'js/vendor/marked.js' | asset}}"></script>
|
||||||
<script defer src="{{'js/markdown.js' | asset}}"></script>
|
<script defer src="{{'js/markdown.js' | asset}}"></script>
|
||||||
<input hidden id="IMAGE_FORMATS" value="{{IMAGE_FORMATS}}">
|
{{macros.image_formats()}}
|
||||||
<script defer src="{{'js/submit.js' | asset}}"></script>
|
<script defer src="{{'js/submit.js' | asset}}"></script>
|
||||||
{% include "modals/emoji.html" %}
|
{% include "modals/emoji.html" %}
|
||||||
{% include "modals/gif.html" %}
|
{% include "modals/gif.html" %}
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
<div class="footer mt-5">
|
<div class="footer mt-5">
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<input id="submit-hat" disabled type="submit" data-nonce="{{g.nonce}}" data-onclick="disable(this)" class="btn btn-primary ml-auto" value="Submit Hat">
|
<input id="submit-btn" disabled type="submit" data-nonce="{{g.nonce}}" data-onclick="disable(this)" class="btn btn-primary ml-auto" value="Submit Hat">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input hidden id="IMAGE_FORMATS" value="{{IMAGE_FORMATS}}">
|
{{macros.image_formats()}}
|
||||||
|
|
||||||
<script defer src="{{'js/submit_hats.js' | asset}}"></script>
|
<script defer src="{{'js/submit_hats.js' | asset}}"></script>
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
<div class="footer mt-5">
|
<div class="footer mt-5">
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<input id="submit-marsey" disabled type="submit" data-nonce="{{g.nonce}}" data-onclick="disable(this)" class="btn btn-primary ml-auto" value="Submit Marsey">
|
<input id="submit-btn" disabled type="submit" data-nonce="{{g.nonce}}" data-onclick="disable(this)" class="btn btn-primary ml-auto" value="Submit Marsey">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input hidden id="IMAGE_FORMATS" value="{{IMAGE_FORMATS}}">
|
{{macros.image_formats()}}
|
||||||
|
|
||||||
<script defer src="{{'js/submit_marseys.js' | asset}}"></script>
|
<script defer src="{{'js/submit_marseys.js' | asset}}"></script>
|
||||||
|
|
||||||
|
|
|
@ -208,3 +208,7 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% macro image_formats() %}
|
||||||
|
<input hidden id="IMAGE_FORMATS" value="{{IMAGE_FORMATS}}">
|
||||||
|
{% endmacro %}
|
||||||
|
|
Loading…
Reference in New Issue