@total_onion/onion-library 2.0.215 → 2.0.217

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,224 +1,246 @@
1
1
  export default function postfiltermoduleJs(options = {}) {
2
2
  try {
3
- customElements.define(
4
- 'post-filter-module',
5
- class extends HTMLElement {
6
- constructor() {
7
- super();
8
- this.enableLogs = this.dataset.enablelogs;
9
- this.filterState = {
10
- allposts: [],
11
- filteredposts: [],
12
- activefilters: new Set(),
13
- allcategories: [],
14
- groupingcategories: [],
15
- filtercategories: [],
16
- setActiveFilters: function (newState) {
17
- Object.assign(this.filterState, newState);
18
- this.filterPosts.bind(this)();
19
- },
20
- setFilteredPosts: function (newState) {
21
- Object.assign(this.filterState, newState);
22
- this.dispatchEvent(
23
- new CustomEvent('filteredposts-updated')
24
- );
25
- this.enableLogs &&
26
- console.log(
27
- '🚀 filter state: ',
28
- this.filterState
3
+ if (!customElements.get('post-filter-module')) {
4
+ customElements.define(
5
+ 'post-filter-module',
6
+ class extends HTMLElement {
7
+ constructor() {
8
+ super();
9
+ this.enableLogs = this.dataset.enablelogs;
10
+ this.filterState = {
11
+ allposts: [],
12
+ filteredposts: [],
13
+ activefilters: new Set(),
14
+ allcategories: [],
15
+ groupingcategories: [],
16
+ filtercategories: [],
17
+ setActiveFilters: function (newState) {
18
+ Object.assign(this.filterState, newState);
19
+ this.filterPosts.bind(this)();
20
+ },
21
+ setFilteredPosts: function (newState) {
22
+ Object.assign(this.filterState, newState);
23
+ this.dispatchEvent(
24
+ new CustomEvent('filteredposts-updated')
29
25
  );
30
- }
31
- };
32
-
33
- const postFilterContainer = document.createElement('div');
34
- postFilterContainer.className =
35
- 'post-filter-module__filter-container';
36
- this.appendChild(postFilterContainer);
37
- this.postFilterContainer = this.querySelector(
38
- '.post-filter-module__filter-container'
39
- );
26
+ this.enableLogs &&
27
+ console.log(
28
+ '🚀 filter state: ',
29
+ this.filterState
30
+ );
31
+ }
32
+ };
40
33
 
41
- const postFilterCatsDisplay = document.createElement('div');
42
- postFilterCatsDisplay.className =
43
- 'post-filter-module__filter-categories-display';
44
- this.postFilterContainer.appendChild(postFilterCatsDisplay);
45
- this.filterCategoriesDisplay = this.querySelector(
46
- '.post-filter-module__filter-categories-display'
47
- );
34
+ const postFilterContainer =
35
+ document.createElement('div');
36
+ postFilterContainer.className =
37
+ 'post-filter-module__filter-container';
38
+ this.appendChild(postFilterContainer);
39
+ this.postFilterContainer = this.querySelector(
40
+ '.post-filter-module__filter-container'
41
+ );
48
42
 
49
- const clearFilters = document.createElement('button');
50
- clearFilters.className =
51
- 'post-filter-module__clear-filters-button';
52
- clearFilters.innerText = 'Clear Filters';
53
- this.postFilterContainer.appendChild(clearFilters);
54
- this.clearFiltersButton = this.querySelector(
55
- '.post-filter-module__clear-filters-button'
56
- );
57
- this.clearFiltersButton.addEventListener(
58
- 'click',
59
- this.clearFilters.bind(this)
60
- );
43
+ const postFilterCatsDisplay =
44
+ document.createElement('div');
45
+ postFilterCatsDisplay.className =
46
+ 'post-filter-module__filter-categories-display';
47
+ this.postFilterContainer.appendChild(
48
+ postFilterCatsDisplay
49
+ );
50
+ this.filterCategoriesDisplay = this.querySelector(
51
+ '.post-filter-module__filter-categories-display'
52
+ );
61
53
 
62
- this.devMode = this.dataset.dev;
63
- this.devModeContent = this.dataset.devcontent;
64
- }
65
- async connectedCallback() {
66
- console.log('Filter Module element added to page.');
67
- let data;
68
- if (this.devMode == 'true') {
69
- data = await import('./dev-content/dev-content.js');
70
- this.filterState.allposts =
71
- data[`devContent${this.devModeContent}`];
54
+ const clearFilters = document.createElement('button');
55
+ clearFilters.className =
56
+ 'post-filter-module__clear-filters-button';
57
+ clearFilters.innerText = 'Clear Filters';
58
+ this.postFilterContainer.appendChild(clearFilters);
59
+ this.clearFiltersButton = this.querySelector(
60
+ '.post-filter-module__clear-filters-button'
61
+ );
62
+ this.clearFiltersButton.addEventListener(
63
+ 'click',
64
+ this.clearFilters.bind(this)
65
+ );
72
66
 
73
- this.filterState.allcategories =
74
- data[`devContentCategories`];
75
- } else {
76
- data = globalThis[this.dataset.dataobjectid];
77
- this.enableLogs && console.log('🚀 dataobject: ', data);
78
- this.filterState.allposts = data[`posts`];
79
- this.filterState.allcategories = data[`categories`];
67
+ this.devMode = this.dataset.dev;
68
+ this.devModeContent = this.dataset.devcontent;
80
69
  }
70
+ async connectedCallback() {
71
+ console.log('Filter Module element added to page.');
72
+ let data;
73
+ if (
74
+ this.devMode == 'true' ||
75
+ this.classList.contains('dev-petz') //Easter Egg :D
76
+ ) {
77
+ const devdatalocation =
78
+ this.dataset.devdatalocation;
79
+ console.log(
80
+ '🚀 ~ connectedCallback ~ devdatalocation:',
81
+ devdatalocation
82
+ );
83
+ data = await import(
84
+ `./dev-content/dev-content${devdatalocation}.js`
85
+ );
86
+ this.filterState.allposts = data[`devContentPets`];
81
87
 
82
- if (this.filterState.allcategories.length > 0) {
83
- this.filterState.allcategories.forEach((category) => {
84
- if (category.parentid != '0') {
85
- this.filterState.filtercategories.push(
86
- category
87
- );
88
- } else {
89
- this.filterState.groupingcategories.push(
90
- category
91
- );
92
- }
93
- });
94
- }
95
- if (this.filterState.groupingcategories.length > 0) {
96
- this.filterState.groupingcategories.forEach(
97
- (category) => {
98
- const groupCategoryContainer =
99
- document.createElement('div');
100
- groupCategoryContainer.className =
101
- 'post-filter-module__grouping-category-container';
102
- groupCategoryContainer.insertAdjacentHTML(
103
- 'beforeend',
104
- `<button class="post-filter-module__grouping-category-button" data-categoryid="${category.id}">${category.name}</button>`
105
- );
106
- const filterCategoryContainer =
107
- document.createElement('div');
108
- filterCategoryContainer.className =
109
- 'post-filter-module__filter-category-container';
110
- const groupedFilters =
111
- this.filterState.filtercategories.filter(
112
- (filtercat) => {
113
- return (
114
- filtercat.parentid ==
115
- category.id
116
- );
117
- }
118
- );
119
- groupedFilters.forEach((filter) => {
120
- filterCategoryContainer.insertAdjacentHTML(
88
+ this.filterState.allcategories =
89
+ data[`devContentCategories`];
90
+ } else {
91
+ data = globalThis[this.dataset.dataobjectid];
92
+ this.enableLogs &&
93
+ console.log('🚀 dataobject: ', data);
94
+ this.filterState.allposts = data[`posts`];
95
+ this.filterState.allcategories = data[`categories`];
96
+ }
97
+
98
+ if (this.filterState.allcategories.length > 0) {
99
+ this.filterState.allcategories.forEach(
100
+ (category) => {
101
+ if (category.parentid != '0') {
102
+ this.filterState.filtercategories.push(
103
+ category
104
+ );
105
+ } else {
106
+ this.filterState.groupingcategories.push(
107
+ category
108
+ );
109
+ }
110
+ }
111
+ );
112
+ }
113
+ if (this.filterState.groupingcategories.length > 0) {
114
+ this.filterState.groupingcategories.forEach(
115
+ (category) => {
116
+ const groupCategoryContainer =
117
+ document.createElement('div');
118
+ groupCategoryContainer.className =
119
+ 'post-filter-module__grouping-category-container';
120
+ groupCategoryContainer.insertAdjacentHTML(
121
121
  'beforeend',
122
- `<button class="post-filter-module__filter-category-button" data-categoryid="${filter.id}">${filter.name}</button>`
122
+ `<button class="post-filter-module__grouping-category-button" data-categoryid="${category.id}">${category.name}</button>`
123
123
  );
124
- });
125
- groupCategoryContainer.appendChild(
126
- filterCategoryContainer
127
- );
128
- this.filterCategoriesDisplay.appendChild(
129
- groupCategoryContainer
130
- );
131
- }
132
- );
133
- } else {
134
- this.filterState.filtercategories.forEach(
135
- (category) => {
136
- if (category.parentid) {
137
- this.filterCategoriesDisplay.insertAdjacentHTML(
138
- 'beforeend',
139
- `<button class="post-filter-module__filter-category-button" data-categoryid="${category.id}">${category.name}</button>`
124
+ const filterCategoryContainer =
125
+ document.createElement('div');
126
+ filterCategoryContainer.className =
127
+ 'post-filter-module__filter-category-container';
128
+ const groupedFilters =
129
+ this.filterState.filtercategories.filter(
130
+ (filtercat) => {
131
+ return (
132
+ filtercat.parentid ==
133
+ category.id
134
+ );
135
+ }
136
+ );
137
+ groupedFilters.forEach((filter) => {
138
+ filterCategoryContainer.insertAdjacentHTML(
139
+ 'beforeend',
140
+ `<button class="post-filter-module__filter-category-button" data-categoryid="${filter.id}">${filter.name}</button>`
141
+ );
142
+ });
143
+ groupCategoryContainer.appendChild(
144
+ filterCategoryContainer
145
+ );
146
+ this.filterCategoriesDisplay.appendChild(
147
+ groupCategoryContainer
140
148
  );
141
149
  }
142
- }
143
- );
144
- }
150
+ );
151
+ } else {
152
+ this.filterState.filtercategories.forEach(
153
+ (category) => {
154
+ if (category.parentid) {
155
+ this.filterCategoriesDisplay.insertAdjacentHTML(
156
+ 'beforeend',
157
+ `<button class="post-filter-module__filter-category-button" data-categoryid="${category.id}">${category.name}</button>`
158
+ );
159
+ }
160
+ }
161
+ );
162
+ }
145
163
 
146
- this.categorybuttons = this.querySelectorAll(
147
- '.post-filter-module__filter-category-button'
148
- );
164
+ this.categorybuttons = this.querySelectorAll(
165
+ '.post-filter-module__filter-category-button'
166
+ );
149
167
 
150
- this.categorybuttons.forEach((button) => {
151
- button.addEventListener('click', () => {
152
- if (
153
- this.filterState.activefilters.has(
154
- Number(button.dataset.categoryid)
155
- )
156
- ) {
157
- const newActiveFilters = new Set(
158
- this.filterState.activefilters
159
- );
160
- button.classList.remove('active-cat');
161
- newActiveFilters.delete(
162
- Number(button.dataset.categoryid)
163
- );
164
- this.filterState.setActiveFilters.bind(this)({
165
- activefilters: newActiveFilters
166
- });
167
- } else {
168
- const newActiveFilters = new Set(
169
- this.filterState.activefilters
170
- );
171
- button.classList.add('active-cat');
172
- newActiveFilters.add(
173
- Number(button.dataset.categoryid)
174
- );
175
- this.filterState.setActiveFilters.bind(this)({
176
- activefilters: newActiveFilters
177
- });
178
- }
168
+ this.categorybuttons.forEach((button) => {
169
+ button.addEventListener('click', () => {
170
+ if (
171
+ this.filterState.activefilters.has(
172
+ Number(button.dataset.categoryid)
173
+ )
174
+ ) {
175
+ const newActiveFilters = new Set(
176
+ this.filterState.activefilters
177
+ );
178
+ button.classList.remove('active-cat');
179
+ newActiveFilters.delete(
180
+ Number(button.dataset.categoryid)
181
+ );
182
+ this.filterState.setActiveFilters.bind(
183
+ this
184
+ )({
185
+ activefilters: newActiveFilters
186
+ });
187
+ } else {
188
+ const newActiveFilters = new Set(
189
+ this.filterState.activefilters
190
+ );
191
+ button.classList.add('active-cat');
192
+ newActiveFilters.add(
193
+ Number(button.dataset.categoryid)
194
+ );
195
+ this.filterState.setActiveFilters.bind(
196
+ this
197
+ )({
198
+ activefilters: newActiveFilters
199
+ });
200
+ }
201
+ });
179
202
  });
180
- });
181
- this.filterState.setFilteredPosts.bind(this)({
182
- filteredposts: this.filterState.allposts
183
- });
184
- this.classList.add('loaded');
185
- }
186
-
187
- attributeChangedCallback(name, oldValue, newValue) {
188
- // console.log(`Attribute ${name} has changed.`);
189
- }
190
- filterPosts(event) {
191
- if (this.filterState.activefilters.size === 0) {
192
203
  this.filterState.setFilteredPosts.bind(this)({
193
204
  filteredposts: this.filterState.allposts
194
205
  });
195
- return;
206
+ this.classList.add('loaded');
196
207
  }
197
208
 
198
- const newFilteredPosts = this.filterState.allposts.filter(
199
- (post) => {
200
- return (
201
- this.filterState.activefilters.intersection(
202
- new Set(post.categories)
203
- ).size > 0
204
- );
209
+ attributeChangedCallback(name, oldValue, newValue) {
210
+ // console.log(`Attribute ${name} has changed.`);
211
+ }
212
+ filterPosts(event) {
213
+ if (this.filterState.activefilters.size === 0) {
214
+ this.filterState.setFilteredPosts.bind(this)({
215
+ filteredposts: this.filterState.allposts
216
+ });
217
+ return;
205
218
  }
206
- );
207
219
 
208
- this.filterState.setFilteredPosts.bind(this)({
209
- filteredposts: newFilteredPosts
210
- });
211
- }
212
- clearFilters(event) {
213
- this.categorybuttons.forEach((button) => {
214
- button.classList.remove('active-cat');
215
- });
216
- this.filterState.setActiveFilters.bind(this)({
217
- activefilters: new Set()
218
- });
220
+ const newFilteredPosts =
221
+ this.filterState.allposts.filter((post) => {
222
+ return (
223
+ this.filterState.activefilters.intersection(
224
+ new Set(post.categories)
225
+ ).size > 0
226
+ );
227
+ });
228
+
229
+ this.filterState.setFilteredPosts.bind(this)({
230
+ filteredposts: newFilteredPosts
231
+ });
232
+ }
233
+ clearFilters(event) {
234
+ this.categorybuttons.forEach((button) => {
235
+ button.classList.remove('active-cat');
236
+ });
237
+ this.filterState.setActiveFilters.bind(this)({
238
+ activefilters: new Set()
239
+ });
240
+ }
219
241
  }
220
- }
221
- );
242
+ );
243
+ }
222
244
  } catch (error) {
223
245
  console.error(error);
224
246
  }
@@ -1,45 +1,47 @@
1
1
  export default function postFilterDisplayJS(options = {}) {
2
2
  try {
3
- customElements.define(
4
- 'post-grid-display-module',
5
- class extends HTMLElement {
6
- static observedAttributes = ['data-posts'];
7
- constructor() {
8
- super();
9
- const gridContainer = document.createElement('div');
10
- gridContainer.className =
11
- 'post-grid-display-module__grid-container';
12
- this.appendChild(gridContainer);
13
- this.gridContainer = this.querySelector(
14
- '.post-grid-display-module__grid-container'
15
- );
16
- }
17
- connectedCallback() {
18
- console.log('Display module added to page.');
19
- this.classList.add('loaded');
20
- }
3
+ if (!customElements.get('post-grid-display-module')) {
4
+ customElements.define(
5
+ 'post-grid-display-module',
6
+ class extends HTMLElement {
7
+ static observedAttributes = ['data-posts'];
8
+ constructor() {
9
+ super();
10
+ const gridContainer = document.createElement('div');
11
+ gridContainer.className =
12
+ 'post-grid-display-module__grid-container';
13
+ this.appendChild(gridContainer);
14
+ this.gridContainer = this.querySelector(
15
+ '.post-grid-display-module__grid-container'
16
+ );
17
+ }
18
+ connectedCallback() {
19
+ console.log('Display module added to page.');
20
+ this.classList.add('loaded');
21
+ }
21
22
 
22
- attributeChangedCallback(name, oldValue, newValue) {
23
- // console.log(`Attribute ${name} has changed.`);
24
- this.gridContainer.innerHTML = '';
25
- if (newValue) {
26
- const posts = JSON.parse(newValue);
23
+ attributeChangedCallback(name, oldValue, newValue) {
24
+ // console.log(`Attribute ${name} has changed.`);
25
+ this.gridContainer.innerHTML = '';
26
+ if (newValue) {
27
+ const posts = JSON.parse(newValue);
27
28
 
28
- posts.forEach((post) => {
29
- const postContent = `
29
+ posts.forEach((post) => {
30
+ const postContent = `
30
31
  <div class="post-grid-display-module__post-container">
31
32
  <h2 class="post-grid-display-module__post-title">${post.name}</h2>
32
33
  <img loading="lazy" class="post-grid-display-module__post-image" src="${post.images?.post_image_src}" alt="${post.name}"></div>
33
34
  `;
34
- this.gridContainer.insertAdjacentHTML(
35
- 'beforeend',
36
- postContent
37
- );
38
- });
35
+ this.gridContainer.insertAdjacentHTML(
36
+ 'beforeend',
37
+ postContent
38
+ );
39
+ });
40
+ }
39
41
  }
40
42
  }
41
- }
42
- );
43
+ );
44
+ }
43
45
  } catch (error) {
44
46
  console.error(error);
45
47
  }
@@ -5,6 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <link rel="stylesheet" href="../../public/publicBundleBase.css" />
7
7
  <link rel="stylesheet" href="./ptfg-9000.css" />
8
+ <link rel="stylesheet" href="../webc-toggle-trigger/toggle-trigger.css" />
8
9
  <link
9
10
  rel="stylesheet"
10
11
  href="../webc-post-filter-module/post-filter-module.css"
@@ -20,29 +21,74 @@
20
21
  class="ptfg-9000 ptfg-9000__main-container cmpl-block-padding"
21
22
  data-assetkey="ptfg-9000"
22
23
  >
24
+ <post-filter-module
25
+ id="filter-module"
26
+ data-dataobjectid=""
27
+ data-dev="true"
28
+ data-devdatalocation="local"
29
+ class="post-filter-module__filter"
30
+ > <toggle-trigger
31
+ id="toggle-trigger"
32
+ data-toggletext="Toggle Text"
33
+ data-toggletarget="#filter-module"
34
+ data-toggleclass="active"
35
+ class="toggle-trigger"
36
+ >
37
+ </post-filter-module>
38
+ <toggle-trigger
39
+ id="toggle-trigger"
40
+ data-toggletext="Toggle Text"
41
+ data-toggletarget="#filter-module"
42
+ data-toggleclass="active"
43
+ class="toggle-trigger"
44
+ >
45
+ </toggle-trigger>
46
+ <post-grid-display-module
47
+ id="display-module"
48
+ data-posts=""
49
+ class="post-grid-display-module cmpl-block-padding cmpl-block-settings"
50
+ >
51
+ </post-grid-display-module>
23
52
  </ptfg-9000>
24
53
 
25
54
  <script type="module">
26
- const postfiltermoduletemplate = await fetch(
27
- "../webc-post-filter-module/post-filter-module.html"
28
- );
29
- const postfiltermodulehtml = await postfiltermoduletemplate.text();
30
- document
31
- .querySelector("ptfg-9000")
32
- .insertAdjacentHTML("beforeend", postfiltermodulehtml);
55
+ // Post filter module
56
+ // const postfiltermoduletemplate = await fetch(
57
+ // "../webc-post-filter-module/post-filter-module.html"
58
+ // );
59
+ // const postfiltermodulehtml = await postfiltermoduletemplate.text();
60
+ // document
61
+ // .querySelector("ptfg-9000")
62
+ // .insertAdjacentHTML("beforeend", postfiltermodulehtml);
33
63
 
34
- const postgriddisplay = await fetch(
35
- "../webc-post-grid-display-module/post-grid-display-module.html"
36
- );
37
- const postgriddisplayhtml = await postgriddisplay.text();
38
- document
39
- .querySelector("ptfg-9000")
40
- .insertAdjacentHTML("beforeend", postgriddisplayhtml);
64
+ //toggle trigger
65
+ // const toggletrigger = await fetch(
66
+ // "../webc-toggle-trigger/toggle-trigger.html"
67
+ // );
68
+ // const toggletriggerhtml = await toggletrigger.text();
69
+ // document
70
+ // .querySelector("ptfg-9000")
71
+ // .insertAdjacentHTML("beforeend", toggletriggerhtml);
41
72
 
73
+ //post grid display
74
+ // const postgriddisplay = await fetch(
75
+ // "../webc-post-grid-display-module/post-grid-display-module.html"
76
+ // );
77
+ // const postgriddisplayhtml = await postgriddisplay.text();
78
+ // document
79
+ // .querySelector("ptfg-9000")
80
+ // .insertAdjacentHTML("beforeend", postgriddisplayhtml);
81
+
82
+ //Run Component JS
42
83
  import blockfilterjs from "../webc-post-filter-module/post-filter-module.js";
43
84
  blockfilterjs();
85
+
86
+ import toggletriggerjs from "../webc-toggle-trigger/toggle-trigger.js";
87
+ toggletriggerjs();
88
+
44
89
  import blockgridjs from "../webc-post-grid-display-module/post-grid-display-module.js";
45
90
  blockgridjs();
91
+
46
92
  import blockptfgjs from "./ptfg-9000.js";
47
93
  blockptfgjs();
48
94
  </script>
@@ -1,5 +1 @@
1
- <ptfg-9000
2
- class="ptfg-9000 ptfg-9000__main-container"
3
- data-assetkey="ptfg-9000"
4
- >
5
- </ptfg-9000>
1
+ <ptfg-9000 class="ptfg-9000 ptfg-9000__main-container"> </ptfg-9000>