contextual.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @file
  3. * Attaches behaviors for the Contextual module.
  4. */
  5. (function ($) {
  6. Drupal.contextualLinks = Drupal.contextualLinks || {};
  7. /**
  8. * Attaches outline behavior for regions associated with contextual links.
  9. */
  10. Drupal.behaviors.contextualLinks = {
  11. attach: function (context) {
  12. $('div.contextual-links-wrapper', context).once('contextual-links', function () {
  13. var $wrapper = $(this);
  14. var $region = $wrapper.closest('.contextual-links-region');
  15. var $links = $wrapper.find('ul.contextual-links');
  16. var $trigger = $('<a class="contextual-links-trigger" href="#" />').text(Drupal.t('Configure')).click(
  17. function () {
  18. $links.stop(true, true).slideToggle(100);
  19. $wrapper.toggleClass('contextual-links-active');
  20. return false;
  21. }
  22. );
  23. // Attach hover behavior to trigger and ul.contextual-links.
  24. $trigger.add($links).hover(
  25. function () { $region.addClass('contextual-links-region-active'); },
  26. function () { $region.removeClass('contextual-links-region-active'); }
  27. );
  28. // Hide the contextual links when user clicks a link or rolls out of the .contextual-links-region.
  29. $region.bind('mouseleave click', Drupal.contextualLinks.mouseleave);
  30. // Prepend the trigger.
  31. $wrapper.prepend($trigger);
  32. });
  33. }
  34. };
  35. /**
  36. * Disables outline for the region contextual links are associated with.
  37. */
  38. Drupal.contextualLinks.mouseleave = function () {
  39. $(this)
  40. .find('.contextual-links-active').removeClass('contextual-links-active')
  41. .find('ul.contextual-links').hide();
  42. };
  43. })(jQuery);