|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* bbCode control by subBlue design [ www.subBlue.com ]
|
|
|
4c79b5 |
* Includes unixsafe colour palette selector by SHS`
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Startup variables
|
|
|
4c79b5 |
var imageTag = false;
|
|
|
4c79b5 |
var theSelection = false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Check for Browser & Platform for PC & IE specific bits
|
|
|
4c79b5 |
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
|
|
|
4c79b5 |
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
|
|
|
4c79b5 |
var clientVer = parseInt(navigator.appVersion); // Get browser version
|
|
|
4c79b5 |
|
|
|
4c79b5 |
var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1));
|
|
|
4c79b5 |
var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
var baseHeight;
|
|
|
4c79b5 |
onload_functions.push('initInsertions()');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Shows the help messages in the helpline window
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function helpline(help)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
document.forms[form_name].helpbox.value = help_line[help];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Fix a bug involving the TextRange object. From
|
|
|
4c79b5 |
* http://www.frostjedi.com/terra/scripts/demo/caretBug.html
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function initInsertions()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var doc;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (document.forms[form_name])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
doc = document;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
doc = opener.document;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
var textarea = doc.forms[form_name].elements[text_name];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (is_ie && typeof(baseHeight) != 'number')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
textarea.focus();
|
|
|
4c79b5 |
baseHeight = doc.selection.createRange().duplicate().boundingHeight;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!document.forms[form_name])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
document.body.focus();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* bbstyle
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function bbstyle(bbnumber)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (bbnumber != -1)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
insert_text('[*]');
|
|
|
4c79b5 |
document.forms[form_name].elements[text_name].focus();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Apply bbcodes
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function bbfontstyle(bbopen, bbclose)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
theSelection = false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
var textarea = document.forms[form_name].elements[text_name];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
textarea.focus();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ((clientVer >= 4) && is_ie && is_win)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Get text selection
|
|
|
4c79b5 |
theSelection = document.selection.createRange().text;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (theSelection)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Add tags around selection
|
|
|
4c79b5 |
document.selection.createRange().text = bbopen + theSelection + bbclose;
|
|
|
4c79b5 |
document.forms[form_name].elements[text_name].focus();
|
|
|
4c79b5 |
theSelection = '';
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (document.forms[form_name].elements[text_name].selectionEnd && (document.forms[form_name].elements[text_name].selectionEnd - document.forms[form_name].elements[text_name].selectionStart > 0))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
mozWrap(document.forms[form_name].elements[text_name], bbopen, bbclose);
|
|
|
4c79b5 |
document.forms[form_name].elements[text_name].focus();
|
|
|
4c79b5 |
theSelection = '';
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
//The new position for the cursor after adding the bbcode
|
|
|
4c79b5 |
var caret_pos = getCaretPosition(textarea).start;
|
|
|
4c79b5 |
var new_pos = caret_pos + bbopen.length;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Open tag
|
|
|
4c79b5 |
insert_text(bbopen + bbclose);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Center the cursor when we don't have a selection
|
|
|
4c79b5 |
// Gecko and proper browsers
|
|
|
4c79b5 |
if (!isNaN(textarea.selectionStart))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
textarea.selectionStart = new_pos;
|
|
|
4c79b5 |
textarea.selectionEnd = new_pos;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
// IE
|
|
|
4c79b5 |
else if (document.selection)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var range = textarea.createTextRange();
|
|
|
4c79b5 |
range.move("character", new_pos);
|
|
|
4c79b5 |
range.select();
|
|
|
4c79b5 |
storeCaret(textarea);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
textarea.focus();
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Insert text at position
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function insert_text(text, spaces, popup)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var textarea;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!popup)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
textarea = document.forms[form_name].elements[text_name];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
textarea = opener.document.forms[form_name].elements[text_name];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
if (spaces)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
text = ' ' + text + ' ';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!isNaN(textarea.selectionStart))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var sel_start = textarea.selectionStart;
|
|
|
4c79b5 |
var sel_end = textarea.selectionEnd;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
mozWrap(textarea, text, '')
|
|
|
4c79b5 |
textarea.selectionStart = sel_start + text.length;
|
|
|
4c79b5 |
textarea.selectionEnd = sel_end + text.length;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (textarea.createTextRange && textarea.caretPos)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (baseHeight != textarea.caretPos.boundingHeight)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
textarea.focus();
|
|
|
4c79b5 |
storeCaret(textarea);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
var caret_pos = textarea.caretPos;
|
|
|
4c79b5 |
caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
textarea.value = textarea.value + text;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
if (!popup)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
textarea.focus();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Add inline attachment at position
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function attach_inline(index, filename)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
|
|
|
4c79b5 |
document.forms[form_name].elements[text_name].focus();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Add quote text to message
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function addquote(post_id, username)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var message_name = 'message_' + post_id;
|
|
|
4c79b5 |
var theSelection = '';
|
|
|
4c79b5 |
var divarea = false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (document.all)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
divarea = document.all[message_name];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
divarea = document.getElementById(message_name);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Get text selection - not only the post content :(
|
|
|
4c79b5 |
if (window.getSelection)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
theSelection = window.getSelection().toString();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (document.getSelection)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
theSelection = document.getSelection();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (document.selection)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
theSelection = document.selection.createRange().text;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (divarea.innerHTML)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
theSelection = divarea.innerHTML.replace(/ /ig, '\n');
|
|
|
4c79b5 |
theSelection = theSelection.replace(/<br\/>/ig, '\n');
|
|
|
4c79b5 |
theSelection = theSelection.replace(/<\;/ig, '<');
|
|
|
4c79b5 |
theSelection = theSelection.replace(/>\;/ig, '>');
|
|
|
4c79b5 |
theSelection = theSelection.replace(/&\;/ig, '&';;
|
|
|
4c79b5 |
theSelection = theSelection.replace(/ \;/ig, ' ');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (document.all)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
theSelection = divarea.innerText;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (divarea.textContent)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
theSelection = divarea.textContent;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (divarea.firstChild.nodeValue)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
theSelection = divarea.firstChild.nodeValue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (theSelection)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
insert_text('[quote="' + username + '"]' + theSelection + '[/quote]');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* From http://www.massless.org/mozedit/
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function mozWrap(txtarea, open, close)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var selLength = txtarea.textLength;
|
|
|
4c79b5 |
var selStart = txtarea.selectionStart;
|
|
|
4c79b5 |
var selEnd = txtarea.selectionEnd;
|
|
|
4c79b5 |
var scrollTop = txtarea.scrollTop;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (selEnd == 1 || selEnd == 2)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
selEnd = selLength;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
var s1 = (txtarea.value).substring(0,selStart);
|
|
|
4c79b5 |
var s2 = (txtarea.value).substring(selStart, selEnd)
|
|
|
4c79b5 |
var s3 = (txtarea.value).substring(selEnd, selLength);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
txtarea.value = s1 + open + s2 + close + s3;
|
|
|
4c79b5 |
txtarea.selectionStart = selEnd + open.length + close.length;
|
|
|
4c79b5 |
txtarea.selectionEnd = txtarea.selectionStart;
|
|
|
4c79b5 |
txtarea.focus();
|
|
|
4c79b5 |
txtarea.scrollTop = scrollTop;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Insert at Caret position. Code from
|
|
|
4c79b5 |
* http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function storeCaret(textEl)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (textEl.createTextRange)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
textEl.caretPos = document.selection.createRange().duplicate();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Color pallette
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function colorPalette(dir, width, height)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var r = 0, g = 0, b = 0;
|
|
|
4c79b5 |
var numberList = new Array(6);
|
|
|
4c79b5 |
var color = '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
numberList[0] = '00';
|
|
|
4c79b5 |
numberList[1] = '40';
|
|
|
4c79b5 |
numberList[2] = '80';
|
|
|
4c79b5 |
numberList[3] = 'BF';
|
|
|
4c79b5 |
numberList[4] = 'FF';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
document.writeln('');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
for (r = 0; r < 5; r++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (dir == 'h')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
document.writeln('');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
for (g = 0; g < 5; g++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (dir == 'v')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
document.writeln('');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
for (b = 0; b < 5; b++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
|
|
|
4c79b5 |
document.write('');
|
|
|
4c79b5 |
document.write('');
|
|
|
4c79b5 |
document.writeln('');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (dir == 'v')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
document.writeln('');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (dir == 'h')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
document.writeln('');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
document.writeln('');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Caret Position object
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function caretPosition()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var start = null;
|
|
|
4c79b5 |
var end = null;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Get the caret position in an textarea
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function getCaretPosition(txtarea)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var caretPos = new caretPosition();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// simple Gecko/Opera way
|
|
|
4c79b5 |
if(txtarea.selectionStart || txtarea.selectionStart == 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
caretPos.start = txtarea.selectionStart;
|
|
|
4c79b5 |
caretPos.end = txtarea.selectionEnd;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
// dirty and slow IE way
|
|
|
4c79b5 |
else if(document.selection)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// get current selection
|
|
|
4c79b5 |
var range = document.selection.createRange();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// a new selection of the whole textarea
|
|
|
4c79b5 |
var range_all = document.body.createTextRange();
|
|
|
4c79b5 |
range_all.moveToElementText(txtarea);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// calculate selection start point by moving beginning of range_all to beginning of range
|
|
|
4c79b5 |
var sel_start;
|
|
|
4c79b5 |
for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
range_all.moveStart('character', 1);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
txtarea.sel_start = sel_start;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// we ignore the end value for IE, this is already dirty enough and we don't need it
|
|
|
4c79b5 |
caretPos.start = txtarea.sel_start;
|
|
|
4c79b5 |
caretPos.end = txtarea.sel_start;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return caretPos;
|
|
|
4c79b5 |
}
|