When I look at a gallery that contains sub galleries and images, the layout is
SUB-GALLERIES
IMAGES pg1
PAGER

If I enable Ajax for the pager, and use the pager to select page 2, I see
SUB-GALLERIES
SUB-GALLERIES
IMAGES pg2
PAGER

If I then click page 3, I see
SUB-GALLERIES
SUB-GALLERIES
SUB-GALLERIES
IMAGES pg3
PAGER

ie Sub-galleries section is duplicated once for each click of the pager.

Is Ajax meant to be supported? I'm hoping that Ajax can be used as it makes viewing pages with a lot of sub-galleries more bearable. Without Ajax, clicking to the next page means the user has to scroll past all the sub-galleries before they can see the next page of images.

Comments

joachim’s picture

Oh dear.

This is happening because I'm rather abusing the Views page display to insert the separate subgalleries view above it -- it's a bit of a hack.
I'm not sure how the ajax stuff in Views works.
I'm guessing it's replacing the view content bit that's given by the view content DIV by what the view display produces as content.
The subgalleries are outside of that DIV, I think, but produced along with content, hence they get returned by the ajax.

I'm afraid I don't have much time to work on a patch, so any debugging or even patching you can do would help get this resolved more quickly.
Possible lines of attack:
1. detect we're in an ajax call in the Gallery display, and don't add the subgalleries if so
2. find a way of being outside the ajaxed div initially
3. change the current implementation -- say output the subgalleries in the header instead of the main view? Or in whichever part of the view attachments get put in -- that might be more elegant. Do attachments get reloaded with ajax?

davidhk’s picture

Thanks for the tips. I've tried putting it in the header, and it works a lot better there. Now the sub-galleries view (the image_gallery_terms view) is just displayed once without duplication.

However, when using the ajax pager to go to the next page, the browser still scrolls to the top of the whole view (ie the top of the sub-galleries view), so if you have a lot of sub-galleries the user has to do a lot of scrolling as they page through the images.

One solution would be to display the two views separately. eg we could leave the image_gallery_page always responsible for building the /image page, but if the views module is installed it can output the two views separately to build the gallery page.

I took the simpler workaround, and only show the sub-galleries view on the first page of the gallery:

1. Delete the render function from file image_gallery_plugin_display_image_gallery.inc
2. Edit the image_gallery view.
2.1 Edit the header, check the 'Display even if view has no result' box (so even if there are no images, still display any sub-galleries). Then insert the following code into the header:

<?php
//Read arguments from current view so we can pass to sub-gallery view
$this_view = views_get_current_view();

//only display sub-galleries on first page
if ($this_view-> pager[ 'current_page' ] ==0) {

  $view_args=array ($this_view-> args[1]);

  $header_view = views_get_view('image_gallery_terms');
  if (!empty($header_view)) {
    print $header_view->execute_display('default', $view_args);
  }
}
?>

3. Edit the image_gallery_terms view.
3.1 Edit the argument and set 'Action to take if argument is not present: ' to be 'Provide default argument' of 0. This causes it to only list top-level galleries when displaying the 'image' url. Otherwise it shows all galleries and sub-galleries.

joachim’s picture

Project: Image » Views catalogue
Version: 6.x-1.0-beta3 »
Component: views support » Code

I'm in the process of generalizing this code to work with any kind of view rather than just galleries.
Moving this issue to my new module, I'll work on it here first and then fix image gallery.

joachim’s picture

I've just committed a change to embed in the header rather than in the main content of the view.
The problem now is that it's not showing at all on the subsequent ajax pages, even with the setting unchecked.