Mozillafix für BBCode und Smilies beim Posten
Verfasst: 18.09.2006 11:28
Dieses Snippet behebt das Problem, dass die Cursorposition bei Browsern, die die Geckoengine verwenden (z.B. Mozilla, Netscape, Firefox) beim Anklicken von Buttons und Smilies (Postfenster) verloren geht.
Das Snippet wurde aus dem "BBCodes & smilies enhancement" Mod von GolfExpert entnommen. Die Codeteile sind zumeist gecodet von markus_petrux und TerraFrost.
Das Snippet wurde aus dem "BBCodes & smilies enhancement" Mod von GolfExpert entnommen. Die Codeteile sind zumeist gecodet von markus_petrux und TerraFrost.
Code: Alles auswählen
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/posting_body.tpl
#
#-----[ FIND ]------------------------------------------
#
// Shows the help messages in the helpline window
#
#-----[ BEFORE, ADD ]------------------------------------------
#
// Start add - BBCodes & smilies enhancement MOD
var baseHeight;
function initInsertions() {
if (is_ie && typeof(baseHeight) != 'number') baseHeight = document.selection.createRange().duplicate().boundingHeight;
}
// End add - BBCodes & smilies enhancement MOD
#
#-----[ FIND ]------------------------------------------
#
# in der function emoticon(text)
#
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
txtarea.focus();
#
#-----[ REPLACE WITH ]------------------------------------------
#
// Start add - BBCodes & smilies enhancement MOD
if (baseHeight != txtarea.caretPos.boundingHeight) {
txtarea.focus();
storeCaret(txtarea);
}
// End add - BBCodes & smilies enhancement MOD
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
txtarea.focus();
// Start add - BBCodes & smilies enhancement MOD
} else
if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
{
mozInsert(txtarea, text, "");
return;
// End add - BBCodes & smilies enhancement MOD
#
#-----[ FIND ]------------------------------------------
#
if (!theSelection) {
#
#-----[ AFTER, ADD ]------------------------------------------
#
// Start add - BBCodes & smilies enhancement MOD
if (txtarea.createTextRange && txtarea.caretPos) {
if (baseHeight != txtarea.caretPos.boundingHeight) {
txtarea.focus();
storeCaret(txtarea);
}
var caretPos = txtarea.caretPos;
var text = bbopen + bbclose;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
} else
// End add - BBCodes & smilies enhancement MOD
#
#-----[ FIND ]------------------------------------------
#
else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
{
mozWrap(txtarea, bbopen, bbclose);
#
#-----[ REPLACE WITH ]------------------------------------------
#
// Start replacement - BBCodes & smilies enhancement MOD
else if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
{
mozInsert(txtarea, bbopen, bbclose);
// End replacement - BBCodes & smilies enhancement MOD
#
#-----[ FIND ]------------------------------------------
#
while (bbcode[0]) {
butnumber = arraypop(bbcode) - 1;
#
#-----[ AFTER, ADD ]------------------------------------------
#
// Start add - BBCodes & smilies enhancement MOD
if (txtarea.createTextRange && txtarea.caretPos) {
if (baseHeight != txtarea.caretPos.boundingHeight) {
txtarea.focus();
storeCaret(txtarea);
}
var caretPos = txtarea.caretPos;
var text = bbtags[butnumber + 1];
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
} else
if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
{
mozInsert(txtarea, bbtags[butnumber + 1], "");
} else
// End add - BBCodes & smilies enhancement MOD
#
#-----[ FIND ]------------------------------------------
#
mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
#
#-----[ REPLACE WITH ]------------------------------------------
#
mozInsert(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
#
#-----[ FIND ]------------------------------------------
#
while (bbcode[bblast]) {
butnumber = arraypop(bbcode) - 1;
#
#-----[ AFTER, ADD ]------------------------------------------
#
// Start add - BBCodes & smilies enhancement MOD
if (txtarea.createTextRange && txtarea.caretPos) {
if (baseHeight != txtarea.caretPos.boundingHeight) {
txtarea.focus();
storeCaret(txtarea);
}
var caretPos = txtarea.caretPos;
var text = bbtags[butnumber + 1];
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
} else
if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
{
mozInsert(txtarea, bbtags[butnumber + 1], "");
} else
// End add - BBCodes & smilies enhancement MOD
#
#-----[ FIND ]------------------------------------------
#
if (imageTag && (bbnumber != 14)) { // Close image tag before adding another
#
#-----[ AFTER, ADD ]------------------------------------------
#
// Start add - BBCodes & smilies enhancement MOD
if (txtarea.createTextRange && txtarea.caretPos) {
if (baseHeight != txtarea.caretPos.boundingHeight) {
txtarea.focus();
storeCaret(txtarea);
}
var caretPos = txtarea.caretPos;
var text = bbtags[15];
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
} else
if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
{
mozInsert(txtarea, bbtags[15], "");
} else
// End add - BBCodes & smilies enhancement MOD
#
#-----[ FIND ]------------------------------------------
#
// Open tag
#
#-----[ AFTER, ADD ]------------------------------------------
#
// Start add - BBCodes & smilies enhancement MOD
if (bbnumber == 16) {
var url = prompt("{L_BBCODE_URL}", "http://");
if (url == null) {
return;
} else if (!url) {
alert("{L_BBCODE_URL_ERRORS}" + "\n" + "\n" + "{L_BBCODE_URL_EMPTY}");
return;
} else {
var title = prompt("{L_BBCODE_URL_TITLE}", "");
if (title == null) {
return;
} else if (!title) {
var text = "[url]" + url + "[/url]";
} else {
var text = "[url=" + url + "]" + title + "[/url]";
}
}
if (txtarea.createTextRange && txtarea.caretPos) {
if (baseHeight != txtarea.caretPos.boundingHeight) {
txtarea.focus();
storeCaret(txtarea);
}
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
} else
if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
{
mozInsert(txtarea, text, "");
} else txtarea.value += text;
} else {
var text = bbtags[bbnumber];
if (txtarea.createTextRange && txtarea.caretPos) {
if (baseHeight != txtarea.caretPos.boundingHeight) {
txtarea.focus();
storeCaret(txtarea);
}
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
} else
if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
{
mozInsert(txtarea, bbtags[bbnumber], "");
} else
// End add - BBCodes & smilies enhancement MOD
#
#-----[ FIND ]------------------------------------------
#
eval('document.post.addbbcode'+bbnumber+'.value += "*"');
#
#-----[ AFTER, ADD ]------------------------------------------
#
// Start add - BBCodes & smilies enhancement MOD
}
// End add - BBCodes & smilies enhancement MOD
#
#-----[ FIND ]------------------------------------------
#
//-->
</script>
#
#-----[ BEFORE, ADD ]------------------------------------------
#
// Start add - BBCodes & smilies enhancement MOD
function mozInsert(txtarea, openTag, closeTag)
{
var scrollTop = ( typeof(txtarea.scrollTop) == 'number' ? txtarea.scrollTop : -1 );
if (txtarea.selectionEnd > txtarea.value.length) { txtarea.selectionEnd = txtarea.value.length; }
var startPos = txtarea.selectionStart;
var endPos = txtarea.selectionEnd+openTag.length;
txtarea.value=txtarea.value.slice(0,startPos)+openTag+txtarea.value.slice(startPos);
txtarea.value=txtarea.value.slice(0,endPos)+closeTag+txtarea.value.slice(endPos);
txtarea.selectionStart = startPos+openTag.length;
txtarea.selectionEnd = endPos;
txtarea.focus();
if( scrollTop >= 0 ) { txtarea.scrollTop = scrollTop; }
}
// End add - BBCodes & smilies enhancement MOD
#
#-----[ FIND ]------------------------------------------
#
<textarea name="message" rows="20" cols="35" wrap="virtual" style="width:600px" tabindex="3" class="post" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onfocus="initInsertions();">{MESSAGE}</textarea><br />
#
#-----[ REPLACE WITH ]------------------------------------------
#
<textarea name="message" rows="20" cols="35" wrap="virtual" style="width:600px" tabindex="3" class="post" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);">{MESSAGE}</textarea><br />
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM