1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| function BBcode5(balise)
{
switch (navigator.appName)
{
//---------------------------------
case "Microsoft Internet Explorer":
//---------------------------------
var haha=document.selection.createRange().text;
if(balise=='color')
{
//A=document.posttopic.color.text;
alert('toto');
//insertion="["+balise+"="+A+"]"+B+"[/"+balise+"]";
}
if(balise=="IMG")
{
var haha=prompt("IMG=","http://");
}
if(balise=="URL")
{
var URL=prompt("URL=","http://");
var insertion="["+balise+"=\""+URL+"\"]"+haha+"[/"+balise+"]";
}
if(balise!='color' && balise!='URL')
{
var insertion="["+balise+"]"+haha+"[/"+balise+"]";
}
document.posttopic.message.focus();
var sel=document.selection.createRange();
sel.text=insertion;
break;
//---------------------------------
case "Netscape": //mozilla, firefox, ...
//---------------------------------
//Récupérer les parties : avant sélection, sélection et après sélection
var AvantB = document.forms['posttopic'].message.value.substring( 0, document.forms['posttopic'].message.selectionStart -1 );
var B = document.forms['posttopic'].message.value.substring( document.forms['posttopic'].message.selectionStart, document.forms['posttopic'].message.selectionEnd );
var ApresB = document.forms['posttopic'].message.value.substring( document.forms['posttopic'].message.selectionEnd +1, document.forms['posttopic'].message.selectionEnd +100000 );
//Modifier la sélection*
if(balise=="color")
{
A=document.forms['posttopic'].color.value;
B="["+balise+"="+A+"]"+B+"[/"+balise+"]";
}
if(balise=="IMG")
{
var B=prompt("IMG=","http://");
}
if(balise=="URL")
{
var URL=prompt("URL=","http://");
B="["+balise+"=\""+URL+"\"]"+B+"[/"+balise+"]";
}
if(balise!='color' && balise!='URL')
{
B="["+balise+"]"+B+"[/"+balise+"]";
}
//Remplacer la sélection
document.forms['posttopic'].message.focus();
document.forms['posttopic'].message.value= AvantB +" "+ B + " "+ApresB;
break;
//---------------------------------
default://les autres navigateurs
//---------------------------------
haha=posttopic.message.value.substring(posttopic.message.selectionStart,posttopic.message.selectionEnd);
if(balise=="URL")
{
var URL=prompt("URL=","http://");
var insertion="["+balise+"=\""+URL+"\"]"+haha+"[/"+balise+"]";
}
else
{
var insertion="["+balise+"]"+haha+"[/"+balise+"]";
}
posttopic.message.value+=insertion;
break;
}
} |
Partager