PageSourceSearch

https://diamondeurogistics.co.uk/sites/all/themes/foundation/cougar/js/cougar.js?tmfkj1

js diamondeurogistics.co.uk collected 2026-10-07 19:41:26 UTC 11,029 bytes, 281 lines download raw bytes

1/**
2 * logResize to assit debugging
3 */
4var logResize = function logResize() {
5
6  this.previousWidth = 0;
7  this.previousHeight = 0;
8  this.currentWidth = 0;
9  this.currentHeight = 0;
10
11  // Retrive sizes
12  this.getPreviousWidth = function() {
13    return this.previousWidth;
14  }
15  this.getPreviousHeight = function() {
16    return this.previousHeight;
17  }
18  this.getCurrentWidth = function() {
19    this.currentWidth = $(window).width();
20    return this.currentWidth;
21  }
22  this.getCurrentHeight = function() {
23    this.currentHeight = $(window).height();
24    return this.currentHeight;
25  }
26  // Update sizes
27  this.updateWidth = function() {
28    this.previousWidth = this.currentWidth;
29    this.currentWidth = this.getCurrentWidth();
30    return;
31  }
32  this.updateHeight = function() {
33    this.previousHeight = this.currentHeight;
34    this.currentHeight = this.getCurrentHeight();
35    return;
36  }
37  this.update = function() {
38    this.updateWidth();
39    this.updateHeight();
40    return;
41  }
42  // Get update direction
43  this.getWidthDirection = function() {
44    var direction = this.currentWidth > this.previousWidth ? 1 : -1;
45        direction = this.previousWidth !== this.currentWidth ? direction : 0;
46    return direction;
47  }
48}
49
50/**
51 * jQuery plugin for selection cousins
52 * @param  {string} selector - jQuery Selector
53 * @return {Object}          - jQuery Object
54 */
55void function($) {
56    $.fn.cousins = function(selector) {
57        return this.parent().siblings().children(selector);
58    };
59}(jQuery);
60
61(function ($, Drupal) {
62
63  Drupal.behaviors.cougar = {
64    attach: function(context, settings) {
65      $(document).ready(function(){
66
67        /**
68         * Feature Region layout
69         */
70
71        // Selectors
72        var featuredLayoutSelectors = {
73          itemContent       : '[data-featured-layout="item-content"]',
74          itemImage         : '[data-featured-layout="item-image"]',
75          boxesContainer    : '[data-featured-layout="boxes-container"]',
76          carouselContainer : '[data-featured-layout="carousel-container"]',
77          carouselWrapper   : '[data-featured-layout="carousel-wrapper"]',
78          carousel          : '[data-featured-layout="carousel"]'
79        };
80
81        function scrollToTop(windowScrollDuration, topOffset) {
82        var windowScrollDuration = typeof windowScrollDuration !== 'undefined' ? windowScrollDuration : 500,    // Defaults to 500ms if not set
83            topOffset = typeof topOffset !== 'undefined' ? topOffset : 0,   // Defaults to 0 if not set 
84            windowCount = $('html').height() / $(window).height(),    // Calculates number of window scrolls required to see all content
85            totalScrollDuration = windowCount * windowScrollDuration;
86        $('html, body').animate({scrollTop : topOffset}, totalScrollDuration, 'swing');
87        }
88        // Add click handler for back to top button
89        $('.back-to-top').click(function(e){
90          e.preventDefault();
91          scrollToTop();
92          return false;
93        });
94
95        // jQuery Objects
96        var $featuredLayoutItemContent = $(featuredLayoutSelectors.itemContent);
97        var $featuredLayoutItemImage = $(featuredLayoutSelectors.itemImage);
98        var $featuredLayoutBoxesContainer = $(featuredLayoutSelectors.boxesContainer).filter(':first');
99        var $featuredLayoutCarouselContainer = $(featuredLayoutSelectors.carouselContainer).filter(':first');
100        var $featuredLayoutCarousel = $(featuredLayoutSelectors.carousel).filter(':first');
101        var $featuredLayoutCarouselWrapper;
102
103        // Defaults
104        var browserLogResize;
105        var carouselIsTaller = false;
106        var carouselIsEqual = false;
107        var featuredLayoutCarouselWrapper = '<div data-featured-layout="carousel-wrapper" />';
108
109        /**
110         * Equalizes heights of the elements to the height of the tallest
111         * @param  {object} $elements jQuery object of selected elements
112         */
113        function equalizeElementHeights($elements) {
114          // Get maxium item height
115          var maxHeight = getTallest($elements);
116          // Set each height to the max height
117          $elements.height(maxHeight);
118        }
119
120      function scrollToTop2(windowScrollDuration, topOffset) {
121        $('html, body').animate({
122          scrollTop: $(".scroll-to-content").offset().top
123          }, 2000);
124        }
125
126      // Add click handler for back to top button
127      $('.to-content').click(function(e){
128        e.preventDefault();
129        scrollToTop2();
130        return false;
131      });
132
133
134        /**
135         * Returns the height of the tallest element
136         * @param  {object} $elements  - jQuery object
137         * @return {int}               - height of tallest object in pixels
138         */
139        function getTallest($elements) {
140          // Get an array of all element heights
141          var elementHeights = $elements.map(function() {
142            return $(this).height();
143          }).get();
144
145          // Math.max takes a variable number of arguments
146          // `apply` is equivalent to passing each height as an argument
147          return Math.max.apply(null, elementHeights);
148        }
149
150        /**
151         * Compares the height of an element against another element
152         * @param  {object} $element          jQuery object to test
153         * @param  {object} $elementToCompare jQuery object to test against
154         * @return {boolean}
155         */
156        function compareIsTaller($element, $elementToCompare) {
157          var elementHeight = $element.height(),
158              elementToCompareHeight = $elementToCompare.height();
159
160          return elementHeight > elementToCompareHeight ? true : false;
161        }
162
163        /**
164         * Detirmns whether to elements are stacked based on their offset from the top
165         * @param  {object} $element          Main element
166         * @param  {object} $elementToCompare Element to compare against main element
167         * @return {boolean}                  Returns true if stacked
168         */
169        function isStacked($element, $elementToCompare) {
170          var elementTopOffset = $element.offset().top,
171              elementToTopOffset = $elementToCompare.offset().top;
172
173          return elementTopOffset != elementToTopOffset ? true : false;
174        }
175
176        /**
177         * Determins the with of an element based on the aspect ratio of another element
178         * @param  {object} $element          Main element (jQuery object)
179         * @param  {object} $elementToCompare Element to compare against main element
180         * @return {integer}                  Returns width in pixles
181         */
182        function scaleWidth($element, $elementToCompare) {
183          var elementHeight = $element.height();
184          var elementToCompareWidth = $elementToCompare.width();
185          var elementToCompareHeight = $elementToCompare.height();
186
187          return (elementHeight * elementToCompareWidth) / elementToCompareHeight;
188        }
189
190        /**
191         * Initialises Feature Regions Layout
192         * @return {[type]} [description]
193         */
194        function featuredLayoutInit() {
195          // Set item content height to initial
196          $featuredLayoutItemContent.height('auto');
197
198          // Match item content heights to tallest
199          equalizeElementHeights($featuredLayoutItemContent);
200
201          // Set the height of each items image to the items content outerHeight
202          $featuredLayoutItemImage.each(function(){
203            var itemContentOuterHeight = $(this).cousins(featuredLayoutSelectors.itemContent).outerHeight(true);
204            $(this).height(itemContentOuterHeight);
205          });
206
207          // Add wrapper if doesn't exist
208          if ($(featuredLayoutSelectors.carouselWrapper).length == 0) {
209            $featuredLayoutCarouselContainer.wrapInner(featuredLayoutCarouselWrapper);
210            $featuredLayoutCarouselWrapper = $(featuredLayoutSelectors.carouselWrapper).filter(':first');
211          }
212          // Wrapper already exists
213          else {
214            // reset previously set dimensional attributes
215            $featuredLayoutCarouselWrapper.width('auto');
216            $featuredLayoutCarouselWrapper.height('auto');
217          }
218
219          // Check if carousel is stacked on boxes
220          carouselIsStacked = isStacked($featuredLayoutCarouselContainer, $featuredLayoutBoxesContainer);
221
222          if(carouselIsStacked === true) {
223            // carousel is stacked, doesn't need resizing manually, get outta here!!!
224            return;
225          }
226          // Compare Carousel to homebanner boxes stack.
227          carouselIsTaller = compareIsTaller($featuredLayoutCarouselContainer, $featuredLayoutBoxesContainer);
228          switch (carouselIsTaller) {
229            case true:
230              // Reset item heights
231              $featuredLayoutItemContent.height('auto');
232
233              // Increase the size of them there featuredLayoutItemContent
234              var numberOfItems = $featuredLayoutItemContent.length;
235              var newItemHeight = $featuredLayoutCarouselContainer.height() / numberOfItems;
236              $featuredLayoutItemContent.outerHeight(newItemHeight);
237
238              // Set the height of each items image to the items content outerHeight
239              $featuredLayoutItemImage.each(function(){
240                var itemContentOuterHeight = $(this).cousins(featuredLayoutSelectors.itemContent).outerHeight(true);
241                $(this).height(itemContentOuterHeight);
242              });
243            case false:
244              // Increase the size of this here featuredLayoutCarouselContainer
245              var featureHeight = $featuredLayoutBoxesContainer.height();
246              $featuredLayoutCarouselWrapper.height(featureHeight);
247
248              // Get containers new width respective to new height
249              var upScaledWidth = scaleWidth($featuredLayoutCarouselWrapper, $featuredLayoutCarousel.parent());
250              var availableSpace = $featuredLayoutCarouselContainer.width();
251
252              // Check this is greater or equal to available space
253              var upScaledWidthIsGreater = upScaledWidth > availableSpace ? true : false;
254
255              // If it is go ahead and DO IT!
256              if(upScaledWidthIsGreater === true) {
257                $featuredLayoutCarouselWrapper.width(upScaledWidth);
258              } else {
259                $featuredLayoutCarouselWrapper.height('auto');
260              }
261              break;
262            default:
263            // Our work here be done
264            console.error('Unable to use compareIsTaller(). Please check what\'s going into it, ja?');
265          }
266        }
267
268        // Initialise Feature Layout
269        featuredLayoutInit();
270        $featuredLayoutCarousel.trigger('resize');
271
272        $(window).on('resize', Foundation.utils.throttle(function(e){
273          // Re-initialise Feature Layout
274          featuredLayoutInit();
275          // Trigger resize on carousel
276          $featuredLayoutCarousel.trigger('updateSizes');
277        }, 150));
278      });
279    }
280  };
281})(jQuery, Drupal);

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.