Home Search Member List Faq Register Login  
UltimateEditor
Re: Scroll to end (like in chat)

Thread Starter: jereed   Started: 05-30-2007 9:53 AM   Replies: 3
 Karamasoft Support Forums » General Discussions » UltimateEditor » Re: Scroll to end (like in chat)
 Printable Version    « Previous Thread   Next Thread »
  30 May 2007, 9:53 AM
jereed is not online. Last active: 11/6/2007 2:46:46 PM jereed

Top 10 Posts
Joined on 05-22-2007
Posts 8
Scroll to end (like in chat)
Hi,

I'm using the editor as part of a "Take Notes" feature of a course managment system.  What I am trying to accomplish is when the user opens the window, the editor is scrolled all the way to the end of the text and the cursor is flashing and ready for the user to start typing.

In other words, when there is a lot of content inside the editor, I want to force the editor's content area to scroll to the bottom of the text and focus just after the last character.

I know there are various javascript methods for doing this with DIV tags such as the ScrollY or ScrollTop properties, but how do I accomplish this with the UltimateEditor?

Here is the JavaScript function I'm trying to use but its not working.  This gets called from the Editor's _OnLoad() javascript method. I have confirmed that tempEditor does have a value by using alert(tempEditor); which reports "Object".

function Karamasoft_ScrollToEnd(id)
  {
  var tempEditor = document.getElementById(id + "i");

  //alert(tempEditor);
  
  try
{ tempEditor.scrollTop = 99999; } catch(e) { }
  try { tempEditor.scrollY = 99999; } catch(e) { }
  try { tempEditor.scrollTo(0,99999); } catch(e) { }
  }

I've tried calling this directly from the _OnLoad() method, it does get called but the textbox area doesn't scroll.

I've also tried using setTimeout() to call the function directly from the _OnLoad() method, it also gets called but the textbox area doesn't scroll either.

  
  30 May 2007, 2:17 PM
jereed is not online. Last active: 11/6/2007 2:46:46 PM jereed

Top 10 Posts
Joined on 05-22-2007
Posts 8
Re: Scroll to end (like in chat)
Okay,

I can now make the editor auto-scroll to the bottom, but I can't get the cursor to be at the end of the text.  The cursor is always next to the first character in the text.

Here is how I'm doing the scrolling, the key was the .contentWindow part:

function Karamasoft_ScrollToEnd(id)
  {
  var tempEditor = document.getElementById(id + "i").contentWindow;

  //alert(tempEditor);
  
  try
{ tempEditor.scrollTop = 99999; } catch(e) { }
  try { tempEditor.scrollY = 99999; } catch(e) { }
  try { tempEditor.scrollTo(0,99999); } catch(e) { }
  }

Any ideas on how to put the cursor at the end of the text instead of the beginning?

  
  31 May 2007, 3:18 AM
Karamasoft is not online. Last active: 5/8/2018 10:36:45 AM Karamasoft

Top 10 Posts
Joined on 09-05-2004
Posts 6,820
Re: Scroll to end (like in chat)

You can set the cursor position by using the range object that can be retrieved using UltimateEditor ClientAPI as follows:

function Karamasoft_ScrollToEnd(id)
  {
  var tempEditor = document.getElementById(id + "i").contentWindow;

  //alert(tempEditor);
  
  try
{ tempEditor.scrollTop = 99999; } catch(e) { }
  try { tempEditor.scrollY = 99999; } catch(e) { }
  try { tempEditor.scrollTo(0,99999); } catch(e) { }

  var ueObj = UltimateEditors[id];
  var
range = ueObj.GetCurrentRange();
  range.collapse(
true
);
  range.moveEnd(
'textedit'
, 1);
  range.moveStart(
'textedit'
, 1);
  range.select();

  }


Please also make sure that Karamasoft_ScrollToEnd method is called after the UltimateEditor is fully loaded in your page. If you get any JavaScript errors, try calling this method using window.setTimeout by giving the method call some time after the page is loaded.

You can normally use [UltimateEditorID]_OnLoad method (that we used in our Chat sample), however, we are currently having some problems with that method. Until we resolve those issues, you can use window.setTimeout.

Please refer to UltimateEditor ClientAPI at http://www.karamasoft.com/UltimateEditor/ClientAPI.htm to learn more about the client-side API functionality.


  
  31 May 2007, 12:50 PM
jereed is not online. Last active: 11/6/2007 2:46:46 PM jereed

Top 10 Posts
Joined on 05-22-2007
Posts 8
Re: Scroll to end (like in chat)
Your suggestion works perfectly. 

I had already discovered that a setTimeout was needed to call the scroll function from the OnLoad method.  I'm using a 1 second delay which seems to work fine.

I implemented the function with the changes you made (above) and the text box scrolls to the end with the cursor position at the end of the text.

Thanks

  
 Page 1 of 1 (4 items)
Karamasoft Support Forums » General Discussions » UltimateEditor » Re: Scroll to end (like in chat)

You can add attachments
You can post new topics
You can reply to topics
You can delete your posts
You can edit your posts
You can create polls
You can vote in polls
Forum statistics are enabled
Forum is unmoderated

© 2002-2018 Karamasoft LLC. All rights reserved.