Ajax customization
sirkitree - June 11, 2008 - 04:58
| Project: | Views Alpha Pager |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Description
Yo, a while back I said I'd contribute back some ajax stuff I did with your module. So here's the basics:
Implementation of a new menu call to return json data:
<?php
$items[] = array(
'path' => 'myplay/artists-a-z',
'callback' => 'myplay_artists_alpha_listing',
'callback arguments' => $_GET['apage'],
'type' => MENU_CALLBACK,
'access' => TRUE,
);
?>corresponding menu callback function:
<?php
// this is for the ajax call used on the frontpage to replicate what views_alphapager returns
function myplay_artists_alpha_listing() {
$args = func_get_args();
$view = views_get_view('artists_pager');
$output = views_build_view('page', $view, $args, FALSE);
$output = str_replace($view->alpha_pager_output, '', $output); // might be a better way?
print $output;
exit;
}
?>a little jquery:
$(document).ready(function(){
old = $('.apager .pager-list strong').html();
$('.apager .pager-list strong').wrap("<a title='Go to " + old + " listings' class='pager-next active' href='/front?apage=" + old + "#artist-alpha'></a>");
$('.apager .pager-list a').click(function(){
target = $(this).html();
data = "apage=" + target;
old = $('.apager .pager-list strong').html();
$('.apager .pager-list strong').parent().html(old);
$(this).html("<strong class='pager-current'>" + target + "</strong>");
$(".view-artists-pager").html("<center><h3>Loading</h3></center>"); // This should be themed somehow, didn't work out how yet
$.ajax({
url: "myplay/artists-a-z",
data: data,
success: function(html){
$(".view-artists-pager").html(html);
}
});
return false;
});
});I did most of this in my site's custom module and didn't really hack up alpha pager, so I've not provided a patch, but if anyone finds this useful I figured it be a good place to post this.
