@ilo-org/twig 0.2.2 → 0.2.4

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.
@@ -63,6 +63,7 @@ export default class Navigation {
63
63
  );
64
64
  this.contextLinks = this.element.querySelectorAll(`.${this.prefix}--context-menu--link`);
65
65
  this.languageLinks = this.element.querySelectorAll(`.${this.prefix}--nav--language`);
66
+ this.body = document.body;
66
67
 
67
68
  return this;
68
69
  }
@@ -74,15 +75,23 @@ export default class Navigation {
74
75
  * @chainable
75
76
  */
76
77
  setupHandlers() {
77
- this.subnavOpenClick = this.handleSubnavClickOpen.bind(this);
78
+ this.subnavClick = this.handleSubnavClick.bind(this);
79
+ this.subnavClickOff = this.handleSubnavClickOff.bind(this);
80
+ this.subnavClickOn = this.handleSubnavClickOn.bind(this);
78
81
  this.subnavBackClick = this.handleSubnavBackClick.bind(this);
79
82
  this.menuCloseClick = this.handleMenuCloseClick.bind(this);
80
83
  this.menuOpenClick = this.handleMenuOpenClick.bind(this);
81
- this.searchButtonClick = this.handleSearchButtonClick.bind(this);
82
- this.contextButtonClick = this.handleContextButtonClick.bind(this);
83
84
  this.languageButtonClick = this.handleLanguageButtonClick.bind(this);
84
85
  this.contextLinkClick = this.handleContextLinkClick.bind(this);
85
86
  this.onResize = this.handleResize.bind(this);
87
+ this.keyPress = this.handleKeyPress.bind(this);
88
+ this.bodyClick = this.removeClass.bind(this);
89
+ this.contextButtonClick = this.handleContextButtonClick.bind(this);
90
+ this.contextButtonClickOff = this.handleContextButtonClickOff.bind(this);
91
+ this.contextButtonClickOn = this.handleContextButtonClickOn.bind(this);
92
+ this.searchButtonClick = this.handleSearchButtonClick.bind(this);
93
+ this.searchButtonClickOff = this.handleSearchButtonClickOff.bind(this);
94
+ this.searchButtonClickOn = this.handleSearchButtonClickOn.bind(this);
86
95
 
87
96
  return this;
88
97
  }
@@ -96,8 +105,8 @@ export default class Navigation {
96
105
  enable() {
97
106
  // subnavButton
98
107
  if (this.subnavButton) {
99
- this.subnavButton.addEventListener(EVENTS.CLICK, () => this.subnavOpenClick());
100
- this.subnavButton.addEventListener(EVENTS.TOUCH_START, () => this.subnavOpenClick());
108
+ this.subnavButton.addEventListener(EVENTS.CLICK, (e) => this.subnavClick(e));
109
+ this.subnavButton.addEventListener(EVENTS.TOUCH_START, (e) => this.subnavClick(e));
101
110
  }
102
111
 
103
112
  // subnavBack
@@ -110,8 +119,8 @@ export default class Navigation {
110
119
 
111
120
  // searchButton
112
121
  if (this.searchButton) {
113
- this.searchButton.addEventListener(EVENTS.CLICK, () => this.searchButtonClick());
114
- this.searchButton.addEventListener(EVENTS.TOUCH_START, () => this.searchButtonClick());
122
+ this.searchButton.addEventListener(EVENTS.CLICK, (e) => this.searchButtonClick(e));
123
+ this.searchButton.addEventListener(EVENTS.TOUCH_START, (e) => this.searchButtonClick(e));
115
124
  }
116
125
  // menuCloseSet
117
126
  if (this.menuCloseSet.length > 0) {
@@ -129,8 +138,8 @@ export default class Navigation {
129
138
 
130
139
  // contextButton
131
140
  if (this.contextButton) {
132
- this.contextButton.addEventListener(EVENTS.CLICK, () => this.contextButtonClick());
133
- this.contextButton.addEventListener(EVENTS.TOUCH_START, () => this.contextButtonClick());
141
+ this.contextButton.addEventListener(EVENTS.CLICK, (e) => this.contextButtonClick(e));
142
+ this.contextButton.addEventListener(EVENTS.TOUCH_START, (e) => this.contextButtonClick(e));
134
143
  }
135
144
 
136
145
  // languageButton
@@ -160,6 +169,22 @@ export default class Navigation {
160
169
  return this;
161
170
  }
162
171
 
172
+ /**
173
+ * Onclick interaction with the body element
174
+ *
175
+ * @param {String} classText - Class name to remove from the element on body click
176
+ * @return {Object} Navigation A reference to the instance of the class
177
+ * @chainable
178
+ */
179
+ removeClass(e, classText) {
180
+ e.stopImmediatePropagation();
181
+ e.stopPropagation();
182
+
183
+ this.element.classList.remove(classText);
184
+
185
+ return this;
186
+ }
187
+
163
188
  /**
164
189
  * Onclick interaction with the context links
165
190
  *
@@ -173,6 +198,26 @@ export default class Navigation {
173
198
  return this;
174
199
  }
175
200
 
201
+ /**
202
+ * Actions performed on key press
203
+ *
204
+ * @param {Event} e - event object
205
+ * @param {Function} callback - function to call if the escape key is pressed
206
+ *
207
+ * @return {Object} Nav A reference to the instance of the class
208
+ * @chainable
209
+ */
210
+ handleKeyPress(e, callback) {
211
+ if (e.key === 'Escape') {
212
+ // this.element.classList.remove(`${this.prefix}--context--open`);
213
+ // this.element.classList.remove(`${this.prefix}--subnav--open`);
214
+ // this.element.classList.remove(`${this.prefix}--search--open`);
215
+ callback(e);
216
+ }
217
+
218
+ return this;
219
+ }
220
+
176
221
  /**
177
222
  * Onclick interaction with the language menu button
178
223
  *
@@ -191,8 +236,56 @@ export default class Navigation {
191
236
  * @return {Object} Navigation A reference to the instance of the class
192
237
  * @chainable
193
238
  */
194
- handleContextButtonClick() {
195
- this.element.classList.toggle(`${this.prefix}--context--open`);
239
+ handleContextButtonClickOn(e) {
240
+ e.stopImmediatePropagation();
241
+ // e.stopPropagation();
242
+ this.element.classList.add(`${this.prefix}--context--open`);
243
+ window.addEventListener(
244
+ EVENTS.KEY_DOWN,
245
+ (ev) => this.keyPress(ev, this.contextButtonClickOff),
246
+ false
247
+ );
248
+ this.body.addEventListener(EVENTS.CLICK, (ev) => this.handleContextButtonClickOff(ev), false);
249
+
250
+ return this;
251
+ }
252
+
253
+ /**
254
+ * Onclick interaction with the context menu button
255
+ *
256
+ * @return {Object} Navigation A reference to the instance of the class
257
+ * @chainable
258
+ */
259
+ handleContextButtonClickOff(e) {
260
+ e.stopImmediatePropagation();
261
+ // e.stopPropagation();
262
+ this.element.classList.remove(`${this.prefix}--context--open`);
263
+ window.removeEventListener(
264
+ EVENTS.KEY_DOWN,
265
+ (ev) => this.keyPress(ev, this.contextButtonClickOff),
266
+ false
267
+ );
268
+ this.body.removeEventListener(
269
+ EVENTS.CLICK,
270
+ (ev) => this.handleContextButtonClickoff(ev, `${this.prefix}--context--open`),
271
+ false
272
+ );
273
+
274
+ return this;
275
+ }
276
+
277
+ /**
278
+ * Onclick interaction with the context menu button
279
+ *
280
+ * @return {Object} Navigation A reference to the instance of the class
281
+ * @chainable
282
+ */
283
+ handleContextButtonClick(e) {
284
+ if (this.element.classList.contains(`${this.prefix}--context--open`)) {
285
+ this.contextButtonClickOff(e);
286
+ } else {
287
+ this.contextButtonClickOn(e);
288
+ }
196
289
 
197
290
  return this;
198
291
  }
@@ -203,10 +296,54 @@ export default class Navigation {
203
296
  * @return {Object} Navigation A reference to the instance of the class
204
297
  * @chainable
205
298
  */
206
- handleSearchButtonClick() {
207
- this.element.classList.toggle(`${this.prefix}--search--open`);
299
+ handleSearchButtonClickOn(e) {
300
+ e.stopImmediatePropagation();
301
+ // e.stopPropagation();
302
+ this.element.classList.add(`${this.prefix}--search--open`);
303
+ window.addEventListener(
304
+ EVENTS.KEY_DOWN,
305
+ (ev) => this.keyPress(ev, this.searchButtonClickOff),
306
+ false
307
+ );
308
+
309
+ return this;
310
+ }
311
+
312
+ /**
313
+ * Onclick interaction with the search button
314
+ *
315
+ * @return {Object} Navigation A reference to the instance of the class
316
+ * @chainable
317
+ */
318
+ handleSearchButtonClickOff(e) {
319
+ e.stopImmediatePropagation();
320
+ // e.stopPropagation();
321
+ this.element.classList.remove(`${this.prefix}--search--open`);
322
+ window.removeEventListener(
323
+ EVENTS.KEY_DOWN,
324
+ (ev) => this.keyPress(ev, this.searchButtonClickOff),
325
+ false
326
+ );
327
+
328
+ return this;
329
+ }
330
+
331
+ /**
332
+ * Onclick interaction with the search button
333
+ *
334
+ * @return {Object} Navigation A reference to the instance of the class
335
+ * @chainable
336
+ */
337
+ handleSearchButtonClick(e) {
338
+ // this.element.classList.toggle(`${this.prefix}--search--open`);
208
339
  this.element.classList.remove(`${this.prefix}--subnav--open`);
209
340
 
341
+ if (this.element.classList.contains(`${this.prefix}--search--open`)) {
342
+ this.searchButtonClickOff(e);
343
+ } else {
344
+ this.searchButtonClickOn(e);
345
+ }
346
+
210
347
  return this;
211
348
  }
212
349
 
@@ -222,16 +359,55 @@ export default class Navigation {
222
359
  return this;
223
360
  }
224
361
 
362
+ /**
363
+ * Onclick interaction with the subnav button
364
+ *
365
+ * @return {Object} Navigation A reference to the instance of the class
366
+ * @chainable
367
+ */
368
+ handleSubnavClickOn(e) {
369
+ e.stopImmediatePropagation();
370
+ // e.stopPropagation();
371
+ this.element.classList.add(`${this.prefix}--subnav--open`);
372
+ window.addEventListener(EVENTS.KEY_DOWN, (ev) => this.keyPress(ev, this.subnavClickOff), false);
373
+
374
+ return this;
375
+ }
376
+
377
+ /**
378
+ * Onclick interaction with the subnav button
379
+ *
380
+ * @return {Object} Navigation A reference to the instance of the class
381
+ * @chainable
382
+ */
383
+ handleSubnavClickOff(e) {
384
+ e.stopImmediatePropagation();
385
+ // e.stopPropagation();
386
+ this.element.classList.remove(`${this.prefix}--subnav--open`);
387
+ window.removeEventListener(
388
+ EVENTS.KEY_DOWN,
389
+ (ev) => this.keyPress(ev, this.subnavClickOff),
390
+ false
391
+ );
392
+
393
+ return this;
394
+ }
395
+
225
396
  /**
226
397
  * Onclick interaction with the Subnav button
227
398
  *
228
399
  * @return {Object} Navigation A reference to the instance of the class
229
400
  * @chainable
230
401
  */
231
- handleSubnavClickOpen() {
232
- this.element.classList.toggle(`${this.prefix}--subnav--open`);
402
+ handleSubnavClick(e) {
233
403
  this.element.classList.remove(`${this.prefix}--search--open`);
234
404
 
405
+ if (this.element.classList.contains(`${this.prefix}--subnav--open`)) {
406
+ this.subnavClickOff(e);
407
+ } else {
408
+ this.subnavClickOn(e);
409
+ }
410
+
235
411
  return this;
236
412
  }
237
413
 
@@ -242,7 +418,8 @@ export default class Navigation {
242
418
  * @chainable
243
419
  */
244
420
  handleSubnavBackClick() {
245
- this.element.classList.remove(`${this.prefix}--subnav--open`);
421
+ // this.element.classList.remove(`${this.prefix}--subnav--open`);
422
+ this.subnavClickOff(e);
246
423
  this.element.classList.remove(`${this.prefix}--select--open`);
247
424
 
248
425
  return this;
@@ -8,6 +8,12 @@
8
8
  <span class="ilo--icon" title="Remove"></span>
9
9
  </button>
10
10
  </li>
11
+ {% elseif tagType == "reset" %}
12
+ <li class="{{prefix}}--tags__item">
13
+ <button class="{{prefix}}--tag {{prefix}}--tag--reset {{prefix}}--tag--active" id="{{ id }}" data-active={{ defaultActive }} type="button">
14
+ {{content}}
15
+ </button>
16
+ </li>
11
17
  {% elseif tagType == "anchor" %}
12
18
  <li class="{{prefix}}--tags__item">
13
19
  <a class="{{prefix}}--tag {{prefix}}--tag--anchor {% if defaultActive %} {{prefix}}--tag--active{% endif %}" href="{{ url }}" id="{{ id }}" data-active={{ defaultActive }}>
@@ -20,7 +20,7 @@ tags:
20
20
  - content: content 3
21
21
  id: tag3
22
22
  defaultActive: false
23
- settings:
23
+ settings:
24
24
  allowMultipleActive:
25
25
  type: select
26
26
  label: Allow Multiple Active
@@ -38,6 +38,7 @@ tags:
38
38
  anchor: Anchor
39
39
  button: Button
40
40
  display: Display
41
+ reset: Reset
41
42
  preview: display
42
43
  required: true
43
44
  visibility: storybook