This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/resources/views/yuuno/forum/elements/replyForm.twig

180 lines
7 KiB
Twig
Raw Normal View History

{% set bbcode = {
'b': ['Bold: [b]text[/b]', 'bold'],
'i': ['Italic: [i]text[/i]', 'italic'],
'u': ['Underline: [u]text[/u]', 'underline'],
's': ['Strikethrough: [s]text[/s]', 'strikethrough'],
'header': ['Header: [header]text[/header]', 'header'],
'url': ['URL: [url]link[/url] or [url=link]text[/url]', 'chain'],
'code': ['Code: [code]text[/code] (bbcodes inside this tag are ignored!)', 'code'],
'spoiler': ['Spoiler: [spoiler]text[/spoiler]', 'minus'],
'box': ['Spoiler box: [box]text[/box] or [box=title]text[/box]', 'folder', true],
'list': ['List: [list][*]item\r\n[*]another item[/list]', 'list-ul'],
'img': ['Image: [img]image link[/img], please use https instead of http if possible', 'picture-o'],
'youtube': ['YouTube video: [youtube]video id (in the link after ?v= up until the first &)[/youtube]', 'youtube-play']
} %}
<div id="reply">
<form id="postingForm" method="post" action="{{ postingAction }}">
<div class="posting-subject" id="postingTitleContainer"{% if titleCache is not defined %} style="display: none;"{% endif %}>
2016-11-09 18:32:23 +00:00
<input type="text" class="input__text" name="title" id="postingTitle" placeholder="Title" value="{{ titleCache is defined ? titleCache : '' }}">
</div>
<div class="posting-text">
2016-11-09 18:32:23 +00:00
<textarea class="input__text" name="text" id="postingText" placeholder="Hit ctrl+enter to submit quickly!"{% if titleCache is defined %} autofocus{% endif %}>{{ textCache }}</textarea>
</div>
<div class="posting-buttons">
<div style="float: left;">
{% for code,meta in bbcode %}
2016-11-09 18:32:23 +00:00
<button onclick="Sakura.Editor.InsertBBCode(Sakura.DOM.ID('postingText'), '{{ code }}'{% if meta[2] is defined %}, true{% endif %});" type="button"{% if meta[0] %} title="{{ meta[0] }}"{% endif %} class="input__button{% if meta[1] %} fa fa-{{ meta[1] }}{% endif %}">{% if not meta[1] %}{{ code }}{% endif %}</button>
{% endfor %}
</div>
<div style="float: right;">
2016-11-09 18:32:23 +00:00
<button class="input__button fa fa-remove" title="Stop editing" style="display: none;" type="button" onclick="stopEdit();" id="postingStopEditing"></button>
<button class="input__button fa fa-send" title="Reply"></button>
</div>
<div class="clear"></div>
</div>
</form>
</div>
<script type="text/javascript">
2016-08-05 20:53:29 +00:00
Sakura.Config.Set({
ForumTitleMin: {{ config('forum.min_title_length') }},
ForumTitleMax: {{ config('forum.max_title_length') }},
ForumTextMin: {{ config('forum.min_post_length') }},
ForumTextMax: {{ config('forum.max_post_length') }},
});
Sakura.Editor.Prepare();
var preview = document.getElementById('postingPreview'),
pTitle = document.getElementById('postingTitle'),
pTitleCont = document.getElementById('postingTitleContainer'),
pText = document.getElementById('postingText'),
pForm = document.getElementById('postingForm'),
pStopEdit = document.getElementById('postingStopEditing'),
pMode = document.getElementById('previewMode'),
2016-07-30 13:48:09 +00:00
tTitle = document.getElementById('topicTitle'),
rTitle = document.getElementById('previewTitle'),
rText = document.getElementById('previewText'),
2016-07-31 19:36:13 +00:00
postFetch = new Sakura.AJAX(),
parserActive = false,
2016-07-30 13:48:09 +00:00
op = {{ topic is defined ? topic.firstPost.id : 0 }},
topicName = "{{ topic is defined ? topic.firstPost.subject : '' }}";
pText.addEventListener("focus", function () {
preview.style.display = null;
});
pText.addEventListener("blur", function () {
if (op && pText.value.length < 1) {
preview.style.display = 'none';
}
});
2016-08-05 20:53:29 +00:00
/*setInterval(function () {
if (lastParsed < Date.now() - 1000
&& lastKeystroke > Date.now() - 1000
&& parserActive !== true) {
lastParsed = Date.now();
var text = pText.value;
if (text.length == 0) {
rText.innerHTML = "";
} else if (text.length < textMin) {
rText.innerHTML = "<span style='color: red;'>Too short!</span>";
} else if (text.length > textMax) {
rText.innerHTML = "<span style='color: red;'>Too long!</span>";
} else {
parserActive = true;
2016-07-31 19:36:13 +00:00
parser.SetSend({"text":text});
2016-07-31 19:36:13 +00:00
parser.AddCallback(200, function () {
rText.innerHTML = parser.Response();
var codeBlocks = rText.querySelectorAll("pre code");
for (var _i in codeBlocks) {
if ((typeof codeBlocks[_i]).toLowerCase() === 'object') {
hljs.highlightBlock(codeBlocks[_i]);
}
}
parserActive = false;
});
2016-07-31 19:36:13 +00:00
parser.Start(Sakura.HTTPMethod.POST);
}
}
2016-08-05 20:53:29 +00:00
}, 1000);*/
pText.addEventListener("keydown", function (e) {
if (e.keyCode == 9) {
e.preventDefault();
insertText('postingText', ' ');
}
if (e.keyCode == 13 && e.ctrlKey) {
pForm.submit();
}
2016-08-05 20:53:29 +00:00
Sakura.Editor.PreviewTimeout(rText, pText);
});
pTitle.addEventListener("keyup", function (e) {
var title = pTitle.value;
if (title.length == 0) {
title = "";
2016-08-05 20:53:29 +00:00
} else if (title.length < Sakura.Config.ForumTitleMin) {
title = "<span style='color: red;'>Too short!</span>";
tTitle.innerHTML = title;
rTitle.innerHTML = title;
return;
2016-08-05 20:53:29 +00:00
} else if (title.length > Sakura.Config.ForumTitleMax) {
title = "<span style='color: red;'>Too long!</span>";
tTitle.innerHTML = title;
rTitle.innerHTML = title;
return;
}
tTitle.innerText = title;
rTitle.innerText = title;
});
function editPost(id) {
pText.disabled = true;
pTitleCont.style.display = 'none';
2016-07-30 13:48:09 +00:00
rTitle.innerText = 'Re: ' + topicName;
url = "{{ route('forums.post.raw', '1') }}".replace('1', id);
2016-07-31 19:36:13 +00:00
postFetch.SetUrl(url);
2016-07-31 19:36:13 +00:00
postFetch.AddCallback(200, function () {
pText.value = postFetch.Response();
pStopEdit.style.display = null;
pForm.action = "{{ route('forums.post.edit', '1') }}".replace('1', id);
pMode.innerText = 'Editing #' + id;
if (id === op) {
pTitleCont.style.display = null;
2016-07-30 13:48:09 +00:00
pTitle.value = topicName;
rTitle.innerText = topicName;
}
pText.disabled = false;
pText.focus();
});
2016-07-31 19:36:13 +00:00
postFetch.Start(Sakura.HTTPMethod.GET);
}
function stopEdit() {
pText.value = "";
pForm.action = "{{ postingAction }}";
pStopEdit.style.display = 'none';
pTitleCont.style.display = 'none';
pMode.innerText = 'Preview';
preview.style.display = 'none';
}
</script>