PageSourceSearch

https://minnetlever.se/wp-content/themes/shapely/assets/js/shapely-scripts.js?ver=20180423

js minnetlever.se collected 2026-10-08 22:39:38 UTC 16,548 bytes, 546 lines download raw bytes

1/* jshint es3:false, esversion:6 */
2(function ($) {
3  // jscs:ignore validateLineBreaks
4
5  let clNav, clNavOuterHeight, windowW, menu, farRight, isOnScreen, difference, videos, recentEntries, searchInterval, shapelyCf, element, newURL, scrollToID;
6
7  $(function () {
8    $('body').imagesLoaded(function () {
9      $(window).trigger('resize').trigger('scroll');
10    });
11
12    $('.shapely-dropdown').on('click', function (evt) {
13      evt.preventDefault();
14      $(this).parent().find('> ul').toggleClass('active');
15      $(window).trigger('resize').trigger('scroll');
16    });
17
18    // Smooth scroll to inner links
19    $('.inner-link').each(function () {
20      let href = $(this).attr('href');
21      if ('#' !== href.charAt(0)) {
22        $(this).removeClass('inner-link');
23      }
24    });
25
26    // Smooth scroll
27    (function () {
28      if ('' === window.location.hash) {
29        return;
30      }
31
32      // Try to extract the target ID from the related menu item, else use the hash as ID
33      let scrollToID = $('#site-navigation #menu a[href="' + window.location.hash + '"]').data('scroll');
34      scrollToID = scrollToID ? '#' + scrollToID : window.location.hash;
35
36      let scrollTarget = $(scrollToID);
37      if (scrollTarget.length < 1) {
38        return;
39      }
40
41      $('html,body').animate(
42        {
43          scrollTop: scrollTarget.offset().top,
44        },
45        2000
46      );
47
48      newURL = window.location.href.replace(window.location.hash, '');
49      window.history.replaceState({}, document.title, newURL);
50    })();
51
52    $('#site-navigation #menu a[href^="#"]:not([href="#"])').on('click', function (evt) {
53      let scrollToID = '#' + $(this).data('scroll');
54
55      if ($(scrollToID).length > 1) {
56        scrollToID = $(this).attr('href');
57      }
58
59      if ($(scrollToID).length < 1) {
60        return;
61      }
62
63      evt.preventDefault();
64      $('html,body').animate(
65        {
66          scrollTop: $(scrollToID).offset().top,
67        },
68        2000
69      );
70    });
71
72    $('.inner-link').on('click', function () {
73      $('html, body').animate(
74        {
75          scrollTop: 0,
76        },
77        500
78      );
79      return false;
80    });
81
82    // Append .background-image-holder <img>'s as CSS backgrounds
83    $('.background-image-holder').each(function () {
84      let imgSrc = $(this).children('img').attr('src');
85      $(this).css('background', 'url("' + imgSrc + '")');
86      $(this).children('img').hide();
87      $(this).css('background-position', 'initial');
88    });
89
90    // Fade in background images
91    setTimeout(function () {
92      $('.background-image-holder').each(function () {
93        $(this).addClass('fadeIn');
94      });
95    }, 200);
96
97    if ('1' === ShapelyAdminObject.sticky_header) {
98      // Fix nav to top while scrolling
99      clNav = $('body .nav-container nav:first');
100      clNavOuterHeight = $('body .nav-container nav:first').outerHeight();
101      windowW = $(window).width();
102      if (windowW > 991) {
103        window.addEventListener('scroll', updateNav, false);
104        updateNav();
105      }
106
107      $(window).resize(function () {
108        windowW = $(window).width();
109        if (windowW < 992) {
110          clNav.removeClass('fixed scrolled outOfSight');
111        } else {
112          window.addEventListener('scroll', updateNav, false);
113          updateNav();
114        }
115      });
116    }
117
118    // Menu dropdown positioning
119
120    $('.menu > li > ul').each(function () {
121      menu = $(this).offset();
122      farRight = menu.left + $(this).outerWidth(true);
123      if (farRight > $(window).width() && !$(this).hasClass('mega-menu')) {
124        $(this).addClass('make-right');
125      } else if (farRight > $(window).width() && $(this).hasClass('mega-menu')) {
126        isOnScreen = $(window).width() - menu.left;
127        difference = $(this).outerWidth(true) - isOnScreen;
128        $(this).css('margin-left', -difference);
129      }
130    });
131
132    // Mobile Menu
133
134    $('.mobile-toggle').on('click', function () {
135      $('.nav-bar').toggleClass('nav-open');
136      $(this).toggleClass('active');
137      $('.search-widget-handle').toggleClass('hidden-xs hidden-sm');
138      $(window).trigger('resize').trigger('scroll');
139    });
140
141    $('.module.widget-handle').on('click', function () {
142      $(this).toggleClass('toggle-search');
143      $(window).trigger('resize').trigger('scroll');
144    });
145
146    $('.search-widget-handle .search-form input').on('click', function (e) {
147      if (!e) {
148        e = window.event;
149      }
150      e.stopPropagation();
151    });
152
153    // Image Sliders
154    $('.slider-all-controls').flexslider({
155      start: function (slider) {
156        if (slider.find('.slides li:first-child').find('.fs-vid-background video').length) {
157          slider.find('.slides li:first-child').find('.fs-vid-background video').get(0).play();
158        }
159      },
160      after: function (slider) {
161        if (slider.find('.fs-vid-background video').length) {
162          if (slider.find('li:not(.flex-active-slide)').find('.fs-vid-background video').length) {
163            slider.find('li:not(.flex-active-slide)').find('.fs-vid-background video').get(0).pause();
164          }
165          if (slider.find('.flex-active-slide').find('.fs-vid-background video').length) {
166            slider.find('.flex-active-slide').find('.fs-vid-background video').get(0).play();
167          }
168        }
169      },
170    });
171    $('.slider-paging-controls').flexslider({
172      animation: 'slide',
173      directionNav: false,
174      after: function (slider) {
175        if (!slider.playing) {
176          slider.pause();
177          slider.play();
178          slider.off('mouseenter mouseleave');
179          slider.off('mouseover mouseout');
180          slider
181            .mouseover(function () {
182              if (!slider.manualPlay && !slider.manualPause) {
183                slider.pause();
184              }
185            })
186            .mouseout(function () {
187              if (!slider.manualPause && !slider.manualPlay && !slider.stopped) {
188                slider.play();
189              }
190            });
191        }
192      },
193    });
194    $('.slider-arrow-controls').flexslider({
195      controlNav: false,
196      after: function (slider) {
197        if (!slider.playing) {
198          slider.pause();
199          slider.play();
200          slider.off('mouseenter mouseleave');
201          slider.off('mouseover mouseout');
202          slider
203            .mouseover(function () {
204              if (!slider.manualPlay && !slider.manualPause) {
205                slider.pause();
206              }
207            })
208            .mouseout(function () {
209              if (!slider.manualPause && !slider.manualPlay && !slider.stopped) {
210                slider.play();
211              }
212            });
213        }
214      },
215    });
216    $('.slider-thumb-controls .slides li').each(function () {
217      let imgSrc = $(this).find('img').attr('src');
218      $(this).attr('data-thumb', imgSrc);
219    });
220    $('.slider-thumb-controls').flexslider({
221      animation: 'slide',
222      controlNav: 'thumbnails',
223      directionNav: true,
224      after: function (slider) {
225        if (!slider.playing) {
226          slider.pause();
227          slider.play();
228          slider.off('mouseenter mouseleave');
229          slider.off('mouseover mouseout');
230          slider
231            .mouseover(function () {
232              if (!slider.manualPlay && !slider.manualPause) {
233                slider.pause();
234              }
235            })
236            .mouseout(function () {
237              if (!slider.manualPause && !slider.manualPlay && !slider.stopped) {
238                slider.play();
239              }
240            });
241        }
242      },
243    });
244    $('.logo-carousel').flexslider({
245      minItems: 1,
246      maxItems: 4,
247      move: 1,
248      itemWidth: 200,
249      itemMargin: 0,
250      animation: 'slide',
251      slideshow: true,
252      slideshowSpeed: 3000,
253      directionNav: false,
254      controlNav: false,
255      after: function (slider) {
256        if (!slider.playing) {
257          slider.pause();
258          slider.play();
259          slider.off('mouseenter mouseleave');
260          slider.off('mouseover mouseout');
261          slider
262            .mouseover(function () {
263              if (!slider.manualPlay && !slider.manualPause) {
264                slider.pause();
265              }
266            })
267            .mouseout(function () {
268              if (!slider.manualPause && !slider.manualPlay && !slider.stopped) {
269                slider.play();
270              }
271            });
272        }
273      },
274    });
275
276    // Lightbox gallery titles
277    $('.lightbox-grid li a').each(function () {
278      let galleryTitle = $(this).closest('.lightbox-grid').attr('data-gallery-title');
279      $(this).attr('data-lightbox', galleryTitle);
280    });
281
282    videos = $('.video-widget');
283    if (videos.length) {
284      $.each(videos, function () {
285        let play = $(this).find('.play-button'),
286          pause = $(this).find('.pause-button'),
287          isYoutube = $(this).hasClass('youtube'),
288          isVimeo = $(this).hasClass('vimeo'),
289          videoId,
290          mute,
291          instance,
292          self,
293          autoplay,
294          data,
295          options,
296          containerId,
297          player;
298
299        if (isYoutube) {
300          videoId = $(this).attr('data-video-id');
301          autoplay = parseInt($(this).attr('data-autoplay'), 10);
302          mute = parseInt($(this).attr('data-mute'), 10);
303          instance = $(this).YTPlayer({
304            fitToBackground: true,
305            videoId: videoId,
306            mute: mute,
307            playerVars: {
308              autoplay: autoplay,
309              autohide: 0,
310              branding: 0,
311              controls: 0,
312              showinfo: 0,
313              modestbranding: 0,
314            },
315            playerlets: {
316              rel: 0,
317            },
318          });
319          self = $(this);
320
321          $(document).on('YTBGREADY', function () {
322            let iframe = self.find('iframe'),
323              height = iframe.height();
324          });
325
326          $(play).on('click', function (e) {
327            let parent = $(this).parents('.video-widget'),
328              instance = $(parent).data('ytPlayer').player;
329            e.preventDefault();
330            instance.playVideo();
331          });
332
333          $(pause).on('click', function (e) {
334            let parent = $(this).parents('.video-widget'),
335              instance = $(parent).data('ytPlayer').player;
336            e.preventDefault();
337            instance.pauseVideo();
338          });
339        } else if (isVimeo) {
340          data = $(this).data();
341          options = {
342            id: data.videoId,
343            autoplay: data.autoplay,
344            loop: 1,
345            title: false,
346            portrait: false,
347            byline: false,
348            height: $(this).height(),
349            width: $(this).width(),
350          };
351          containerId = $(this).find('.vimeo-holder').attr('id');
352          player = new Vimeo.Player(containerId, options);
353
354          if (data.mute) {
355            player.setVolume(0);
356          }
357
358          $(play).on('click', function () {
359            player.play();
360          });
361          $(pause).on('click', function () {
362            player.pause();
363          });
364        } else {
365          $(play).on('click', function (e) {
366            let parent = $(this).parents('.video-widget'),
367              instance = $(parent).data('vide'),
368              video = instance.getVideoObject();
369            e.preventDefault();
370            video.play();
371          });
372
373          $(pause).on('click', function (e) {
374            let parent = $(this).parents('.video-widget'),
375              instance = $(parent).data('vide'),
376              video = instance.getVideoObject();
377            e.preventDefault();
378            video.pause();
379          });
380        }
381      });
382    }
383
384    recentEntries = $('.widget_recent_entries').find('li');
385    $.each(recentEntries, function () {
386      $(this).find('a').insertAfter($(this).find('.post-date'));
387    });
388
389    $('.comment-form').find('textarea').insertAfter($('.comment-form > #url'));
390
391    if ('undefined' !== typeof $.fn.owlCarousel) {
392      $('.owlCarousel').each(function (index) {
393        let sliderSelector = '#owlCarousel-' + $(this).data('slider-id'); // This is the slider selector
394        let sliderItems = $(this).data('slider-items');
395        let sliderSpeed = $(this).data('slider-speed');
396        let sliderAutoPlay = $(this).data('slider-auto-play');
397        let sliderSingleItem = $(this).data('slider-single-item');
398
399        //Conversion of 1 to true & 0 to false
400        // auto play
401        sliderAutoPlay = !(0 === sliderAutoPlay || 'false' === sliderAutoPlay);
402
403        // Custom Navigation events outside of the owlCarousel mark-up
404        $('.shapely-owl-next').on('click', function (event) {
405          event.preventDefault();
406          $(sliderSelector).trigger('next.owl.carousel');
407        });
408        $('.shapely-owl-prev').on('click', function (event) {
409          event.preventDefault();
410          $(sliderSelector).trigger('prev.owl.carousel');
411        });
412
413        // Instantiate the slider with all the options
414        $(sliderSelector).owlCarousel({
415          items: sliderItems,
416          loop: false,
417          margin: 2,
418          autoplay: sliderAutoPlay,
419          dots: false,
420          autoplayTimeout: sliderSpeed * 10,
421          responsive: {
422            0: {
423              items: 1,
424            },
425            768: {
426              items: sliderItems,
427            },
428          },
429        });
430      });
431    } // End
432
433    $('#masthead .function #s').on('focus', function () {
434      $(this).parents('.function').addClass('active');
435    });
436
437    $('#masthead .function #s').focusout(function () {
438      searchInterval = setInterval(function () {
439        $('#masthead .function').removeClass('active');
440      }, 500);
441    });
442
443    $('#masthead .function #searchsubmit').on('focus', function () {
444      clearInterval(searchInterval);
445      $(this).parents('.function').addClass('active');
446    });
447
448    $('#masthead .function #searchsubmit').focusout(function () {
449      $(this).parents('.function').removeClass('active');
450    });
451
452    // Check if is a contact form 7 with parallax background
453    shapelyCf = $('.contact-section.image-bg .wpcf7');
454    if (shapelyCf.length > 0) {
455      shapelyCf.on('wpcf7submit', function () {
456        setTimeout(function () {
457          $(window).trigger('resize').trigger('scroll');
458        }, 800);
459      });
460    }
461  });
462
463  $(window).on('load', function () {
464    // "use strict";
465    // Resetting testimonial parallax height
466    let msnry, container, clFirstSectionHeight;
467    if (0 !== $('.testimonial-section').length) {
468      testimonialHeight();
469      setTimeout(function () {
470        testimonialHeight();
471      }, 3000);
472    }
473
474    // Initialize Masonry
475    if ($('.masonry').length && 'undefined' !== typeof Masonry) {
476      container = document.querySelector('.masonry');
477      msnry = new Masonry(container, {
478        itemSelector: '.masonry-item',
479      });
480
481      msnry.on('layoutComplete', function () {
482        clFirstSectionHeight = $('.main-container section:nth-of-type(1)').outerHeight(true);
483        $('.masonry').addClass('fadeIn');
484        $('.masonry-loader').addClass('fadeOut');
485        if ($('.masonryFlyIn').length) {
486          masonryFlyIn();
487        }
488      });
489
490      msnry.layout();
491    }
492
493    // Navigation height
494    clFirstSectionHeight = $('.main-container section:nth-of-type(1)').outerHeight(true);
495  });
496
497  /* Function To
498   * keep menu fixed
499   **/
500  function updateNav() {
501    let scroll = $(window).scrollTop();
502    let windowW = $(window).width();
503
504    if (windowW < 992) {
505      return;
506    }
507
508    if (scroll > clNavOuterHeight) {
509      clNav.addClass('outOfSight');
510    }
511
512    if ($(window).scrollTop() > clNavOuterHeight + 65) {
513      //If href = #element id
514      clNav.addClass('fixed scrolled');
515    }
516
517    if (0 === $(window).scrollTop()) {
518      clNav.removeClass('fixed scrolled outOfSight');
519    }
520  }
521
522  function masonryFlyIn() {
523    let $items = $('.masonryFlyIn .masonry-item');
524    let time = 0;
525
526    $items.each(function () {
527      let item = $(this);
528      setTimeout(function () {
529        item.addClass('fadeIn');
530      }, time);
531      time += 170;
532    });
533  }
534
535  $('body').imagesLoaded(function () {
536    $(window).trigger('resize').trigger('scroll');
537  });
538})(jQuery);
539
540/*
541 * Resetting testimonial parallax height
542 */
543function testimonialHeight() {
544  jQuery('.testimonial-section .parallax-window').css('height', jQuery('.testimonial-section .parallax-window .container').outerHeight() + 150);
545  jQuery(window).trigger('resize').trigger('scroll');
546}

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.