[ Index ] |
PHP Cross Reference of phpBB 3.0 Beta 3 |
[Summary view] [Print] [Text view]
1 /** 2 * bbCode control by subBlue design [ www.subBlue.com ] 3 * Includes unixsafe colour palette selector by SHS` 4 */ 5 6 // Startup variables 7 var imageTag = false; 8 var theSelection = false; 9 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 14 15 var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1)); 16 var is_nav = ((clientPC.indexOf('mozilla') != -1) && (clientPC.indexOf('spoofer') == -1) && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera') == -1) && (clientPC.indexOf('webtv') == -1) && (clientPC.indexOf('hotjava') == -1)); 17 18 var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1)); 19 var is_mac = (clientPC.indexOf('mac') != -1); 20 21 /** 22 * Shows the help messages in the helpline window 23 */ 24 function helpline(help) 25 { 26 document.forms[form_name].helpbox.value = eval(help + '_help'); 27 } 28 29 /** 30 * Replacement for arrayname.length property 31 */ 32 function getarraysize(thearray) 33 { 34 for (i = 0; i < thearray.length; i++) 35 { 36 if (typeof thearray[i] == 'undefined' || thearray[i] == '' || thearray[i] == null) 37 { 38 return i; 39 } 40 } 41 42 return thearray.length; 43 } 44 45 /** 46 * Replacement for arrayname.push(value) not implemented in IE until version 5.5 47 * Appends element to the array 48 */ 49 function arraypush(thearray,value) 50 { 51 thearray[getarraysize(thearray)] = value; 52 } 53 54 /** 55 * Replacement for arrayname.pop() not implemented in IE until version 5.5 56 * Removes and returns the last element of an array 57 */ 58 function arraypop(thearray) 59 { 60 thearraysize = getarraysize(thearray); 61 retval = thearray[thearraysize - 1]; 62 delete thearray[thearraysize - 1]; 63 64 return retval; 65 } 66 67 /** 68 * Insert emoticon 69 */ 70 function smiley(text) 71 { 72 text = ' ' + text + ' '; 73 74 if (document.forms[form_name].elements[text_name].createTextRange && document.forms[form_name].elements[text_name].caretPos) 75 { 76 var caretPos = document.forms[form_name].elements[text_name].caretPos; 77 78 caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text; 79 document.forms[form_name].elements[text_name].focus(); 80 } 81 else 82 { 83 var selStart = document.forms[form_name].elements[text_name].selectionStart; 84 var selEnd = document.forms[form_name].elements[text_name].selectionEnd; 85 86 mozWrap(document.forms[form_name].elements[text_name], text, '') 87 document.forms[form_name].elements[text_name].focus(); 88 document.forms[form_name].elements[text_name].selectionStart = selStart + text.length; 89 document.forms[form_name].elements[text_name].selectionEnd = selEnd + text.length; 90 } 91 } 92 93 /** 94 * Apply bbcodes 95 */ 96 function bbfontstyle(bbopen, bbclose) 97 { 98 theSelection = false; 99 document.forms[form_name].elements[text_name].focus(); 100 101 if ((clientVer >= 4) && is_ie && is_win) 102 { 103 // Get text selection 104 theSelection = document.selection.createRange().text; 105 106 if (theSelection) 107 { 108 // Add tags around selection 109 document.selection.createRange().text = bbopen + theSelection + bbclose; 110 document.forms[form_name].elements[text_name].focus(); 111 theSelection = ''; 112 return; 113 } 114 } 115 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)) 116 { 117 mozWrap(document.forms[form_name].elements[text_name], bbopen, bbclose); 118 document.forms[form_name].elements[text_name].focus(); 119 theSelection = ''; 120 return; 121 } 122 123 // Close image tag before adding 124 if (imageTag) 125 { 126 insert_text(bbtags[15]); 127 128 // Remove the close image tag from the list 129 lastValue = arraypop(bbcode) - 1; 130 131 // Return button back to normal state 132 document.forms[form_name].addbbcode14.value = 'Img'; 133 imageTag = false; 134 } 135 136 // Open tag 137 insert_text(bbopen + bbclose); 138 139 document.forms[form_name].elements[text_name].focus(); 140 141 storeCaret(document.forms[form_name].elements[text_name]); 142 return; 143 } 144 145 /** 146 * Insert text at position 147 */ 148 function insert_text(text) 149 { 150 if (document.forms[form_name].elements[text_name].createTextRange && document.forms[form_name].elements[text_name].caretPos) 151 { 152 var caretPos = document.forms[form_name].elements[text_name].caretPos; 153 caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text; 154 } 155 else if (document.forms[form_name].elements[text_name].selectionStart) 156 { 157 var selStart = document.forms[form_name].elements[text_name].selectionStart; 158 var selEnd = document.forms[form_name].elements[text_name].selectionEnd; 159 160 mozWrap(document.forms[form_name].elements[text_name], text, '') 161 document.forms[form_name].elements[text_name].selectionStart = selStart + text.length; 162 document.forms[form_name].elements[text_name].selectionEnd = selEnd + text.length; 163 } 164 else 165 { 166 document.forms[form_name].elements[text_name].value = document.forms[form_name].elements[text_name].value + text; 167 } 168 } 169 170 /** 171 * Add inline attachment at position 172 */ 173 function attach_inline() 174 { 175 insert_text('[attachment=' + document.forms[form_name].elements['attachments'].value + ']' + document.forms[form_name].elements['attachments'].options[document.forms[form_name].elements['attachments'].selectedIndex].text + '[/attachment]'); 176 document.forms[form_name].elements[text_name].focus(); 177 } 178 179 /** 180 * Add quote text to message 181 */ 182 function addquote(post_id, username) 183 { 184 var message_name = 'message_' + post_id; 185 var theSelection = ''; 186 var divarea = false; 187 188 if (document.all) 189 { 190 eval('divarea = document.all.' + message_name + ';'); 191 } 192 else 193 { 194 eval("divarea = document.getElementById('" + message_name + "');"); 195 } 196 197 // Get text selection - not only the post content :( 198 if (window.getSelection) 199 { 200 theSelection = window.getSelection().toString(); 201 } 202 else if (document.getSelection) 203 { 204 theSelection = document.getSelection(); 205 } 206 else if (document.selection) 207 { 208 theSelection = document.selection.createRange().text; 209 } 210 211 if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null) 212 { 213 if (document.all) 214 { 215 theSelection = divarea.innerText; 216 } 217 else if (divarea.textContent) 218 { 219 theSelection = divarea.textContent; 220 } 221 else if (divarea.firstChild.nodeValue) 222 { 223 theSelection = divarea.firstChild.nodeValue; 224 } 225 } 226 227 if (theSelection) 228 { 229 insert_text('[quote="' + username + '"]' + theSelection + '[/quote]'); 230 } 231 232 return; 233 } 234 235 /** 236 * bbstyle 237 */ 238 function bbstyle(bbnumber) 239 { 240 donotinsert = false; 241 theSelection = false; 242 bblast = 0; 243 document.forms[form_name].elements[text_name].focus(); 244 245 // Close all open tags & default button names 246 if (bbnumber == -1) 247 { 248 while (bbcode[0]) 249 { 250 butnumber = arraypop(bbcode) - 1; 251 document.forms[form_name].elements[text_name].value += bbtags[butnumber + 1]; 252 buttext = eval('document.forms[form_name].addbbcode' + butnumber + '.value'); 253 254 if (buttext != '[*]') 255 { 256 eval('document.forms[form_name].addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"'); 257 } 258 } 259 260 document.forms[form_name].addbbcode10.value = 'List'; 261 bbtags[10] = '[list]'; 262 263 document.forms[form_name].addbbcode12.value = 'List='; 264 bbtags[12] = '[list=]'; 265 266 // All tags are closed including image tags :D 267 imageTag = false; 268 document.forms[form_name].elements[text_name].focus(); 269 270 return; 271 } 272 273 // [*] doesn't have an end tag 274 noEndTag = (bbtags[bbnumber] == '[*]') 275 276 if ((clientVer >= 4) && is_ie && is_win) 277 { 278 // Get text selection 279 theSelection = document.selection.createRange().text; 280 281 if (theSelection) 282 { 283 // Add tags around selection 284 document.selection.createRange().text = bbtags[bbnumber] + theSelection + ((!noEndTag) ? bbtags[bbnumber+1] : ''); 285 document.forms[form_name].elements[text_name].focus(); 286 theSelection = ''; 287 return; 288 } 289 } 290 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)) 291 { 292 mozWrap(document.forms[form_name].elements[text_name], bbtags[bbnumber], ((!noEndTag) ? bbtags[bbnumber+1] : '')); 293 document.forms[form_name].elements[text_name].focus(); 294 theSelection = ''; 295 return; 296 } 297 298 // Find last occurance of an open tag the same as the one just clicked 299 for (i = 0; i < bbcode.length; i++) 300 { 301 if (bbcode[i] == bbnumber+1) 302 { 303 bblast = i; 304 donotinsert = true; 305 } 306 } 307 308 if (bbnumber == 10 && bbtags[10] != '[*]') 309 { 310 if (donotinsert) 311 { 312 document.forms[form_name].addbbcode12.value = 'List='; 313 tmp_help = o_help; 314 o_help = e_help; 315 e_help = tmp_help; 316 bbtags[12] = '[list=]'; 317 } 318 else 319 { 320 document.forms[form_name].addbbcode12.value = '[*]'; 321 tmp_help = o_help; 322 o_help = e_help; 323 e_help = tmp_help; 324 bbtags[12] = '[*]'; 325 } 326 } 327 328 if (bbnumber == 12 && bbtags[12] != '[*]') 329 { 330 if (donotinsert) 331 { 332 document.forms[form_name].addbbcode10.value = 'List'; 333 tmp_help = l_help; 334 l_help = e_help; 335 e_help = tmp_help; 336 bbtags[10] = '[list]'; 337 } 338 else 339 { 340 document.forms[form_name].addbbcode10.value = '[*]'; 341 tmp_help = l_help; 342 l_help = e_help; 343 e_help = tmp_help; 344 bbtags[10] = '[*]'; 345 } 346 } 347 348 // Close all open tags up to the one just clicked & default button names 349 if (donotinsert) 350 { 351 while (bbcode[bblast]) 352 { 353 butnumber = arraypop(bbcode) - 1; 354 355 if (bbtags[butnumber] != '[*]') 356 { 357 insert_text(bbtags[butnumber + 1]); 358 } 359 else 360 { 361 insert_text(bbtags[butnumber]); 362 } 363 364 buttext = eval('document.forms[form_name].addbbcode' + butnumber + '.value'); 365 366 if (bbtags[butnumber] != '[*]') 367 { 368 eval('document.forms[form_name].addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"'); 369 } 370 imageTag = false; 371 } 372 document.forms[form_name].elements[text_name].focus(); 373 return; 374 } 375 else 376 { 377 // Open tags 378 379 // Close image tag before adding another 380 if (imageTag && (bbnumber != 14)) 381 { 382 insert_text(bbtags[15]); 383 384 // Remove the close image tag from the list 385 lastValue = arraypop(bbcode) - 1; 386 387 // Return button back to normal state 388 document.forms[form_name].addbbcode14.value = 'Img'; 389 imageTag = false; 390 } 391 392 // Open tag 393 insert_text(bbtags[bbnumber]); 394 395 // Check to stop additional tags after an unclosed image tag 396 if (bbnumber == 14 && imageTag == false) 397 { 398 imageTag = 1; 399 } 400 401 if (bbtags[bbnumber] != '[*]') 402 { 403 arraypush(bbcode, bbnumber + 1); 404 eval('document.forms[form_name].addbbcode'+bbnumber+'.value += "*"'); 405 } 406 407 document.forms[form_name].elements[text_name].focus(); 408 return; 409 } 410 411 storeCaret(document.forms[form_name].elements[text_name]); 412 } 413 414 /** 415 * From http://www.massless.org/mozedit/ 416 */ 417 function mozWrap(txtarea, open, close) 418 { 419 var selLength = txtarea.textLength; 420 var selStart = txtarea.selectionStart; 421 var selEnd = txtarea.selectionEnd; 422 var scrollTop = txtarea.scrollTop; 423 424 if (selEnd == 1 || selEnd == 2) 425 { 426 selEnd = selLength; 427 } 428 429 var s1 = (txtarea.value).substring(0,selStart); 430 var s2 = (txtarea.value).substring(selStart, selEnd) 431 var s3 = (txtarea.value).substring(selEnd, selLength); 432 433 txtarea.value = s1 + open + s2 + close + s3; 434 txtarea.selectionStart = selEnd + open.length + close.length; 435 txtarea.selectionEnd = txtarea.selectionStart; 436 txtarea.focus(); 437 txtarea.scrollTop = scrollTop; 438 439 return; 440 } 441 442 /** 443 * Insert at Claret position. Code from 444 * http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130 445 */ 446 function storeCaret(textEl) 447 { 448 if (textEl.createTextRange) 449 { 450 textEl.caretPos = document.selection.createRange().duplicate(); 451 } 452 } 453 454 /** 455 * Color pallette 456 */ 457 function colorPalette(dir, width, height) 458 { 459 var r = 0, g = 0, b = 0; 460 var numberList = new Array(6); 461 462 numberList[0] = '00'; 463 numberList[1] = '40'; 464 numberList[2] = '80'; 465 numberList[3] = 'BF'; 466 numberList[4] = 'FF'; 467 468 document.write('<table cellspacing="1" cellpadding="0" border="0" class="type2">'); 469 470 for (r = 0; r < 5; r++) 471 { 472 if (dir == 'h') 473 { 474 document.writeln('<tr>'); 475 } 476 477 for (g = 0; g < 5; g++) 478 { 479 if (dir == 'v') 480 { 481 document.writeln('<tr>'); 482 } 483 484 for (b = 0; b < 5; b++) 485 { 486 color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]); 487 document.write('<td style="line-height: ' + height + 'px; background-color:#' + color + '; width: ' + width + 'px; height: ' + height + 'px;">'); 488 document.write('<a href="#" onclick="bbfontstyle(\'[color=#' + color + ']\', \'[/color]\'); return false;" onmouseover="helpline(\'s\');"><img src="images/spacer.gif" width="' + width + '" height="' + height + '" alt="#' + color + '" title="#' + color + '" /></a>'); 489 document.writeln('</td>'); 490 } 491 492 if (dir == 'v') 493 { 494 document.writeln('</tr>'); 495 } 496 } 497 498 if (dir == 'h') 499 { 500 document.writeln('</tr>'); 501 } 502 } 503 document.writeln('</table>'); 504 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 22 00:35:05 2006 | Cross-referenced by PHPXref 0.6 |