On 29 Oct 2008, at 11:41, Peter De Berdt wrote:
> I just don't understand why people want to make it so hard on
> themselves. I know for a fact that will_paginate wraps the
> pagination links in a <div> with a class you can use, called
> "pagination". In your application.js file, you just put the
> following (I've also provided a link to a syntax highlighted pastie
> below, easier to read):
>
> document.observe("dom:loaded", function() {
> // pagination is the class will_paginate wraps around the links
> // let's keep the number of observers limited to one, your browser
> will thank you
> $$('.pagination').observe('click', function(e) {
> var clicked = $(e.target);
> // time to see if the clicked item was indeed one of the links
> if(clicked.match('a')) {
> // if it was, stop the default page refresh and fire an ajax
> request instead
> // let's not forget a RESTful design wants use to use GET
> instead of the default POST method
> e.stop();
> new Ajax.Request(clicked.href, {method: 'get'});
> }
> });
> }
>
> http://pastie.org/303029
>
> The code is untested, but looks to me like I didn't make a mistake.
> You could even take the event delegation a bit further and put it on
> the window element, but that's up to you guys to experiment with.
>
Memo to self: don't write code while being ill, you make stupid
mistakes. Updated code that should work better (pastie has also been
updated):
document.observe("dom:loaded", function() {
// pagination is the class will_paginate wraps around the links
$$('.pagination').each(function(pagination) {
// let's put the observer on the div element and not all the
links, your browser will thank you
pagination.observe('click', function(e) {
var clicked = $(e.target);
// time to see if the clicked item was indeed one of the links
if(clicked.match('a')) {
// if it was, stop the default page refresh and fire an ajax
request instead
// let's not forget a RESTful design wants use to use GET
instead of the default POST method
e.stop();
new Ajax.Request(clicked.href, {method: 'get'});
}
})
});
}
Best regards
Peter De Berdt
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---