PageSourceSearch

https://heroncity.se/wp-content/themes/heroncity/build/blocks/post…/viewscript.js?ver=ac223729433710773fa7

js heroncity.se collected 2026-09-26 16:10:16 UTC 5,020 bytes, 126 lines download raw bytes

1/******/ (() => { // webpackBootstrap
2/*!***********************************************!*\
3  !*** ./src/blocks/post-archive/viewscript.js ***!
4  \***********************************************/
5(function ($) {
6  $(function () {
7    $('.posts-layout > button').each(function () {
8      $(this).on('click', function () {
9        var $this = $(this);
10        var $parent = $this.parent();
11        $parent.find('button').removeClass('active');
12        $this.addClass('active');
13
14        // Get layout value from button (e.g., data-layout attribute or value)
15        var layout = $this.data('layout') || $this.val();
16
17        // Update URL parameter
18        var url = new URL(window.location);
19        url.searchParams.set('layout', layout);
20        window.history.replaceState({}, '', url);
21        $this.closest('.posts-archive').find('.posts-container').attr('data-layout', layout);
22      });
23    });
24    $('.filter-items .filter-button').on('click', function () {
25      var $this = $(this);
26      $this.siblings().removeClass('active');
27      $this.addClass('active');
28      var filter = $this.data('cat');
29      var $items = $this.closest('.posts-archive').find('.posts-container .post-container');
30      updateVisibility(filter, $items);
31      updateTaxonomyUrl(filter);
32    });
33    function updateTaxonomyUrl(filter) {
34      var currentUrl = new URL(window.location.href);
35      var currentPath = currentUrl.pathname.replace(/\/$/, ''); // remove trailing slash
36      var pathSegments = currentPath.split('/').filter(Boolean);
37      var languages = ['en', 'sv'];
38      var hasLangPrefix = languages.includes(pathSegments[0]);
39      var basePath;
40      if (hasLangPrefix) {
41        basePath = '/' + pathSegments[0] + '/' + pathSegments[1];
42      } else {
43        basePath = '/' + pathSegments[0];
44      }
45      var newPath;
46      if (filter && filter.length > 0) {
47        if (hasLangPrefix) {
48          newPath = '/' + pathSegments[0] + '/' + pathSegments[1] + '/' + filter;
49        } else {
50          newPath = '/' + pathSegments[0] + '/' + filter;
51        }
52      } else {
53        newPath = basePath;
54      }
55      window.history.replaceState({}, '', newPath);
56    }
57    function updateVisibility(filter, $items) {
58      $items.each(function () {
59        var $item = $(this);
60        if ($item.data('cat').includes(filter)) {
61          $item.addClass('visible');
62        } else {
63          $item.removeClass('visible');
64        }
65      });
66      var $count = $items.filter('.visible').length;
67      $('.posts-count span.count-number').text($count);
68      if ($count === 1) {
69        $('.posts-count .singular-label').show();
70        $('.posts-count .plural-label').hide();
71      } else {
72        $('.posts-count .singular-label').hide();
73        $('.posts-count .plural-label').show();
74      }
75    }
76    // Helper: safely extract filter segment whether there's a lang prefix or not
77    function getUrlFilterFromPath(pathname) {
78      var segments = pathname.split('/').filter(Boolean);
79      var languages = ['en', 'sv'];
80      var hasLangPrefix = segments.length && languages.includes(segments[0]);
81      var filterIndex = hasLangPrefix ? 2 : 1;
82      return segments.length > filterIndex ? segments[filterIndex] : '';
83    }
84    var pathSegments = window.location.pathname.split('/').filter(Boolean);
85    if (pathSegments.length > 1) {
86      var urlFilter = getUrlFilterFromPath(window.location.pathname);
87      if (urlFilter) {
88        var $activeButton = $(".filter-items .filter-button[data-cat=\"".concat(urlFilter, "\"]"));
89        if ($activeButton.length) {
90          $activeButton.addClass('active').siblings().removeClass('active');
91        }
92        var $items = $('.posts-archive .posts-container .post-container');
93        updateVisibility(urlFilter, $items);
94      } else {
95        // Default: no filter selected
96        var activeFilter = $('.filter-items .filter-button.active').data('cat') || '';
97        updateVisibility(activeFilter, $('.posts-archive .posts-container .post-container'));
98        updateTaxonomyUrl(activeFilter);
99      }
100    } else {
101      // Default: no filter selected
102      var _activeFilter = $('.filter-items .filter-button.active').data('cat') || '';
103      updateVisibility(_activeFilter, $('.posts-archive .posts-container .post-container'));
104      updateTaxonomyUrl(_activeFilter);
105    }
106    if ($('.filter-items').length == 0) {
107      updateVisibility('', $('.posts-archive .posts-container .post-container'));
108    } else {
109      updateVisibility($('.filter-items .filter-button.active').data('cat'), $('.posts-archive .posts-container .post-container'));
110    }
111    $('.filter-dropdown-button').each(function () {
112      var $this = $(this);
113      $this.on('click', function () {
114        var $parent = $this.closest('.filter-container');
115        if ($parent.hasClass('open')) {
116          $parent.removeClass('open');
117        } else {
118          $parent.addClass('open');
119        }
120      });
121    });
122  });
123})(jQuery);
124/******/ })()
125;
126//# sourceMappingURL=viewscript.js.map

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.