diff --git a/js/rubik.js b/js/rubik.js index 04522ce..c0b2e83 100644 --- a/js/rubik.js +++ b/js/rubik.js @@ -4,25 +4,26 @@ Drupal.behaviors.rubik = function(context) { // If there are both main column and side column buttons, only show the main // column buttons if the user scrolls past the ones to the side. - $('div.form:has(div.column-main div.buttons):not(.rubik-processed)').each(function() { + $('div.column-main').find('div.buttons').parents('div.form').not('.rubik-processed').each(function() { var form = $(this); - var offset = $('div.column-side div.buttons', form).height() + $('div.column-side div.buttons', form).offset().top; + var offset = $('div.column-side', form).find('div.buttons').height() + $('div.column-side', form).find('div.buttons').offset().top; $(window).scroll(function () { if ($(this).scrollTop() > offset) { - $('div.column-main div.buttons', form).show(); + $('div.column-main', form).find('div.buttons').show(); } else { - $('div.column-main div.buttons', form).hide(); + $('div.column-main', form).find('div.buttons').hide(); } }); form.addClass('rubik-processed'); }); - $('a.toggler:not(.rubik-processed)', context).each(function() { - var id = $(this).attr('href').split('#')[1]; + $('a.toggler', context).find('.rubik-processed').each(function() { + var $this = $(this); + var id = $this.attr('href').split('#')[1]; // Target exists, add click handler. if ($('#' + id).size() > 0) { - $(this).click(function() { + $this.click(function() { toggleable = $('#' + id); toggleable.toggle(); $(this).toggleClass('toggler-active'); @@ -31,10 +32,10 @@ Drupal.behaviors.rubik = function(context) { } // Target does not exist, remove click handler. else { - $(this).addClass('toggler-disabled'); - $(this).click(function() { return false; }); + $this.addClass('toggler-disabled'); + $this.click(function() { return false; }); } // Mark as processed. - $(this).addClass('rubik-processed'); + $this.addClass('rubik-processed'); }); };