View file bymas/js/bbcode.js

File size: 3.39Kb
// JavaScript Document

function savesel(doc)
        {
                if(document.selection) {                
                        doc.sel = document.selection.createRange().duplicate();
                }               
        }
        function click_bb(aid,Open,Close) {
                var doc = document.getElementById(aid);
                doc.focus();
                if (window.attachEvent && navigator.userAgent.indexOf('Opera') === -1) {                                        
                        var s = doc.sel;
                        if(s){                                  
                                var l = s.text.length;
                                s.text = Open + s.text + Close;
                                s.moveEnd("character", -Close.length);
                                s.moveStart("character", -l);                                           
                                s.select();                
                        }
                }   else {                                              
                        var ss = doc.scrollTop;
                        sel1 = doc.value.substr(0, doc.selectionStart);
                        sel2 = doc.value.substr(doc.selectionEnd);
                        sel = doc.value.substr(doc.selectionStart, doc.selectionEnd - doc.selectionStart);                                              
                        doc.value = sel1 + Open + sel + Close + sel2;
                        doc.selectionStart = sel1.length + Open.length;
                        doc.selectionEnd = doc.selectionStart + sel.length;
                        doc.scrollTop = ss;                                             
                }
                return false;
        }

function bb_u(id)
{
// подчеркивание
click_bb(id,'[u]','[/u]');
}
function bb_i(id)
{
// курсив

click_bb(id,'[i]','[/i]');
}

function bb_b(id)
{
// жирный
click_bb(id,'[b]','[/b]');
}

function bb_url(id)
{
click_bb(id,'[url=]','[/url]');
}
function bb_img(id)
{
click_bb(id,'[img]','[/img]');
}

function bb_s(id)
{
click_bb(id,'[s]','[/s]');
}

function bb_q(id)
{
click_bb(id,'[q]','[/q]');
}

function bb_blue(id)
{
click_bb(id,'[blue]','[/blue]');
}

function bb_green(id)
{
click_bb(id,'[green]','[/green]');
}

function bb_black(id)
{
click_bb(id,'[black]','[/black]');
}

function bb_red(id)
{
click_bb(id,'[red]','[/red]');
}
function bb_code(id)
{
click_bb(id,'[code]','[/code]');
}

function filesAdd () {
        var fl = document.getElementById("fl"),
            f = document.createElement("fl");
       fl.innerHTML += 'Вариант: <br /><input name="f[]" type="text" value="" />';
         
        //f.setAttribute("name", "f[]");
        //f.setAttribute("type", "text");
         
        fl.insertBefore(f, null);
        //fl.document.createElement("br");
       //fl.appendChild(document.createTextNode("Вариант:"));
//fl.appendChild(document.createElement("br"));
fl.appendChild(document.innerHTML = 'kkkkkkkkkk');
    }


function filesDel () {
        var fl = document.getElementById("fl");
        var flb = fl.lastChild;
        var fli = flb.previousSibling;

        if (fli.previousSibling !== null) {
            flb.parentNode.removeChild(flb);
            fli.parentNode.removeChild(fli);
           
       }

    }