From 542b1400380690dd5b171fff25cdeb53668e8093 Mon Sep 17 00:00:00 2001 From: Joe Clay <27cupsofcoffee@gmail.com> Date: Sat, 25 Jan 2025 19:06:32 +0000 Subject: [PATCH 1/6] Add sort menu to category pages --- sass/_extra.scss | 4 +++ sass/_semantic.scss | 2 +- static/assets/js/sortCrates.js | 42 ++++++++++++++++++++++++++++++++ templates/categories/macros.html | 2 +- templates/categories/page.html | 27 ++++++++++++++++++-- 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 static/assets/js/sortCrates.js diff --git a/sass/_extra.scss b/sass/_extra.scss index 172239bb..997bf7d8 100644 --- a/sass/_extra.scss +++ b/sass/_extra.scss @@ -78,6 +78,10 @@ ul.ui.list li::before { margin-left: 0.5em; } +#sort-menu { + margin-bottom: 1em; +} + @media only screen and (max-width: 991px) { .masthead .ui.menu a.item { display: none; diff --git a/sass/_semantic.scss b/sass/_semantic.scss index a8a7134f..289b906e 100644 --- a/sass/_semantic.scss +++ b/sass/_semantic.scss @@ -31,7 +31,7 @@ // @import 'semantic/accordion'; // @import 'semantic/checkbox'; // @import 'semantic/dimmer'; -// @import 'semantic/dropdown'; +@import 'semantic/dropdown'; //@import 'semantic/embed'; //@import 'semantic/video'; // @import 'semantic/modal'; diff --git a/static/assets/js/sortCrates.js b/static/assets/js/sortCrates.js new file mode 100644 index 00000000..534a3e3b --- /dev/null +++ b/static/assets/js/sortCrates.js @@ -0,0 +1,42 @@ +function sortCrates(attribute, numeric, ascending) { + var section = $("#crates-section .cards"); + var cards = section.children(".card"); + + var default_value = numeric ? 0 : ""; + + cards.sort(function (a, b) { + var aAttr = a.getAttribute(attribute) || default_value; + var bAttr = b.getAttribute(attribute) || default_value; + + if (numeric) { + aAttr = parseInt(aAttr); + bAttr = parseInt(bAttr); + } else { + aAttr = aAttr.toUpperCase(); + bAttr = bAttr.toUpperCase(); + } + + if (aAttr > bAttr) { + return ascending ? 1 : -1; + } else if (aAttr < bAttr) { + return ascending ? -1 : 1; + } else { + return 0; + } + }); + + cards.detach().appendTo(section); +} + +$(document).ready(function () { + var sortDropdown = $("#sort-menu"); + + sortDropdown.dropdown({ + onChange: function (value, text, selected) { + var type = selected[0].getAttribute("data-type"); + var order = selected[0].getAttribute("data-order"); + + sortCrates(value, type == "num", order == "asc"); + }, + }); +}); diff --git a/templates/categories/macros.html b/templates/categories/macros.html index cb6ca57f..a1a334d3 100644 --- a/templates/categories/macros.html +++ b/templates/categories/macros.html @@ -82,7 +82,7 @@ {% endif %} {% endif %} -
  • +
  • {% if item.image %} {% if primary_url %} diff --git a/templates/categories/page.html b/templates/categories/page.html index 2f1b8b47..4ad71cdb 100644 --- a/templates/categories/page.html +++ b/templates/categories/page.html @@ -48,7 +48,7 @@

    {% endif %} {% endfor %} -
    +

    @@ -58,6 +58,24 @@

    + +
      {% for item in crates %} {{ category_macros::info(item=item, section=section) }} @@ -115,4 +133,9 @@

    -{% endblock content %} \ No newline at end of file +{% endblock content %} + +{% block footer %} + + +{% endblock %} \ No newline at end of file From 621e021c19136a3909e98334b013d58e282f50bc Mon Sep 17 00:00:00 2001 From: Joe Clay <27cupsofcoffee@gmail.com> Date: Sat, 25 Jan 2025 19:23:07 +0000 Subject: [PATCH 2/6] Use CSS grid for cards The way that Semantic UI does columns for the cards is a massive pain to override (it uses negative margins for everything), and this was making the menu glitch out on mobile. CSS grid is supported by every major browser now, so there's no reason not to use it. --- sass/_extra.scss | 37 +++++++++++++++++++++++++++------- static/assets/js/sortCrates.js | 2 +- templates/categories/page.html | 6 +++--- templates/index.html | 2 +- templates/macros.html | 2 +- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/sass/_extra.scss b/sass/_extra.scss index 997bf7d8..5a1d933f 100644 --- a/sass/_extra.scss +++ b/sass/_extra.scss @@ -41,16 +41,38 @@ padding: 5em 0em; } +// This is a replacement for Semantic UI's .cards class, using CSS Grid +// instead of relying on negative margins for layout. +.card-grid { + display: grid; + grid-template-columns: 1fr; + gap: 1.5em; + margin: 0; +} + +.card-grid.three { + grid-template-columns: repeat(3, 1fr); +} + +.card-grid.four { + grid-template-columns: repeat(4, 1fr); +} + +.card-grid .ui.card { + width: 100%; + margin: 0; +} + .ui.card .image { height: 256px; } -.ui.cards > .card > .content > .header:not(.ui, .center.aligned), .ui.card > .content > .header:not(.ui, .center.aligned) { +.ui.card > .content > .header:not(.ui, .center.aligned) { display: inline-block; margin-bottom: 0; } -.ui.card > .image > img, .ui.cards > .card > .image > img { +.ui.card > .image > img { object-fit: cover; width: 100%; height: 100%; @@ -79,7 +101,7 @@ ul.ui.list li::before { } #sort-menu { - margin-bottom: 1em; + margin-bottom: 1.5em; } @media only screen and (max-width: 991px) { @@ -111,6 +133,10 @@ ul.ui.list li::before { .vertical.stripe .text.container p { font-size: 1.1em; } + + .card-grid.three, .card-grid.four { + grid-template-columns: 1fr; + } } /* Colors overridden to avoid inaccessible contrast levels */ @@ -120,11 +146,8 @@ a { } .ui.card > .extra, -.ui.cards > .card > .extra, .ui.card .meta, -.ui.cards > .card .meta, -.ui.card .meta > a:not(.ui), -.ui.cards > .card .meta > a:not(.ui) { +.ui.card .meta > a:not(.ui) { color: #767676; } diff --git a/static/assets/js/sortCrates.js b/static/assets/js/sortCrates.js index 534a3e3b..123f80be 100644 --- a/static/assets/js/sortCrates.js +++ b/static/assets/js/sortCrates.js @@ -1,5 +1,5 @@ function sortCrates(attribute, numeric, ascending) { - var section = $("#crates-section .cards"); + var section = $("#crates-section .card-grid"); var cards = section.children(".card"); var default_value = numeric ? 0 : ""; diff --git a/templates/categories/page.html b/templates/categories/page.html index 4ad71cdb..775d0c56 100644 --- a/templates/categories/page.html +++ b/templates/categories/page.html @@ -66,7 +66,7 @@

    -