2
* bbCode control by subBlue design [ www.subBlue.com ]
3
* Includes unixsafe colour palette selector by SHS`
8
var theSelection = false;
10
// Check for Browser & Platform for PC & IE specific bits
11
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
12
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
13
var clientVer = parseInt(navigator.appVersion); // Get browser version
15
var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1));
16
var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1));
19
window.onload = initInsertions;
22
* Shows the help messages in the helpline window
24
function helpline(help)
26
document.forms[form_name].helpbox.value = help_line[help];
30
* Fix a bug involving the TextRange object. From
31
* http://www.frostjedi.com/terra/scripts/demo/caretBug.html
33
function initInsertions()
36
if(document.forms[form_name])
42
doc = opener.document;
45
var textarea = doc.forms[form_name].elements[text_name];
46
if (is_ie && typeof(baseHeight) != 'number')
49
baseHeight = doc.selection.createRange().duplicate().boundingHeight;
50
// document.body.focus();
57
function bbstyle(bbnumber)
61
bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]);
66
document.forms[form_name].elements[text_name].focus();
73
function bbfontstyle(bbopen, bbclose)
77
var textarea = document.forms[form_name].elements[text_name];
81
if ((clientVer >= 4) && is_ie && is_win)
84
theSelection = document.selection.createRange().text;
88
// Add tags around selection
89
document.selection.createRange().text = bbopen + theSelection + bbclose;
90
document.forms[form_name].elements[text_name].focus();
95
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))
97
mozWrap(document.forms[form_name].elements[text_name], bbopen, bbclose);
98
document.forms[form_name].elements[text_name].focus();
103
//The new position for the cursor after adding the bbcode
104
var caret_pos = getCaretPosition(textarea).start;
105
var new_pos = caret_pos + bbopen.length;
108
insert_text(bbopen + bbclose);
110
// Center the cursor when we don't have a selection
111
// Gecko and proper browsers
112
if (!isNaN(textarea.selectionStart))
114
textarea.selectionStart = new_pos;
115
textarea.selectionEnd = new_pos;
118
else if (document.selection)
120
var range = textarea.createTextRange();
121
range.move("character", new_pos);
123
storeCaret(textarea);
131
* Insert text at position
133
function insert_text(text, spaces, popup)
139
textarea = document.forms[form_name].elements[text_name];
143
textarea = opener.document.forms[form_name].elements[text_name];
148
text = ' ' + text + ' ';
151
if (!isNaN(textarea.selectionStart))
153
var sel_start = textarea.selectionStart;
154
var sel_end = textarea.selectionEnd;
156
mozWrap(textarea, text, '')
157
textarea.selectionStart = sel_start + text.length;
158
textarea.selectionEnd = sel_end + text.length;
161
else if (textarea.createTextRange && textarea.caretPos)
163
if (baseHeight != textarea.caretPos.boundingHeight)
166
storeCaret(textarea);
168
var caret_pos = textarea.caretPos;
169
caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
174
textarea.value = textarea.value + text;
185
* Add inline attachment at position
187
function attach_inline(index, filename)
189
insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
190
document.forms[form_name].elements[text_name].focus();
194
* Add quote text to message
196
function addquote(post_id, username)
198
var message_name = 'message_' + post_id;
199
var theSelection = '';
204
divarea = document.all[message_name];
208
divarea = document.getElementById(message_name);
211
// Get text selection - not only the post content :(
212
if (window.getSelection)
214
theSelection = window.getSelection().toString();
216
else if (document.getSelection)
218
theSelection = document.getSelection();
220
else if (document.selection)
222
theSelection = document.selection.createRange().text;
225
if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null)
227
if (divarea.innerHTML)
229
theSelection = divarea.innerHTML.replace(/<br>/ig, '\n');
230
theSelection = theSelection.replace(/<br\/>/ig, '\n');
231
theSelection = theSelection.replace(/<\;/ig, '<');
232
theSelection = theSelection.replace(/>\;/ig, '>');
233
theSelection = theSelection.replace(/&\;/ig, '&');
235
else if (document.all)
237
theSelection = divarea.innerText;
239
else if (divarea.textContent)
241
theSelection = divarea.textContent;
243
else if (divarea.firstChild.nodeValue)
245
theSelection = divarea.firstChild.nodeValue;
251
insert_text('[quote="' + username + '"]' + theSelection + '[/quote]');
258
* From http://www.massless.org/mozedit/
260
function mozWrap(txtarea, open, close)
262
var selLength = txtarea.textLength;
263
var selStart = txtarea.selectionStart;
264
var selEnd = txtarea.selectionEnd;
265
var scrollTop = txtarea.scrollTop;
267
if (selEnd == 1 || selEnd == 2)
272
var s1 = (txtarea.value).substring(0,selStart);
273
var s2 = (txtarea.value).substring(selStart, selEnd)
274
var s3 = (txtarea.value).substring(selEnd, selLength);
276
txtarea.value = s1 + open + s2 + close + s3;
277
txtarea.selectionStart = selEnd + open.length + close.length;
278
txtarea.selectionEnd = txtarea.selectionStart;
280
txtarea.scrollTop = scrollTop;
286
* Insert at Caret position. Code from
287
* http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
289
function storeCaret(textEl)
291
if (textEl.createTextRange)
293
textEl.caretPos = document.selection.createRange().duplicate();
300
function colorPalette(dir, width, height)
302
var r = 0, g = 0, b = 0;
303
var numberList = new Array(6);
306
numberList[0] = '00';
307
numberList[1] = '40';
308
numberList[2] = '80';
309
numberList[3] = 'BF';
310
numberList[4] = 'FF';
312
document.writeln('<table class="type2">');
314
for (r = 0; r < 5; r++)
318
document.writeln('<tr>');
321
for (g = 0; g < 5; g++)
325
document.writeln('<tr>');
328
for (b = 0; b < 5; b++)
330
color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
331
document.write('<td bgcolor="#' + color + '">');
332
document.write('<a href="#" onclick="bbfontstyle(\'[color=#' + color + ']\', \'[/color]\'); return false;" onmouseover="helpline(\'s\');" onmouseout="helpline(\'tip\');"><img src="images/spacer.gif" width="' + width + '" height="' + height + '" alt="#' + color + '" title="#' + color + '" /></a>');
333
document.writeln('</td>');
338
document.writeln('</tr>');
344
document.writeln('</tr>');
347
document.writeln('</table>');
352
* Caret Position object
354
function caretPosition()
362
* Get the caret position in an textarea
364
function getCaretPosition(txtarea)
366
var caretPos = new caretPosition();
368
// simple Gecko/Opera way
369
if (txtarea.selectionStart || txtarea.selectionStart == 0)
371
caretPos.start = txtarea.selectionStart;
372
caretPos.end = txtarea.selectionEnd;
374
// dirty and slow IE way
375
else if (document.selection)
377
// get current selection
378
var range = document.selection.createRange();
380
// a new selection of the whole textarea
381
var range_all = document.body.createTextRange();
382
range_all.moveToElementText(txtarea);
384
// calculate selection start point by moving beginning of range_all to beginning of range
386
for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++)
388
range_all.moveStart('character', 1);
391
txtarea.sel_start = sel_start;
393
// we ignore the end value for IE, this is already dirty enough and we don't need it
394
caretPos.start = txtarea.sel_start;
395
caretPos.end = txtarea.sel_start;
b'\\ No newline at end of file'