From bfff0017521eaf0bd0ad6f76bf804fb9f532212b Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Thu, 10 May 2018 11:11:29 +0200 Subject: [PATCH] Use
and for variations --- .../presale/templates/pretixpresale/base.html | 1 + .../templates/pretixpresale/event/index.html | 8 +-- .../static/pretixpresale/js/ui/details.js | 51 +++++++++++++++++++ src/pretix/static/pretixpresale/js/ui/main.js | 6 +-- .../static/pretixpresale/scss/_event.scss | 14 +++++ 5 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 src/pretix/static/pretixpresale/js/ui/details.js diff --git a/src/pretix/presale/templates/pretixpresale/base.html b/src/pretix/presale/templates/pretixpresale/base.html index 5efc616b28..3b66226719 100644 --- a/src/pretix/presale/templates/pretixpresale/base.html +++ b/src/pretix/presale/templates/pretixpresale/base.html @@ -25,6 +25,7 @@ + diff --git a/src/pretix/presale/templates/pretixpresale/event/index.html b/src/pretix/presale/templates/pretixpresale/event/index.html index bb00435844..dd8a3f2b6b 100644 --- a/src/pretix/presale/templates/pretixpresale/event/index.html +++ b/src/pretix/presale/templates/pretixpresale/event/index.html @@ -217,8 +217,8 @@ {% endif %} {% for item in tup.1 %} {% if item.has_variations %} -
{% else %}
diff --git a/src/pretix/static/pretixpresale/js/ui/details.js b/src/pretix/static/pretixpresale/js/ui/details.js new file mode 100644 index 0000000000..357e86a373 --- /dev/null +++ b/src/pretix/static/pretixpresale/js/ui/details.js @@ -0,0 +1,51 @@ +/*global $ */ + +$(function () { + "use strict"; + + var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]'; + + $("details summary, details summary a").click(function (e) { + var $details = $(this).closest("details"); + var isOpen = $details.prop("open"); + var $detailsNotSummary = $details.children(':not(summary)'); + if ($detailsNotSummary.is(':animated')) { + e.preventDefault(); + return false; + } + if (isOpen) { + $detailsNotSummary.stop().show().slideUp(500, function () { + $details.prop("open", false); + }); + } else { + $detailsNotSummary.stop().hide(); + $details.prop("open", true); + $detailsNotSummary.slideDown(); + } + e.preventDefault(); + return false; + }).keyup(function (event) { + if (32 == event.keyCode || (13 == event.keyCode && !isOpera)) { + // Space or Enter is pressed — trigger the `click` event on the `summary` element + // Opera already seems to trigger the `click` event when Enter is pressed + event.preventDefault(); + $(this).click(); + } + }); + + $('details').each(function () { + var $details = $(this), + $detailsSummary = $('summary', $details).first(), + $detailsNotSummary = $details.children(':not(summary)'); + $details.prop('open', typeof $details.attr('open') == 'string'); + if (!$details.prop('open')) { + $detailsNotSummary.hide(); + } + $detailsSummary.attr({ + 'role': 'button', + 'aria-controls': $details.attr('id') + }).prop('tabIndex', 0).bind('selectstart dragstart mousedown', function () { + return false; + }); + }); +}); diff --git a/src/pretix/static/pretixpresale/js/ui/main.js b/src/pretix/static/pretixpresale/js/ui/main.js index 17a1645401..4647011c3b 100644 --- a/src/pretix/static/pretixpresale/js/ui/main.js +++ b/src/pretix/static/pretixpresale/js/ui/main.js @@ -103,11 +103,7 @@ $(function () { }); $(".js-only").removeClass("js-only"); $(".js-hidden").hide(); - $(".variations-collapsed").hide(); - $("a[data-toggle=variations]").click(function (e) { - $(this).closest(".item-with-variations").find(".variations").slideToggle(); - e.preventDefault(); - }); + $("div.collapsed").removeClass("collapsed").addClass("collapse"); $(".has-error, .alert-danger").each(function () { $(this).closest("div.panel-collapse").collapse("show"); diff --git a/src/pretix/static/pretixpresale/scss/_event.scss b/src/pretix/static/pretixpresale/scss/_event.scss index 048acc6380..4db96f55a1 100644 --- a/src/pretix/static/pretixpresale/scss/_event.scss +++ b/src/pretix/static/pretixpresale/scss/_event.scss @@ -65,6 +65,20 @@ line-height: inherit; } } +details.item-with-variations { + list-style: none; +} +details.item-with-variations > summary::-webkit-details-marker { + display: none; +} + +details summary { + -moz-user-select: none; + -ms-user-select: none; + -webkit-user-select: none; + user-select: none; +} + .radio .variation-description { padding-left: 20px; }