Advertisement
Guest User

Contextual Links Fix, Mothership...

a guest
Feb 6th, 2014
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.95 KB | None | 0 0
  1. /**
  2.  * @file
  3.  * Attaches behaviors for the Contextual module.
  4.  */
  5.  
  6. (function ($) {
  7.  
  8. Drupal.contextualLinks = Drupal.contextualLinks || {};
  9.  
  10. /**
  11.  * Attaches outline behavior for regions associated with contextual links.
  12.  */
  13. Drupal.behaviors.contextualLinks = {
  14.   attach: function (context) {
  15.     // added the wrapper to the parent
  16.     $(".contextual-links-wrapper").parent().addClass('contextual-links-region clearfix');
  17.  
  18.     $('div.contextual-links-wrapper', context).once('contextual-links', function () {
  19.       var $wrapper = $(this);
  20.       var $region = $wrapper.closest('.contextual-links-region');
  21.       var $links = $wrapper.find('ul.contextual-links');
  22.       var $trigger = $('<a class="contextual-links-trigger" href="#" />').text(Drupal.t('Configure')).click(
  23.         function () {
  24.           $links.stop(true, true).slideToggle(100);
  25.           $wrapper.toggleClass('contextual-links-active');
  26.           return false;
  27.         }
  28.       );
  29.       // Attach hover behavior to trigger and ul.contextual-links.
  30.       $trigger.add($links).hover(
  31.         function () { $region.addClass('contextual-links-region-active'); },
  32.         function () { $region.removeClass('contextual-links-region-active'); }
  33.       );
  34.       // Hide the contextual links when user clicks a link or rolls out of the .contextual-links-region.
  35.       $region.bind('mouseleave click', Drupal.contextualLinks.mouseleave);
  36.       $region.hover(
  37.         function() { $trigger.addClass('contextual-links-trigger-active'); },
  38.         function() { $trigger.removeClass('contextual-links-trigger-active'); }
  39.      );
  40.  
  41.  
  42.       // Prepend the trigger.
  43.       $wrapper.prepend($trigger);
  44.     });
  45.   }
  46. };
  47.  
  48. /**
  49.  * Disables outline for the region contextual links are associated with.
  50.  */
  51. Drupal.contextualLinks.mouseleave = function () {
  52.   $(this)
  53.     .find('.contextual-links-active').removeClass('contextual-links-active')
  54.     .find('ul.contextual-links').hide();
  55. };
  56.  
  57. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement