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

@ -21,8 +21,10 @@ ComunicWeb would not exists without the following technologies developped by the
- jquery.hotkeys - jquery.hotkeys
- bootstrap-wysiwyg (https://github.com/steveathon/bootstrap-wysiwyg/) - bootstrap-wysiwyg (https://github.com/steveathon/bootstrap-wysiwyg/)
- wdt-emoji-bundle (http://ned.im/wdt-emoji-bundle) - wdt-emoji-bundle (http://ned.im/wdt-emoji-bundle)
- PNGLib (http://www.xarg.org/2010/03/generate-client-side-png-files-using-javascript/) (BSD Licence) - PNGLib (http://www.xarg.org/2010/03/generate-client-side-png-files-using-javascript/) (BSD License)
- Identicon (http://github.com/stewartlord/identicon.js) (BSD Licence) - Identicon (http://github.com/stewartlord/identicon.js) (BSD License)
- FileSaver.js (http://eligrey.com) (by Eli Grey) (MIT Licence) - FileSaver.js (http://eligrey.com) (by Eli Grey) (MIT License)
- JSZip (https://github.com/Stuk/jszip.git) (MIT Licence) - JSZip (https://github.com/Stuk/jszip.git) (MIT License)
- JSZip Utils (https://github.com/Stuk/jszip-utils.git) (MIT Licence) - JSZip Utils (https://github.com/Stuk/jszip-utils.git) (MIT License)
- SCEditor (BBC WYIWYG editor) (https://github.com/samclarke/SCEditor) (MIT License)
- JavaScript BBCode Parser (https://github.com/Frug/js-bbcode-parser) (MIT License)

View File

@ -0,0 +1,289 @@
/*
* Javascript BBCode Parser Config Options
* @author Philip Nicolcev
* @license MIT License
*/
var parserColors = [ 'gray', 'silver', 'white', 'yellow', 'orange', 'red', 'fuchsia', 'blue', 'green', 'black', '#cd38d9' ];
var parserTags = {
'b': {
openTag: function(params,content) {
return '<b>';
},
closeTag: function(params,content) {
return '</b>';
}
},
'code': {
openTag: function(params,content) {
return '<code>';
},
closeTag: function(params,content) {
return '</code>';
},
noParse: true
},
'color': {
openTag: function(params,content) {
var colorCode = params.substr(1) || "inherit";
BBCodeParser.regExpAllowedColors.lastIndex = 0;
BBCodeParser.regExpValidHexColors.lastIndex = 0;
if ( !BBCodeParser.regExpAllowedColors.test( colorCode ) ) {
if ( !BBCodeParser.regExpValidHexColors.test( colorCode ) ) {
colorCode = "inherit";
} else {
if (colorCode.substr(0,1) !== "#") {
colorCode = "#" + colorCode;
}
}
}
return '<span style="color:' + colorCode + '">';
},
closeTag: function(params,content) {
return '</span>';
}
},
'i': {
openTag: function(params,content) {
return '<i>';
},
closeTag: function(params,content) {
return '</i>';
}
},
'img': {
openTag: function(params,content) {
var myUrl = content;
BBCodeParser.urlPattern.lastIndex = 0;
if ( !BBCodeParser.urlPattern.test( myUrl ) ) {
myUrl = "";
}
return '<img class="bbCodeImage" src="' + myUrl + '">';
},
closeTag: function(params,content) {
return '';
},
content: function(params,content) {
return '';
}
},
'list': {
openTag: function(params,content) {
return '<ul>';
},
closeTag: function(params,content) {
return '</ul>';
},
restrictChildrenTo: ["*", "li"]
},
'noparse': {
openTag: function(params,content) {
return '';
},
closeTag: function(params,content) {
return '';
},
noParse: true
},
'quote': {
openTag: function(params,content) {
return '<q>';
},
closeTag: function(params,content) {
return '</q>';
}
},
's': {
openTag: function(params,content) {
return '<s>';
},
closeTag: function(params,content) {
return '</s>';
}
},
'size': {
openTag: function(params,content) {
var mySize = parseInt(params.substr(1),10) || 0;
if (mySize < 10 || mySize > 20) {
mySize = 'inherit';
} else {
mySize = mySize + 'px';
}
return '<span style="font-size:' + mySize + '">';
},
closeTag: function(params,content) {
return '</span>';
}
},
'u': {
openTag: function(params,content) {
return '<span style="text-decoration:underline">';
},
closeTag: function(params,content) {
return '</span>';
}
},
'url': {
openTag: function(params,content) {
var myUrl;
if (!params) {
myUrl = content.replace(/<.*?>/g,"");
} else {
myUrl = params.substr(1);
}
BBCodeParser.urlPattern.lastIndex = 0;
if ( !BBCodeParser.urlPattern.test( myUrl ) ) {
myUrl = "#";
}
BBCodeParser.urlPattern.lastIndex = 0;
if ( !BBCodeParser.urlPattern.test( myUrl ) ) {
myUrl = "";
}
return '<a href="' + myUrl + '">';
},
closeTag: function(params,content) {
return '</a>';
}
},
//COMUNIC ADD BEGIN
'left': {
openTag: function(params,content) {
return '<p style="text-align: left;">';
},
closeTag: function(params,content) {
return '</p>';
}
},
'center': {
openTag: function(params,content) {
return '<p style="text-align: center;">';
},
closeTag: function(params,content) {
return '</p>';
}
},
'right': {
openTag: function(params,content) {
return '<p style="text-align: right;">';
},
closeTag: function(params,content) {
return '</p>';
}
},
'justify': {
openTag: function(params,content) {
return '<p style="text-align: justify;">';
},
closeTag: function(params,content) {
return '</p>';
}
},
'ul': {
openTag: function(params,content) {
return '<ul>';
},
closeTag: function(params,content) {
return '</ul>';
}
},
'ol': {
openTag: function(params,content) {
return '<ol>';
},
closeTag: function(params,content) {
return '</ol>';
}
},
'li': {
openTag: function(params,content) {
return '<li>';
},
closeTag: function(params,content) {
return '</li>';
}
},
'sup': {
openTag: function(params,content) {
return '<sup>';
},
closeTag: function(params,content) {
return '</sup>';
}
},
'sub': {
openTag: function(params,content) {
return '<sub>';
},
closeTag: function(params,content) {
return '</sub>';
}
},
'ltr': {
openTag: function(params,content) {
return '<div style="text-align: left;">';
},
closeTag: function(params,content) {
return '</div>';
}
},
'rtl': {
openTag: function(params,content) {
return '<div style="text-align: right;">';
},
closeTag: function(params,content) {
return '</div>';
}
},
'table': {
openTag: function(params,content) {
return '<table border="1" style="margin: auto;">';
},
closeTag: function(params,content) {
return '</table>';
}
},
'tr': {
openTag: function(params,content) {
return '<tr>';
},
closeTag: function(params,content) {
return '</tr>';
}
},
'td': {
openTag: function(params,content) {
return '<td>';
},
closeTag: function(params,content) {
return '</td>';
}
},
//COMUNIC ADD END
};

View File

@ -0,0 +1,152 @@
/*
* Javascript BBCode Parser
* @author Philip Nicolcev
* @license MIT License
*/
var BBCodeParser = (function(parserTags, parserColors) {
'use strict';
var me = {},
urlPattern = /^(?:https?|file|c):(?:\/{1,3}|\\{1})[-a-zA-Z0-9:;@#%&()~_?\+=\/\\\.]*$/,
emailPattern = /[^\s@]+@[^\s@]+\.[^\s@]+/,
fontFacePattern = /^([a-z][a-z0-9_]+|"[a-z][a-z0-9_\s]+")$/i,
tagNames = [],
tagNamesNoParse = [],
regExpAllowedColors,
regExpValidHexColors = /^#?[a-fA-F0-9]{6}$/,
ii, tagName, len;
// create tag list and lookup fields
for (tagName in parserTags) {
if (!parserTags.hasOwnProperty(tagName))
continue;
if (tagName === '*') {
tagNames.push('\\' + tagName);
} else {
tagNames.push(tagName);
if ( parserTags[tagName].noParse ) {
tagNamesNoParse.push(tagName);
}
}
parserTags[tagName].validChildLookup = {};
parserTags[tagName].validParentLookup = {};
parserTags[tagName].restrictParentsTo = parserTags[tagName].restrictParentsTo || [];
parserTags[tagName].restrictChildrenTo = parserTags[tagName].restrictChildrenTo || [];
len = parserTags[tagName].restrictChildrenTo.length;
for (ii = 0; ii < len; ii++) {
parserTags[tagName].validChildLookup[ parserTags[tagName].restrictChildrenTo[ii] ] = true;
}
len = parserTags[tagName].restrictParentsTo.length;
for (ii = 0; ii < len; ii++) {
parserTags[tagName].validParentLookup[ parserTags[tagName].restrictParentsTo[ii] ] = true;
}
}
regExpAllowedColors = new RegExp('^(?:' + parserColors.join('|') + ')$');
/*
* Create a regular expression that captures the innermost instance of a tag in an array of tags
* The returned RegExp captures the following in order:
* 1) the tag from the array that was matched
* 2) all (optional) parameters included in the opening tag
* 3) the contents surrounded by the tag
*
* @param {type} tagsArray - the array of tags to capture
* @returns {RegExp}
*/
function createInnermostTagRegExp(tagsArray) {
var openingTag = '\\[(' + tagsArray.join('|') + ')\\b(?:[ =]([\\w"#\\-\\:\\/= ]*?))?\\]',
notContainingOpeningTag = '((?:(?=([^\\[]+))\\4|\\[(?!\\1\\b(?:[ =](?:[\\w"#\\-\\:\\/= ]*?))?\\]))*?)',
closingTag = '\\[\\/\\1\\]';
return new RegExp( openingTag + notContainingOpeningTag + closingTag, 'i');
}
/*
* Escape the contents of a tag and mark the tag with a null unicode character.
* To be used in a loop with a regular expression that captures tags.
* Marking the tag prevents it from being matched again.
*
* @param {type} matchStr - the full match, including the opening and closing tags
* @param {type} tagName - the tag that was matched
* @param {type} tagParams - parameters passed to the tag
* @param {type} tagContents - everything between the opening and closing tags
* @returns {String} - the full match with the tag contents escaped and the tag marked with \u0000
*/
function escapeInnerTags(matchStr, tagName, tagParams, tagContents) {
tagParams = tagParams || "";
tagContents = tagContents || "";
tagContents = tagContents.replace(/\[/g, "&#91;").replace(/\]/g, "&#93;");
return "[\u0000" + tagName + tagParams + "]" + tagContents + "[/\u0000" + tagName + "]";
}
/*
* Escape all BBCodes that are inside the given tags.
*
* @param {string} text - the text to search through
* @param {string[]} tags - the tags to search for
* @returns {string} - the full text with the required code escaped
*/
function escapeBBCodesInsideTags(text, tags) {
var innerMostRegExp;
if (tags.length === 0 || text.length < 7)
return text;
innerMostRegExp = createInnermostTagRegExp(tags);
while (
text !== (text = text.replace(innerMostRegExp, escapeInnerTags))
);
return text.replace(/\u0000/g,'');
}
/*
* Process a tag and its contents according to the rules provided in parserTags.
*
* @param {type} matchStr - the full match, including the opening and closing tags
* @param {type} tagName - the tag that was matched
* @param {type} tagParams - parameters passed to the tag
* @param {type} tagContents - everything between the opening and closing tags
* @returns {string} - the fully processed tag and its contents
*/
function replaceTagsAndContent(matchStr, tagName, tagParams, tagContents) {
tagName = tagName.toLowerCase();
tagParams = tagParams || "";
tagContents = tagContents || "";
return parserTags[tagName].openTag(tagParams, tagContents) + (parserTags[tagName].content ? parserTags[tagName].content(tagParams, tagContents) : tagContents) + parserTags[tagName].closeTag(tagParams, tagContents);
}
function processTags(text, tagNames) {
var innerMostRegExp;
if (tagNames.length === 0 || text.length < 7)
return text;
innerMostRegExp = createInnermostTagRegExp(tagNames);
while (
text !== (text = text.replace(innerMostRegExp, replaceTagsAndContent))
);
return text;
}
/*
* Public Methods and Properties
*/
me.process = function(text, config) {
text = escapeBBCodesInsideTags(text, tagNamesNoParse);
return processTags(text, tagNames);
};
me.allowedTags = tagNames;
me.urlPattern = urlPattern;
me.emailPattern = emailPattern;
me.regExpAllowedColors = regExpAllowedColors;
me.regExpValidHexColors = regExpValidHexColors;
return me;
})(parserTags, parserColors);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,3 @@
/* SCEditor v2.1.3 | (C) 2017, Sam Clarke | sceditor.com/license */
!function(e){"use strict";var t="sce-autodraft-"+location.pathname+location.search;function i(e){localStorage.removeItem(e||t)}e.plugins.autosave=function(){var a,e=this,o=t,r=864e5,n=function(e){localStorage.setItem(o,JSON.stringify(e))},s=function(){return JSON.parse(localStorage.getItem(o))};e.init=function(){var e=(a=this).opts&&a.opts.autosave||{};n=e.save||n,s=e.load||s,o=e.storageKey||o,r=e.expires||r,function(){for(var e=0;e<localStorage.length;e++){var t=localStorage.key(e);if(/^sce\-autodraft\-/.test(t)){var a=JSON.parse(localStorage.getItem(o));a&&a.time<Date.now()-r&&i(t)}}}()},e.signalReady=function(){for(var e=a.getContentAreaContainer();e;){if(/form/i.test(e.nodeName)){e.addEventListener("submit",i.bind(null,o),!0);break}e=e.parentNode}var t=s();t&&(a.sourceMode(t.sourceMode),a.val(t.value,!1),a.focus(),t.sourceMode?a.sourceEditorCaret(t.caret):a.getRangeHelper().restoreRange()),n({caret:this.sourceEditorCaret(),sourceMode:this.sourceMode(),value:a.val(null,!1),time:Date.now()})},e.signalValuechangedEvent=function(e){n({caret:this.sourceEditorCaret(),sourceMode:this.sourceMode(),value:e.detail.rawValue,time:Date.now()})}},e.plugins.autosave.clear=i}(sceditor);

View File

@ -0,0 +1,3 @@
/* SCEditor v2.1.3 | (C) 2017, Sam Clarke | sceditor.com/license */
!function(u,e){"use strict";var a=e.dom,c=/(^|\s)(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/watch\?v=)([^"&?\/ ]{11})(?:\&[\&_\?0-9a-z\#]+)?(\s|$)/i;e.plugins.autoyoutube=function(){this.signalPasteRaw=function(e){if(!a.closest(this.currentNode(),"code")&&(e.html||e.text)){var t=u.createElement("div");e.html?t.innerHTML=e.html:t.textContent=e.text,function e(t){for(var o,n=t.firstChild;n;){if(3===n.nodeType){var i=n.nodeValue,r=n.parentNode,s=i.match(c);s&&(r.insertBefore(u.createTextNode(i.substr(0,s.index)+s[1]),n),r.insertBefore(a.parseHTML('<iframe width="560" height="315" frameborder="0" src="https://www.youtube-nocookie.com/embed/'+(o=s[2])+'" data-youtube-id="'+o+'" allowfullscreen></iframe>'),n),n.nodeValue=s[3]+i.substr(s.index+s[0].length))}else a.is(n,"code")||e(n);n=n.nextSibling}}(t),e.html=t.innerHTML}}}}(document,sceditor);

View File

@ -0,0 +1,3 @@
/* SCEditor v2.1.3 | (C) 2017, Sam Clarke | sceditor.com/license */
!function(n){"use strict";var v="data:image/gif;base64,R0lGODlhlgBkAPABAH19ffb29iH5BAAKAAAAIf4aQ3JlYXRlZCB3aXRoIGFqYXhsb2FkLmluZm8AIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAlgBkAAAC1YyPqcvtD6OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5LL5jE6r1+y2+w2Py+f0uv2OvwD2fP6iD/gH6Pc2GIhg2JeQSNjGuLf4GMlYKIloefAIUEl52ZmJyaY5mUhqyFnqmQr6KRoaMKp66hbLumpQ69oK+5qrOyg4a6qYV2x8jJysvMzc7PwMHS09TV1tfY2drb3N3e39DR4uPk5ebn6Onq6+zt7u/g4fL99UAAAh+QQACgAAACwAAAAAlgBkAIEAAAB9fX329vYAAAAC3JSPqcvtD6OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5LL5jE6r1+y2+w2Py+f0uv2OvwD2fP4iABgY+CcoCNeHuJdQyLjIaOiWiOj4CEhZ+SbZd/nI2RipqYhQOThKGpAZCuBZyArZprpqSupaCqtaazmLCRqai7rb2av5W5wqSShcm8fc7PwMHS09TV1tfY2drb3N3e39DR4uPk5ebn6Onq6+zt7u/g4fLz9PX29/j5/vVAAAIfkEAAoAAAAsAAAAAJYAZACBAAAAfX199vb2AAAAAuCUj6nL7Q+jnLTai7PevPsPhuJIluaJpurKtu4Lx/JM1/aN5/rO9/4PDAqHxKLxiEwql8ym8wmNSqfUqvWKzWq33K73Cw6Lx+Sy+YxOq9fstvsNj8vn9Lr9jr8E9nz+AgAYGLjQVwhXiJgguAiYgGjo9tinyCjoKLn3hpmJUGmJsBmguUnpCXCJOZraaXoKShoJe9DqehCqKlnqiZobuzrbyvuIO8xqKpxIPKlwrPCbBx0tPU1dbX2Nna29zd3t/Q0eLj5OXm5+jp6uvs7e7v4OHy8/T19vf4+fr7/P379UAAAh+QQACgAAACwAAAAAlgBkAIEAAAB9fX329vYAAAAC4JSPqcvtD6OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5LL5jE6r1+y2+w2Py+f0uv2OvwT2fP6iD7gAMEhICAeImIAYiFDoOPi22KcouZfw6BhZGUBZeYlp6LbJiTD6CQqg6Vm6eQqqKtkZ24iaKtrKunpQa9tmmju7Wwu7KFtMi3oYDMzompkHHS09TV1tfY2drb3N3e39DR4uPk5ebn6Onq6+zt7u/g4fLz9PX29/j5+vv8/f31QAADs=",c=void 0!==window.FileReader,u=/data:[^;]+;base64,/i;function g(e){for(var t=e.substr(5,e.indexOf(";")-5),n=atob(e.substr(e.indexOf(",")+1)),r=new Uint8Array(n.length),i=0;i<n.length;i++)r[i]=n[i].charCodeAt(0);try{return new Blob([r],{type:t})}catch(e){return null}}n.plugins.dragdrop=function(){if(c){var A,r,o,i,a,s=0;this.signalReady=function(){A=(r=this).opts.dragdrop||{},o=A.handleFile,i=r.getContentAreaContainer().parentNode,a=i.appendChild(n.dom.parseHTML('<div class="sceditor-dnd-cover" style="display: none"><p>'+r._("Drop files here")+"</p></div>").firstChild),i.addEventListener("dragover",e),i.addEventListener("dragleave",d),i.addEventListener("dragend",d),i.addEventListener("drop",t),r.getBody().addEventListener("dragover",e),r.getBody().addEventListener("drop",d)},this.signalPasteHtml=function(e){if(!("handlePaste"in A)||A.handlePaste){var t=document.createElement("div");t.innerHTML=e.val;for(var n=t.querySelectorAll("img"),r=0;r<n.length;r++){var i=n[r];if(u.test(i.src)){var a=g(i.src);a&&l(a)?o(a,f(i)):i.parentNode.removeChild(i)}}e.val=t.innerHTML}}}function d(){a.style.display="none",i.className=i.className.replace(/(^| )dnd( |$)/g,"")}function l(e){return!("application/x-moz-file"!==e.type&&A.allowedTypes&&A.allowedTypes.indexOf(e.type)<0)&&(!A.isAllowed||A.isAllowed(e))}function f(e){var n=document.createElement("img");function t(e){var t=r.getBody().ownerDocument.getElementById(n.id);t&&("string"==typeof e&&t.insertAdjacentHTML("afterend",e),t.parentNode.removeChild(t))}return n.src=v,n.className="sceditor-ignore",n.id="sce-dragdrop-"+s++,function(){return e?e.parentNode.replaceChild(n,e):r.wysiwygEditorInsertHtml(n.outerHTML),{insert:function(e){t(e)},cancel:t}}}function e(e){for(var t=e.dataTransfer,n=t.files.length||!t.items?t.files:t.items,r=0;r<n.length;r++)if("string"===n[r].kind)return;"none"===a.style.display&&(a.style.display="block",i.className+=" dnd"),e.preventDefault()}function t(e){var t=e.dataTransfer,n=t.files.length||!t.items?t.files:t.items;d();for(var r=0;r<n.length;r++){if("string"===n[r].kind)return;l(n[r])&&o(n[r],f())}e.preventDefault()}}}(sceditor);

View File

@ -0,0 +1,3 @@
/* SCEditor v2.1.3 | (C) 2017, Sam Clarke | sceditor.com/license */
!function(i){"use strict";i.plugins.format=function(){var n,a,c={p:"Paragraph",h1:"Heading 1",h2:"Heading 2",h3:"Heading 3",h4:"Heading 4",h5:"Heading 5",h6:"Heading 6",address:"Address",pre:"Preformatted Text"};this.init=function(){var e=this.opts,t=e.paragraphformat;e.format&&"bbcode"===e.format||(t&&(t.tags&&(c=t.tags),t.excludeTags&&t.excludeTags.forEach(function(e){delete c[e]})),this.commands.format||(this.commands.format={exec:a,txtExec:a,tooltip:"Format Paragraph"}),e.toolbar===i.defaultOptions.toolbar&&(e.toolbar=e.toolbar.replace(",color,",",color,format,")))},n=function(e,t){e.sourceMode()?e.insert("<"+t+">","</"+t+">"):e.execCommand("formatblock","<"+t+">")},a=function(e){var o=this,r=document.createElement("div");i.utils.each(c,function(t,a){var e=document.createElement("a");e.className="sceditor-option",e.textContent=a.name||a,e.addEventListener("click",function(e){o.closeDropDown(!0),a.exec?a.exec(o):n(o,t),e.preventDefault()}),r.appendChild(e)}),o.createDropDown(e,"format",r)}}}(sceditor);

View File

@ -0,0 +1,3 @@
/* SCEditor v2.1.3 | (C) 2017, Sam Clarke | sceditor.com/license */
!function(t){"use strict";var i=t.utils.extend;t.plugins.plaintext=function(){var e=!0;this.init=function(){var t=this.commands,n=this.opts;n&&n.plaintext&&n.plaintext.addButton&&(e=n.plaintext.enabled,t.pastetext=i(t.pastetext||{},{state:function(){return e?1:0},exec:function(){e=!e}}))},this.signalPasteRaw=function(t){if(e){if(t.html&&!t.text){var n=document.createElement("div");n.innerHTML=t.html,t.text=n.innerText}t.html=null}}}}(sceditor);

View File

@ -0,0 +1,2 @@
/* SCEditor v2.1.3 | (C) 2017, Sam Clarke | sceditor.com/license */

View File

@ -0,0 +1,3 @@
/* SCEditor v2.1.3 | (C) 2017, Sam Clarke | sceditor.com/license */
!function(e){"use strict";sceditor.plugins.undo=function(){var r,o,e=this,u=0,a=50,n=[],c=[],s=!1,l=function(e){s=!0,o=e.value,r.sourceMode(e.sourceMode),r.val(e.value,!1),r.focus(),e.sourceMode?r.sourceEditorCaret(e.caret):r.getRangeHelper().restoreRange(),s=!1};e.init=function(){a=(r=this).undoLimit||a,r.addShortcut("ctrl+z",e.undo),r.addShortcut("ctrl+shift+z",e.redo),r.addShortcut("ctrl+y",e.redo)},e.undo=function(){var e=c.pop(),t=r.val(null,!1);return e&&!n.length&&t===e.value&&(e=c.pop()),e&&(n.length||n.push({caret:r.sourceEditorCaret(),sourceMode:r.sourceMode(),value:t}),n.push(e),l(e)),!1},e.redo=function(){var e=n.pop();return c.length||(c.push(e),e=n.pop()),e&&(c.push(e),l(e)),!1},e.signalReady=function(){var e=r.val(null,!1);o=e,c.push({caret:this.sourceEditorCaret(),sourceMode:this.sourceMode(),value:e})},e.signalValuechangedEvent=function(e){var t=e.detail.rawValue;0<a&&c.length>a&&c.shift(),!s&&o&&o!==t&&(n.length=0,(u+=function(e,t){var r,o,u,a,n=e.length,c=t.length,s=Math.max(n,c);for(r=0;r<s&&e.charAt(r)===t.charAt(r);r++);for(u=n<c?c-n:0,a=c<n?n-c:0,o=s-1;0<=o&&e.charAt(o-u)===t.charAt(o-a);o--);return o-r+1}(o,t))<20||u<50&&!/\s$/g.test(e.rawValue)||(c.push({caret:r.sourceEditorCaret(),sourceMode:r.sourceMode(),value:t}),u=0,o=t))}}}();

View File

@ -0,0 +1,3 @@
/* SCEditor v2.1.3 | (C) 2017, Sam Clarke | sceditor.com/license */
!function(t,r){"use strict";var e=t.plugins;function n(c){if(c._scePatched)return c;var t=function(){for(var t=[],e=0;e<arguments.length;e++){var n=arguments[e];n&&n.nodeType?t.push(r(n)):t.push(n)}return c.apply(this,t)};return t._scePatched=!0,t}function c(t){if(t._scePatched)return t;var e=function(){return r(t.apply(this,arguments))};return e._scePatched=!0,e}var o=t.command.set;if(t.command.set=function(t,e){return e&&"function"==typeof e.exec&&(e.exec=n(e.exec)),e&&"function"==typeof e.txtExec&&(e.txtExec=n(e.txtExec)),o.call(this,t,e)},e.bbcode){var a=e.bbcode.bbcode.set;e.bbcode.bbcode.set=function(t,e){return e&&"function"==typeof e.format&&(e.format=n(e.format)),a.call(this,t,e)}}var i=t.create;t.create=function(t,e){if(i.call(this,t,e),t&&t._sceditor){var n=t._sceditor;n.getBody=c(n.getBody),n.getContentAreaContainer=c(n.getContentAreaContainer)}}}(sceditor,jQuery);

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
/*! SCEditor | (C) 2011-2013, Sam Clarke | sceditor.com/license */body,code:before,html,p,table{margin:0;padding:0;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:14px;color:#111;line-height:1.25;overflow:visible}html{height:100%}.ios{overflow:auto;-webkit-overflow-scrolling:touch}.ios body{position:relative;overflow:auto}body{min-height:100%;word-wrap:break-word}body.placeholder::before{content:attr(placeholder);color:#555;font-style:italic}ol,ul{margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0}table,td{border:1px dotted #000;empty-cells:show}table td{min-width:5px}code{display:block;background:#f1f1f1;white-space:pre;padding:1em;text-align:left;margin:.25em 0;direction:ltr}blockquote{background:#fff7d9;margin:.25em 0;border-left:.3em solid #f4e59f;padding:.5em .5em .5em .75em}blockquote cite{font-weight:700;display:block;font-size:1em;margin:0 -.5em .25em -.75em;padding:0 .5em .15em .75em;border-bottom:1px solid #f4e59f}h1,h2,h3,h4,h5,h6{padding:0;margin:0}div,p{min-height:1.25em}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -416,6 +416,10 @@ function checkString(value){
*/ */
function removeHtmlTags(input){ function removeHtmlTags(input){
//Check if input string is empty
if(input == null)
return "";
//Prepare update //Prepare update
var output = input; var output = input;
@ -435,6 +439,25 @@ function removeHtmlTags(input){
return output; 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 * Check a URL validity
* *

View File

@ -106,13 +106,19 @@ ComunicWeb.components.posts.edit = {
}); });
//Create update editor //Create update editor
var editorDiv = createElem2({ var editorTextarea = createElem2({
appendTo: updateDiv, appendTo: updateDiv,
type: "div", type: "textarea",
class: "editor", 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 //Create function to close modal
var closeModal = function(){ var closeModal = function(){
@ -131,7 +137,7 @@ ComunicWeb.components.posts.edit = {
} }
//Get the new post content //Get the new post content
var new_content = editorDiv.innerHTML; var new_content = sceditor.instance(editorTextarea).getWysiwygEditorValue();
//Check the new post content //Check the new post content
if(!ComunicWeb.components.posts.form._check_message(new_content)){ if(!ComunicWeb.components.posts.form._check_message(new_content)){

View File

@ -42,18 +42,35 @@ ComunicWeb.components.posts.form = {
}); });
//Create post message textarea //Create post message textarea
var inputMessageDiv = createElem2({ var inputMessageTextarea = createElem2({
appendTo: newPostMessageContener, appendTo: newPostMessageContener,
type: "div", type: "textarea",
class: "new-message wdt-emoji-bundle-enabled", class: "new-message",
innerHTML: "" innerHTML: ""
}); });
//Enable bootstrap-wysiwyg var inputMessageToolbarTarget = createElem2({
$(inputMessageDiv).wysiwyg(); 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 //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 //Add the different post types
@ -344,7 +361,7 @@ ComunicWeb.components.posts.form = {
var datas = new FormData(); var datas = new FormData();
//Get the message content //Get the message content
var message_content = inputMessageDiv.innerHTML; var message_content = sceditor.instance(inputMessageTextarea).getWysiwygEditorValue();
datas.append("content", message_content); datas.append("content", message_content);
//Check if the message includes an image //Check if the message includes an image

View File

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

View File

@ -73,6 +73,9 @@ class Dev {
//Emoji picker //Emoji picker
"3rdparty/wdt-emoji/wdt-emoji-bundle.css", "3rdparty/wdt-emoji/wdt-emoji-bundle.css",
//SCEditor (BBCode editor)
"3rdparty/sceditor/themes/default.min.css"
); );
/** /**
@ -146,6 +149,15 @@ class Dev {
//JSZip utils //JSZip utils
"3rdparty/jszip-utils/jszip-utils.js", "3rdparty/jszip-utils/jszip-utils.js",
//SCEditor (BBCode editor)
"3rdparty/sceditor/sceditor.min.js",
"3rdparty/sceditor/formats/bbcode.js",
"3rdparty/sceditor/formats/xhtml.js",
//JS BBCode Parser
"3rdparty/js-bbcode-parser/bbcode-config.js",
"3rdparty/js-bbcode-parser/bbcode-parser.js",
); );
/** /**