From adfae379fbb207f4f164f0f9db6db0247782a7b9 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Sun, 26 Sep 2021 13:08:00 +0200 Subject: [PATCH 1/3] SGD8-2142: Add support for Ajax It should be possible to add openinghours with an Ajax callback. --- js/opening-hours.binding.js | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/js/opening-hours.binding.js b/js/opening-hours.binding.js index 804a0df..0529c1a 100644 --- a/js/opening-hours.binding.js +++ b/js/opening-hours.binding.js @@ -15,28 +15,26 @@ attach: function (context, settings) { var self = this; - $(document).once('openingHoursWidget').each(function () { - var items = document.querySelectorAll('.openinghours-widget'); + var items = document.querySelectorAll('.openinghours-widget'); - var options = { - 'endpoint': settings.openingHours.endpoint, - 'endpoint_key': settings.openingHours.endpoint_key, - 'language': settings.openingHours.language, - 'error' : function (item) { - var elem = getClosest(item, '.openinghours-wrapper'); - if (elem && elem.parentNode) { - elem.parentNode.removeChild(elem); - } + var options = { + 'endpoint': settings.openingHours.endpoint, + 'endpoint_key': settings.openingHours.endpoint_key, + 'language': settings.openingHours.language, + 'error' : function (item) { + var elem = getClosest(item, '.openinghours-wrapper'); + if (elem && elem.parentNode) { + elem.parentNode.removeChild(elem); } - }; + } + }; - new OpeningHours(items, options); + new OpeningHours(items, options); - var navLinks = document.querySelectorAll('.openinghours-navigation a'); - for (var y = 0; y < navLinks.length; y++) { - navLinks[y].addEventListener('click', self.switchViewMode(options)); - } - }); + var navLinks = document.querySelectorAll('.openinghours-navigation a'); + for (var y = 0; y < navLinks.length; y++) { + navLinks[y].addEventListener('click', self.switchViewMode(options)); + } }, /** From 1fe6ca71707b6996cc9836692e17ea512f9d331d Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Sun, 26 Sep 2021 17:03:53 +0200 Subject: [PATCH 2/3] Only load widgets once --- js/opening-hours.binding.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/js/opening-hours.binding.js b/js/opening-hours.binding.js index 0529c1a..0a92947 100644 --- a/js/opening-hours.binding.js +++ b/js/opening-hours.binding.js @@ -15,25 +15,24 @@ attach: function (context, settings) { var self = this; - var items = document.querySelectorAll('.openinghours-widget'); + var items = $('.openinghours-widget', context).once('openingHoursWidget'); - var options = { - 'endpoint': settings.openingHours.endpoint, - 'endpoint_key': settings.openingHours.endpoint_key, - 'language': settings.openingHours.language, - 'error' : function (item) { - var elem = getClosest(item, '.openinghours-wrapper'); - if (elem && elem.parentNode) { - elem.parentNode.removeChild(elem); + if (items.length) { + var options = { + 'endpoint': settings.openingHours.endpoint, + 'endpoint_key': settings.openingHours.endpoint_key, + 'language': settings.openingHours.language, + 'error' : function (item) { + var elem = getClosest(item, '.openinghours-wrapper'); + if (elem && elem.parentNode) { + elem.parentNode.removeChild(elem); + } } - } - }; + }; - new OpeningHours(items, options); + new OpeningHours(items, options); - var navLinks = document.querySelectorAll('.openinghours-navigation a'); - for (var y = 0; y < navLinks.length; y++) { - navLinks[y].addEventListener('click', self.switchViewMode(options)); + $('.openinghours-navigation a', context).click(self.switchViewMode(options)); } }, From d71ddca200625f999454bc3283ea20804fe186f3 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Mon, 27 Sep 2021 09:27:02 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e3c01f..b55d3d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All Notable changes to `drupal/opening-hours` module. +## [1.4.1] + +### Changed + +* Added support for Ajax. + ## [1.4.0] ### Changed @@ -207,6 +213,7 @@ for the same widget. * DMOH-20: Added the opening hours field type. * DMOH-21: Added the opening hours field widget. +[1.4.1]: https://github.com/StadGent/drupal_module_opening-hours/compare/1.4.0...1.4.1 [1.4.0]: https://github.com/StadGent/drupal_module_opening-hours/compare/8.x-1.3...1.4.0 [8.x-1.3]: https://github.com/StadGent/drupal_module_opening-hours/compare/8.x-1.2...8.x-1.3 [8.x-1.2]: https://github.com/StadGent/drupal_module_opening-hours/compare/8.x-1.1...8.x-1.2