Yanick Rochon
Yanick Rochon

Reputation: 53616

GWT - RichTextArea - ScrollTo

If I have an RichTextArea like this :

RichTextArea rta = new RichTextArea();
rta.setHTML("<p id=\"foo\">Foo</p>....<p id=\"bar\">Bar</p>");

If I extend the RichTextArea class, how would be the proper way (cross-browser wise) to write a scrollTo() method?

Ex:

class RichTextAreaExt extends RichTextArea {
   ...
   /**
    * This method should be called only when the widget has properly been attached
    * @param id String the HTML element id within the RichTextArea to scroll to
    */
   public native void scrollToElement(String id) /*-{
       var cWin = [email protected]::getElement()().contentWindow;
       var el = cWin.document.getElementById(id);
       if (el) {
           cWin.scrollTo(el.offsetLeft,el.offsetTop);
       }
   }-*/;       ...
}

This seems to work in some browsers, but I don't have all of them to test, so inputs are welcome!

Thanks!

Upvotes: 1

Views: 768

Answers (1)

Gipsy King
Gipsy King

Reputation: 1577

http://code.google.com/p/doctype/wiki/WindowScrollMethod - seems to be ok across browsers. http://code.google.com/p/doctype/wiki/ArticleOffsetLeftAndFriends - seems to be inconsistent.

Upvotes: 1

Related Questions