1/** 2 * @file 3 * Defines Javascript behaviors for the commerce cart module. 4 */ 5 6(function ($, Drupal, drupalSettings) { 7 'use strict'; 8 9 Drupal.behaviors.commerceCartBlock = { 10 attach: function (context) { 11 var $context = $(context); 12 var $cart = $context.find('.cart--cart-block'); 13 var $cartButton = $context.find('.cart-block--link__expand'); 14 var $cartContents = $cart.find('.cart-block--contents'); 15 16 if ($cartContents.length > 0) { 17 // Expand the block when the link is clicked. 18 $cartButton.once('cart-button-processed').on('click', function (e) { 19 // Prevent it from going to the cart. 20 e.preventDefault(); 21 // Get the shopping cart width + the offset to the left. 22 var windowWidth = $(window).width(); 23 var cartWidth = $cartContents.width() + $cart.offset().left; 24 // If the cart goes out of the viewport we should align it right. 25 if (cartWidth > windowWidth) { 26 $cartContents.addClass('is-outside-horizontal'); 27 } 28 // Toggle the expanded class. 29 $cartContents 30 .toggleClass('cart-block--contents__expanded') 31 .slideToggle(); 32 }); 33 } 34 } 35 }; 36})(jQuery, Drupal, drupalSettings);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.