2016-07-29 19:31:36 +00:00
|
|
|
{% 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">
|
2016-12-09 19:25:22 +00:00
|
|
|
<form id="postingForm" method="post" action="javascript:void(0)" onsubmit="yuunoForumSubmit(this)">
|
|
|
|
<input type="hidden" name="session" value="{{ session_id() }}">
|
|
|
|
<div id="postingTitleContainer"{% if topic is defined %} style="display: none;"{% endif %}>
|
|
|
|
<input type="text" class="input__text" name="title" id="postingTitle" placeholder="Title">
|
2016-07-29 19:31:36 +00:00
|
|
|
</div>
|
2016-12-04 14:55:53 +00:00
|
|
|
<div>
|
2017-03-24 16:59:54 +00:00
|
|
|
<textarea class="input__text input__text--grow" name="text" id="postingText" placeholder="Hit ctrl+enter to submit quickly!"></textarea>
|
2016-07-29 19:31:36 +00:00
|
|
|
</div>
|
2016-12-04 14:55:53 +00:00
|
|
|
<div>
|
2016-07-29 19:31:36 +00:00
|
|
|
<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>
|
2016-07-29 19:31:36 +00:00
|
|
|
{% 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>
|
2016-07-29 19:31:36 +00:00
|
|
|
</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'),
|
2016-07-29 19:31:36 +00:00
|
|
|
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'),
|
2016-07-29 19:31:36 +00:00
|
|
|
rTitle = document.getElementById('previewTitle'),
|
|
|
|
rText = document.getElementById('previewText'),
|
2016-07-31 19:36:13 +00:00
|
|
|
postFetch = new Sakura.AJAX(),
|
2016-07-29 19:31:36 +00:00
|
|
|
parserActive = false,
|
2016-12-22 18:10:09 +00:00
|
|
|
op = {{ topic is defined ? topic.post : 0 }},
|
|
|
|
topicName = "{{ topic is defined ? topic.title : '' }}",
|
2016-12-09 19:25:22 +00:00
|
|
|
editing = 0;
|
2016-07-29 19:31:36 +00:00
|
|
|
|
|
|
|
pText.addEventListener("focus", function () {
|
|
|
|
preview.style.display = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
pText.addEventListener("blur", function () {
|
|
|
|
if (op && pText.value.length < 1) {
|
|
|
|
preview.style.display = 'none';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-09 16:29:32 +00:00
|
|
|
function postUpdateEvent(e) {
|
2016-07-29 19:31:36 +00:00
|
|
|
if (e.keyCode == 9) {
|
|
|
|
e.preventDefault();
|
2016-12-09 16:29:32 +00:00
|
|
|
var tab = ' ';
|
|
|
|
Sakura.DOM.EnterAtCursor(e.target, tab);
|
|
|
|
Sakura.DOM.SetPosition(e.target, Sakura.DOM.GetPosition(e.target) + tab.length);
|
2016-07-29 19:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (e.keyCode == 13 && e.ctrlKey) {
|
2016-12-09 19:25:22 +00:00
|
|
|
pForm.onsubmit();
|
2016-07-29 19:31:36 +00:00
|
|
|
}
|
2016-08-05 20:53:29 +00:00
|
|
|
|
|
|
|
Sakura.Editor.PreviewTimeout(rText, pText);
|
2016-12-09 16:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pText.addEventListener("change", postUpdateEvent);
|
|
|
|
pText.addEventListener("keydown", postUpdateEvent);
|
2016-07-29 19:31:36 +00:00
|
|
|
|
|
|
|
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) {
|
2016-07-29 19:31:36 +00:00
|
|
|
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) {
|
2016-07-29 19:31:36 +00:00
|
|
|
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;
|
2016-12-09 19:25:22 +00:00
|
|
|
editing = id;
|
2016-07-29 19:31:36 +00:00
|
|
|
|
|
|
|
url = "{{ route('forums.post.raw', '1') }}".replace('1', id);
|
|
|
|
|
2016-07-31 19:36:13 +00:00
|
|
|
postFetch.SetUrl(url);
|
2016-07-29 19:31:36 +00:00
|
|
|
|
2016-07-31 19:36:13 +00:00
|
|
|
postFetch.AddCallback(200, function () {
|
|
|
|
pText.value = postFetch.Response();
|
2016-07-29 19:31:36 +00:00
|
|
|
pStopEdit.style.display = null;
|
2016-12-09 19:25:22 +00:00
|
|
|
pForm.setAttribute('onsubmit', "editSave(this, " + id + ")");
|
2016-07-29 19:31:36 +00:00
|
|
|
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;
|
2016-07-29 19:31:36 +00:00
|
|
|
}
|
|
|
|
pText.disabled = false;
|
|
|
|
pText.focus();
|
|
|
|
});
|
|
|
|
|
2016-07-31 19:36:13 +00:00
|
|
|
postFetch.Start(Sakura.HTTPMethod.GET);
|
2016-07-29 19:31:36 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 19:25:22 +00:00
|
|
|
function editSave(form, id) {
|
|
|
|
var client = new Sakura.AJAX;
|
|
|
|
client.SetUrl("{{ route('forums.post.edit', '1') }}".replace('1', id));
|
|
|
|
client.SetFormData(new FormData(form));
|
|
|
|
client.AddCallback(200, function () {
|
|
|
|
var result = client.JSON();
|
|
|
|
|
|
|
|
if (result.error) {
|
|
|
|
var error = new Sakura.Dialogue;
|
|
|
|
error.Title = "Error";
|
|
|
|
error.Text = result.error;
|
|
|
|
error.SetType(Sakura.DialogueType.Info);
|
|
|
|
error.Display();
|
|
|
|
} else {
|
|
|
|
stopEdit();
|
|
|
|
|
|
|
|
if (result.id === op) {
|
|
|
|
topicName = result.title;
|
|
|
|
}
|
|
|
|
|
|
|
|
var post = Sakura.DOM.ID('p' + result.id);
|
|
|
|
post.querySelector('.post__text').innerHTML = result.text;
|
|
|
|
post.querySelector('.post__title').innerText = result.title.substring(0, 50) + (result.title.length > 50 ? '...' : '');
|
|
|
|
post.scrollIntoView(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
client.Start(Sakura.HTTPMethod.POST);
|
|
|
|
}
|
|
|
|
|
2016-07-29 19:31:36 +00:00
|
|
|
function stopEdit() {
|
2016-12-09 19:25:22 +00:00
|
|
|
editing = 0;
|
2016-07-29 19:31:36 +00:00
|
|
|
pText.value = "";
|
|
|
|
pStopEdit.style.display = 'none';
|
|
|
|
pTitleCont.style.display = 'none';
|
|
|
|
pMode.innerText = 'Preview';
|
|
|
|
preview.style.display = 'none';
|
|
|
|
}
|
2016-12-09 19:25:22 +00:00
|
|
|
|
|
|
|
function yuunoForumSubmit(form) {
|
|
|
|
if (editing) {
|
|
|
|
editSave(form, editing);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var client = new Sakura.AJAX;
|
|
|
|
client.SetUrl("{{ postingAction }}");
|
|
|
|
client.SetFormData(new FormData(form));
|
|
|
|
client.AddCallback(200, function () {
|
|
|
|
var result = client.JSON();
|
|
|
|
|
|
|
|
if (result.error) {
|
|
|
|
var error = new Sakura.Dialogue;
|
|
|
|
error.Title = "Error";
|
|
|
|
error.Text = result.error;
|
|
|
|
error.SetType(Sakura.DialogueType.Info);
|
|
|
|
error.Display();
|
|
|
|
} else if (result.go) {
|
|
|
|
window.location.assign(result.go)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
client.Start(Sakura.HTTPMethod.POST);
|
|
|
|
}
|
2016-07-29 19:31:36 +00:00
|
|
|
</script>
|