Masonry javascript not loading for AJAX view

Created on 23 August 2018, over 6 years ago
Updated 26 April 2023, over 1 year ago

While working on a site, I've noticed that the required JS for Masonry isn't being loaded via XHR requests. It appears fine in Views UI but when used on an actual page it's not coming through XHR requests as it does through the admin interface.

A temporary fix for now has been adding it via the theme's template.php:

function hook_views_pre_render(&$view) {
  if ($view->name == '<view name>' && $view->current_display == '<view display>') {
    // load the libraries
    drupal_add_js(libraries_get_path('masonry') . '/masonry.pkgd.min.js');
    drupal_add_js(libraries_get_path('imagesloaded') . '/imagesloaded.pkgd.min.js');
    drupal_add_css(drupal_get_path('module', 'masonry') . '/masonry.js');
    // copy paste from template_preprocess_views_view_masonry() in masonry_views.module.
      // Display content in a Masonry layout
      $container = '.view-' . drupal_clean_css_identifier($view->name) . '.view-display-id-' . $view->current_display . ' > .view-content';
      if (!empty($options['grouping'])) {
        $vars['grouping'] = true;
        static $groupid;
        $container .= ' .masonry-group-' . ++$groupid;
        $vars['prefix'] = "<div class=\"masonry-group masonry-group-$groupid\">";
        $vars['suffix'] = "</div>";
      }
      $options['masonry_item_selector'] = '.masonry-item';
      masonry_apply($container, $options);
  }
}
🐛 Bug report
Status

Closed: outdated

Version

3.0

Component

Code

Created by

🇯🇵Japan paul.kim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024