diff --git a/wowchemy/assets/js/wowchemy.js b/wowchemy/assets/js/wowchemy.js index 76fb1fcb..7cb0470c 100644 --- a/wowchemy/assets/js/wowchemy.js +++ b/wowchemy/assets/js/wowchemy.js @@ -125,27 +125,57 @@ // Publication container. let $grid_pubs = $('#container-publications'); - // Initialise Isotope. - $grid_pubs.isotope({ - itemSelector: '.isotope-item', - percentPosition: true, - masonry: { - // Use Bootstrap compatible grid layout. - columnWidth: '.grid-sizer' - }, - filter: function () { - let $this = $(this); - let searchResults = searchRegex ? $this.text().match(searchRegex) : true; - let filterResults = filterValues ? $this.is(filterValues) : true; - return searchResults && filterResults; - } - }); + // Initialise Isotope publication layout if required. + if ($grid_pubs.length) + { + $grid_pubs.isotope({ + itemSelector: '.isotope-item', + percentPosition: true, + masonry: { + // Use Bootstrap compatible grid layout. + columnWidth: '.grid-sizer' + }, + filter: function () { + let $this = $(this); + let searchResults = searchRegex ? $this.text().match(searchRegex) : true; + let filterResults = filterValues ? $this.is(filterValues) : true; + return searchResults && filterResults; + } + }); - // Filter by search term. - let $quickSearch = $('.filter-search').keyup(debounce(function () { - searchRegex = new RegExp($quickSearch.val(), 'gi'); - $grid_pubs.isotope(); - })); + // Filter by search term. + let $quickSearch = $('.filter-search').keyup(debounce(function () { + searchRegex = new RegExp($quickSearch.val(), 'gi'); + $grid_pubs.isotope(); + })); + + $('.pub-filters').on('change', function () { + let $this = $(this); + + // Get group key. + let filterGroup = $this[0].getAttribute('data-filter-group'); + + // Set filter for group. + pubFilters[filterGroup] = this.value; + + // Combine filters. + filterValues = concatValues(pubFilters); + + // Activate filters. + $grid_pubs.isotope(); + + // If filtering by publication type, update the URL hash to enable direct linking to results. + if (filterGroup === "pubtype") { + // Set hash URL to current filter. + let url = $(this).val(); + if (url.substr(0, 9) === '.pubtype-') { + window.location.hash = url.substr(9); + } else { + window.location.hash = ''; + } + } + }); + } // Debounce input to prevent spamming filter requests. function debounce(fn, threshold) { @@ -173,35 +203,12 @@ return value; } - $('.pub-filters').on('change', function () { - let $this = $(this); - - // Get group key. - let filterGroup = $this[0].getAttribute('data-filter-group'); - - // Set filter for group. - pubFilters[filterGroup] = this.value; - - // Combine filters. - filterValues = concatValues(pubFilters); - - // Activate filters. - $grid_pubs.isotope(); - - // If filtering by publication type, update the URL hash to enable direct linking to results. - if (filterGroup == "pubtype") { - // Set hash URL to current filter. - let url = $(this).val(); - if (url.substr(0, 9) == '.pubtype-') { - window.location.hash = url.substr(9); - } else { - window.location.hash = ''; - } - } - }); - // Filter publications according to hash in URL. function filter_publications() { + // Check for Isotope publication layout. + if (!$grid_pubs.length) + return + let urlHash = window.location.hash.replace('#', ''); let filterValue = '*'; diff --git a/wowchemy/layouts/partials/site_js.html b/wowchemy/layouts/partials/site_js.html index 88c2d8f3..18017466 100644 --- a/wowchemy/layouts/partials/site_js.html +++ b/wowchemy/layouts/partials/site_js.html @@ -6,8 +6,13 @@ {{ else }} {{ printf "" (printf $js.jQuery.url $js.jQuery.version) $js.jQuery.sri | safeHTML }} - {{ printf "" (printf $js.imagesLoaded.url $js.imagesLoaded.version) $js.imagesLoaded.sri | safeHTML }} - {{ printf "" (printf $js.isotope.url $js.isotope.version) $js.isotope.sri | safeHTML }} + + {{ $require_isotope := site.Params.require_isotope | default true }} + {{ if $require_isotope }} + {{ printf "" (printf $js.imagesLoaded.url $js.imagesLoaded.version) $js.imagesLoaded.sri | safeHTML }} + {{ printf "" (printf $js.isotope.url $js.isotope.version) $js.isotope.sri | safeHTML }} + {{ end }} + {{ printf "" (printf $js.fancybox.url $js.fancybox.version) $js.fancybox.sri | safeHTML }} {{ printf "" (printf $js.instantpage.url $js.instantpage.version) $js.instantpage.sri | safeHTML }} diff --git a/wowchemy/test/config.yaml b/wowchemy/test/config.yaml index 79a5f275..be8f2479 100644 --- a/wowchemy/test/config.yaml +++ b/wowchemy/test/config.yaml @@ -4,3 +4,5 @@ module: - path: github.com/wowchemy/wowchemy-hugo-modules/wowchemy outputs: home: [HTML, RSS, JSON, WebAppManifest] +params: + require_isotope: false diff --git a/wowchemy/test/content/home/section.md b/wowchemy/test/content/home/section.md index 725fdc4c..8e4d94a0 100644 --- a/wowchemy/test/content/home/section.md +++ b/wowchemy/test/content/home/section.md @@ -1 +1,9 @@ +--- +widget: blank +headless: true +weight: 1 +design: + columns: '1' +--- + Hello world 😃 diff --git a/wowchemy/test/view.sh b/wowchemy/test/view.sh new file mode 100644 index 00000000..1079ef68 --- /dev/null +++ b/wowchemy/test/view.sh @@ -0,0 +1 @@ +hugo server -p 1330 --minify