Mozilla/Firefox text scroll fix. - Postet den (1819 Views)
Starting Member
Eric Coleman
Innlegg: 10
10
This really isn't a full mod, but I didn't know where else to post this.
The bug is when using the javascript formating options, such as bold, italics, etc, in a textbox with enough lines of text to have scroll bars, the textbox scrolls all the way to the top.

This easy fix keeps the scroll bar where it is when click the formating buttons.

Open inc_code.js and find the following function AddText
Code needs to be placed at the beginning of the function and at the end of the function:

Paste the following
Code:

	var crtScrollTop;
var crtScrollLeft;
try {
var tarea = document.PostTopic.Message;
if (typeof tarea.scrollTop != 'undefined') {
crtScrollTop = tarea.scrollTop;
crtScrollLeft = tarea.scrollLeft;
}
} catch (e) {};

at the top, immediatly after function AddText(text) {

Then, at the bottom of the function, paste the following:
Code:

	;
try {
var tarea = document.PostTopic.Message;
if (typeof tarea.scrollTop != 'undefined') {
tarea.scrollTop = crtScrollTop;
tarea.scrollLeft = crtScrollLeft;
}
} catch (e) {};

immediately BEFORE the closing } of the function.

That's it.

If you haven't made any changes to your javascript then the default function, as being used by this forum right now, would look like this where new code is blue and old code is red.
Code:

function AddText(text) {
	var crtScrollTop;
var crtScrollLeft;
try {
var tarea = document.PostTopic.Message;
if (typeof tarea.scrollTop != 'undefined') {
crtScrollTop = tarea.scrollTop;
crtScrollLeft = tarea.scrollLeft;
}
} catch (e) {};
var tarea = document.PostTopic.Message;
if (typeof tarea.selectionStart != 'undefined'){ // if it supports DOM2
start = tarea.selectionStart;
end = tarea.selectionEnd;
tarea.value = tarea.value.substr(0,tarea.selectionStart)
+ text + tarea.value.substr(tarea.selectionEnd);
tarea.focus();
tarea.selectionStart = ((start - end) == 0) ? start + text.length : start;
tarea.selectionEnd = start + text.length;
} else {
if (tarea.createTextRange && tarea.caretPos) {
var caretPos = tarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
}
else {
tarea.value += text;
}
tarea.focus(caretPos);
}
;

try {
var tarea = document.PostTopic.Message;
if (typeof tarea.scrollTop != 'undefined') {
tarea.scrollTop = crtScrollTop;
tarea.scrollLeft = crtScrollLeft;
}
} catch (e) {};
}
<
   
 Sidestørrelse 
Postet den
Forum Admin
HuwR
Innlegg: 20611
20611
nice one, I guess it should be included in a future release at some point.<
Postet den
Support Moderator
Shaggy
Innlegg: 6780
6780
Ah-ha! Knew I'd seen this somewhere smile
But, of course, the byte-scrimping coder in me had to clean it up a bit wink
Code:
function AddText(text) {
var tarea = document.PostTopic.Message;
if (typeof tarea.selectionStart != 'undefined'){ // if it supports DOM2
start = tarea.selectionStart;
end = tarea.selectionEnd;
var posTop = tarea.scrollTop;
var posLeft = tarea.scrollLeft;
tarea.value = tarea.value.substr(0,tarea.selectionStart)
+ text + tarea.value.substr(tarea.selectionEnd);
tarea.focus();
tarea.selectionStart = ((start - end) == 0) ? start + text.length : start;
tarea.selectionEnd = start + text.length;
tarea.scrollTop = posTop;
tarea.scrollLeft = posLeft;
} else if (tarea.createTextRange && tarea.caretPos) {
var caretPos = tarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
tarea.focus(caretPos);
} else {
tarea.value += text;
}
}
<
Search is your friend “I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”
 
Du må legge inn en melding