cms/drupal/modules/contextual/contextual.js
changeset 541 e756a8c72c3d
equal deleted inserted replaced
540:07239de796bb 541:e756a8c72c3d
       
     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     $('div.contextual-links-wrapper', context).once('contextual-links', function () {
       
    16       var $wrapper = $(this);
       
    17       var $region = $wrapper.closest('.contextual-links-region');
       
    18       var $links = $wrapper.find('ul.contextual-links');
       
    19       var $trigger = $('<a class="contextual-links-trigger" href="#" />').text(Drupal.t('Configure')).click(
       
    20         function () {
       
    21           $links.stop(true, true).slideToggle(100);
       
    22           $wrapper.toggleClass('contextual-links-active');
       
    23           return false;
       
    24         }
       
    25       );
       
    26       // Attach hover behavior to trigger and ul.contextual-links.
       
    27       $trigger.add($links).hover(
       
    28         function () { $region.addClass('contextual-links-region-active'); },
       
    29         function () { $region.removeClass('contextual-links-region-active'); }
       
    30       );
       
    31       // Hide the contextual links when user clicks a link or rolls out of the .contextual-links-region.
       
    32       $region.bind('mouseleave click', Drupal.contextualLinks.mouseleave);
       
    33       $region.hover(
       
    34         function() { $trigger.addClass('contextual-links-trigger-active'); },
       
    35         function() { $trigger.removeClass('contextual-links-trigger-active'); }
       
    36       );
       
    37       // Prepend the trigger.
       
    38       $wrapper.prepend($trigger);
       
    39     });
       
    40   }
       
    41 };
       
    42 
       
    43 /**
       
    44  * Disables outline for the region contextual links are associated with.
       
    45  */
       
    46 Drupal.contextualLinks.mouseleave = function () {
       
    47   $(this)
       
    48     .find('.contextual-links-active').removeClass('contextual-links-active')
       
    49     .find('ul.contextual-links').hide();
       
    50 };
       
    51 
       
    52 })(jQuery);