// bbCode control by // subBlue design // www.subBlue.com // adapted for Joomlaboard by the Two Shoes Module Factory (www.tsmf.net) // Startup variables var imageTag = false; var theSelection = false; // Check for Browser & Platform for PC & IE specific bits // More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html var clientPC = navigator.userAgent.toLowerCase(); // Get client info var clientVer = parseInt(navigator.appVersion); // Get browser version var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1)); 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)); var is_moz = 0; var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1)); var is_mac = (clientPC.indexOf("mac")!=-1); // Define the bbCode tags bbcode = new Array(); bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[ul]','[/ul]','[ol]','[/ol]','[img size=150]','[/img]','[url]','[/url]','[li]','[/li]'); imageTag = false; // Shows the help messages in the helpline window function helpline(help) { document.postform.helpbox.value = eval(help + "_help"); } // Replacement for arrayname.length property function getarraysize(thearray) { for (i = 0; i < thearray.length; i++) { if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null)) return i; } return thearray.length; } // Replacement for arrayname.push(value) not implemented in IE until version 5.5 // Appends element to the array function arraypush(thearray,value) { thearray[ getarraysize(thearray) ] = value; } // Replacement for arrayname.pop() not implemented in IE until version 5.5 // Removes and returns the last element of an array function arraypop(thearray) { thearraysize = getarraysize(thearray); retval = thearray[thearraysize - 1]; delete thearray[thearraysize - 1]; return retval; } function bbstyle(bbnumber) { var txtarea = document.postform.message; txtarea.focus(); donotinsert = false; theSelection = false; bblast = 0; if (bbnumber == -1) { // Close all open tags & default button names while (bbcode[0]) { butnumber = arraypop(bbcode) - 1; txtarea.value += bbtags[butnumber + 1]; buttext = eval('document.postform.addbbcode' + butnumber + '.value'); eval('document.postform.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"'); } imageTag = false; // All tags are closed including image tags :D txtarea.focus(); return; } if ((clientVer >= 4) && is_ie && is_win) { theSelection = document.selection.createRange().text; // Get text selection if (theSelection) { // Add tags around selection document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1]; txtarea.focus(); theSelection = ''; return; } else { txtarea.focus(); document.selection.createRange().text = bbtags[bbnumber] + bbtags[bbnumber + 1]; return; } } else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0)) { mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]); return; } else //if (txtarea.selectionEnd == txtarea.selectionStart) // don't know if we need it... it works even if commented out. ;) { txtarea.value = txtarea.value.substring(0, txtarea.selectionStart) + bbtags[bbnumber] + bbtags[bbnumber + 1] + txtarea.value.substring(txtarea.selectionEnd, txtarea.value.length); return; } // Find last occurance of an open tag the same as the one just clicked for (i = 0; i < bbcode.length; i++) { if (bbcode[i] == bbnumber+1) { bblast = i; donotinsert = true; } } if (donotinsert) { // Close all open tags up to the one just clicked & default button names while (bbcode[bblast]) { butnumber = arraypop(bbcode) - 1; txtarea.value += bbtags[butnumber + 1]; buttext = eval('document.postform.addbbcode' + butnumber + '.value'); eval('document.postform.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"'); imageTag = false; } txtarea.focus(); return; } else { // Open tags if (imageTag && (bbnumber != 14)) { // Close image tag before adding another txtarea.value += bbtags[15]; lastValue = arraypop(bbcode) - 1; // Remove the close image tag from the list document.postform.addbbcode14.value = "Img"; // Return button back to normal state imageTag = false; } // Open tag txtarea.value += bbtags[bbnumber]; if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag arraypush(bbcode,bbnumber+1); eval('document.postform.addbbcode'+bbnumber+'.value += "*"'); txtarea.focus(); return; } storeCaret(txtarea); } // From http://www.massless.org/mozedit/ function mozWrap(txtarea, open, close) { var selLength = txtarea.textLength; var selStart = txtarea.selectionStart; var selEnd = txtarea.selectionEnd; if (selEnd == 1 || selEnd == 2) selEnd = selLength; var s1 = (txtarea.value).substring(0,selStart); var s2 = (txtarea.value).substring(selStart, selEnd) var s3 = (txtarea.value).substring(selEnd, selLength); txtarea.value = s1 + open + s2 + close + s3; return; } // Insert at Claret position. Code from // http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130 function storeCaret(textEl) { if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate(); } function bbfontstyle(bbopen, bbclose) { var txtarea = document.postform.message; if ((clientVer >= 4) && is_ie && is_win) { theSelection = document.selection.createRange().text; txtarea.focus(); if (!theSelection) { document.selection.createRange().text = bbopen + bbclose; } else { document.selection.createRange().text = bbopen + theSelection + bbclose; } txtarea.focus(); return; } else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0)) { mozWrap(txtarea, bbopen, bbclose); return; } else { txtarea.value = txtarea.value.substring(0, txtarea.selectionStart) + bbopen + bbclose + txtarea.value.substring(txtarea.selectionEnd, txtarea.value.length); txtarea.focus(); } storeCaret(txtarea); } //####################################################### //code used in My Profile (userprofile.php) function textCounter(field, countfield, maxlimit) { if(field.value.length > maxlimit){ field.value = field.value.substring(0, maxlimit); } else{ countfield.value = maxlimit - field.value.length; } } //********************************************************* // Insert emoticons function emo($e) { var textfield = document.postform.message; // Support for IE if (document.selection) { textfield.focus(); var sel = document.selection.createRange(); sel.text = $e; } // Support for Mozilla else if (textfield.selectionStart || textfield.selectionStart == '0') { var start = textfield.selectionStart; var end = textfield.selectionEnd; textfield.value = textfield.value.substring(0, start) + $e + textfield.value.substring(end, textfield.value.length); } else { textfield.value = textfield.value + $e; } textfield.focus(); } function submitForm() { submitme=1; formname=document.postform.sb_authorname.value; if ((formname.length<1)) { alert("You forgot to enter your name"); submitme=0; } formmail=document.postform.email.value; if ((formmail.length<1)) { alert("You forgot to enter your email"); submitme=0; } formsubject=document.postform.subject.value; if ((formsubject.length<1)) { alert("You forgot to enter a subject"); submitme=0; } if (submitme>0) { // var message = document.postform.message.value; // message = message.replace(//g,">"); // document.postform.message.value = message; //change the following line to true to submit form return true; }else{ return false; } } function cancelForm() { document.forms['postform'].action.value = "cancel"; return true; } //********************************************** // Helpline messages b_help = "Жирный текст: [b]текст[/b] "; i_help = "Наклонный текст: [i]текст[/i]"; u_help = "Подчеркнутый текст: [u]текст[/u]"; q_help = "Текст цитаты: [quote]текст[/quote]"; c_help = "Текст кода: [code]код[/code]"; k_help = "Ненумерованный список: [ul] [li]текст[/li] [/ul] - Подсказка: список должен содержать элементы списка"; o_help = "Нумерованный список: [ol] [li]текст[/li] [/ol] - Подсказка: список должен содержать элементы списка"; p_help = "Изображение: [img size=(01-499)]http://www.google.com/images/web_logo_left.gif[/img]"; w_help = "Ссылка: [url]http://www.zzz.com/[/url] or [url=http://www.zzz.com/]This is a link[/url]"; a_help = "Закрыть все открытые тэги bbCode"; s_help = "Цвет: [color=#FF6600]текст[/color]"; f_help = "Размер: [size=1]размер текста[/size] - Подсказка: размер в пределах от 1 до 5"; l_help = "Элемент списка: [li] элемент списка [/li]"; iu_help = "Файл изображения может иметь размеры, не более, чем (ширина x высота): 499x499 - 50 KB"; fu_help = "Ваш файл может иметь тип - макс. размер: zip,txt,doc,gz - 65 KB"; ip_help = "Вставьте тэг [img] в текст сообщения для присоединения изображения"; fp_help = "Вставьте тэг [file] в текст сообщения для присоединения файла"; submit_help = "Кликните для отправки сообщения"; preview_help = "Кликните для просмотра Вашего сообщения перед публикацией"; cancel_help = "Кликните для отмены Вашего сообщения"; //************************************************** // Open the preview window (with some post parsing) function Preview(stylesheet, sbs, template, disemoticons) { //changed to fix the preview problem in IE with mod_login //message=document.getElementById('message'); var message = document.postform.message; //these gotta be in both... I don't knwo why, but it works... messageString = message.innertext; messageString = message.value; messageString = messageString.replace(/<(.*?)>/g,"<$1>"); messageString = messageString.replace(/"); messageString = messageString.replace(/\[b\]/g,""); messageString = messageString.replace(/\[\/b\]/g,""); messageString = messageString.replace(/\[i\]/g,""); messageString = messageString.replace(/\[\/i\]/g,""); messageString = messageString.replace(/\[u\]/g,""); messageString = messageString.replace(/\[\/u\]/g,""); messageString = messageString.replace(/\[quote\]/g,'
'); messageString = messageString.replace(/\[\/quote\]/g,'
'); messageString = messageString.replace(/\[code\]/g,'
Code:
');
messageString = messageString.replace(/\[\/code\]/g,'
'); messageString = messageString.replace(/\[code:1\]/g,'
Code:
');
messageString = messageString.replace(/\[\/code:1\]/g,'
'); messageString = messageString.replace(/\[ul\]/g,""); messageString = messageString.replace(/\[ol\]/g,"
    "); messageString = messageString.replace(/\[\/ol\]/g,"
"); messageString = messageString.replace(/\[li\]/g,"
  • "); messageString = messageString.replace(/\[\/li\]/g,"
  • "); if (disemoticons == 0) { messageString = messageString.replace(/B\)/g,'');messageString = messageString.replace(/;-\)/g,'');messageString = messageString.replace(/;\)/g,'');messageString = messageString.replace(/:y32b4:/g,'');messageString = messageString.replace(/:x/g,'');messageString = messageString.replace(/:woohoo:/g,'');messageString = messageString.replace(/:whistle:/g,'');messageString = messageString.replace(/:unsure:/g,'');messageString = messageString.replace(/:silly:/g,'');messageString = messageString.replace(/:side:/g,'');messageString = messageString.replace(/:sick:/g,'');messageString = messageString.replace(/:s/g,'');messageString = messageString.replace(/:rolleyes:/g,'');messageString = messageString.replace(/:pinch:/g,'');messageString = messageString.replace(/:p/g,'');messageString = messageString.replace(/:ohmy:/g,'');messageString = messageString.replace(/:mad:/g,'');messageString = messageString.replace(/:lol:/g,'');messageString = messageString.replace(/:laugh:/g,'');messageString = messageString.replace(/:kiss:/g,'');messageString = messageString.replace(/:huh:/g,'');messageString = messageString.replace(/:evil:/g,'');messageString = messageString.replace(/:ermm:/g,'');messageString = messageString.replace(/:dry:/g,'');messageString = messageString.replace(/:cheer:/g,'');messageString = messageString.replace(/:blush:/g,'');messageString = messageString.replace(/:blink:/g,'');messageString = messageString.replace(/:angry:/g,'');messageString = messageString.replace(/:X/g,'');messageString = messageString.replace(/:S/g,'');messageString = messageString.replace(/:P/g,'');messageString = messageString.replace(/:D/g,'');messageString = messageString.replace(/:-\)/g,'');messageString = messageString.replace(/:-\(/g,'');messageString = messageString.replace(/:\)/g,'');messageString = messageString.replace(/:\(/g,'');} messageString = messageString.replace(/\[img size=([1-4][0-9][0-9])\](.*?)\[\/img\]/g,"\"\""); messageString = messageString.replace(/\[img\](.*?)\[\/img\]/g,"\"\""); messageString = messageString.replace(/(\[url\])(.*?)(\[\/url\])/g,"$2"); messageString = messageString.replace(/\[url=(.*?)\](.*?)\[\/url\]/g,"$2"); messageString = messageString.replace(/\[size=([1-7])\](.+?)\[\/size\]/g,"$2"); messageString = messageString.replace(/\[color=(.*?)\](.*?)\[\/color\]/g,"$2"); messageString = messageString.replace(/\[file name=(.*?) size=(.*?)\](.*?)\[\/file\]/g,"
    File Attachment:
    File name: $1
    File size:$2 bytes
    "); //and finally open the window for displaying the lot win = window.open('','Preview','width=640, height=480, toolbar = no, status = no, resizable, scrollbars'); win.document.write(""); win.document.write(""); win.document.write("
    "); win.document.write('' + messageString + ''); win.document.write("
    "); win.document.write(" Закрыть это окно "); win.document.write("
    "); } /** * Pops up a new window in the middle of the screen */ function popupWindow(mypage, myname, w, h, scroll) { var winl = (screen.width - w) / 2; var wint = (screen.height - h) / 2; winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable' win = window.open(mypage, myname, winprops); if (win.opener == null) win.opener = self; if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); } } function popUp(URL) { eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=no,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=250,left = 262,top = 184');"); }