I have this code - which works perfectly when pages aren't lazy loaded with AJAX.
As soon as AJAX gets involved it doesn't work at all until the page is refreshed.
omShortcodes.modules.toggle = {
init: function() {
jQuery('.omsc-accordion .omsc-toggle').addClass('omsc-in-accordion').find('.omsc-toggle-title').click(function(){
var $toggle=jQuery(this).parent();
if($toggle.hasClass('omsc-expanded')) {
$toggle.removeClass('omsc-expanded');
$toggle.find('.omsc-toggle-inner').slideUp(300);
return false;
}
var $acc=$toggle.parents('.omsc-accordion');
if(!$acc.hasClass('omsc-multiopen'))
$acc.find('.omsc-toggle.omsc-expanded').removeClass('omsc-expanded').find('.omsc-toggle-inner').slideUp(300);
$toggle.find('.omsc-toggle-inner').slideDown(300,function(){
var h=jQuery(this).parent().height();
var pos=jQuery(this).parent().find('.omsc-toggle-title').offset();
var scroll=jQuery(window).scrollTop();
var wh=jQuery(window).height();
if(pos.top < scroll || (pos.top > scroll && pos.top+h > scroll+wh))
jQuery('html,body').animate({ scrollTop: pos.top+'px' }, 200);
}).find('iframe[src*="maps.google"]').each(function(){
jQuery(this).attr('src',jQuery(this).attr('src'));
});
$toggle.addClass('omsc-expanded');
});
jQuery('.omsc-toggle').not('.in-accordion').find('.omsc-toggle-title').click(function(){
var $toggle=jQuery(this).parent();
var $inner=$toggle.find('.omsc-toggle-inner');
if(!$inner.length)
return false;
if($inner.is(':animated'))
return false;
$toggle.toggleClass('omsc-expanded');
$inner.slideToggle(300);
if($toggle.hasClass('omsc-expanded')) {
$inner.find('iframe[src*="maps.google"]').each(function(){
jQuery(this).attr('src',jQuery(this).attr('src'));
});
}
return false;
});
}
}
Is there another way of handling this to be able to work properly with AJAX?