ho migliorato una funzione (BBCurl) che avevo trovato in giro per i pulsante URL. Quella funzione utilizzava due box per inserire URL e testo dell'URL nel messaggio. Ma non permetteva di inserire automaticamente un testo selezionandolo nell'area dei messaggi.
Bene ora è possibile selezionare un testo e creare un link, così come avviene in vBulletin board.
per implementare questa funzionalità dovete:
1) Andare nelle cartella dei template del vostro forum.
2) Trovare posting_buttons.html
3) In questo file trovare:
var imageTag = false;
Giusto sotto inserire:
function doGetCaretPosition (ctrl) {
var CaretPos = 0;
// IE Support
if (document.selection) {
ctrl.focus ();
var Sel = document.selection.createRange ();
Sel.moveStart ('character', -ctrl.value.length);
CaretPos = Sel.text.length;
}
// Firefox support
else if (ctrl.selectionStart || ctrl.selectionStart == '0')
CaretPos = ctrl.selectionStart;
return (CaretPos);
}
function BBCurl()
{
var selection = "";
var FoundErrors = '';
var textarea = document.getElementById("message");
if ('selectionStart' in textarea) {
// check whether some text is selected in the textarea
if (textarea.selectionStart != textarea.selectionEnd) {
selection = textarea.value.substring (textarea.selectionStart, textarea.selectionEnd);
}
}
else { // Internet Explorer before version 9
// create a range from the current selection
var textRange = document.selection.createRange ();
// check whether the selection is within the textarea
var rangeParent = textRange.parentElement ();
if (rangeParent === textarea) {
selection = textRange.text;
}
}
if (selection == "") {
var enterURL = prompt("Inserisci l'URL", "http://");
var enterTITLE = prompt("Inserisci il testo", "Testo dell'URL");
}
else {
var enterTITLE = selection
var enterURL = prompt("Inserisci l'URL", "http://");
}
if (!enterURL) {
FoundErrors += "Non hai inserito l'URL. ";
}
if (!enterTITLE)
{
FoundErrors += "Non hai inserito il testo dell'URL";
}
if (FoundErrors)
{
alert("Errore : "+FoundErrors);
return;
}
var str1=textarea.value
var bbtags = "[url="+enterURL+"]"+enterTITLE+"[/url]";
if (selection != "") {
document.forms[form_name].elements[text_name].value=str1.replace(selection,bbtags);
document.forms[form_name].elements[text_name].focus();
}
else {
textarea.value=str1.substr(0,doGetCaretPosition(textarea))+bbtags+str1.substr(doGetCaretPosition(textarea));
}
}
Poi trovare:
<input accesskey="w" class="button2" name="addbbcode16" onclick="bbstyle(16)" style="text-decoration: underline; width: 40px;" title="{L_BBCODE_W_HELP}" type="button" value="URL" />
e sostituire con:
<input accesskey="w" class="button2" name="addbbcode16" onclick="BBCurl()" style="text-decoration: underline; width: 40px;" title="{L_BBCODE_W_HELP}" type="button" value="URL" />Fatto. Arrivederci
Nessun commento
Posta un commento