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

 All Forums
 Help Groups for Snitz Forums 2000 Users
 Help: MOD Implementation
 A little javascript help please?
 New Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bobby131313
Senior Member

USA
1163 Posts

Posted - 10 April 2016 :  14:13:25  Show Profile  Visit bobby131313's Homepage  Reply with Quote
I've created buttons to pop in a standardized url format for a link....

function ussellerlink() {
	var text = getText();
		AddTxt="http://www.ebay.com/sch/m.html?_nkw=&_sop=10&_ssn=";
		AddText(AddTxt);
	}		


It works great with one little nuisance. The curser always end up in the middle of the inserted link. Can I do something to the js to force the cursor to the end?

TIA.

Switch the order of your title tags

Edited by - bobby131313 on 10 April 2016 14:15:35

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 10 April 2016 :  15:21:27  Show Profile
The AddText() js function is the function that actually does the inserting. Can we take a look at that?

Support Snitz Forums
Go to Top of Page

bobby131313
Senior Member

USA
1163 Posts

Posted - 10 April 2016 :  16:12:21  Show Profile  Visit bobby131313's Homepage
Ah. Interesting, didn't realize that. I may have to clone it then and rename it. I don't want it affecting everything else.


   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();

		if (start === end )
		{
			res = text.split("/");
			if (res.length > 1)
			{
				tarea.selectionStart = start + (text.length) / 2;
				tarea.selectionEnd = tarea.selectionStart;
			}
			
		}
		else
		{
			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) {}; 
}



Or maybe come up with a new function just for this?

Switch the order of your title tags

Edited by - bobby131313 on 10 April 2016 16:13:11
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20578 Posts

Posted - 11 April 2016 :  13:18:51  Show Profile  Visit HuwR's Homepage
Your AddText function is slightly different to the default AddText the behaviour of which I'm pretty certain places the cursor after the inserted text.

Do you know what MOD you installed that changed your AddText function?

MVC .net dev/test site | MVC .net running on Raspberry Pi
Go to Top of Page

bobby131313
Senior Member

USA
1163 Posts

Posted - 11 April 2016 :  14:03:04  Show Profile  Visit bobby131313's Homepage
Honestly Hu, it could be any of dozens of things we've changed. We are incredibly modded.

Maybe I'll grab it from a fresh download and rename it, then see if that works.

Switch the order of your title tags
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20578 Posts

Posted - 11 April 2016 :  14:06:08  Show Profile  Visit HuwR's Homepage
yep, would be worth it, just give the original function a different name and call that one from your code see if it works

MVC .net dev/test site | MVC .net running on Raspberry Pi
Go to Top of Page

bobby131313
Senior Member

USA
1163 Posts

Posted - 11 April 2016 :  14:39:38  Show Profile  Visit bobby131313's Homepage
Works like a charm.

It's much smaller than my current one.

Thanks!

Switch the order of your title tags
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000 Version 3.4.07