1.1 --- a/styles/cubometry-style/template/editor.js Sat Mar 10 00:18:56 2012 +0400
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,459 +0,0 @@
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 -
1.13 -var bbcodeEnabled = true;
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 -var baseHeight;
1.22 -
1.23 -/**
1.24 -* Shows the help messages in the helpline window
1.25 -*/
1.26 -function helpline(help)
1.27 -{
1.28 - document.forms[form_name].helpbox.value = help_line[help];
1.29 -}
1.30 -
1.31 -/**
1.32 -* Fix a bug involving the TextRange object. From
1.33 -* http://www.frostjedi.com/terra/scripts/demo/caretBug.html
1.34 -*/
1.35 -function initInsertions()
1.36 -{
1.37 - var doc;
1.38 -
1.39 - if (document.forms[form_name])
1.40 - {
1.41 - doc = document;
1.42 - }
1.43 - else
1.44 - {
1.45 - doc = opener.document;
1.46 - }
1.47 -
1.48 - var textarea = doc.forms[form_name].elements[text_name];
1.49 -
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 - else if (textarea.createTextRange && textarea.caretPos)
1.170 - {
1.171 - if (baseHeight != textarea.caretPos.boundingHeight)
1.172 - {
1.173 - textarea.focus();
1.174 - storeCaret(textarea);
1.175 - }
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 - else
1.181 - {
1.182 - textarea.value = textarea.value + text;
1.183 - }
1.184 - if (!popup)
1.185 - {
1.186 - textarea.focus();
1.187 - }
1.188 -}
1.189 -
1.190 -/**
1.191 -* Add inline attachment at position
1.192 -*/
1.193 -function attach_inline(index, filename)
1.194 -{
1.195 - insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
1.196 - document.forms[form_name].elements[text_name].focus();
1.197 -}
1.198 -
1.199 -/**
1.200 -* Add quote text to message
1.201 -*/
1.202 -function addquote(post_id, username, l_wrote)
1.203 -{
1.204 - var message_name = 'message_' + post_id;
1.205 - var theSelection = '';
1.206 - var divarea = false;
1.207 -
1.208 - if (l_wrote === undefined)
1.209 - {
1.210 - // Backwards compatibility
1.211 - l_wrote = 'wrote';
1.212 - }
1.213 -
1.214 - if (document.all)
1.215 - {
1.216 - divarea = document.all[message_name];
1.217 - }
1.218 - else
1.219 - {
1.220 - divarea = document.getElementById(message_name);
1.221 - }
1.222 -
1.223 - // Get text selection - not only the post content :(
1.224 - // IE9 must use the document.selection method but has the *.getSelection so we just force no IE
1.225 - if (window.getSelection && !is_ie)
1.226 - {
1.227 - theSelection = window.getSelection().toString();
1.228 - }
1.229 - else if (document.getSelection && !is_ie)
1.230 - {
1.231 - theSelection = document.getSelection();
1.232 - }
1.233 - else if (document.selection)
1.234 - {
1.235 - theSelection = document.selection.createRange().text;
1.236 - }
1.237 -
1.238 - if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null)
1.239 - {
1.240 - if (divarea.innerHTML)
1.241 - {
1.242 - theSelection = divarea.innerHTML.replace(/<br>/ig, '\n');
1.243 - theSelection = theSelection.replace(/<br\/>/ig, '\n');
1.244 - theSelection = theSelection.replace(/<\;/ig, '<');
1.245 - theSelection = theSelection.replace(/>\;/ig, '>');
1.246 - theSelection = theSelection.replace(/&\;/ig, '&');
1.247 - theSelection = theSelection.replace(/ \;/ig, ' ');
1.248 - }
1.249 - else if (document.all)
1.250 - {
1.251 - theSelection = divarea.innerText;
1.252 - }
1.253 - else if (divarea.textContent)
1.254 - {
1.255 - theSelection = divarea.textContent;
1.256 - }
1.257 - else if (divarea.firstChild.nodeValue)
1.258 - {
1.259 - theSelection = divarea.firstChild.nodeValue;
1.260 - }
1.261 - }
1.262 -
1.263 - if (theSelection)
1.264 - {
1.265 - if (bbcodeEnabled)
1.266 - {
1.267 - insert_text('[quote="' + username + '"]' + theSelection + '[/quote]');
1.268 - }
1.269 - else
1.270 - {
1.271 - insert_text(username + ' ' + l_wrote + ':' + '\n');
1.272 - var lines = split_lines(theSelection);
1.273 - for (i = 0; i < lines.length; i++)
1.274 - {
1.275 - insert_text('> ' + lines[i] + '\n');
1.276 - }
1.277 - }
1.278 - }
1.279 -
1.280 - return;
1.281 -}
1.282 -
1.283 -function split_lines(text)
1.284 -{
1.285 - var lines = text.split('\n');
1.286 - var splitLines = new Array();
1.287 - var j = 0;
1.288 - for(i = 0; i < lines.length; i++)
1.289 - {
1.290 - if (lines[i].length <= 80)
1.291 - {
1.292 - splitLines[j] = lines[i];
1.293 - j++;
1.294 - }
1.295 - else
1.296 - {
1.297 - var line = lines[i];
1.298 - do
1.299 - {
1.300 - var splitAt = line.indexOf(' ', 80);
1.301 -
1.302 - if (splitAt == -1)
1.303 - {
1.304 - splitLines[j] = line;
1.305 - j++;
1.306 - }
1.307 - else
1.308 - {
1.309 - splitLines[j] = line.substring(0, splitAt);
1.310 - line = line.substring(splitAt);
1.311 - j++;
1.312 - }
1.313 - }
1.314 - while(splitAt != -1);
1.315 - }
1.316 - }
1.317 - return splitLines;
1.318 -}
1.319 -/**
1.320 -* From http://www.massless.org/mozedit/
1.321 -*/
1.322 -function mozWrap(txtarea, open, close)
1.323 -{
1.324 - var selLength = (typeof(txtarea.textLength) == 'undefined') ? txtarea.value.length : txtarea.textLength;
1.325 - var selStart = txtarea.selectionStart;
1.326 - var selEnd = txtarea.selectionEnd;
1.327 - var scrollTop = txtarea.scrollTop;
1.328 -
1.329 - if (selEnd == 1 || selEnd == 2)
1.330 - {
1.331 - selEnd = selLength;
1.332 - }
1.333 -
1.334 - var s1 = (txtarea.value).substring(0,selStart);
1.335 - var s2 = (txtarea.value).substring(selStart, selEnd);
1.336 - var s3 = (txtarea.value).substring(selEnd, selLength);
1.337 -
1.338 - txtarea.value = s1 + open + s2 + close + s3;
1.339 - txtarea.selectionStart = selStart + open.length;
1.340 - txtarea.selectionEnd = selEnd + open.length;
1.341 - txtarea.focus();
1.342 - txtarea.scrollTop = scrollTop;
1.343 -
1.344 - return;
1.345 -}
1.346 -
1.347 -/**
1.348 -* Insert at Caret position. Code from
1.349 -* http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
1.350 -*/
1.351 -function storeCaret(textEl)
1.352 -{
1.353 - if (textEl.createTextRange)
1.354 - {
1.355 - textEl.caretPos = document.selection.createRange().duplicate();
1.356 - }
1.357 -}
1.358 -
1.359 -/**
1.360 -* Color pallette
1.361 -*/
1.362 -function colorPalette(dir, width, height)
1.363 -{
1.364 - var r = 0, g = 0, b = 0;
1.365 - var numberList = new Array(6);
1.366 - var color = '';
1.367 -
1.368 - numberList[0] = '00';
1.369 - numberList[1] = '40';
1.370 - numberList[2] = '80';
1.371 - numberList[3] = 'BF';
1.372 - numberList[4] = 'FF';
1.373 -
1.374 - document.writeln('<table cellspacing="1" cellpadding="0" border="0">');
1.375 -
1.376 - for (r = 0; r < 5; r++)
1.377 - {
1.378 - if (dir == 'h')
1.379 - {
1.380 - document.writeln('<tr>');
1.381 - }
1.382 -
1.383 - for (g = 0; g < 5; g++)
1.384 - {
1.385 - if (dir == 'v')
1.386 - {
1.387 - document.writeln('<tr>');
1.388 - }
1.389 -
1.390 - for (b = 0; b < 5; b++)
1.391 - {
1.392 - color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
1.393 - document.write('<td bgcolor="#' + color + '" style="width: ' + width + 'px; height: ' + height + 'px;">');
1.394 - 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.395 - document.writeln('</td>');
1.396 - }
1.397 -
1.398 - if (dir == 'v')
1.399 - {
1.400 - document.writeln('</tr>');
1.401 - }
1.402 - }
1.403 -
1.404 - if (dir == 'h')
1.405 - {
1.406 - document.writeln('</tr>');
1.407 - }
1.408 - }
1.409 - document.writeln('</table>');
1.410 -}
1.411 -
1.412 -
1.413 -/**
1.414 -* Caret Position object
1.415 -*/
1.416 -function caretPosition()
1.417 -{
1.418 - var start = null;
1.419 - var end = null;
1.420 -}
1.421 -
1.422 -
1.423 -/**
1.424 -* Get the caret position in an textarea
1.425 -*/
1.426 -function getCaretPosition(txtarea)
1.427 -{
1.428 - var caretPos = new caretPosition();
1.429 -
1.430 - // simple Gecko/Opera way
1.431 - if(txtarea.selectionStart || txtarea.selectionStart == 0)
1.432 - {
1.433 - caretPos.start = txtarea.selectionStart;
1.434 - caretPos.end = txtarea.selectionEnd;
1.435 - }
1.436 - // dirty and slow IE way
1.437 - else if(document.selection)
1.438 - {
1.439 -
1.440 - // get current selection
1.441 - var range = document.selection.createRange();
1.442 -
1.443 - // a new selection of the whole textarea
1.444 - var range_all = document.body.createTextRange();
1.445 - range_all.moveToElementText(txtarea);
1.446 -
1.447 - // calculate selection start point by moving beginning of range_all to beginning of range
1.448 - var sel_start;
1.449 - for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++)
1.450 - {
1.451 - range_all.moveStart('character', 1);
1.452 - }
1.453 -
1.454 - txtarea.sel_start = sel_start;
1.455 -
1.456 - // we ignore the end value for IE, this is already dirty enough and we don't need it
1.457 - caretPos.start = txtarea.sel_start;
1.458 - caretPos.end = txtarea.sel_start;
1.459 - }
1.460 -
1.461 - return caretPos;
1.462 -}
1.463 \ No newline at end of file