Switched to BBCode language for posts.

This commit is contained in:
Pierre HUBERT
2018-12-27 14:02:01 +01:00
parent f6e2c83dbd
commit 2890b03283
32 changed files with 573 additions and 18 deletions

View File

@ -416,6 +416,10 @@ function checkString(value){
*/
function removeHtmlTags(input){
//Check if input string is empty
if(input == null)
return "";
//Prepare update
var output = input;
@ -435,6 +439,25 @@ function removeHtmlTags(input){
return output;
}
/**
* Replace all line break with paragraph tags
*
* @param {string} input Input string to convert
* @return {string} Generated string
*/
function lineBreakToPTags(input){
//Check if the string is empty
if(input == null || input == "")
return input;
//Change string
while(input.includes("\n"))
input = input.replace("\n", "</p><p>");
return "<p>"+input+"</p>";
}
/**
* Check a URL validity
*

View File

@ -106,13 +106,19 @@ ComunicWeb.components.posts.edit = {
});
//Create update editor
var editorDiv = createElem2({
var editorTextarea = createElem2({
appendTo: updateDiv,
type: "div",
type: "textarea",
class: "editor",
innerHTML: infos.content
value: infos.content
});
sceditor.create(editorTextarea, {
format: 'bbcode',
height: "200px",
width: "100%",
toolbarExclude: "youtube,image,size,link"
});
$(editorDiv).wysiwyg();
//Create function to close modal
var closeModal = function(){
@ -131,7 +137,7 @@ ComunicWeb.components.posts.edit = {
}
//Get the new post content
var new_content = editorDiv.innerHTML;
var new_content = sceditor.instance(editorTextarea).getWysiwygEditorValue();
//Check the new post content
if(!ComunicWeb.components.posts.form._check_message(new_content)){

View File

@ -42,18 +42,35 @@ ComunicWeb.components.posts.form = {
});
//Create post message textarea
var inputMessageDiv = createElem2({
var inputMessageTextarea = createElem2({
appendTo: newPostMessageContener,
type: "div",
class: "new-message wdt-emoji-bundle-enabled",
type: "textarea",
class: "new-message",
innerHTML: ""
});
//Enable bootstrap-wysiwyg
$(inputMessageDiv).wysiwyg();
var inputMessageToolbarTarget = createElem2({
appendTo: newPostMessageContener,
type: "div"
});
sceditor.create(inputMessageTextarea, {
format: 'bbcode',
height: "200px",
width: "100%",
toolbar: 'bold,italic,underline,subscript,superscript|' +
'left,center,right,justify|color|' +
'bulletlist,orderedlist|table,code,quote|source',
toolbarContainer: inputMessageToolbarTarget
});
//Enable emojies picker
ComunicWeb.components.emoji.picker.addPicker(inputMessageDiv);
ComunicWeb.components.emoji.picker.addDetachedPicker(newPostMessageContener, (emojie) => {
//Append new emojie to the instance
sceditor.instance(inputMessageTextarea).insertText(emojie);
});
//Add the different post types
@ -344,7 +361,7 @@ ComunicWeb.components.posts.form = {
var datas = new FormData();
//Get the message content
var message_content = inputMessageDiv.innerHTML;
var message_content = sceditor.instance(inputMessageTextarea).getWysiwygEditorValue();
datas.append("content", message_content);
//Check if the message includes an image

View File

@ -826,7 +826,7 @@ ComunicWeb.components.posts.ui = {
appendTo: postRoot,
type: "div",
class: "post_content",
innerHTML: removeJavascriptEventsFromHTML(info.content)
innerHTML: lineBreakToPTags(BBCodeParser.process(removeHtmlTags(info.content)))
});
//Parse emojies