HighDots Forums  

Firefox Probleme beim Einfuegen von Text in ein textarea

Javascript (German) Programmiersprache JavaScript. (de.comp.lang.javascript)


Discuss Firefox Probleme beim Einfuegen von Text in ein textarea in the Javascript (German) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Reiner Mustermann
 
Posts: n/a

Default Firefox Probleme beim Einfuegen von Text in ein textarea - 04-12-2005 , 07:59 AM






Hallo,

phpBB (www.phpBB.com) ist eine auf PHP basierende Forensoftware.
Leider unterstützt phpBB von Haus aus nur den IE zu 100%. Mozilla,
Firefox, Opera & Co werden stiefmütterlich behandelt. Speziell wenn es
um javacript und um das Einfügen von phpBB Code/Smilies geht. Für
Firefox gibt es einen Patch, der z.B. die Funktion emoticon(text)
ersetzt. Diese neue Funktion fügt nun auch unter Firefox Smilies an
der aktuellen Cursorposition ein, springt dann aber wieder an den
Anfang des Textes. Gleiches Verhalten mit Firefox beim Einfügen von
BBcode. Beim IE bleibt der Text in Position. Dieses Firefox-Verhalten
ist beim Editieren längerer Texte mehr als lästig, da man nach jedem
Einfügen eines Smilies (oder BBcode) immer wieder manuell an die
letzte Position zurück-scrollen muß.

function emoticon(text)
{
text = ' ' + text + ' ';
if (document.post.message.createTextRange &&
document.post.message.caretPos)
{
var caretPos = document.post.message.caretPos;
caretPos.text =
caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' :
text;
document.post.message.focus();
}
else if(typeof document.post.message.selectionStart !=
'undefined')
{
// Firefox
posttextarea = document.post.message;

selected=(posttextarea.value).substring(posttextar ea.selectionStart,posttextarea.selectionEnd);
posttextarea.focus();
start=posttextarea.selectionStart;
end=posttextarea.textLength;

endtext=posttextarea.value.substring(posttextarea. selectionEnd,end);
starttext=posttextarea.value.substring(0,start);
posttextarea.value=starttext + text + endtext;
posttextarea.selectionStart=start;
posttextarea.selectionEnd=start;
return;
}
else
{
// Opera & Co
document.post.message.value+= text;
document.post.message.focus();
}
}


Der IE-Part funktioniert wie gewünscht:

if (document.post.message.createTextRange &&
document.post.message.caretPos)
{
var caretPos = document.post.message.caretPos;
caretPos.text =
caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' :
text;
document.post.message.focus();
}


Der Firefox-Part:

else if(typeof document.post.message.selectionStart != 'undefined')
{
// Firefox
posttextarea = document.post.message;

selected=(posttextarea.value).substring(posttextar ea.selectionStart,posttextarea.selectionEnd);
posttextarea.focus();
start=posttextarea.selectionStart;
end=posttextarea.textLength;

endtext=posttextarea.value.substring(posttextarea. selectionEnd,end);
starttext=posttextarea.value.substring(0,start);
posttextarea.value=starttext + text + endtext;
posttextarea.selectionStart=start;
posttextarea.selectionEnd=start;
return;
}

positioniert zum Schluß der Funktion offenbar an den Anfang des
Textes. Wie kann man das unterbinden?

Ich kenne mich mit javascript nicht aus. Eine Lösung würde der Firefox
phpBB- Community sehr helfen.


Gruß Reiner

Reply With Quote
  #2  
Old   
Martin Honnen
 
Posts: n/a

Default Re: Firefox Probleme beim Einfuegen von Text in ein textarea - 04-12-2005 , 08:14 AM








Reiner Mustermann wrote:


Quote:
posttextarea = document.post.message;

selected=(posttextarea.value).substring(posttextar ea.selectionStart,posttextarea.selectionEnd);
posttextarea.focus();
start=posttextarea.selectionStart;
end=posttextarea.textLength;

endtext=posttextarea.value.substring(posttextarea. selectionEnd,end);
starttext=posttextarea.value.substring(0,start);
posttextarea.value=starttext + text + endtext;
posttextarea.selectionStart=start;
posttextarea.selectionEnd=start;
Man kann mit Mozilla per
textControl.setSelectionRange(selectionStart, selectionEnd)
die Selektion manipulieren, eventuell also statt
posttextarea.selectionStart=start;
posttextarea.selectionEnd=start;
einfach
var newPos = starttext.length + text.length;
textControl.setSelectionRange(newPos, newPos);


--

Martin Honnen
http://JavaScript.FAQTs.com/


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.