var almsamim = {}; // objects var comm, bbcode; // vars var isIE, isOpera,isGecko, isWebKit,ua,Editor; // Browsers check ua = navigator.userAgent; almsamim.isOpera = isOpera = window['opera'] && opera.buildNumber; almsamim.isWebKit = isWebKit = /WebKit/.test(ua); almsamim.isGecko = isGecko = !isWebKit && /Gecko/.test(ua); almsamim.isIE = isIE = !isWebKit && !isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(navigator.appName); // ----------- almsamim plug-ins object -----------// almsamim.plugins = {}; //thanks tuantrinh smilies replace with bbocde if (typeof window['smiley_wysiwyg'] == 'undefined') { var smiley_wysiwyg = false; } if (smiley_wysiwyg) { var smiley_code_bbcode = new Array(); var smiley_img_bbcode = new Array(); var t = document.URL; t = t.replace("http://", ""); var u = t.split("/"); var v = "http://"; for (var d = 0; d < u.length; d++) { if (d < u.length - 1) { v += u[d] + "/"; } } for(var i = 0; i < smiley_total; i++) { smiley_code_bbcode[i] = smiley_code[i]; smiley_img_bbcode[i] = "[IMG]" + v + smiley_path + smiley_img[i] + "[/IMG]"; } function Smiley_BBcodetoHTML(str) { for(var i = 0; i < smiley_total; i++) { while (str.indexOf(smiley_code_bbcode[i]) > -1) { str = str.replace(smiley_code_bbcode[i], smiley_img_bbcode[i]); } } return str; }; function Smiley_HTMLtoBBcode(str) { for(var i = 0; i < smiley_total; i++) { while (str.indexOf(smiley_img_bbcode[i]) > -1) { str = str.replace(smiley_img_bbcode[i], smiley_code_bbcode[i]); } } return str; }; } // ----------- almsamim bbcode object -----------// almsamim.bbcode = bbcode = { // turning the editor on Start : function (){ var tDiv = document.getElementById("dvSample"); Editor = document.getElementById('box').contentWindow.document; //writing iframe content and style of the editor var iframeContent; iframeContent = '\n'; iframeContent += '
'; if (tDiv.value !== ""){ var v = tDiv.value; iframeContent += this._BBcodetoHTML(v) ; } iframeContent += ''; iframeContent += ''; Editor.open(); Editor.write(iframeContent); Editor.close(); if(isIE){ Editor.attachEvent('onkeypress', editorEvents); Editor.attachEvent('onmousedown', editorEvents); Editor.attachEvent('onmousedown', hideall); Editor.body.contentEditable = true; }else{ Editor.addEventListener('keypress', editorEvents, true); Editor.addEventListener('mousedown', editorEvents, true); Editor.addEventListener('mousedown', hideall, true); Editor.designMode = "on"; } if(!isWebKit){ // disable CSS in Geko ,IE and opera try { // Try new Gecko method Editor.execCommand("styleWithCSS", 0, false); } catch (e) { // Use old method try {Editor.execCommand("useCSS", 0, true);} catch (e) {}; } } }, // convert BBcode to HTML code _BBcodetoHTML : function (a) { function r(re, str) { a = a.replace(re, str); }; if (smiley_wysiwyg) { a=Smiley_BBcodetoHTML(a); } r(/\n+(\[\/list\])/gi,'[/list]'); r(/\[list\]\n+/gi,'[list]'); r(/\[list=1\]\n+/gi,'[list=1]'); r(/\[list=a\]\n+/gi,'[list=a]'); r(/\n+\[\/tr\]/gi,'[/tr]'); r(/\n+\[tr\]/gi,'[tr]'); r(/\n+\[td\]/gi,'[td]'); r(/\n+\[\/td\]/gi,'[/td]'); r(/\n+\[\/table\]/gi,'[/table]'); r(/\[\/table\]$/gi,"[/table]\n"); r(/&/g,'&'); r(//g,'>'); r(/ /g,' '); r(/\t/g,' '); r(/\n/g,'