microblog.pub/templates/new.html

71 lines
2.3 KiB
HTML
Raw Normal View History

2018-05-18 18:41:41 +00:00
{% extends "layout.html" %}
{% import 'utils.html' as utils %}
2018-05-21 19:03:21 +00:00
{% block title %}New - {{ config.NAME }}{% endblock %}
2019-04-10 20:50:36 +00:00
{% block headers %}
{% endblock %}
2018-05-18 18:41:41 +00:00
{% block content %}
<div id="container">
{% include "header.html" %}
<div id="new">
2018-06-03 19:28:06 +00:00
{% if thread %}
<h3 style="padding-bottom: 30px">Replying to {{ content }}</h3>
{{ utils.display_thread(thread) }}
{% else %}
<h3 style="padding-bottom:20px;">New note</h3>
{% endif %}
<form action="/api/new_note" method="POST" enctype="multipart/form-data">
<input type="hidden" name="redirect" value="/">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
2018-05-18 18:41:41 +00:00
{% if reply %}<input type="hidden" name="reply" value="{{reply}}">{% endif %}
2019-04-10 20:50:36 +00:00
<p>
{% for emoji in emojis %}
<span class="ji">{{ emoji }}</span>
{% endfor %}
</p>
<textarea name="content" rows="10" cols="50" autofocus="autofocus" designMode="on">{{ content }}</textarea>
<input type="file" name="file">
2018-05-18 18:41:41 +00:00
<div style="margin-top:20px;">
<input type="submit" value="post">
</div>
</form>
</div>
</div>
2019-04-10 20:50:36 +00:00
<script>
2019-04-10 20:57:20 +00:00
// The new post textarea
2019-04-10 20:50:36 +00:00
var ta = document.getElementsByTagName("textarea")[0];
2019-04-10 20:57:20 +00:00
// Helper for inserting text (emojis) in the textarea
2019-04-10 20:50:36 +00:00
function insertAtCursor (textToInsert) {
2019-04-10 20:57:20 +00:00
ta.focus();
const isSuccess = document.execCommand("insertText", false, textToInsert);
// Firefox (non-standard method)
if (!isSuccess) {
// Credits to https://www.everythingfrontend.com/posts/insert-text-into-textarea-at-cursor-position.html
// get current text of the input
const value = ta.value;
// save selection start and end position
const start = ta.selectionStart;
const end = ta.selectionEnd;
// update the value with our text inserted
ta.value = value.slice(0, start) + textToInsert + value.slice(end);
// update cursor to be at the end of insertion
ta.selectionStart = ta.selectionEnd = start + textToInsert.length;
}
2019-04-10 20:50:36 +00:00
}
2019-04-10 20:57:20 +00:00
// Emoji click callback func
2019-04-10 20:50:36 +00:00
var ji = function (ev) {
2019-04-10 20:57:20 +00:00
insertAtCursor(ev.target.attributes.alt.value + " ");
2019-04-10 20:50:36 +00:00
ta.focus()
//console.log(document.execCommand('insertText', false /*no UI*/, ev.target.attributes.alt.value));
}
2019-04-10 20:57:20 +00:00
// Enable the click for each emojis
2019-04-10 20:50:36 +00:00
var items = document.getElementsByClassName("ji")
for (var i = 0; i < items.length; i++) {
items[i].addEventListener('click', ji);
}
</script>{% endblock %}