Skip to content

Instantly share code, notes, and snippets.

@Legend-of-iPhoenix
Created September 16, 2020 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Legend-of-iPhoenix/d901960fb0be86764f229dc45bc2cb87 to your computer and use it in GitHub Desktop.
Save Legend-of-iPhoenix/d901960fb0be86764f229dc45bc2cb87 to your computer and use it in GitHub Desktop.
<!--
// bbCode control by
// subBlue design
// www.subBlue.com
// Startup variables
var imageTag = false;
var theSelection = false;
// Helpline messages
b_help = "Bold text: [b]text[/b] (alt+b)";
i_help = "Italic text: [i]text[/i] (alt+i)";
u_help = "Underline text: [u]text[/u] (alt+u)";
q_help = "Quote text: [quote]text[/quote] (alt+q)";
c_help = "Code display: [code]code[/code] (alt+c)";
l_help = "List: [list]text[/list] (alt+l)";
o_help = "Ordered list: [list=]text[/list] (alt+o)";
p_help = "Insert image: [img]http://image_url[/img] (alt+p)";
w_help = "Insert URL: [url]http://url[/url] or [url=http://url]URL text[/url] (alt+w)";
a_help = "Close all open bbCode tags";
s_help = "Font color: [color=red]text[/color] Tip: you can also use color=#FF0000";
f_help = "Font size: [size=x-small]small text[/size]";
// Define the bbCode tags
bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]','[youtube]','[/youtube]');
imageTag = false;
// Shows the help messages in the helpline window
function helpline(help) {
document.post.helpbox.value = eval(help + "_help");
}
function checkForm() {
formErrors = false;
if (document.post.message.value.length < 2) {
formErrors = "You must enter a message when posting.";
}
if (formErrors) {
alert(formErrors);
return false;
}
return true;
}
function emoticon(text) {
text = ' ' + text + ' ';
insertAtCursor(text);
}
function insertAtCursor(text) {
var el = document.post.message;
var val = el.value, endIndex, range, doc = el.ownerDocument;
if (typeof el.selectionStart == "number"
&& typeof el.selectionEnd == "number") {
endIndex = el.selectionEnd;
el.value = val.slice(0, endIndex) + text + val.slice(endIndex);
el.selectionStart = el.selectionEnd = endIndex + text.length;
} else if (doc.selection != "undefined" && doc.selection.createRange) {
el.focus();
range = doc.selection.createRange();
range.collapse(false);
range.text = text;
range.select();
}
el.focus();
}
function bbfontstyle(bbopen, bbclose) {
var txtarea = document.post.message;
if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
{
mozWrap(txtarea, bbopen, bbclose);
return;
}
else
{
txtarea.value += bbopen + bbclose;
txtarea.focus();
}
storeCaret(txtarea);
}
function bbstyle(bbnumber) {
var txtarea = document.post.message;
txtarea.focus();
donotinsert = false;
theSelection = false;
bblast = 0;
if (bbnumber == -1) { // Close all open tags & default button names
while (bbcode[0]) {
butnumber = bbcode.pop() - 1;
txtarea.value += bbtags[butnumber + 1];
buttext = eval('document.post.addbbcode' + butnumber + '.value');
eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
}
imageTag = false; // All tags are closed including image tags :D
txtarea.focus();
return;
}
if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
{
mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
return;
}
// Find last occurance of an open tag the same as the one just clicked
for (i = 0; i < bbcode.length; i++) {
if (bbcode[i] == bbnumber+1) {
bblast = i;
donotinsert = true;
}
}
if (donotinsert) { // Close all open tags up to the one just clicked & default button names
while (bbcode[bblast]) {
butnumber = bbcode.pop() - 1;
txtarea.value += bbtags[butnumber + 1];
buttext = eval('document.post.addbbcode' + butnumber + '.value');
eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
imageTag = false;
}
txtarea.focus();
return;
} else { // Open tags
if (imageTag && (bbnumber != 14)) { // Close image tag before adding another
txtarea.value += bbtags[15];
lastvalue = bbcode.pop() - 1; // Remove the close image tag from the list
document.post.addbbcode14.value = "Img"; // Return button back to normal state
imageTag = false;
}
// Open tag
txtarea.value += bbtags[bbnumber];
if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
bbcode.push(bbnumber + 1);
eval('document.post.addbbcode'+bbnumber+'.value += "*"');
txtarea.focus();
return;
}
storeCaret(txtarea);
}
function bbsymbol(symbol) {
insertAtCursor(symbol);
}
// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
var selLength = txtarea.textLength;
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
if (selEnd == 1 || selEnd == 2)
selEnd = selLength;
var s1 = (txtarea.value).substring(0,selStart);
var s2 = (txtarea.value).substring(selStart, selEnd)
var s3 = (txtarea.value).substring(selEnd, selLength);
txtarea.value = s1 + open + s2 + close + s3;
return;
}
// Insert at Caret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}
//-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment