sneed
parent
6d21ad0272
commit
691b80431c
|
@ -3,6 +3,42 @@
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<script>
|
<script>
|
||||||
|
// Auto-suggest title given URL
|
||||||
|
|
||||||
|
function autoSuggestTitle() {
|
||||||
|
|
||||||
|
var urlField = document.getElementById("post-URL");
|
||||||
|
|
||||||
|
var titleField = document.getElementById("post-title");
|
||||||
|
|
||||||
|
var isValidURL = urlField.checkValidity();
|
||||||
|
|
||||||
|
if (isValidURL && urlField.value.length > 0 && titleField.value === "") {
|
||||||
|
|
||||||
|
var x = new XMLHttpRequest();
|
||||||
|
x.withCredentials=true;
|
||||||
|
x.onreadystatechange = function() {
|
||||||
|
if (x.readyState == 4 && x.status == 200) {
|
||||||
|
|
||||||
|
title=JSON.parse(x.responseText)["title"];
|
||||||
|
titleField.value=title;
|
||||||
|
|
||||||
|
checkForRequired()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x.open('get','/submit/title?url=' + urlField.value);
|
||||||
|
x.send(null);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// Run AutoSuggestTitle function on load
|
||||||
|
|
||||||
|
if (window.location.pathname=='/submit') {
|
||||||
|
window.onload = autoSuggestTitle();
|
||||||
|
}
|
||||||
|
|
||||||
// Paste to create submission
|
// Paste to create submission
|
||||||
|
|
||||||
document.addEventListener('paste', function (event) {
|
document.addEventListener('paste', function (event) {
|
||||||
|
@ -39,48 +75,47 @@
|
||||||
|
|
||||||
function checkForRequired() {
|
function checkForRequired() {
|
||||||
|
|
||||||
// Divs
|
// Divs
|
||||||
|
|
||||||
var title = document.getElementById("post-title");
|
var title = document.getElementById("post-title");
|
||||||
|
|
||||||
var url = document.getElementById("post-URL");
|
var url = document.getElementById("post-URL");
|
||||||
|
|
||||||
var text = document.getElementById("post-text");
|
var text = document.getElementById("post-text");
|
||||||
|
|
||||||
var button = document.getElementById("create_button");
|
var button = document.getElementById("create_button");
|
||||||
|
|
||||||
var image = document.getElementById("file-upload");
|
var image = document.getElementById("file-upload");
|
||||||
|
|
||||||
// Toggle reuqired attribute
|
// Toggle reuqired attribute
|
||||||
|
|
||||||
if (url.value.length > 0 || image.value.length > 0) {
|
if (url.value.length > 0 || image.value.length > 0) {
|
||||||
text.required = false;
|
text.required = false;
|
||||||
url.required=false;
|
url.required=false;
|
||||||
} else if (text.value.length > 0 || image.value.length > 0) {
|
} else if (text.value.length > 0 || image.value.length > 0) {
|
||||||
url.required = false;
|
url.required = false;
|
||||||
} else {
|
} else {
|
||||||
text.required = true;
|
text.required = true;
|
||||||
url.required = true;
|
url.required = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validity check
|
// Validity check
|
||||||
|
|
||||||
var isValidTitle = title.checkValidity();
|
var isValidTitle = title.checkValidity();
|
||||||
|
|
||||||
var isValidURL = url.checkValidity();
|
var isValidURL = url.checkValidity();
|
||||||
|
|
||||||
var isValidText = text.checkValidity();
|
var isValidText = text.checkValidity();
|
||||||
|
|
||||||
// Disable submit button if invalid inputs
|
// Disable submit button if invalid inputs
|
||||||
|
|
||||||
if (isValidTitle && (isValidURL || image.value.length>0)) {
|
|
||||||
button.disabled = false;
|
|
||||||
} else if (isValidTitle && isValidText) {
|
|
||||||
button.disabled = false;
|
|
||||||
} else {
|
|
||||||
button.disabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (isValidTitle && (isValidURL || image.value.length>0)) {
|
||||||
|
button.disabled = false;
|
||||||
|
} else if (isValidTitle && isValidText) {
|
||||||
|
button.disabled = false;
|
||||||
|
} else {
|
||||||
|
button.disabled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
|
Loading…
Reference in New Issue