Skip to content

Commit 29ad0c3

Browse files
author
mtthwmnc
authored
Hotfix/js (#5)
* Bind events for triggers on section widgets * Add flag for styles * Compile assets * Update readme. Update version number
1 parent a631a35 commit 29ad0c3

File tree

6 files changed

+23
-22
lines changed

6 files changed

+23
-22
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ This bundle contains two widgets for a complete ApostropheCMS accordion widget.
1010
The schema for `pk-accordion-section-widgets` contains a title `string` field as well as an area of widgets that you can configure yourself.
1111

1212
## How To Use
13-
Declare the bundle in app.js
13+
Declare the bundle in app.js. If you want to init the module with the basic css, set `options.styles` of `pk-accordion` to `true`
14+
1415
```js
1516

1617
bundles: [ 'pk-accordion' ],
1718
modules: {
18-
'pk-accordion': {},
19+
'pk-accordion': {
20+
styles: true
21+
},
1922
'pk-accordion-widgets': {},
2023
'pk-accordion-section-widgets': {}
2124
}

index.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ module.exports = {
55
modules: ['pk-accordion-section-widgets', 'pk-accordion-widgets'],
66
directory: 'lib/modules'
77
},
8-
afterConstruct: function (self) {
8+
afterConstruct: (self) => {
9+
if (self.options.styles) {
10+
self.pushAsset('stylesheet', 'always', {
11+
when: 'always'
12+
});
13+
}
914
self.pushAsset('script', 'always', {
1015
when: 'always'
1116
});
12-
self.pushAsset('stylesheet', 'always', {
13-
when: 'always'
14-
});
1517
}
1618
};

lib/modules/pk-accordion-section-widgets/views/widgetBase.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% set section = data.widget %}
22
{% set namespace = data.options.namespace %}
33

4-
<div class="pk-accordion__section {% if namespace %} {{namespace}}__section {% endif %}">
4+
<div class="pk-accordion__section {% if namespace %} {{namespace}}__section {% endif %}" data-component="pk-accordion-section">
55
<div class="pk-accordion__section-header {% if namespace %} {{namespace}}__section-header {% endif %}" data-role="pk-accordion-section-header">
66
<div class="pk-accordion__section-title {% if namespace %} {{namespace}}__section-title {% endif %}">
77
{%- block sectionTitle -%}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pk-accordion",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "A bundle of accordion widgets for ApostropheCMS",
55
"main": "index.js",
66
"scripts": {

public/js/always.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/accordion.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pkutils from 'pk-utilities';
2-
const component = '[data-component=pk-accordion]';
2+
const component = '[data-component=pk-accordion-section]';
33
const header = '[data-role=pk-accordion-section-header]';
44
const trigger = '[data-role=pk-accordion-section-trigger]';
55

@@ -8,21 +8,17 @@ export default {
88
};
99

1010
function init () {
11-
apos.define('pk-accordion-widgets', {
11+
apos.define('pk-accordion-section-widgets', {
1212
extend: 'apostrophe-widgets',
1313
construct: function (self, options) {
1414
self.play = function ($widget, data, options) {
15-
const accordion = $widget[0].querySelector(component);
16-
const triggers = accordion.querySelectorAll(trigger);
17-
18-
triggers.forEach(trigger => {
19-
const currentTrigger = trigger;
20-
const currentViewport = pkutils.helpers.closest(currentTrigger, header).nextElementSibling;
21-
trigger.addEventListener('click', (event) => {
22-
toggleSection({
23-
trigger: currentTrigger,
24-
viewport: currentViewport
25-
});
15+
const section = $widget[0].querySelector(component);
16+
const currentTrigger = section.querySelector(trigger);
17+
const currentViewport = pkutils.helpers.closest(currentTrigger, header).nextElementSibling;
18+
currentTrigger.addEventListener('click', (event) => {
19+
toggleSection({
20+
trigger: currentTrigger,
21+
viewport: currentViewport
2622
});
2723
});
2824

0 commit comments

Comments
 (0)