This commit is contained in:
Aevann1 2022-02-22 12:38:28 +02:00
parent 79c99b812c
commit 37eec8d46b
3 changed files with 20 additions and 22 deletions

View file

@ -1,6 +1,6 @@
function hide_image() { function hide_image() {
x=document.getElementById('image-upload-block'); x=document.getElementById('image-upload-block');
url=document.getElementById('post-URL').value; url=document.getElementById('post-url').value;
if (url.length>=1){ if (url.length>=1){
x.classList.add('d-none'); x.classList.add('d-none');
} }
@ -48,16 +48,16 @@ document.getElementById('file-upload').addEventListener('change', function(){
}) })
function savetext() { function savetext() {
let post_title = document.getElementById('post-title').value localStorage.setItem("post_title", document.getElementById('post-title').value)
let post_text = document.getElementById('post-text').value localStorage.setItem("post_text", document.getElementById('post-text').value)
localStorage.setItem("post_title", post_title) localStorage.setItem("post_url", document.getElementById('post-url').value)
localStorage.setItem("post_text", post_text) localStorage.setItem("sub", document.getElementById('sub').value)
} }
function autoSuggestTitle() { function autoSuggestTitle() {
var urlField = document.getElementById("post-URL"); var urlField = document.getElementById("post-url");
var titleField = document.getElementById("post-title"); var titleField = document.getElementById("post-title");

View file

@ -862,7 +862,7 @@ def submit_post(v, sub=None):
return render_template("submit.html", SUBS=SUBS, v=v, error=error, title=title, url=url, body=body, ghost=submit_ghost(v,g.db)), 400 return render_template("submit.html", SUBS=SUBS, v=v, error=error, title=title, url=url, body=body, ghost=submit_ghost(v,g.db)), 400
sub = request.values.get("sub") sub = request.values.get("sub").replace('/s/','')
if sub and sub != 'none': if sub and sub != 'none':
sub = g.db.query(Sub.name).filter_by(name=sub.strip().lower()).one_or_none() sub = g.db.query(Sub.name).filter_by(name=sub.strip().lower()).one_or_none()

View file

@ -80,22 +80,20 @@
<input autocomplete="off" type="hidden" name="formkey" value="{{v.formkey}}"> <input autocomplete="off" type="hidden" name="formkey" value="{{v.formkey}}">
{% if SITE_NAME != 'Drama' or sub %} {% if SITE_NAME != 'Drama' or sub %}
<label class='mt-4' for="title">Sub</label> <label class='mt-4' for="title">Sub</label>
<div class="input-group mb2"> <div class="input-group mb2">
<select autocomplete="off" id='sub' class="form-control" form="submitform" name="sub"> <input list="subs" autocomplete="off" id='sub' class="form-control" form="submitform" name="sub" oninput="savetext()">
<datalist id="subs">
{% if SITE_NAME != 'Ruqqus' %} {% if SITE_NAME != 'Ruqqus' %}
<option value="none" selected> <option value="/s/none" selected></option>
None
</option>
{% endif %} {% endif %}
{% for s in SUBS %} {% for s in SUBS %}
<option value="{{s}}" {% if sub and sub.name == s %}selected{% endif %}> <option value="/s/{{s}}" {% if sub and sub.name == s %}selected{% endif %}></option>
/s/{{s}}
</option>
{% endfor %} {% endfor %}
</select> </datalist>
</div> </div>
{% endif %} {% endif %}
@ -110,7 +108,7 @@
<div id="urlblock"> <div id="urlblock">
<label for="URL" class="mt-3">URL</label> <label for="URL" class="mt-3">URL</label>
<input autocomplete="off" class="form-control" id="post-URL" aria-describedby="URLHelp" name="url" placeholder="Optional if you have text." value="{{request.values.get('url','')}}" required oninput="checkForRequired();hide_image();autoSuggestTitle()"> <input autocomplete="off" class="form-control" id="post-url" aria-describedby="URLHelp" name="url" placeholder="Optional if you have text." value="{{request.values.get('url','')}}" required oninput="checkForRequired();hide_image();autoSuggestTitle();savetext()">
<small class="form-text text-muted">To post an image, use a direct image link such as i.imgur.com</small> <small class="form-text text-muted">To post an image, use a direct image link such as i.imgur.com</small>
</div> </div>
<div id="image-upload-block"> <div id="image-upload-block">
@ -225,16 +223,16 @@
{% endblock %} {% endblock %}
<script> <script>
let fetched_title = localStorage.getItem("post_title") document.getElementById('post-title').value = localStorage.getItem("post_title")
document.getElementById('post-title').value = fetched_title document.getElementById('post-text').value = localStorage.getItem("post_text")
let fetched_text = localStorage.getItem("post_text") document.getElementById('post-url').value = localStorage.getItem("post_url")
document.getElementById('post-text').value = fetched_text document.getElementById('sub').value = localStorage.getItem("sub")
function checkForRequired() { function checkForRequired() {
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");
@ -271,7 +269,7 @@
<script src="/static/assets/js/marked.js?a=242"></script> <script src="/static/assets/js/marked.js?a=242"></script>
<script src="/static/assets/js/formatting.js?a=240"></script> <script src="/static/assets/js/formatting.js?a=240"></script>
<script src="/static/assets/js/submit.js?a=244"></script> <script src="/static/assets/js/submit.js?a=246"></script>
{% include "emoji_modal.html" %} {% include "emoji_modal.html" %}
{% include "gif_modal.html" %} {% include "gif_modal.html" %}