Hi,

if you have a page that reloads with AJAX, Drupal can re-initialize the javascript by calling Drupal.attachBehaviors('#my-block-id');. This reboots all jQuery run as a Drupal.behaviour.

Lazy Image Loader does not implement its jQuery correctly. Here is the simple solution for the D7 module:

1. Change the init() function like this:

/**
 * Implements hook_init().
 */
function lazy_image_loader_init() {
  if (_lazy_image_loader_page_match()) {
    $path = drupal_get_path('module', 'lazy_image_loader');
    
    drupal_add_js($path . '/jquery.lazyload.js');
    drupal_add_js($path . '/lazy_image_loader.js');
    
    drupal_add_js(array('lazy_image_loader_classes' => variable_get('lazy_image_loader_classes', '.content img')), 'setting');
    drupal_add_js(array('lazy_image_loader_threshold' => variable_get('lazy_image_loader_threshold', 0)), 'setting');
    drupal_add_js(array('lazy_image_loader_placeholder' => _lazy_image_loader_get_placeholder_image()), 'setting');
    drupal_add_js(array('lazy_image_loader_event' =>  variable_get('lazy_image_loader_event', 'scroll')), 'setting');
    drupal_add_js(array('lazy_image_loader_effect' =>  variable_get('lazy_image_loader_effect', 'show')), 'setting');
    drupal_add_js(array('lazy_image_loader_failurelimit' =>  variable_get('lazy_image_loader_failurelimit', 10)), 'setting');
  }
}

2. Add a file lazy_image_loader.js and it contains this:

(function($){
  Drupal.behaviors.lazy_image_loader = {
    attach: function(context, settings){
    
      // initialize Lazy Load Images
      // @see jquery.lazyload.js
      $(Drupal.settings.lazy_image_loader_classes).lazyload({
        threshhold: Drupal.settings.lazy_image_loader_threshold,
        placeholder: Drupal.settings.lazy_image_loader_placeholder,
        event: Drupal.settings.lazy_image_loader_event,
        effect: Drupal.settings.lazy_image_loader_effect,
        failurelimit: Drupal.settings.lazy_image_loader_failurelimit
      });
      
    }
  };
})(jQuery);

That's it!

Now Lazy Loader is a Drupal.behavior which people can re-fire on blocks/divs using Drupal.attachBehaviors()

Comments

sinasalek’s picture

Issue tags: +6.x-1.4 Roadmap

Marked

sinasalek’s picture

Drupal 6 version Committed , new dev snapshot will become available soon

sinasalek’s picture

Status: Active » Fixed
Anonymous’s picture

Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -6.x-1.4 Roadmap

Automatically closed -- issue fixed for 2 weeks with no activity.