1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/styles/subsilver2/template/editor.js Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,462 @@
1.4 +/**
1.5 +* bbCode control by subBlue design [ www.subBlue.com ]
1.6 +* Includes unixsafe colour palette selector by SHS`
1.7 +*/
1.8 +
1.9 +// Startup variables
1.10 +var imageTag = false;
1.11 +var theSelection = false;
1.12 +var bbcodeEnabled = true;
1.13 +
1.14 +// Check for Browser & Platform for PC & IE specific bits
1.15 +// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
1.16 +var clientPC = navigator.userAgent.toLowerCase(); // Get client info
1.17 +var clientVer = parseInt(navigator.appVersion); // Get browser version
1.18 +
1.19 +var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1));
1.20 +var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1));
1.21 +
1.22 +var baseHeight;
1.23 +
1.24 +/**
1.25 +* Shows the help messages in the helpline window
1.26 +*/
1.27 +function helpline(help)
1.28 +{
1.29 + document.forms[form_name].helpbox.value = help_line[help];
1.30 +}
1.31 +
1.32 +/**
1.33 +* Fix a bug involving the TextRange object. From
1.34 +* http://www.frostjedi.com/terra/scripts/demo/caretBug.html
1.35 +*/
1.36 +function initInsertions()
1.37 +{
1.38 + var doc;
1.39 +
1.40 + if (document.forms[form_name])
1.41 + {
1.42 + doc = document;
1.43 + }
1.44 + else
1.45 + {
1.46 + doc = opener.document;
1.47 + }
1.48 +
1.49 + var textarea = doc.forms[form_name].elements[text_name];
1.50 + if (is_ie && typeof(baseHeight) != 'number')
1.51 + {
1.52 + textarea.focus();
1.53 + baseHeight = doc.selection.createRange().duplicate().boundingHeight;
1.54 +
1.55 + if (!document.forms[form_name])
1.56 + {
1.57 + document.body.focus();
1.58 + }
1.59 + }
1.60 +}
1.61 +
1.62 +/**
1.63 +* bbstyle
1.64 +*/
1.65 +function bbstyle(bbnumber)
1.66 +{
1.67 + if (bbnumber != -1)
1.68 + {
1.69 + bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]);
1.70 + }
1.71 + else
1.72 + {
1.73 + insert_text('[*]');
1.74 + document.forms[form_name].elements[text_name].focus();
1.75 + }
1.76 +}
1.77 +
1.78 +/**
1.79 +* Apply bbcodes
1.80 +*/
1.81 +function bbfontstyle(bbopen, bbclose)
1.82 +{
1.83 + theSelection = false;
1.84 +
1.85 + var textarea = document.forms[form_name].elements[text_name];
1.86 +
1.87 + textarea.focus();
1.88 +
1.89 + if ((clientVer >= 4) && is_ie && is_win)
1.90 + {
1.91 + // Get text selection
1.92 + theSelection = document.selection.createRange().text;
1.93 +
1.94 + if (theSelection)
1.95 + {
1.96 + // Add tags around selection
1.97 + document.selection.createRange().text = bbopen + theSelection + bbclose;
1.98 + document.forms[form_name].elements[text_name].focus();
1.99 + theSelection = '';
1.100 + return;
1.101 + }
1.102 + }
1.103 + 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))
1.104 + {
1.105 + mozWrap(document.forms[form_name].elements[text_name], bbopen, bbclose);
1.106 + document.forms[form_name].elements[text_name].focus();
1.107 + theSelection = '';
1.108 + return;
1.109 + }
1.110 +
1.111 + //The new position for the cursor after adding the bbcode
1.112 + var caret_pos = getCaretPosition(textarea).start;
1.113 + var new_pos = caret_pos + bbopen.length;
1.114 +
1.115 + // Open tag
1.116 + insert_text(bbopen + bbclose);
1.117 +
1.118 + // Center the cursor when we don't have a selection
1.119 + // Gecko and proper browsers
1.120 + if (!isNaN(textarea.selectionStart))
1.121 + {
1.122 + textarea.selectionStart = new_pos;
1.123 + textarea.selectionEnd = new_pos;
1.124 + }
1.125 + // IE
1.126 + else if (document.selection)
1.127 + {
1.128 + var range = textarea.createTextRange();
1.129 + range.move("character", new_pos);
1.130 + range.select();
1.131 + storeCaret(textarea);
1.132 + }
1.133 +
1.134 + textarea.focus();
1.135 + return;
1.136 +}
1.137 +
1.138 +/**
1.139 +* Insert text at position
1.140 +*/
1.141 +function insert_text(text, spaces, popup)
1.142 +{
1.143 + var textarea;
1.144 +
1.145 + if (!popup)
1.146 + {
1.147 + textarea = document.forms[form_name].elements[text_name];
1.148 + }
1.149 + else
1.150 + {
1.151 + textarea = opener.document.forms[form_name].elements[text_name];
1.152 + }
1.153 + if (spaces)
1.154 + {
1.155 + text = ' ' + text + ' ';
1.156 + }
1.157 +
1.158 + // Since IE9, IE also has textarea.selectionStart, but it still needs to be treated the old way.
1.159 + // Therefore we simply add a !is_ie here until IE fixes the text-selection completely.
1.160 + if (!isNaN(textarea.selectionStart) && !is_ie)
1.161 + {
1.162 + var sel_start = textarea.selectionStart;
1.163 + var sel_end = textarea.selectionEnd;
1.164 +
1.165 + mozWrap(textarea, text, '');
1.166 + textarea.selectionStart = sel_start + text.length;
1.167 + textarea.selectionEnd = sel_end + text.length;
1.168 + }
1.169 +
1.170 + else if (textarea.createTextRange && textarea.caretPos)
1.171 + {
1.172 + if (baseHeight != textarea.caretPos.boundingHeight)
1.173 + {
1.174 + textarea.focus();
1.175 + storeCaret(textarea);
1.176 + }
1.177 + var caret_pos = textarea.caretPos;
1.178 + caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
1.179 +
1.180 + }
1.181 + else
1.182 + {
1.183 + textarea.value = textarea.value + text;
1.184 + }
1.185 + if (!popup)
1.186 + {
1.187 + textarea.focus();
1.188 + }
1.189 +
1.190 +}
1.191 +
1.192 +/**
1.193 +* Add inline attachment at position
1.194 +*/
1.195 +function attach_inline(index, filename)
1.196 +{
1.197 + insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
1.198 + document.forms[form_name].elements[text_name].focus();
1.199 +}
1.200 +
1.201 +/**
1.202 +* Add quote text to message
1.203 +*/
1.204 +function addquote(post_id, username, l_wrote)
1.205 +{
1.206 + var message_name = 'message_' + post_id;
1.207 + var theSelection = '';
1.208 + var divarea = false;
1.209 +
1.210 + if (l_wrote === undefined)
1.211 + {
1.212 + // Backwards compatibility
1.213 + l_wrote = 'wrote';
1.214 + }
1.215 +
1.216 + if (document.all)
1.217 + {
1.218 + divarea = document.all[message_name];
1.219 + }
1.220 + else
1.221 + {
1.222 + divarea = document.getElementById(message_name);
1.223 + }
1.224 +
1.225 + // Get text selection - not only the post content :(
1.226 + // IE9 must use the document.selection method but has the *.getSelection so we just force no IE
1.227 + if (window.getSelection && !is_ie)
1.228 + {
1.229 + theSelection = window.getSelection().toString();
1.230 + }
1.231 + else if (document.getSelection && !is_ie)
1.232 + {
1.233 + theSelection = document.getSelection();
1.234 + }
1.235 + else if (document.selection)
1.236 + {
1.237 + theSelection = document.selection.createRange().text;
1.238 + }
1.239 +
1.240 + if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null)
1.241 + {
1.242 + if (divarea.innerHTML)
1.243 + {
1.244 + theSelection = divarea.innerHTML.replace(/<br>/ig, '\n');
1.245 + theSelection = theSelection.replace(/<br\/>/ig, '\n');
1.246 + theSelection = theSelection.replace(/<\;/ig, '<');
1.247 + theSelection = theSelection.replace(/>\;/ig, '>');
1.248 + theSelection = theSelection.replace(/&\;/ig, '&');
1.249 + theSelection = theSelection.replace(/ \;/ig, ' ');
1.250 + }
1.251 + else if (document.all)
1.252 + {
1.253 + theSelection = divarea.innerText;
1.254 + }
1.255 + else if (divarea.textContent)
1.256 + {
1.257 + theSelection = divarea.textContent;
1.258 + }
1.259 + else if (divarea.firstChild.nodeValue)
1.260 + {
1.261 + theSelection = divarea.firstChild.nodeValue;
1.262 + }
1.263 + }
1.264 +
1.265 + if (theSelection)
1.266 + {
1.267 + if (bbcodeEnabled)
1.268 + {
1.269 + insert_text('[quote="' + username + '"]' + theSelection + '[/quote]');
1.270 + }
1.271 + else
1.272 + {
1.273 + insert_text(username + ' ' + l_wrote + ':' + '\n');
1.274 + var lines = split_lines(theSelection);
1.275 + for (i = 0; i < lines.length; i++)
1.276 + {
1.277 + insert_text('> ' + lines[i] + '\n');
1.278 + }
1.279 + }
1.280 + }
1.281 +
1.282 + return;
1.283 +}
1.284 +
1.285 +
1.286 +function split_lines(text)
1.287 +{
1.288 + var lines = text.split('\n');
1.289 + var splitLines = new Array();
1.290 + var j = 0;
1.291 + for(i = 0; i < lines.length; i++)
1.292 + {
1.293 + if (lines[i].length <= 80)
1.294 + {
1.295 + splitLines[j] = lines[i];
1.296 + j++;
1.297 + }
1.298 + else
1.299 + {
1.300 + var line = lines[i];
1.301 + do
1.302 + {
1.303 + var splitAt = line.indexOf(' ', 80);
1.304 +
1.305 + if (splitAt == -1)
1.306 + {
1.307 + splitLines[j] = line;
1.308 + j++;
1.309 + }
1.310 + else
1.311 + {
1.312 + splitLines[j] = line.substring(0, splitAt);
1.313 + line = line.substring(splitAt);
1.314 + j++;
1.315 + }
1.316 + }
1.317 + while(splitAt != -1);
1.318 + }
1.319 + }
1.320 + return splitLines;
1.321 +}
1.322 +
1.323 +/**
1.324 +* From http://www.massless.org/mozedit/
1.325 +*/
1.326 +function mozWrap(txtarea, open, close)
1.327 +{
1.328 + var selLength = (typeof(txtarea.textLength) == 'undefined') ? txtarea.value.length : txtarea.textLength;
1.329 + var selStart = txtarea.selectionStart;
1.330 + var selEnd = txtarea.selectionEnd;
1.331 + var scrollTop = txtarea.scrollTop;
1.332 +
1.333 + if (selEnd == 1 || selEnd == 2)
1.334 + {
1.335 + selEnd = selLength;
1.336 + }
1.337 +
1.338 + var s1 = (txtarea.value).substring(0,selStart);
1.339 + var s2 = (txtarea.value).substring(selStart, selEnd);
1.340 + var s3 = (txtarea.value).substring(selEnd, selLength);
1.341 +
1.342 + txtarea.value = s1 + open + s2 + close + s3;
1.343 + txtarea.selectionStart = selStart + open.length;
1.344 + txtarea.selectionEnd = selEnd + open.length;
1.345 + txtarea.focus();
1.346 + txtarea.scrollTop = scrollTop;
1.347 +
1.348 + return;
1.349 +}
1.350 +
1.351 +/**
1.352 +* Insert at Caret position. Code from
1.353 +* http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
1.354 +*/
1.355 +function storeCaret(textEl)
1.356 +{
1.357 + if (textEl.createTextRange)
1.358 + {
1.359 + textEl.caretPos = document.selection.createRange().duplicate();
1.360 + }
1.361 +}
1.362 +
1.363 +/**
1.364 +* Color pallette
1.365 +*/
1.366 +function colorPalette(dir, width, height)
1.367 +{
1.368 + var r = 0, g = 0, b = 0;
1.369 + var numberList = new Array(6);
1.370 + var color = '';
1.371 +
1.372 + numberList[0] = '00';
1.373 + numberList[1] = '40';
1.374 + numberList[2] = '80';
1.375 + numberList[3] = 'BF';
1.376 + numberList[4] = 'FF';
1.377 +
1.378 + document.writeln('<table cellspacing="1" cellpadding="0" border="0">');
1.379 +
1.380 + for (r = 0; r < 5; r++)
1.381 + {
1.382 + if (dir == 'h')
1.383 + {
1.384 + document.writeln('<tr>');
1.385 + }
1.386 +
1.387 + for (g = 0; g < 5; g++)
1.388 + {
1.389 + if (dir == 'v')
1.390 + {
1.391 + document.writeln('<tr>');
1.392 + }
1.393 +
1.394 + for (b = 0; b < 5; b++)
1.395 + {
1.396 + color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
1.397 + document.write('<td bgcolor="#' + color + '" style="width: ' + width + 'px; height: ' + height + 'px;">');
1.398 + document.write('<a href="#" onclick="bbfontstyle(\'[color=#' + color + ']\', \'[/color]\'); return false;"><img src="images/spacer.gif" width="' + width + '" height="' + height + '" alt="#' + color + '" title="#' + color + '" /></a>');
1.399 + document.writeln('</td>');
1.400 + }
1.401 +
1.402 + if (dir == 'v')
1.403 + {
1.404 + document.writeln('</tr>');
1.405 + }
1.406 + }
1.407 +
1.408 + if (dir == 'h')
1.409 + {
1.410 + document.writeln('</tr>');
1.411 + }
1.412 + }
1.413 + document.writeln('</table>');
1.414 +}
1.415 +
1.416 +
1.417 +/**
1.418 +* Caret Position object
1.419 +*/
1.420 +function caretPosition()
1.421 +{
1.422 + var start = null;
1.423 + var end = null;
1.424 +}
1.425 +
1.426 +
1.427 +/**
1.428 +* Get the caret position in an textarea
1.429 +*/
1.430 +function getCaretPosition(txtarea)
1.431 +{
1.432 + var caretPos = new caretPosition();
1.433 +
1.434 + // simple Gecko/Opera way
1.435 + if(txtarea.selectionStart || txtarea.selectionStart == 0)
1.436 + {
1.437 + caretPos.start = txtarea.selectionStart;
1.438 + caretPos.end = txtarea.selectionEnd;
1.439 + }
1.440 + // dirty and slow IE way
1.441 + else if(document.selection)
1.442 + {
1.443 + // get current selection
1.444 + var range = document.selection.createRange();
1.445 +
1.446 + // a new selection of the whole textarea
1.447 + var range_all = document.body.createTextRange();
1.448 + range_all.moveToElementText(txtarea);
1.449 +
1.450 + // calculate selection start point by moving beginning of range_all to beginning of range
1.451 + var sel_start;
1.452 + for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++)
1.453 + {
1.454 + range_all.moveStart('character', 1);
1.455 + }
1.456 +
1.457 + txtarea.sel_start = sel_start;
1.458 +
1.459 + // we ignore the end value for IE, this is already dirty enough and we don't need it
1.460 + caretPos.start = txtarea.sel_start;
1.461 + caretPos.end = txtarea.sel_start;
1.462 + }
1.463 +
1.464 + return caretPos;
1.465 +}
1.466 \ No newline at end of file