Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/Code)
 Mozilla/Firefox text scroll fix.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Eric Coleman
Starting Member

USA
10 Posts

Posted - 15 December 2006 :  11:30:53  Show Profile  Reply with Quote
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

	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:

	;
	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.


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) {}; 
}

<

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 15 December 2006 :  11:46:04  Show Profile  Visit HuwR's Homepage  Reply with Quote
nice one, I guess it should be included in a future release at some point.<
Go to Top of Page

Shaggy
Support Moderator

Ireland
6780 Posts

Posted - 17 April 2008 :  12:11:19  Show Profile  Reply with Quote
Ah-ha! Knew I'd seen this somewhere

But, of course, the byte-scrimping coder in me had to clean it up a bit
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.”

Edited by - Shaggy on 17 April 2008 12:12:32
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.13 seconds. Powered By: Snitz Forums 2000 Version 3.4.07