vrembem 1.38.0 → 1.40.2

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.
@@ -329,14 +329,6 @@ const closeTransition = (el, settings) => {
329
329
  });
330
330
  };
331
331
 
332
- const breakpoints = {
333
- xs: '480px',
334
- sm: '620px',
335
- md: '760px',
336
- lg: '990px',
337
- xl: '1380px'
338
- };
339
-
340
332
  var index = {
341
333
  __proto__: null,
342
334
  setInert: setInert,
@@ -354,8 +346,7 @@ var index = {
354
346
  removeClass: removeClass,
355
347
  toggleClass: toggleClass,
356
348
  openTransition: openTransition,
357
- closeTransition: closeTransition,
358
- breakpoints: breakpoints
349
+ closeTransition: closeTransition
359
350
  };
360
351
 
361
352
  function _extends() {
@@ -456,7 +447,7 @@ var defaults$2 = {
456
447
  selectorInert: null,
457
448
  selectorOverflow: null,
458
449
  // Feature toggles
459
- breakpoints: breakpoints,
450
+ breakpoints: null,
460
451
  customEventPrefix: 'drawer:',
461
452
  eventListeners: true,
462
453
  stateSave: true,
@@ -465,51 +456,11 @@ var defaults$2 = {
465
456
  transition: true
466
457
  };
467
458
 
468
- async function switchToModal(drawerKey, obj) {
469
- // Initial guards
470
- const drawer = obj.getDrawer(drawerKey);
471
- if (!drawer) return obj.drawerNotFound(drawerKey);
472
- if (hasClass(drawer, obj.settings.classModal)) return; // Enable modal state
473
-
474
- addClass(drawer, obj.settings.classModal);
475
- addClass(drawer, obj.settings.stateClosed);
476
- removeClass(drawer, obj.settings.stateOpened); // Dispatch custom event
477
-
478
- drawer.dispatchEvent(new CustomEvent(obj.settings.customEventPrefix + 'toModal', {
479
- bubbles: true
480
- }));
481
- return drawer;
482
- }
483
- async function switchToDefault(drawerKey, obj) {
484
- // Initial guards
485
- const drawer = obj.getDrawer(drawerKey);
486
- if (!drawer) return obj.drawerNotFound(drawerKey);
487
- if (!hasClass(drawer, obj.settings.classModal)) return; // Tear down modal state
488
-
489
- setInert(false, obj.settings.selectorInert);
490
- setOverflowHidden(false, obj.settings.selectorOverflow);
491
- removeClass(drawer, obj.settings.classModal);
492
- obj.focusTrap.destroy(); // Restore drawers saved state
493
-
494
- drawerKey = drawer.getAttribute(`data-${obj.settings.dataDrawer}`);
495
- const drawerState = obj.state[drawerKey];
496
-
497
- if (drawerState == obj.settings.stateOpened) {
498
- addClass(drawer, obj.settings.stateOpened);
499
- removeClass(drawer, obj.settings.stateClosed);
500
- } // Dispatch custom event
501
-
502
-
503
- drawer.dispatchEvent(new CustomEvent(obj.settings.customEventPrefix + 'toDefault', {
504
- bubbles: true
505
- }));
506
- return drawer;
507
- }
508
-
509
459
  class Breakpoint {
510
460
  constructor(parent) {
511
461
  this.mediaQueryLists = [];
512
462
  this.parent = parent;
463
+ this.prefix = this.getVariablePrefix();
513
464
  this.__check = this.check.bind(this);
514
465
  }
515
466
 
@@ -518,7 +469,7 @@ class Breakpoint {
518
469
  drawers.forEach(drawer => {
519
470
  const id = drawer.getAttribute(`data-${this.parent.settings.dataDrawer}`);
520
471
  const key = drawer.getAttribute(`data-${this.parent.settings.dataBreakpoint}`);
521
- const bp = this.parent.settings.breakpoints[key] ? this.parent.settings.breakpoints[key] : key;
472
+ const bp = this.getBreakpoint(key);
522
473
  const mql = window.matchMedia('(min-width:' + bp + ')');
523
474
  this.match(mql, drawer);
524
475
  mql.addEventListener('change', this.__check);
@@ -557,12 +508,66 @@ class Breakpoint {
557
508
 
558
509
  match(mql, drawer) {
559
510
  if (mql.matches) {
560
- switchToDefault(drawer, this.parent);
511
+ this.parent.switchToDefault(drawer);
561
512
  } else {
562
- switchToModal(drawer, this.parent);
513
+ this.parent.switchToModal(drawer);
563
514
  }
564
515
  }
565
516
 
517
+ getBreakpoint(key) {
518
+ let breakpoint = key;
519
+
520
+ if (this.parent.settings.breakpoints && this.parent.settings.breakpoints[key]) {
521
+ breakpoint = this.parent.settings.breakpoints[key];
522
+ } else if (getComputedStyle(document.body).getPropertyValue(this.prefix + key)) {
523
+ breakpoint = getComputedStyle(document.body).getPropertyValue(this.prefix + key);
524
+ }
525
+
526
+ return breakpoint;
527
+ }
528
+
529
+ getVariablePrefix() {
530
+ let prefix = '--';
531
+ prefix += getComputedStyle(document.body).getPropertyValue('--vrembem-variable-prefix');
532
+ prefix += 'breakpoint-';
533
+ return prefix;
534
+ }
535
+
536
+ }
537
+
538
+ function getDrawer(drawerKey) {
539
+ if (typeof drawerKey !== 'string') return drawerKey;
540
+ return document.querySelector(`[data-${this.settings.dataDrawer}="${drawerKey}"]`);
541
+ }
542
+ function drawerNotFound(key) {
543
+ return Promise.reject(new Error(`Did not find drawer with key: "${key}"`));
544
+ }
545
+
546
+ async function close$2(drawerKey) {
547
+ const drawer = this.getDrawer(drawerKey);
548
+ if (!drawer) return drawerNotFound(drawerKey);
549
+
550
+ if (hasClass(drawer, this.settings.stateOpened)) {
551
+ this.working = true;
552
+
553
+ if (hasClass(drawer, this.settings.classModal)) {
554
+ setInert(false, this.settings.selectorInert);
555
+ setOverflowHidden(false, this.settings.selectorOverflow);
556
+ }
557
+
558
+ await closeTransition(drawer, this.settings);
559
+ this.stateSave(drawer);
560
+ focusTrigger(this);
561
+ this.focusTrap.destroy();
562
+ drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'closed', {
563
+ detail: this,
564
+ bubbles: true
565
+ }));
566
+ this.working = false;
567
+ return drawer;
568
+ } else {
569
+ return drawer;
570
+ }
566
571
  }
567
572
 
568
573
  function handlerClick$2(event) {
@@ -627,6 +632,39 @@ function handlerKeydown$2(event) {
627
632
  }
628
633
  }
629
634
 
635
+ async function open$2(drawerKey) {
636
+ const drawer = this.getDrawer(drawerKey);
637
+ if (!drawer) return drawerNotFound(drawerKey);
638
+
639
+ if (!hasClass(drawer, this.settings.stateOpened)) {
640
+ this.working = true;
641
+ const isModal = hasClass(drawer, this.settings.classModal);
642
+
643
+ if (isModal) {
644
+ setOverflowHidden(true, this.settings.selectorOverflow);
645
+ }
646
+
647
+ await openTransition(drawer, this.settings);
648
+ this.stateSave(drawer);
649
+
650
+ if (isModal) {
651
+ this.focusTrap.init(drawer);
652
+ setInert(true, this.settings.selectorInert);
653
+ }
654
+
655
+ focusTarget(drawer, this.settings);
656
+ drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'opened', {
657
+ detail: this,
658
+ bubbles: true
659
+ }));
660
+ this.working = false;
661
+ return drawer;
662
+ } else {
663
+ focusTarget(drawer, this.settings);
664
+ return drawer;
665
+ }
666
+ }
667
+
630
668
  function stateSet(settings) {
631
669
  // If save state is disabled
632
670
  if (!settings.stateSave) return stateClear(settings); // If there isn't an existing state to set
@@ -671,6 +709,59 @@ function stateClear(settings) {
671
709
  return {};
672
710
  }
673
711
 
712
+ async function switchToModal(drawerKey) {
713
+ // Initial guards
714
+ const drawer = this.getDrawer(drawerKey);
715
+ if (!drawer) return drawerNotFound(drawerKey);
716
+ if (hasClass(drawer, this.settings.classModal)) return; // Enable modal state
717
+
718
+ addClass(drawer, this.settings.classModal);
719
+ addClass(drawer, this.settings.stateClosed);
720
+ removeClass(drawer, this.settings.stateOpened); // Dispatch custom event
721
+
722
+ drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'toModal', {
723
+ bubbles: true
724
+ }));
725
+ return drawer;
726
+ }
727
+ async function switchToDefault(drawerKey) {
728
+ // Initial guards
729
+ const drawer = this.getDrawer(drawerKey);
730
+ if (!drawer) return drawerNotFound(drawerKey);
731
+ if (!hasClass(drawer, this.settings.classModal)) return; // Tear down modal state
732
+
733
+ setInert(false, this.settings.selectorInert);
734
+ setOverflowHidden(false, this.settings.selectorOverflow);
735
+ removeClass(drawer, this.settings.classModal);
736
+ this.focusTrap.destroy(); // Restore drawers saved state
737
+
738
+ drawerKey = drawer.getAttribute(`data-${this.settings.dataDrawer}`);
739
+ const drawerState = this.state[drawerKey];
740
+
741
+ if (drawerState == this.settings.stateOpened) {
742
+ addClass(drawer, this.settings.stateOpened);
743
+ removeClass(drawer, this.settings.stateClosed);
744
+ } // Dispatch custom event
745
+
746
+
747
+ drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'toDefault', {
748
+ bubbles: true
749
+ }));
750
+ return drawer;
751
+ }
752
+
753
+ async function toggle(drawerKey) {
754
+ const drawer = this.getDrawer(drawerKey);
755
+ if (!drawer) return drawerNotFound(drawerKey);
756
+ const isClosed = !hasClass(drawer, this.settings.stateOpened);
757
+
758
+ if (isClosed) {
759
+ return this.open(drawer);
760
+ } else {
761
+ return this.close(drawer);
762
+ }
763
+ }
764
+
674
765
  class Drawer {
675
766
  constructor(options) {
676
767
  this.defaults = defaults$2;
@@ -732,20 +823,14 @@ class Drawer {
732
823
 
733
824
 
734
825
  getDrawer(drawerKey) {
735
- if (typeof drawerKey !== 'string') return drawerKey;
736
- return document.querySelector(`[data-${this.settings.dataDrawer}="${drawerKey}"]`);
737
- }
738
-
739
- drawerNotFound(key) {
740
- return Promise.reject(new Error(`Did not find drawer with key: "${key}"`));
826
+ return getDrawer.call(this, drawerKey);
741
827
  }
742
828
 
743
829
  setTabindex() {
744
- const selectorTabindex = `
830
+ return setTabindex(`
745
831
  [data-${this.settings.dataDrawer}]
746
832
  [data-${this.settings.dataDialog}]
747
- `;
748
- setTabindex(selectorTabindex);
833
+ `);
749
834
  }
750
835
  /**
751
836
  * Save state functionality
@@ -769,87 +854,27 @@ class Drawer {
769
854
 
770
855
 
771
856
  switchToDefault(drawerKey) {
772
- return switchToDefault(drawerKey, this);
857
+ return switchToDefault.call(this, drawerKey);
773
858
  }
774
859
 
775
860
  switchToModal(drawerKey) {
776
- return switchToModal(drawerKey, this);
861
+ return switchToModal.call(this, drawerKey);
777
862
  }
778
863
  /**
779
864
  * Change state functionality
780
865
  */
781
866
 
782
867
 
783
- async toggle(drawerKey) {
784
- const drawer = this.getDrawer(drawerKey);
785
- if (!drawer) return this.drawerNotFound(drawerKey);
786
- const isClosed = !hasClass(drawer, this.settings.stateOpened);
787
-
788
- if (isClosed) {
789
- return this.open(drawer);
790
- } else {
791
- return this.close(drawer);
792
- }
868
+ toggle(drawerKey) {
869
+ return toggle.call(this, drawerKey);
793
870
  }
794
871
 
795
- async open(drawerKey) {
796
- const drawer = this.getDrawer(drawerKey);
797
- if (!drawer) return this.drawerNotFound(drawerKey);
798
-
799
- if (!hasClass(drawer, this.settings.stateOpened)) {
800
- this.working = true;
801
- const isModal = hasClass(drawer, this.settings.classModal);
802
-
803
- if (isModal) {
804
- setOverflowHidden(true, this.settings.selectorOverflow);
805
- }
806
-
807
- await openTransition(drawer, this.settings);
808
- this.stateSave(drawer);
809
-
810
- if (isModal) {
811
- this.focusTrap.init(drawer);
812
- setInert(true, this.settings.selectorInert);
813
- }
814
-
815
- focusTarget(drawer, this.settings);
816
- drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'opened', {
817
- detail: this,
818
- bubbles: true
819
- }));
820
- this.working = false;
821
- return drawer;
822
- } else {
823
- focusTarget(drawer, this.settings);
824
- return drawer;
825
- }
872
+ open(drawerKey) {
873
+ return open$2.call(this, drawerKey);
826
874
  }
827
875
 
828
- async close(drawerKey) {
829
- const drawer = this.getDrawer(drawerKey);
830
- if (!drawer) return this.drawerNotFound(drawerKey);
831
-
832
- if (hasClass(drawer, this.settings.stateOpened)) {
833
- this.working = true;
834
-
835
- if (hasClass(drawer, this.settings.classModal)) {
836
- setInert(false, this.settings.selectorInert);
837
- setOverflowHidden(false, this.settings.selectorOverflow);
838
- }
839
-
840
- await closeTransition(drawer, this.settings);
841
- this.stateSave(drawer);
842
- focusTrigger(this);
843
- this.focusTrap.destroy();
844
- drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'closed', {
845
- detail: this,
846
- bubbles: true
847
- }));
848
- this.working = false;
849
- return drawer;
850
- } else {
851
- return drawer;
852
- }
876
+ close(drawerKey) {
877
+ return close$2.call(this, drawerKey);
853
878
  }
854
879
 
855
880
  }
@@ -882,6 +907,27 @@ var defaults$1 = {
882
907
  transition: true
883
908
  };
884
909
 
910
+ async function close$1(returnFocus = true) {
911
+ const modal = document.querySelector(`[data-${this.settings.dataModal}].${this.settings.stateOpened}`);
912
+
913
+ if (modal) {
914
+ this.working = true;
915
+ setInert(false, this.settings.selectorInert);
916
+ setOverflowHidden(false, this.settings.selectorOverflow);
917
+ await closeTransition(modal, this.settings);
918
+ if (returnFocus) focusTrigger(this);
919
+ this.focusTrap.destroy();
920
+ modal.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'closed', {
921
+ detail: this,
922
+ bubbles: true
923
+ }));
924
+ this.working = false;
925
+ return modal;
926
+ } else {
927
+ return modal;
928
+ }
929
+ }
930
+
885
931
  async function handlerClick$1(event) {
886
932
  // Working catch
887
933
  if (this.working) return; // Trigger click
@@ -924,21 +970,57 @@ function handlerKeydown$1(event) {
924
970
  }
925
971
  }
926
972
 
927
- function setInitialState(obj) {
928
- const modals = document.querySelectorAll(`[data-${obj.settings.dataModal}]`);
973
+ function getModal(modalKey) {
974
+ if (typeof modalKey !== 'string') return modalKey;
975
+ return document.querySelector(`[data-${this.settings.dataModal}="${modalKey}"]`);
976
+ }
977
+ function modalNotFound(key) {
978
+ return Promise.reject(new Error(`Did not find modal with key: "${key}"`));
979
+ }
980
+ function moveModals(type = this.settings.moveModals.type, ref = this.settings.moveModals.ref) {
981
+ const modals = document.querySelectorAll(`[data-${this.settings.dataModal}]`);
982
+ if (modals.length) moveElement(modals, type, ref);
983
+ }
984
+
985
+ function setInitialState() {
986
+ const modals = document.querySelectorAll(`[data-${this.settings.dataModal}]`);
929
987
  modals.forEach(el => {
930
- if (el.classList.contains(obj.settings.stateOpened)) {
931
- setInert(false, obj.settings.selectorInert);
932
- setOverflowHidden(false, obj.settings.selectorOverflow);
933
- focusTrigger(obj);
934
- obj.focusTrap.destroy();
935
- }
988
+ // Remove opened state setup
989
+ if (el.classList.contains(this.settings.stateOpened)) {
990
+ setInert(false, this.settings.selectorInert);
991
+ setOverflowHidden(false, this.settings.selectorOverflow);
992
+ focusTrigger(this);
993
+ this.focusTrap.destroy();
994
+ } // Remove all state classes and add the default state (closed)
995
+
936
996
 
937
- removeClass(el, obj.settings.stateOpened, obj.settings.stateOpening, obj.settings.stateClosing);
938
- addClass(el, obj.settings.stateClosed);
997
+ removeClass(el, this.settings.stateOpened, this.settings.stateOpening, this.settings.stateClosing);
998
+ addClass(el, this.settings.stateClosed);
939
999
  });
940
1000
  }
941
1001
 
1002
+ async function open$1(modalKey) {
1003
+ const modal = getModal.call(this, modalKey);
1004
+ if (!modal) return modalNotFound(modalKey);
1005
+
1006
+ if (hasClass(modal, this.settings.stateClosed)) {
1007
+ this.working = true;
1008
+ setOverflowHidden(true, this.settings.selectorOverflow);
1009
+ await openTransition(modal, this.settings);
1010
+ this.focusTrap.init(modal);
1011
+ focusTarget(modal, this.settings);
1012
+ setInert(true, this.settings.selectorInert);
1013
+ modal.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'opened', {
1014
+ detail: this,
1015
+ bubbles: true
1016
+ }));
1017
+ this.working = false;
1018
+ return modal;
1019
+ } else {
1020
+ return modal;
1021
+ }
1022
+ }
1023
+
942
1024
  class Modal {
943
1025
  constructor(options) {
944
1026
  this.defaults = defaults$1;
@@ -954,13 +1036,12 @@ class Modal {
954
1036
  init(options = null) {
955
1037
  if (options) this.settings = _extends({}, this.settings, options);
956
1038
  this.moveModals();
1039
+ this.setInitialState();
957
1040
 
958
1041
  if (this.settings.setTabindex) {
959
1042
  this.setTabindex();
960
1043
  }
961
1044
 
962
- this.setInitialState();
963
-
964
1045
  if (this.settings.eventListeners) {
965
1046
  this.initEventListeners();
966
1047
  }
@@ -995,76 +1076,34 @@ class Modal {
995
1076
 
996
1077
 
997
1078
  getModal(modalKey) {
998
- if (typeof modalKey !== 'string') return modalKey;
999
- return document.querySelector(`[data-${this.settings.dataModal}="${modalKey}"]`);
1000
- }
1001
-
1002
- modalNotFound(key) {
1003
- return Promise.reject(new Error(`Did not find modal with key: "${key}"`));
1079
+ return getModal.call(this, modalKey);
1004
1080
  }
1005
1081
 
1006
1082
  setTabindex() {
1007
- const selectorTabindex = `
1083
+ return setTabindex(`
1008
1084
  [data-${this.settings.dataModal}]
1009
1085
  [data-${this.settings.dataDialog}]
1010
- `;
1011
- setTabindex(selectorTabindex);
1086
+ `);
1012
1087
  }
1013
1088
 
1014
1089
  setInitialState() {
1015
- setInitialState(this);
1090
+ return setInitialState.call(this);
1016
1091
  }
1017
1092
 
1018
- moveModals(type = this.settings.moveModals.type, ref = this.settings.moveModals.ref) {
1019
- const modals = document.querySelectorAll(`[data-${this.settings.dataModal}]`);
1020
- if (modals.length) moveElement(modals, type, ref);
1093
+ moveModals(type, ref) {
1094
+ return moveModals.call(this, type, ref);
1021
1095
  }
1022
1096
  /**
1023
1097
  * Change state functionality
1024
1098
  */
1025
1099
 
1026
1100
 
1027
- async open(modalKey) {
1028
- const modal = this.getModal(modalKey);
1029
- if (!modal) return this.modalNotFound(modalKey);
1030
-
1031
- if (hasClass(modal, this.settings.stateClosed)) {
1032
- this.working = true;
1033
- setOverflowHidden(true, this.settings.selectorOverflow);
1034
- await openTransition(modal, this.settings);
1035
- this.focusTrap.init(modal);
1036
- focusTarget(modal, this.settings);
1037
- setInert(true, this.settings.selectorInert);
1038
- modal.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'opened', {
1039
- detail: this,
1040
- bubbles: true
1041
- }));
1042
- this.working = false;
1043
- return modal;
1044
- } else {
1045
- return modal;
1046
- }
1101
+ open(modalKey) {
1102
+ return open$1.call(this, modalKey);
1047
1103
  }
1048
1104
 
1049
- async close(returnFocus = true) {
1050
- const modal = document.querySelector(`[data-${this.settings.dataModal}].${this.settings.stateOpened}`);
1051
-
1052
- if (modal) {
1053
- this.working = true;
1054
- setInert(false, this.settings.selectorInert);
1055
- setOverflowHidden(false, this.settings.selectorOverflow);
1056
- await closeTransition(modal, this.settings);
1057
- if (returnFocus) focusTrigger(this);
1058
- this.focusTrap.destroy();
1059
- modal.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'closed', {
1060
- detail: this,
1061
- bubbles: true
1062
- }));
1063
- this.working = false;
1064
- return modal;
1065
- } else {
1066
- return modal;
1067
- }
1105
+ close(returnFocus) {
1106
+ return close$1.call(this, returnFocus);
1068
1107
  }
1069
1108
 
1070
1109
  }
@@ -1085,9 +1124,9 @@ var defaults = {
1085
1124
  placement: 'bottom-start'
1086
1125
  };
1087
1126
 
1088
- function hide$2(popover, obj) {
1127
+ function close(popover) {
1089
1128
  // Update state class
1090
- popover.target.classList.remove(obj.settings.stateActive); // Update a11y attributes
1129
+ popover.target.classList.remove(this.settings.stateActive); // Update a11y attributes
1091
1130
 
1092
1131
  popover.trigger.setAttribute('aria-expanded', 'false'); // Disable popper event listeners
1093
1132
 
@@ -1098,32 +1137,39 @@ function hide$2(popover, obj) {
1098
1137
  }]
1099
1138
  }); // Update collection status with new state
1100
1139
 
1101
- const index = obj.collection.findIndex(item => {
1140
+ const index = this.collection.findIndex(item => {
1102
1141
  return item.target === popover.target;
1103
1142
  });
1104
- obj.collection[index].state = 'hide'; // Return the popover
1143
+ this.collection[index].state = 'closed'; // Clear the memory if popover trigger matches the ones saved in memory
1144
+
1145
+ if (popover.trigger === this.memory.trigger) {
1146
+ this.memory.trigger = null;
1147
+ } // Return the popover
1148
+
1105
1149
 
1106
1150
  return popover;
1107
1151
  }
1108
- function hideAll(obj) {
1109
- obj.collection.forEach(popover => {
1110
- if (popover.state === 'show') {
1111
- hide$2(popover, obj);
1152
+ function closeAll() {
1153
+ this.collection.forEach(popover => {
1154
+ if (popover.state === 'opened') {
1155
+ this.close(popover);
1112
1156
  }
1113
1157
  }); // Return the collection
1114
1158
 
1115
- return obj.collection;
1159
+ return this.collection;
1116
1160
  }
1117
- function hideCheck(popover, obj) {
1118
- // Needed to correctly check which element is currently being focused
1161
+ function closeCheck(popover) {
1162
+ // Only run closeCheck if provided popover is currently open
1163
+ if (popover.state != 'opened') return; // Needed to correctly check which element is currently being focused
1164
+
1119
1165
  setTimeout(() => {
1120
1166
  // Check if trigger or target are being hovered
1121
1167
  const isHovered = popover.target.closest(':hover') === popover.target || popover.trigger.closest(':hover') === popover.trigger; // Check if trigger or target are being focused
1122
1168
 
1123
- const isFocused = document.activeElement.closest(`[data-${obj.settings.dataPopover}]`) === popover.target || document.activeElement.closest(`[data-${obj.settings.dataTrigger}]`) === popover.trigger; // Hide if the trigger and target are not currently hovered or focused
1169
+ const isFocused = document.activeElement.closest(`[data-${this.settings.dataPopover}]`) === popover.target || document.activeElement.closest(`[data-${this.settings.dataTrigger}]`) === popover.trigger; // Close if the trigger and target are not currently hovered or focused
1124
1170
 
1125
1171
  if (!isHovered && !isFocused) {
1126
- hide$2(popover, obj);
1172
+ this.close(popover);
1127
1173
  } // Return the popover
1128
1174
 
1129
1175
 
@@ -1131,6 +1177,55 @@ function hideCheck(popover, obj) {
1131
1177
  }, 1);
1132
1178
  }
1133
1179
 
1180
+ function handlerClick(popover) {
1181
+ if (popover.target.classList.contains(this.settings.stateActive)) {
1182
+ this.close(popover);
1183
+ } else {
1184
+ this.memory.trigger = popover.trigger;
1185
+ this.open(popover);
1186
+ documentClick.call(this, popover);
1187
+ }
1188
+ }
1189
+ function handlerKeydown(event) {
1190
+ switch (event.key) {
1191
+ case 'Escape':
1192
+ if (this.memory.trigger) {
1193
+ this.memory.trigger.focus();
1194
+ }
1195
+
1196
+ this.closeAll();
1197
+ return;
1198
+
1199
+ case 'Tab':
1200
+ this.collection.forEach(popover => {
1201
+ closeCheck.call(this, popover);
1202
+ });
1203
+ return;
1204
+
1205
+ default:
1206
+ return;
1207
+ }
1208
+ }
1209
+ function documentClick(popover) {
1210
+ const obj = this;
1211
+ document.addEventListener('click', function _f(event) {
1212
+ const result = event.target.closest(`[data-${obj.settings.dataPopover}], [data-${obj.settings.dataTrigger}]`);
1213
+ const match = result === popover.target || result === popover.trigger;
1214
+
1215
+ if (!match) {
1216
+ if (popover.target.classList.contains(obj.settings.stateActive)) {
1217
+ obj.close(popover);
1218
+ }
1219
+
1220
+ this.removeEventListener('click', _f);
1221
+ } else {
1222
+ if (!popover.target.classList.contains(obj.settings.stateActive)) {
1223
+ this.removeEventListener('click', _f);
1224
+ }
1225
+ }
1226
+ });
1227
+ }
1228
+
1134
1229
  function getConfig(el, settings) {
1135
1230
  // Get the computed styles of the popover
1136
1231
  const styles = getComputedStyle(el); // Setup the config obj with default values
@@ -1147,7 +1242,8 @@ function getConfig(el, settings) {
1147
1242
 
1148
1243
  for (const prop in config) {
1149
1244
  // Get the CSS variable property values
1150
- const val = styles.getPropertyValue(`--popover-${prop}`).trim(); // If a value was found, replace the default in config obj
1245
+ const prefix = getComputedStyle(document.body).getPropertyValue('--vrembem-variable-prefix');
1246
+ const val = styles.getPropertyValue(`--${prefix}popover-${prop}`).trim(); // If a value was found, replace the default in config obj
1151
1247
 
1152
1248
  if (val) {
1153
1249
  config[prop] = val;
@@ -1250,16 +1346,16 @@ function getPopover(trigger, settings) {
1250
1346
  }
1251
1347
  }
1252
1348
 
1253
- function show(popover, obj) {
1349
+ function open(popover) {
1254
1350
  // Update state class
1255
- popover.target.classList.add(obj.settings.stateActive); // Update a11y attributes
1351
+ popover.target.classList.add(this.settings.stateActive); // Update a11y attributes
1256
1352
 
1257
1353
  popover.trigger.setAttribute('aria-expanded', 'true'); // Update popover config
1258
1354
 
1259
- popover.config = getConfig(popover.target, obj.settings); // Enable popper event listeners and set placement/modifiers
1355
+ popover.config = getConfig(popover.target, this.settings); // Enable popper event listeners and set placement/modifiers
1260
1356
 
1261
1357
  popover.popper.setOptions({
1262
- placement: getData(popover.target, obj.settings.dataPlacement, popover.config['placement']),
1358
+ placement: getData(popover.target, this.settings.dataPlacement, popover.config['placement']),
1263
1359
  modifiers: [{
1264
1360
  name: 'eventListeners',
1265
1361
  enabled: true
@@ -1268,46 +1364,14 @@ function show(popover, obj) {
1268
1364
 
1269
1365
  popover.popper.update(); // Update collection status with new state
1270
1366
 
1271
- const index = obj.collection.findIndex(item => {
1367
+ const index = this.collection.findIndex(item => {
1272
1368
  return item.target === popover.target;
1273
1369
  });
1274
- obj.collection[index].state = 'show'; // Return the popover
1370
+ this.collection[index].state = 'opened'; // Return the popover
1275
1371
 
1276
1372
  return popover;
1277
1373
  }
1278
1374
 
1279
- function handlerClick(popover) {
1280
- if (popover.target.classList.contains(this.settings.stateActive)) {
1281
- hide$2(popover, this);
1282
- } else {
1283
- show(popover, this);
1284
- documentClick(popover, this);
1285
- }
1286
- }
1287
- function handlerKeydown(event) {
1288
- if (event.key === 'Escape') {
1289
- hideAll(this);
1290
- }
1291
- }
1292
- function documentClick(popover, obj) {
1293
- document.addEventListener('click', function _f(event) {
1294
- const result = event.target.closest(`[data-${obj.settings.dataPopover}], [data-${obj.settings.dataTrigger}]`);
1295
- const match = result === popover.target || result === popover.trigger;
1296
-
1297
- if (!match) {
1298
- if (popover.target.classList.contains(obj.settings.stateActive)) {
1299
- hide$2(popover, obj);
1300
- }
1301
-
1302
- this.removeEventListener('click', _f);
1303
- } else {
1304
- if (!popover.target.classList.contains(obj.settings.stateActive)) {
1305
- this.removeEventListener('click', _f);
1306
- }
1307
- }
1308
- });
1309
- }
1310
-
1311
1375
  var top = 'top';
1312
1376
  var bottom = 'bottom';
1313
1377
  var right = 'right';
@@ -3091,11 +3155,11 @@ var createPopper = /*#__PURE__*/popperGenerator({
3091
3155
  defaultModifiers: defaultModifiers
3092
3156
  }); // eslint-disable-next-line import/no-unused-modules
3093
3157
 
3094
- function register(trigger, target, obj) {
3158
+ function register(trigger, target) {
3095
3159
  // If no target is passed
3096
3160
  if (!target) {
3097
3161
  // Try and get the target
3098
- target = getPopover(trigger, obj.settings); // If still no target is returned, log an error and return false
3162
+ target = getPopover(trigger, this.settings); // If still no target is returned, log an error and return false
3099
3163
 
3100
3164
  if (!target) {
3101
3165
  console.error('No popover associated with the provided trigger:', trigger);
@@ -3104,7 +3168,7 @@ function register(trigger, target, obj) {
3104
3168
  } // Check if this item has already been registered in the collection
3105
3169
 
3106
3170
 
3107
- const index = obj.collection.findIndex(item => {
3171
+ const index = this.collection.findIndex(item => {
3108
3172
  return item.trigger === trigger && item.target === target;
3109
3173
  }); // Initiate popover variable
3110
3174
 
@@ -3112,45 +3176,45 @@ function register(trigger, target, obj) {
3112
3176
 
3113
3177
  if (index >= 0) {
3114
3178
  // Set popover as item from collection
3115
- popover = obj.collection[index];
3179
+ popover = this.collection[index];
3116
3180
  } else {
3117
3181
  // Create popper instance
3118
3182
  const popperInstance = createPopper(trigger, target); // Build popover object and push to collection array
3119
3183
 
3120
3184
  popover = {
3121
- state: 'hide',
3185
+ state: 'closed',
3122
3186
  trigger: trigger,
3123
3187
  target: target,
3124
3188
  popper: popperInstance,
3125
- config: getConfig(target, obj.settings)
3189
+ config: getConfig(target, this.settings)
3126
3190
  }; // Add item to collection
3127
3191
 
3128
- obj.collection.push(popover);
3192
+ this.collection.push(popover);
3129
3193
  } // Setup event listeners
3130
3194
 
3131
3195
 
3132
- registerEventListeners(popover, obj); // Set initial state of popover
3196
+ registerEventListeners.call(this, popover); // Set initial state of popover
3133
3197
 
3134
- if (popover.target.classList.contains(obj.settings.stateActive)) {
3135
- show(popover, obj);
3136
- documentClick(popover, obj);
3198
+ if (popover.target.classList.contains(this.settings.stateActive)) {
3199
+ this.open(popover);
3200
+ documentClick.call(this, popover);
3137
3201
  } else {
3138
- hide$2(popover, obj);
3202
+ this.close(popover);
3139
3203
  } // Return the popover object
3140
3204
 
3141
3205
 
3142
3206
  return popover;
3143
3207
  }
3144
- function deregister(popover, obj) {
3208
+ function deregister(popover) {
3145
3209
  // Check if this item has been registered in the collection
3146
- const index = obj.collection.findIndex(item => {
3210
+ const index = this.collection.findIndex(item => {
3147
3211
  return item.trigger === popover.trigger && item.target === popover.target;
3148
3212
  }); // If the item exists in the collection
3149
3213
 
3150
3214
  if (index >= 0) {
3151
- // Hide the popover
3152
- if (popover.state === 'show') {
3153
- hide$2(popover, obj);
3215
+ // Close the popover
3216
+ if (popover.state === 'opened') {
3217
+ this.close(popover);
3154
3218
  } // Clean up the popper instance
3155
3219
 
3156
3220
 
@@ -3158,28 +3222,28 @@ function deregister(popover, obj) {
3158
3222
 
3159
3223
  deregisterEventListeners(popover); // Remove item from collection
3160
3224
 
3161
- obj.collection.splice(index, 1);
3225
+ this.collection.splice(index, 1);
3162
3226
  } // Return the new collection
3163
3227
 
3164
3228
 
3165
- return obj.collection;
3229
+ return this.collection;
3166
3230
  }
3167
- function registerEventListeners(popover, obj) {
3231
+ function registerEventListeners(popover) {
3168
3232
  // If event listeners aren't already setup
3169
3233
  if (!popover.__eventListeners) {
3170
3234
  // Add event listeners based on event type
3171
- const eventType = getData(popover.target, obj.settings.dataEventType, popover.config['event']);
3235
+ const eventType = getData(popover.target, this.settings.dataEventType, popover.config['event']);
3172
3236
 
3173
3237
  if (eventType === 'hover') {
3174
3238
  // Setup event listeners object for hover
3175
3239
  popover.__eventListeners = [{
3176
3240
  el: ['trigger'],
3177
3241
  type: ['mouseenter', 'focus'],
3178
- listener: show.bind(null, popover, obj)
3242
+ listener: open.bind(this, popover)
3179
3243
  }, {
3180
3244
  el: ['trigger', 'target'],
3181
3245
  type: ['mouseleave', 'focusout'],
3182
- listener: hideCheck.bind(null, popover, obj)
3246
+ listener: closeCheck.bind(this, popover)
3183
3247
  }]; // Loop through listeners and apply to appropriate elements
3184
3248
 
3185
3249
  popover.__eventListeners.forEach(evObj => {
@@ -3194,7 +3258,7 @@ function registerEventListeners(popover, obj) {
3194
3258
  popover.__eventListeners = [{
3195
3259
  el: ['trigger'],
3196
3260
  type: ['click'],
3197
- listener: handlerClick.bind(obj, popover)
3261
+ listener: handlerClick.bind(this, popover)
3198
3262
  }]; // Loop through listeners and apply to appropriate elements
3199
3263
 
3200
3264
  popover.__eventListeners.forEach(evObj => {
@@ -3229,24 +3293,24 @@ function deregisterEventListeners(popover) {
3229
3293
 
3230
3294
  return popover;
3231
3295
  }
3232
- function registerCollection(obj) {
3296
+ function registerCollection() {
3233
3297
  // Get all the triggers
3234
- const triggers = document.querySelectorAll(`[data-${obj.settings.dataTrigger}]`);
3298
+ const triggers = document.querySelectorAll(`[data-${this.settings.dataTrigger}]`);
3235
3299
  triggers.forEach(trigger => {
3236
3300
  // Register the popover and save to collection array
3237
- register(trigger, false, obj);
3301
+ this.register(trigger, false);
3238
3302
  }); // Return the popover collection
3239
3303
 
3240
- return obj.collection;
3304
+ return this.collection;
3241
3305
  }
3242
- function deregisterCollection(obj) {
3306
+ function deregisterCollection() {
3243
3307
  // Loop through all items within the collection and pass them to deregister()
3244
- while (obj.collection.length > 0) {
3245
- deregister(obj.collection[0], obj);
3308
+ while (this.collection.length > 0) {
3309
+ this.deregister(this.collection[0]);
3246
3310
  } // Return the popover collection
3247
3311
 
3248
3312
 
3249
- return obj.collection;
3313
+ return this.collection;
3250
3314
  }
3251
3315
 
3252
3316
  class Popover {
@@ -3254,6 +3318,9 @@ class Popover {
3254
3318
  this.defaults = defaults;
3255
3319
  this.settings = _extends({}, this.defaults, options);
3256
3320
  this.collection = [];
3321
+ this.memory = {
3322
+ trigger: null
3323
+ };
3257
3324
  this.__handlerKeydown = handlerKeydown.bind(this);
3258
3325
  if (this.settings.autoInit) this.init();
3259
3326
  }
@@ -3262,7 +3329,7 @@ class Popover {
3262
3329
  // Update settings with passed options
3263
3330
  if (options) this.settings = _extends({}, this.settings, options); // Build the collections array with popover instances
3264
3331
 
3265
- registerCollection(this); // If eventListeners is enabled
3332
+ this.registerCollection(); // If eventListeners is enabled
3266
3333
 
3267
3334
  if (this.settings.eventListeners) {
3268
3335
  // Pass false to initEventListeners() since registerCollection()
@@ -3273,7 +3340,7 @@ class Popover {
3273
3340
 
3274
3341
  destroy() {
3275
3342
  // Deregister all popovers from collection
3276
- deregisterCollection(this); // If eventListeners is enabled
3343
+ this.deregisterCollection(); // If eventListeners is enabled
3277
3344
 
3278
3345
  if (this.settings.eventListeners) {
3279
3346
  // Pass false to destroyEventListeners() since deregisterCollection()
@@ -3290,7 +3357,7 @@ class Popover {
3290
3357
  if (processCollection) {
3291
3358
  // Loop through collection and setup event listeners
3292
3359
  this.collection.forEach(popover => {
3293
- registerEventListeners(popover, this);
3360
+ registerEventListeners.call(this, popover);
3294
3361
  });
3295
3362
  } // Add keydown global event listener
3296
3363
 
@@ -3315,35 +3382,35 @@ class Popover {
3315
3382
 
3316
3383
 
3317
3384
  register(trigger, target = false) {
3318
- return register(trigger, target, this);
3385
+ return register.call(this, trigger, target);
3319
3386
  }
3320
3387
 
3321
3388
  deregister(popover) {
3322
- return deregister(popover, this);
3389
+ return deregister.call(this, popover);
3323
3390
  }
3324
3391
 
3325
3392
  registerCollection() {
3326
- return registerCollection(this);
3393
+ return registerCollection.call(this);
3327
3394
  }
3328
3395
 
3329
3396
  deregisterCollection() {
3330
- return deregisterCollection(this);
3397
+ return deregisterCollection.call(this);
3331
3398
  }
3332
3399
  /**
3333
3400
  * Change state functionality
3334
3401
  */
3335
3402
 
3336
3403
 
3337
- show(popover) {
3338
- return show(popover, this);
3404
+ open(popover) {
3405
+ return open.call(this, popover);
3339
3406
  }
3340
3407
 
3341
- hide(popover) {
3342
- return hide$2(popover, this);
3408
+ close(popover) {
3409
+ return close.call(this, popover);
3343
3410
  }
3344
3411
 
3345
- hideAll() {
3346
- return hideAll(this);
3412
+ closeAll() {
3413
+ return closeAll.call(this);
3347
3414
  }
3348
3415
 
3349
3416
  }