1

I've created a view with Views Isotope and Views Load More contributed modules.

The objective is to have a Isitope grid that we can zoom in/out on items.

After long time to get it working I got a strange bug:

  1. When I load the page it works fine.
  2. When I click on load more first time the grid breaks.
  3. When I click on load more second time the grid works fine.
  4. When I click on load more third time the grid breaks.
  5. And so on...

See it working here.

This is my javascript:

(function ($) {
Drupal.behaviors.skeletonthemeCustomBehavior = {

attach: function (context, settings) {

  // $grid.isotope('destroy');

  var $grid = $('#isotope-container').isotope();

  $grid.isotope({
    masonry: {
      columnWidth: 10
    }
  });

$grid.on( 'click', '.isotope-element', function() {
  if ($( this ).hasClass( 'gigante' )) {
    $( this ).toggleClass('gigante');
  } else {
    // change size of item by toggling gigante class
    $( '.isotope-element' ).removeClass( 'gigante' );
    $( this ).toggleClass('gigante');
  }
  $grid.isotope('layout');
});

$('#destroy').bind( 'click' ,function(e) {
  event.preventDefault(e);
  $grid.isotope( 'destroy' );
});

  $('.relayout').bind( 'click' ,function(e) {
    event.preventDefault(e);
    var $grid = $('#isotope-container').isotope();
    $grid.isotope({
      masonry: {
        columnWidth: 10
      }
    });
    $grid.isotope('reloadItems');
  });

  $( document ).ajaxComplete(function() {
    var $grid = $('#isotope-container').isotope();
    $grid.isotope({
      masonry: {
        columnWidth: 10
      }
    });
    $grid.isotope('reloadItems');
  });
}

};
})(jQuery);
1
  • The last time I checked Views load more was pretty buggy. I'm using Jquery IAS for load more functionality. You may also want to check Isotopia module drupal.org/sandbox/nyariv/2223945
    – rreiss
    Commented Oct 9, 2015 at 12:48

2 Answers 2

2

I did noticed that after the 1st load more, you can't zoom in, then after the 2nd load more zoom works, and after the 3rd load more zoom doesn't work again.

I believe it's your code. You need to add the zoom in/out part again inside the ajaxComplete function

(function ($) {
Drupal.behaviors.skeletonthemeCustomBehavior = {

attach: function (context, settings) {

  // $grid.isotope('destroy');

  var $grid = $('#isotope-container').isotope();

  $grid.isotope({
    masonry: {
      columnWidth: 10
    }
  });

$grid.on( 'click', '.isotope-element', function() {
  if ($( this ).hasClass( 'gigante' )) {
    $( this ).toggleClass('gigante');
  } else {
    // change size of item by toggling gigante class
    $( '.isotope-element' ).removeClass( 'gigante' );
    $( this ).toggleClass('gigante');
  }
  $grid.isotope('layout');
});

$('#destroy').bind( 'click' ,function(e) {
  event.preventDefault(e);
  $grid.isotope( 'destroy' );
});

  $('.relayout').bind( 'click' ,function(e) {
    event.preventDefault(e);
    var $grid = $('#isotope-container').isotope();
    $grid.isotope({
      masonry: {
        columnWidth: 10
      }
    });
    $grid.isotope('reloadItems');
  });

  $( document ).ajaxComplete(function() {
    var $grid = $('#isotope-container').isotope();
    $grid.isotope({
      masonry: {
        columnWidth: 10
      }
    });
    $grid.isotope('reloadItems');
    // adding the zoom in/out after ajax complete
       $grid.on( 'click', '.isotope-element', function() {
       if ($( this ).hasClass( 'gigante' )) {
       $( this ).toggleClass('gigante');
       } else {
       // change size of item by toggling gigante class
       $( '.isotope-element' ).removeClass( 'gigante' );
       $( this ).toggleClass('gigante');
       }
       $grid.isotope('layout');
       });
  });
}

};
})(jQuery);
2
  • Hi, I did what you sugested(No Sssweat) and the behaviour now is diferent. First and second clicks break the zoom functionality of the grid, third and fourth clicks the grid works fine. Fifth click breaks again. I'm going crazy here.
    – MasterD
    Commented Oct 12, 2015 at 16:34
  • humm so weird. Try using Views Infinite Scroll module, it has a load more link option.
    – No Sssweat
    Commented Oct 13, 2015 at 6:15
1

It works fine for me. (your site) However if you want to prevent default behaviour you can indeed call e.preventDefault(); You just might want to try omitting the parameter.

new answer, now I understand the question better:

1) Drupal has an old version of jQuery by default with enough code that breaks. An easy solution without breaking modules that depend on the old version is adding a new version og jQuery with drupal_add_js() and then write

var nQuery = $.noConflict(true); //or any name you want
nQuery('#divID').click();//and use it like the $

2) jQuery selectors don't work on elements that are generated (bij XHR /ajax for example) But if you use the .on (a delegate) it does work:

$(document).on('click', '.relayout', function () {
    //show big pic
});

3) combining those:

 nQuery(document).on('click', '.relayout', function () {
        //show big pic
 });
5
  • Sorry but it's not working fine.
    – MasterD
    Commented Oct 9, 2015 at 15:32
  • when he said the grid breaks he meant the zoom in/out does not work, not the grid structure as one might think if you don't pay close attention to the The objective is to have a Isitope grid that we can zoom in/out on items part.
    – No Sssweat
    Commented Oct 10, 2015 at 5:22
  • ah exactly where I went wrong
    – Thomas
    Commented Oct 10, 2015 at 14:07
  • @MasterD I've made a new answer based on the additional info I got. Please try it.
    – Thomas
    Commented Oct 12, 2015 at 15:02
  • I'm already using the lastest jQuery version with jQuery update module. Your hack didn't work.
    – MasterD
    Commented Oct 12, 2015 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.