@iamproperty/components 2.7.7 → 2.9.0

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.
Files changed (138) hide show
  1. package/README.md +136 -136
  2. package/assets/css/core.min.css +1 -1
  3. package/assets/css/core.min.css.map +1 -1
  4. package/assets/css/email.min.css +1 -1
  5. package/assets/css/email.min.css.map +1 -1
  6. package/assets/css/error.min.css +1 -1
  7. package/assets/css/error.min.css.map +1 -1
  8. package/assets/css/style.min.css +1 -1
  9. package/assets/css/style.min.css.map +1 -1
  10. package/assets/js/modules/accordion.js +32 -36
  11. package/assets/js/modules/alert.js +56 -56
  12. package/assets/js/modules/carousel.js +101 -101
  13. package/assets/js/modules/chart.js +216 -216
  14. package/assets/js/modules/drawer.js +15 -15
  15. package/assets/js/modules/form.js +158 -158
  16. package/assets/js/modules/helpers.js +119 -97
  17. package/assets/js/modules/modal.js +89 -89
  18. package/assets/js/modules/nav.js +26 -26
  19. package/assets/js/modules/table.js +584 -584
  20. package/assets/js/modules/testimonial.js +82 -82
  21. package/assets/js/modules/youtubevideo.js +145 -145
  22. package/assets/js/scripts.bundle.js +174 -85
  23. package/assets/js/scripts.bundle.js.map +1 -1
  24. package/assets/js/scripts.bundle.min.js +2 -2
  25. package/assets/js/scripts.bundle.min.js.map +1 -1
  26. package/assets/sass/_components.scss +14 -14
  27. package/assets/sass/_corefiles.scss +40 -40
  28. package/assets/sass/_fonts.scss +16 -16
  29. package/assets/sass/_forms.scss +9 -9
  30. package/assets/sass/_func.scss +12 -10
  31. package/assets/sass/_functions/functions.scss +141 -141
  32. package/assets/sass/_functions/mixins.scss +170 -170
  33. package/assets/sass/_functions/utilities.scss +250 -250
  34. package/assets/sass/_functions/variables.scss +466 -462
  35. package/assets/sass/_print.scss +61 -61
  36. package/assets/sass/components/accordion.scss +197 -197
  37. package/assets/sass/components/alert.scss +98 -98
  38. package/assets/sass/components/cardDeck.scss +107 -107
  39. package/assets/sass/components/carousel.scss +234 -234
  40. package/assets/sass/components/charts.scss +569 -569
  41. package/assets/sass/components/drawer.scss +46 -46
  42. package/assets/sass/components/header.scss +63 -63
  43. package/assets/sass/components/modal.scss +136 -136
  44. package/assets/sass/components/nav.scss +916 -820
  45. package/assets/sass/components/property-searchbar.scss +143 -143
  46. package/assets/sass/components/snapshot.scss +70 -70
  47. package/assets/sass/components/stepper.scss +164 -164
  48. package/assets/sass/components/tabs.scss +87 -74
  49. package/assets/sass/components/testimonial.scss +132 -132
  50. package/assets/sass/components/timeline.scss +95 -95
  51. package/assets/sass/core.scss +6 -6
  52. package/assets/sass/elements/buttons.scss +209 -209
  53. package/assets/sass/elements/card.scss +177 -177
  54. package/assets/sass/elements/container.scss +225 -225
  55. package/assets/sass/elements/forms.scss +194 -194
  56. package/assets/sass/elements/links.scss +96 -96
  57. package/assets/sass/elements/lists.scss +112 -112
  58. package/assets/sass/elements/panel.scss +161 -161
  59. package/assets/sass/elements/tables.scss +290 -290
  60. package/assets/sass/elements/tooltips.scss +84 -84
  61. package/assets/sass/elements/type.scss +136 -136
  62. package/assets/sass/email.scss +65 -65
  63. package/assets/sass/error.scss +4 -4
  64. package/assets/sass/foundations/brand.scss +72 -72
  65. package/assets/sass/foundations/circles.scss +74 -74
  66. package/assets/sass/foundations/icons.scss +72 -72
  67. package/assets/sass/foundations/media.scss +50 -50
  68. package/assets/sass/foundations/reboot.scss +130 -129
  69. package/assets/sass/foundations/root.scss +106 -104
  70. package/assets/sass/main.scss +7 -7
  71. package/assets/svg/icons.svg +598 -588
  72. package/assets/svg/logo.svg +42 -42
  73. package/assets/{js/main.js → ts/main.ts} +68 -67
  74. package/assets/ts/modules/accordion.ts +43 -0
  75. package/dist/components.common.js +148 -98
  76. package/dist/components.common.js.map +1 -1
  77. package/dist/components.css +1 -1
  78. package/dist/components.css.map +1 -1
  79. package/dist/components.umd.js +182 -132
  80. package/dist/components.umd.js.map +1 -1
  81. package/dist/components.umd.min.js +1 -1
  82. package/dist/components.umd.min.js.map +1 -1
  83. package/package.json +108 -103
  84. package/src/components/Accordion/Accordion.vue +22 -22
  85. package/src/components/Accordion/AccordionItem.vue +52 -52
  86. package/src/components/Accordion/README.md +34 -34
  87. package/src/components/Alert/Alert.vue +39 -39
  88. package/src/components/Alert/README.md +28 -28
  89. package/src/components/Banner/Banner.vue +38 -38
  90. package/src/components/Banner/README.md +23 -23
  91. package/src/components/CardDeck/CardDeck.vue +77 -77
  92. package/src/components/CardDeck/README.md +24 -24
  93. package/src/components/Carousel/Carousel.vue +85 -85
  94. package/src/components/Carousel/README.md +19 -19
  95. package/src/components/Chart/Chart.vue +88 -88
  96. package/src/components/Chart/README.md +17 -17
  97. package/src/components/Drawer/Drawer.vue +53 -53
  98. package/src/components/Drawer/README.md +22 -22
  99. package/src/components/Header/Header.vue +38 -38
  100. package/src/components/Header/README.md +27 -27
  101. package/src/components/Modal/Modal.vue +43 -43
  102. package/src/components/Modal/README.md +19 -19
  103. package/src/components/Nav/Nav.vue +212 -189
  104. package/src/components/Nav/README.md +22 -22
  105. package/src/components/NoteFeed/NoteFeed.vue +79 -79
  106. package/src/components/NoteFeed/README.md +16 -16
  107. package/src/components/PropertySearchbar/PropertySearchbar.vue +204 -204
  108. package/src/components/PropertySearchbar/README.md +25 -25
  109. package/src/components/Snapshot/README.md +20 -20
  110. package/src/components/Snapshot/Snapshot.vue +32 -32
  111. package/src/components/Stepper/README.md +32 -32
  112. package/src/components/Stepper/Step.vue +28 -28
  113. package/src/components/Stepper/Stepper.vue +33 -33
  114. package/src/components/Tabs/README.md +27 -27
  115. package/src/components/Tabs/Tab.vue +26 -26
  116. package/src/components/Tabs/Tabs.vue +75 -75
  117. package/src/components/Testimonial/README.md +25 -25
  118. package/src/components/Testimonial/Testimonial.vue +60 -60
  119. package/src/components/Timeline/README.md +18 -18
  120. package/src/components/Timeline/Timeline.vue +24 -24
  121. package/src/elements/Card/Card.vue +113 -113
  122. package/src/elements/Card/README.md +24 -24
  123. package/src/elements/FileUploads/FileUploads.vue +48 -48
  124. package/src/elements/FileUploads/README.md +24 -24
  125. package/src/elements/Input/Input.vue +268 -268
  126. package/src/elements/Input/README.md +19 -19
  127. package/src/elements/Table/README.md +62 -62
  128. package/src/elements/Table/Table.vue +126 -116
  129. package/src/foundations/Icon/Icon.vue +24 -24
  130. package/src/foundations/Icon/README.md +11 -11
  131. package/src/foundations/Logo/Logo.vue +39 -39
  132. package/src/foundations/Logo/README.md +20 -20
  133. package/src/foundations/YoutubeVideo/README.md +11 -11
  134. package/src/foundations/YoutubeVideo/YoutubeVideo.vue +24 -24
  135. package/src/helpers/strings.js +12 -12
  136. package/src/index.js +27 -27
  137. package/assets/.DS_Store +0 -0
  138. package/src/.DS_Store +0 -0
@@ -1,159 +1,159 @@
1
- // Create a link between two input/selects with one acting as setting a minimum value and the second a maximum
2
- // The link between the two will prevent the max input field form setting a lower value than the min and vice versa
3
- function inputRange(inputWrapper){
4
-
5
- inputWrapper.addEventListener('change', function(e){
6
-
7
- var min = parseInt(inputWrapper.querySelector('[data-min] select,[data-min] input').value);
8
- var max = parseInt(inputWrapper.querySelector('[data-max] select,[data-max] input').value);
9
-
10
- // Set attributes for input fields
11
- Array.from(inputWrapper.querySelectorAll('[data-min] input')).forEach((input, index) => {
12
-
13
- input.setAttribute('max',max);
14
- });
15
-
16
- Array.from(inputWrapper.querySelectorAll('[data-max] input')).forEach((input, index) => {
17
-
18
- input.setAttribute('min',min);
19
- });
20
-
21
- // Hide select options if they are higher or lower than the min and max values
22
- Array.from(inputWrapper.querySelectorAll('[data-min] select option')).forEach((option, index) => {
23
-
24
- if(parseInt(option.getAttribute('value')) > max)
25
- option.classList.add('d-none');
26
- else
27
- option.classList.remove('d-none');
28
- });
29
-
30
- Array.from(inputWrapper.querySelectorAll('[data-max] select option')).forEach((option, index) => {
31
-
32
- if(parseInt(option.getAttribute('value')) < min)
33
- option.classList.add('d-none');
34
- else
35
- option.classList.remove('d-none');
36
- });
37
-
38
- }, false);
39
- }
40
-
41
- function inputRedirect(inputWrapper){
42
-
43
- inputWrapper.addEventListener('change', function(e){
44
-
45
- const url = inputWrapper.getAttribute('data-redirect');
46
- const desiredValue = inputWrapper.getAttribute('data-value-if');
47
-
48
- if(inputWrapper.value == desiredValue)
49
- document.location.href = url;
50
-
51
- }, false);
52
- }
53
-
54
- //
55
- function multipleFileUploads(wrapper){
56
-
57
- const fileTenplate = wrapper.querySelector('.row');
58
- const clone = fileTenplate.cloneNode(true);
59
- const addButton = wrapper.querySelector('[data-add]');
60
-
61
- wrapper.addEventListener('click', function(e){
62
- for (var target = e.target; target && target != this; target = target.parentNode) {
63
- if (target.matches('[data-add]')) { // Add a new row upload file input fields
64
-
65
- const tempClone = clone.cloneNode(true);
66
- wrapper.insertBefore(tempClone,target);
67
-
68
- if(addButton.matches('[data-maxfiles]') && Array.from(wrapper.querySelectorAll(':scope > .row')).length >= addButton.dataset.maxfiles)
69
- addButton.setAttribute('disabled','disabled');
70
-
71
- break;
72
- }
73
- if (target.matches('[data-delete]')) { // Delete the current row
74
-
75
- let row = target.closest('.row');
76
- row.remove();
77
-
78
- if(addButton.matches('[data-maxfiles]') && Array.from(wrapper.querySelectorAll(':scope > .row')).length < addButton.dataset.maxfiles)
79
- addButton.removeAttribute('disabled');
80
-
81
- break;
82
- }
83
- }
84
-
85
- }, false);
86
- }
87
-
88
- // Acts as an overall initialise function to trigger other functions.
89
- function form(formElement) {
90
-
91
- // Check for input range groups
92
- Array.from(formElement.querySelectorAll('[data-input-range]')).forEach((arrayElement, index) => {
93
- inputRange(arrayElement);
94
- });
95
-
96
- Array.from(formElement.querySelectorAll('[data-redirect][data-value-if]')).forEach((arrayElement, index) => {
97
- inputRedirect(arrayElement);
98
- });
99
-
100
- Array.from(formElement.querySelectorAll('.multiple-file-uploads')).forEach((arrayElement, index) => {
101
- multipleFileUploads(arrayElement);
102
- });
103
-
104
-
105
- // Check the file size of a file when uploaded in case it exceeds the max file size set
106
- formElement.addEventListener('change', function(e){
107
- for (var target = e.target; target && target != this; target = target.parentNode) {
108
- if (target.matches('[type="file"][data-filesize]') && target.files && target.files[0]) {
109
-
110
- const maxAllowedSize = target.dataset.filesize;
111
- if (target.files[0].size > maxAllowedSize) {
112
-
113
- target.value = '';
114
- alert('File too large');
115
- }
116
- break;
117
- }
118
- }
119
- }, false);
120
-
121
-
122
- // When a form is updated we may want to update some of the existing input fields; setting active fields when some data is selected.
123
- formElement.addEventListener('change', function(e){
124
-
125
- // Remove disabled attribute when a pre-selected input field equals a certain value
126
- Array.from(formElement.querySelectorAll('select[data-activeif][data-equals],input[data-activeif][data-equals]')).forEach((arrayElement, index) => {
127
-
128
- let group = arrayElement.closest('[data-group]') ? arrayElement.closest('[data-group]') : formElement;
129
- let selector = arrayElement.dataset.activeif;
130
- let value = arrayElement.dataset.equals;
131
- let testElement = group.querySelector(`select[data-id="${selector}"],input[data-id="${selector}"]`);
132
-
133
- if(testElement.value == value){
134
- arrayElement.removeAttribute('disabled');
135
- }
136
- else {
137
- arrayElement.setAttribute('disabled','disabled');
138
- arrayElement.value = '';
139
- }
140
- });
141
-
142
- // Show this input wrapper when a pre-selected input field equals a certain value
143
- Array.from(formElement.querySelectorAll('.form-control__wrapper[data-displayif][data-equals]')).forEach((arrayElement, index) => {
144
-
145
- let group = arrayElement.closest('[data-group]') ? arrayElement.closest('[data-group]') : formElement;
146
- let selector = arrayElement.dataset.activeif;
147
- let value = arrayElement.dataset.equals;
148
- let testElement = group.querySelector(`select[data-id="${selector}"],input[data-id="${selector}"]`);
149
-
150
- if(testElement.value == value)
151
- arrayElement.classList.remove('d-none');
152
- else
153
- arrayElement.classList.add('d-none');
154
- });
155
-
156
- }, false);
157
- }
158
-
1
+ // Create a link between two input/selects with one acting as setting a minimum value and the second a maximum
2
+ // The link between the two will prevent the max input field form setting a lower value than the min and vice versa
3
+ function inputRange(inputWrapper){
4
+
5
+ inputWrapper.addEventListener('change', function(e){
6
+
7
+ var min = parseInt(inputWrapper.querySelector('[data-min] select,[data-min] input').value);
8
+ var max = parseInt(inputWrapper.querySelector('[data-max] select,[data-max] input').value);
9
+
10
+ // Set attributes for input fields
11
+ Array.from(inputWrapper.querySelectorAll('[data-min] input')).forEach((input, index) => {
12
+
13
+ input.setAttribute('max',max);
14
+ });
15
+
16
+ Array.from(inputWrapper.querySelectorAll('[data-max] input')).forEach((input, index) => {
17
+
18
+ input.setAttribute('min',min);
19
+ });
20
+
21
+ // Hide select options if they are higher or lower than the min and max values
22
+ Array.from(inputWrapper.querySelectorAll('[data-min] select option')).forEach((option, index) => {
23
+
24
+ if(parseInt(option.getAttribute('value')) > max)
25
+ option.classList.add('d-none');
26
+ else
27
+ option.classList.remove('d-none');
28
+ });
29
+
30
+ Array.from(inputWrapper.querySelectorAll('[data-max] select option')).forEach((option, index) => {
31
+
32
+ if(parseInt(option.getAttribute('value')) < min)
33
+ option.classList.add('d-none');
34
+ else
35
+ option.classList.remove('d-none');
36
+ });
37
+
38
+ }, false);
39
+ }
40
+
41
+ function inputRedirect(inputWrapper){
42
+
43
+ inputWrapper.addEventListener('change', function(e){
44
+
45
+ const url = inputWrapper.getAttribute('data-redirect');
46
+ const desiredValue = inputWrapper.getAttribute('data-value-if');
47
+
48
+ if(inputWrapper.value == desiredValue)
49
+ document.location.href = url;
50
+
51
+ }, false);
52
+ }
53
+
54
+ //
55
+ function multipleFileUploads(wrapper){
56
+
57
+ const fileTenplate = wrapper.querySelector('.row');
58
+ const clone = fileTenplate.cloneNode(true);
59
+ const addButton = wrapper.querySelector('[data-add]');
60
+
61
+ wrapper.addEventListener('click', function(e){
62
+ for (var target = e.target; target && target != this; target = target.parentNode) {
63
+ if (target.matches('[data-add]')) { // Add a new row upload file input fields
64
+
65
+ const tempClone = clone.cloneNode(true);
66
+ wrapper.insertBefore(tempClone,target);
67
+
68
+ if(addButton.matches('[data-maxfiles]') && Array.from(wrapper.querySelectorAll(':scope > .row')).length >= addButton.dataset.maxfiles)
69
+ addButton.setAttribute('disabled','disabled');
70
+
71
+ break;
72
+ }
73
+ if (target.matches('[data-delete]')) { // Delete the current row
74
+
75
+ let row = target.closest('.row');
76
+ row.remove();
77
+
78
+ if(addButton.matches('[data-maxfiles]') && Array.from(wrapper.querySelectorAll(':scope > .row')).length < addButton.dataset.maxfiles)
79
+ addButton.removeAttribute('disabled');
80
+
81
+ break;
82
+ }
83
+ }
84
+
85
+ }, false);
86
+ }
87
+
88
+ // Acts as an overall initialise function to trigger other functions.
89
+ function form(formElement) {
90
+
91
+ // Check for input range groups
92
+ Array.from(formElement.querySelectorAll('[data-input-range]')).forEach((arrayElement, index) => {
93
+ inputRange(arrayElement);
94
+ });
95
+
96
+ Array.from(formElement.querySelectorAll('[data-redirect][data-value-if]')).forEach((arrayElement, index) => {
97
+ inputRedirect(arrayElement);
98
+ });
99
+
100
+ Array.from(formElement.querySelectorAll('.multiple-file-uploads')).forEach((arrayElement, index) => {
101
+ multipleFileUploads(arrayElement);
102
+ });
103
+
104
+
105
+ // Check the file size of a file when uploaded in case it exceeds the max file size set
106
+ formElement.addEventListener('change', function(e){
107
+ for (var target = e.target; target && target != this; target = target.parentNode) {
108
+ if (target.matches('[type="file"][data-filesize]') && target.files && target.files[0]) {
109
+
110
+ const maxAllowedSize = target.dataset.filesize;
111
+ if (target.files[0].size > maxAllowedSize) {
112
+
113
+ target.value = '';
114
+ alert('File too large');
115
+ }
116
+ break;
117
+ }
118
+ }
119
+ }, false);
120
+
121
+
122
+ // When a form is updated we may want to update some of the existing input fields; setting active fields when some data is selected.
123
+ formElement.addEventListener('change', function(e){
124
+
125
+ // Remove disabled attribute when a pre-selected input field equals a certain value
126
+ Array.from(formElement.querySelectorAll('select[data-activeif][data-equals],input[data-activeif][data-equals]')).forEach((arrayElement, index) => {
127
+
128
+ let group = arrayElement.closest('[data-group]') ? arrayElement.closest('[data-group]') : formElement;
129
+ let selector = arrayElement.dataset.activeif;
130
+ let value = arrayElement.dataset.equals;
131
+ let testElement = group.querySelector(`select[data-id="${selector}"],input[data-id="${selector}"]`);
132
+
133
+ if(testElement.value == value){
134
+ arrayElement.removeAttribute('disabled');
135
+ }
136
+ else {
137
+ arrayElement.setAttribute('disabled','disabled');
138
+ arrayElement.value = '';
139
+ }
140
+ });
141
+
142
+ // Show this input wrapper when a pre-selected input field equals a certain value
143
+ Array.from(formElement.querySelectorAll('.form-control__wrapper[data-displayif][data-equals]')).forEach((arrayElement, index) => {
144
+
145
+ let group = arrayElement.closest('[data-group]') ? arrayElement.closest('[data-group]') : formElement;
146
+ let selector = arrayElement.dataset.activeif;
147
+ let value = arrayElement.dataset.equals;
148
+ let testElement = group.querySelector(`select[data-id="${selector}"],input[data-id="${selector}"]`);
149
+
150
+ if(testElement.value == value)
151
+ arrayElement.classList.remove('d-none');
152
+ else
153
+ arrayElement.classList.add('d-none');
154
+ });
155
+
156
+ }, false);
157
+ }
158
+
159
159
  export default form
@@ -1,97 +1,119 @@
1
- /**
2
- * Global helper functions to help maintain and enhance framework elements.
3
- * @module Helpers
4
- */
5
-
6
- /**
7
- * Add global classes used by the CSS and later JavaScript.
8
- * @param {HTMLElement} body Dom element, this doesn't have to be the body but it is recommended.
9
- */
10
- export const addBodyClasses = (body) => {
11
-
12
- body.classList.add("js-enabled");
13
-
14
- if(navigator.userAgent.indexOf('MSIE')!==-1 || navigator.appVersion.indexOf('Trident/') > 0){
15
-
16
- body.classList.add("ie");
17
- }
18
-
19
- return null
20
- }
21
-
22
- /**
23
- * Check if an element contains certain elements that needs enhancing with the JavaScript helpers, it is recommended to do this on the page body after the dom is loaded. Elements that are loaded via ajax should also run this function.
24
- * @param {HTMLElement} element Dom element, this doesn't have to be the body but it is recommended.
25
- */
26
- export const checkElements = (element) => {
27
-
28
- // Tables
29
- Array.from(element.querySelectorAll('table')).forEach((table, index) => {
30
-
31
- tableStacked(table);
32
- tableWrap(table);
33
- });
34
- }
35
-
36
- /**
37
- * Wrap tables with a table wrapper div to help maintain its responsive design.
38
- * @param {HTMLElement} table Dom table element
39
- */
40
- export const tableWrap = (table) => {
41
-
42
- if(!table.parentNode.classList.contains('table__wrapper')){
43
-
44
- const tableHTML = table.outerHTML;
45
-
46
- table.outerHTML = `<div class="table__wrapper">${tableHTML}</div>`;
47
- }
48
- }
49
-
50
- /**
51
- * Creates data attributes to be used by the CSS for mobile views.
52
- * @param {HTMLElement} table Dom table element
53
- */
54
- export const tableStacked = (table) => {
55
-
56
- const colHeadings = Array.from(table.querySelectorAll('thead th'));
57
- const colRows = Array.from(table.querySelectorAll('tbody tr'));
58
-
59
- colRows.forEach((row, index) => {
60
-
61
- const cells = Array.from(row.querySelectorAll('th, td'));
62
-
63
- cells.forEach((cell, cellIndex) => {
64
-
65
- const heading = colHeadings[cellIndex];
66
- if(typeof heading != "undefined"){
67
-
68
- let tempDiv = document.createElement("div");
69
- tempDiv.innerHTML = heading.innerHTML;
70
- let headingText = tempDiv.textContent || tempDiv.innerText || "";
71
- cell.setAttribute('data-label',headingText);
72
- }
73
- });
74
- });
75
- }
76
-
77
-
78
- export const isNumeric = function(str) {
79
- if (typeof str != "string") return false // we only process strings!
80
- return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
81
- !isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail
82
- }
83
-
84
- export const zeroPad = (num, places) => String(num).padStart(places, '0')
85
-
86
- export const ucfirst = (str) => str.charAt(0).toUpperCase() + str.slice(1)
87
- export const ucwords = (str) => str.split(' ').map(s => ucfirst(s)).join(' ')
88
- export const unsnake = (str) => str.replace(/_/g, ' ')
89
- export const snake = (str) => str.replace(/ /g, '_')
90
- export const safeID = function(str){
91
-
92
- str = str.toLowerCase();
93
- str = snake(str);
94
- str = str.replace(/\W/g,'');
95
-
96
- return str;
97
- }
1
+ /**
2
+ * Global helper functions to help maintain and enhance framework elements.
3
+ * @module Helpers
4
+ */
5
+
6
+ /**
7
+ * Add global classes used by the CSS and later JavaScript.
8
+ * @param {HTMLElement} body Dom element, this doesn't have to be the body but it is recommended.
9
+ */
10
+ export const addBodyClasses = (body) => {
11
+
12
+ body.classList.add("js-enabled");
13
+
14
+ if(navigator.userAgent.indexOf('MSIE')!==-1 || navigator.appVersion.indexOf('Trident/') > 0){
15
+
16
+ body.classList.add("ie");
17
+ }
18
+
19
+ return null
20
+ }
21
+
22
+ /**
23
+ * Add global events.
24
+ * @param {HTMLElement} body Dom element, this doesn't have to be the body but it is recommended.
25
+ */
26
+ export const addGlobalEvents = (body) => {
27
+
28
+ window.addEventListener('hashchange', function() {
29
+
30
+ const hash = location.hash.replace('#','');
31
+ const label = document.querySelector(`label[for="${hash}"]`);
32
+ const detail = document.querySelector(`details[id="${hash}"]:not([open])`);
33
+
34
+ if(label)
35
+ label.click();
36
+ else if(detail)
37
+ detail.setAttribute('open','open');
38
+
39
+ }, false);
40
+
41
+ return null
42
+ }
43
+
44
+ /**
45
+ * Check if an element contains certain elements that needs enhancing with the JavaScript helpers, it is recommended to do this on the page body after the dom is loaded. Elements that are loaded via ajax should also run this function.
46
+ * @param {HTMLElement} element Dom element, this doesn't have to be the body but it is recommended.
47
+ */
48
+ export const checkElements = (element) => {
49
+
50
+ // Tables
51
+ Array.from(element.querySelectorAll('table')).forEach((table, index) => {
52
+
53
+ tableStacked(table);
54
+ tableWrap(table);
55
+ });
56
+ }
57
+
58
+ /**
59
+ * Wrap tables with a table wrapper div to help maintain its responsive design.
60
+ * @param {HTMLElement} table Dom table element
61
+ */
62
+ export const tableWrap = (table) => {
63
+
64
+ if(!table.parentNode.classList.contains('table__wrapper')){
65
+
66
+ const tableHTML = table.outerHTML;
67
+
68
+ table.outerHTML = `<div class="table__wrapper">${tableHTML}</div>`;
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Creates data attributes to be used by the CSS for mobile views.
74
+ * @param {HTMLElement} table Dom table element
75
+ */
76
+ export const tableStacked = (table) => {
77
+
78
+ const colHeadings = Array.from(table.querySelectorAll('thead th'));
79
+ const colRows = Array.from(table.querySelectorAll('tbody tr'));
80
+
81
+ colRows.forEach((row, index) => {
82
+
83
+ const cells = Array.from(row.querySelectorAll('th, td'));
84
+
85
+ cells.forEach((cell, cellIndex) => {
86
+
87
+ const heading = colHeadings[cellIndex];
88
+ if(typeof heading != "undefined"){
89
+
90
+ let tempDiv = document.createElement("div");
91
+ tempDiv.innerHTML = heading.innerHTML;
92
+ let headingText = tempDiv.textContent || tempDiv.innerText || "";
93
+ cell.setAttribute('data-label',headingText);
94
+ }
95
+ });
96
+ });
97
+ }
98
+
99
+
100
+ export const isNumeric = function(str) {
101
+ if (typeof str != "string") return false // we only process strings!
102
+ return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
103
+ !isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail
104
+ }
105
+
106
+ export const zeroPad = (num, places) => String(num).padStart(places, '0')
107
+
108
+ export const ucfirst = (str) => str.charAt(0).toUpperCase() + str.slice(1)
109
+ export const ucwords = (str) => str.split(' ').map(s => ucfirst(s)).join(' ')
110
+ export const unsnake = (str) => str.replace(/_/g, ' ')
111
+ export const snake = (str) => str.replace(/ /g, '_')
112
+ export const safeID = function(str){
113
+
114
+ str = str.toLowerCase();
115
+ str = snake(str);
116
+ str = str.replace(/\W/g,'');
117
+
118
+ return str;
119
+ }