rubik.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * Implementation of Drupal behavior.
  3. */
  4. (function($) {
  5. Drupal.behaviors.rubik = {};
  6. Drupal.behaviors.rubik.attach = function(context) {
  7. // If there are both main column and side column buttons, only show the main
  8. // column buttons if the user scrolls past the ones to the side.
  9. $('div.form:has(div.column-main div.form-actions):not(.rubik-processed)').each(function() {
  10. var form = $(this);
  11. var offset = $('div.column-side div.form-actions', form).height() + $('div.column-side div.form-actions', form).offset().top;
  12. $(window).scroll(function () {
  13. if ($(this).scrollTop() > offset) {
  14. $('div.column-main div.form-actions', form).show();
  15. }
  16. else {
  17. $('div.column-main div.form-actions', form).hide();
  18. }
  19. });
  20. form.addClass('rubik-processed');
  21. });
  22. $('a.toggler:not(.rubik-processed)', context).each(function() {
  23. var id = $(this).attr('href').split('#')[1];
  24. // Target exists, add click handler.
  25. if ($('#' + id).size() > 0) {
  26. $(this).click(function() {
  27. toggleable = $('#' + id);
  28. toggleable.toggle();
  29. $(this).toggleClass('toggler-active');
  30. return false;
  31. });
  32. }
  33. // Target does not exist, remove click handler.
  34. else {
  35. $(this).addClass('toggler-disabled');
  36. $(this).click(function() { return false; });
  37. }
  38. // Mark as processed.
  39. $(this).addClass('rubik-processed');
  40. });
  41. };
  42. })(jQuery);