diff options
author | Jonas Kohl | 2024-10-12 19:56:49 +0200 |
---|---|---|
committer | Jonas Kohl | 2024-10-12 19:56:49 +0200 |
commit | 5420ba37c5d5037617d6daab03272a5146af263c (patch) | |
tree | c1665a7244d15d01944032577e374ad93418c63c /src/application/views/template_end.php | |
parent | 0c45ffac2d8648fec4fa5e935754f4d34952983b (diff) |
Add rich text editor to New topic pagev0.5.1
Diffstat (limited to 'src/application/views/template_end.php')
-rw-r--r-- | src/application/views/template_end.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/application/views/template_end.php b/src/application/views/template_end.php index 9207170..b162def 100644 --- a/src/application/views/template_end.php +++ b/src/application/views/template_end.php @@ -43,6 +43,63 @@ </div> </footer> +<script type="text/javascript"> + $(function() { + function insertAroundSelection(textarea, before, after) { + var start = textarea.selectionStart; + var end = textarea.selectionEnd; + var text = textarea.value; + var pre = text.substring(0, start); + var inner = text.substring(start, end); + var post = text.substring(end); + start += before.length; + end += before.length; + text = pre + before + inner + after + post; + textarea.value = text; + textarea.focus(); + textarea.selectionStart = start; + textarea.selectionEnd = end; + } + + function getTextarea(btn) { + return $($(btn).attr("data-area"))[0]; + } + + var commands = { + bold: function(textarea) { + insertAroundSelection(textarea, "[b]", "[/b]"); + }, + italic: function(textarea) { + insertAroundSelection(textarea, "[i]", "[/i]"); + }, + underline: function(textarea) { + insertAroundSelection(textarea, "[u]", "[/u]"); + }, + strikethrough: function(textarea) { + insertAroundSelection(textarea, "[s]", "[/s]"); + }, + sup: function(textarea) { + insertAroundSelection(textarea, "[^]", "[/^]"); + }, + sub: function(textarea) { + insertAroundSelection(textarea, "[_]", "[/_]"); + }, + quote: function(textarea) { + insertAroundSelection(textarea, "> ", ""); + }, + spoiler: function(textarea) { + insertAroundSelection(textarea, "[spoiler]", "[/spoiler]"); + } + } + + $("button[data-editor-command]").attr("data-toggle", "tooltip").attr("data-placement", "bottom").click(function() { + var command = $(this).attr("data-editor-command"); + var textarea = getTextarea(this); + commands[command](textarea); + }).tooltip(); + }); +</script> + <script> $(function() { var _messages = <?= json_encode([ |