Is there an rjs helper for zooming or scrolling to a DOM object, e.g.
page.view_object "object"?
I''ve tried using named anchors in combination with link_to_function,
but
unless I''m doing something wrong, the onclick seems to override the
default browser behavior of skipping to a DOM element. For example;
This works;
<%= link_to "Nav", "#header" %>
But this doesn''t;
<%= link_to_function("Nav", :href => "#header") do
|page|
some javascript
end %>
It doesn''t seem to matter which rjs helpers I use, or even if I
don''t
use any at all, the onclick seems to kill the skip to the named anchor.
So I was hoping I could just call an additional rjs helper to avoid the
problem.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Apr 12, 11:30 am, Neil Cauldwell <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Is there an rjs helper for zooming or scrolling to a DOM object, e.g. > page.view_object "object"? >page[''some_id''].scrollTo() should do the trick. The reason why the default behaviour is overriden is that rails generates you something that looks like <a href="#header" onclick="someJavascript(); return false;"> and the return false prevents the default action. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On Apr 12, 11:30�am, Neil Cauldwell <rails-mailing-l...@andreas-s.net> > wrote: >> Is there an rjs helper for zooming or scrolling to a DOM object, e.g. >> page.view_object "object"? >> > page[''some_id''].scrollTo() should do the trick. The reason why the > default behaviour is overriden is that rails generates you something > that looks like <a href="#header" onclick="someJavascript(); return > false;"> and the return false prevents the default action. > > FredThat works just fine, thank you. Slightly related; is there an easy way to get the cursor to sit inside the page[''some_id'']? I''m looking to use the same behavior on a textarea, so it would make sense to put the cursor inside the textarea. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The reason the link_to_function doesn''t scroll to your named element
is that it appends a "return false;" after your javascript, which
stops the default action.
You can use prototype javascript call
Element.scrollTo(''header'').
<%= link_to_function "Nav",
"Element.scrollTo(''header'')" %>
On Apr 12, 6:30 am, Neil Cauldwell
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Is there an rjs helper for zooming or scrolling to a DOM object, e.g.
> page.view_object "object"?
>
> I''ve tried using named anchors in combination with
link_to_function, but
> unless I''m doing something wrong, the onclick seems to override
the
> default browser behavior of skipping to a DOM element. For example;
>
> This works;
>
> <%= link_to "Nav", "#header" %>
>
> But this doesn''t;
>
> <%= link_to_function("Nav", :href => "#header")
do |page|
> some javascript
> end %>
>
> It doesn''t seem to matter which rjs helpers I use, or even if I
don''t
> use any at all, the onclick seems to kill the skip to the named anchor.
> So I was hoping I could just call an additional rjs helper to avoid the
> problem.
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---