@iamproperty/components 3.2.0 → 3.4.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.
Files changed (92) hide show
  1. package/assets/css/core.min.css.map +1 -1
  2. package/assets/css/style.min.css.map +1 -1
  3. package/assets/js/main.js +9 -9
  4. package/assets/js/modules/accordion.js +1 -0
  5. package/assets/js/modules/alert.js +37 -53
  6. package/assets/js/modules/carousel.js +74 -100
  7. package/assets/js/modules/chart.js +142 -209
  8. package/assets/js/modules/drawer.js +9 -15
  9. package/assets/js/modules/file-upload.js +30 -45
  10. package/assets/js/modules/form.js +111 -157
  11. package/assets/js/modules/helpers.js +64 -93
  12. package/assets/js/modules/modal.js +67 -88
  13. package/assets/js/modules/nav.js +17 -27
  14. package/assets/js/modules/orderablelist.js +84 -115
  15. package/assets/js/modules/table.js +387 -521
  16. package/assets/js/modules/testimonial.js +61 -80
  17. package/assets/js/modules/youtubevideo.js +104 -135
  18. package/assets/js/scripts.bundle.js +870 -936
  19. package/assets/js/scripts.bundle.js.map +1 -1
  20. package/assets/js/scripts.bundle.min.js +3 -3
  21. package/assets/js/scripts.bundle.min.js.map +1 -1
  22. package/assets/sass/_corefiles.scss +9 -9
  23. package/assets/sass/_forms.scss +1 -1
  24. package/assets/sass/_tests/{sass.spec.js → colours.spec.js} +2 -2
  25. package/assets/sass/_tests/func.spec.js +9 -0
  26. package/assets/sass/_tests/mixins.spec.js +9 -0
  27. package/assets/sass/_tests/typography.spec.js +9 -0
  28. package/assets/ts/main.ts +9 -9
  29. package/assets/ts/modules/accordion.ts +1 -0
  30. package/assets/ts/modules/alert.ts +58 -0
  31. package/assets/ts/modules/carousel.ts +103 -0
  32. package/assets/ts/modules/chart.ts +219 -0
  33. package/assets/ts/modules/drawer.ts +17 -0
  34. package/assets/ts/modules/file-upload.ts +49 -0
  35. package/assets/ts/modules/form.ts +169 -0
  36. package/assets/ts/modules/helpers.ts +120 -0
  37. package/assets/ts/modules/modal.ts +91 -0
  38. package/assets/ts/modules/nav.ts +29 -0
  39. package/assets/ts/modules/orderablelist.ts +123 -0
  40. package/assets/ts/modules/table.ts +586 -0
  41. package/assets/ts/modules/testimonial.ts +84 -0
  42. package/assets/ts/modules/youtubevideo.ts +146 -0
  43. package/dist/components.es.js +405 -421
  44. package/dist/components.umd.js +8 -8
  45. package/package.json +48 -35
  46. package/src/components/Accordion/Accordion.vue +1 -1
  47. package/src/components/Alert/Alert.vue +1 -1
  48. package/src/{elements → components}/Card/Card.vue +1 -1
  49. package/src/components/CardDeck/CardDeck.spec.js +1 -1
  50. package/src/components/CardDeck/CardDeck.vue +1 -1
  51. package/src/components/Carousel/Carousel.vue +2 -2
  52. package/src/components/Chart/Chart.vue +2 -2
  53. package/src/components/Drawer/Drawer.vue +1 -1
  54. package/src/{elements → components}/FileUploads/FileUploads.vue +1 -1
  55. package/src/components/Modal/Modal.vue +1 -1
  56. package/src/components/Nav/Nav.vue +2 -2
  57. package/src/components/NoteFeed/NoteFeed.vue +2 -2
  58. package/src/components/PropertySearchbar/PropertySearchbar.vue +1 -1
  59. package/src/{elements → components}/Table/Table.vue +1 -1
  60. package/src/components/Testimonial/Testimonial.vue +1 -1
  61. package/src/foundations/YoutubeVideo/YoutubeVideo.vue +1 -1
  62. package/src/index.js +4 -4
  63. package/assets/.DS_Store +0 -0
  64. package/assets/css/email.min.css +0 -1
  65. package/assets/css/email.min.css.map +0 -1
  66. package/assets/css/error.min.css +0 -1
  67. package/assets/css/error.min.css.map +0 -1
  68. package/assets/ts/main.js +0 -57
  69. package/assets/ts/main.js.map +0 -1
  70. package/assets/ts/modules/accordion.js +0 -33
  71. package/assets/ts/modules/accordion.js.map +0 -1
  72. package/src/.DS_Store +0 -0
  73. package/src/components/Accordion/Accordion.screenshot.vue +0 -57
  74. package/src/components/Accordion/__screenshots__/win32/laptop/Accordion.png +0 -0
  75. package/src/components/Accordion/__screenshots__/win32/mobile/Accordion.png +0 -0
  76. package/src/components/Accordion/__screenshots__/win32/tablet/Accordion.png +0 -0
  77. /package/assets/sass/{elements → components}/buttons.scss +0 -0
  78. /package/assets/sass/{elements → components}/card.scss +0 -0
  79. /package/assets/sass/{elements → components}/container.scss +0 -0
  80. /package/assets/sass/{elements → components}/forms.scss +0 -0
  81. /package/assets/sass/{elements → components}/links.scss +0 -0
  82. /package/assets/sass/{elements → components}/lists.scss +0 -0
  83. /package/assets/sass/{elements → components}/panel.scss +0 -0
  84. /package/assets/sass/{elements → components}/tables.scss +0 -0
  85. /package/assets/sass/{elements → components}/tooltips.scss +0 -0
  86. /package/assets/sass/{elements → foundations}/type.scss +0 -0
  87. /package/src/{elements → components}/Card/README.md +0 -0
  88. /package/src/{elements → components}/FileUploads/README.md +0 -0
  89. /package/src/{elements → components}/Input/Input.vue +0 -0
  90. /package/src/{elements → components}/Input/README.md +0 -0
  91. /package/src/{elements → components}/Table/README.md +0 -0
  92. /package/src/{elements → components}/Table/Table.spec.js +0 -0
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @jest-environment jest-environment-node-single-context
3
+ */
4
+
5
+ const path = require('path');
6
+ const sassTrue = require('sass-true');
7
+
8
+ const sassFile = path.join(__dirname, 'func.spec.scss');
9
+ sassTrue.runSass({ describe, it }, sassFile);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @jest-environment jest-environment-node-single-context
3
+ */
4
+
5
+ const path = require('path');
6
+ const sassTrue = require('sass-true');
7
+
8
+ const sassFile = path.join(__dirname, 'mixins.spec.scss');
9
+ sassTrue.runSass({ describe, it }, sassFile);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @jest-environment jest-environment-node-single-context
3
+ */
4
+
5
+ const path = require('path');
6
+ const sassTrue = require('sass-true');
7
+
8
+ const sassFile = path.join(__dirname, 'typography.spec.scss');
9
+ sassTrue.runSass({ describe, it }, sassFile);
package/assets/ts/main.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  // @ts-nocheck
2
2
  // Modules
3
- import * as helpers from '../js/modules/helpers'
4
- import nav from '../js/modules/nav'
5
- import table from '../js/modules/table'
6
- import accordion from '../js/modules/accordion'
7
- import testimonial from '../js/modules/testimonial'
8
- import carousel from '../js/modules/carousel'
9
- import form from '../js/modules/form'
10
- import youtubeVideo from '../js/modules/youtubevideo'
11
- import modal from '../js/modules/modal'
3
+ import * as helpers from './modules/helpers'
4
+ import nav from './modules/nav'
5
+ import table from './modules/table'
6
+ import accordion from './modules/accordion'
7
+ import testimonial from './modules/testimonial'
8
+ import carousel from './modules/carousel'
9
+ import form from './modules/form'
10
+ import youtubeVideo from './modules/youtubevideo'
11
+ import modal from './modules/modal'
12
12
 
13
13
  // Attach classes to dom elements
14
14
  document.addEventListener("DOMContentLoaded", function() {
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  function accordion(accordionElement: Element) {
2
3
 
3
4
  // Fetch all the details element.
@@ -0,0 +1,58 @@
1
+ // @ts-nocheck
2
+ function alert(element) {
3
+
4
+ // Create a dissmissable button
5
+ element.addEventListener('click', function(e){
6
+
7
+ for (var target = e.target; target && target != this; target = target.parentNode) {
8
+ if (target.matches('.btn-close')) {
9
+
10
+ e.preventDefault();
11
+
12
+ element.classList.remove('show');
13
+ setTimeout(function () {
14
+ element.remove();
15
+ }, 300); // Execute something() 1 second later.
16
+
17
+ break;
18
+ }
19
+ }
20
+ }, false);
21
+
22
+ // Self disappearing alert
23
+ if(element.hasAttribute('data-timeout')){
24
+
25
+ let timeOut = element.getAttribute('data-timeout');
26
+
27
+ setTimeout(function () {
28
+ element.classList.remove('show');
29
+ setTimeout(function () {
30
+ element.remove();
31
+ }, 300); // Execute something() 1 second later.
32
+ }, timeOut); // Execute something() 1 second later.
33
+ }
34
+
35
+
36
+
37
+ // Create an alert holder thats fixed to the bottom of the page, alerts with the class of alert--fix are then moved to this area. Creating a fixed but scrollable area that alerts can be stacked up on.
38
+ if(!document.querySelector('.alert__holder')){
39
+ var bodyElement = document.getElementsByTagName("BODY")[0];
40
+
41
+ let newDiv = document.createElement("div");
42
+ newDiv.classList.add('alert__holder');
43
+
44
+ if(document.querySelector('main'))
45
+ document.querySelector('main').appendChild(newDiv);
46
+ else
47
+ document.body.appendChild(newDiv);
48
+ }
49
+
50
+ let alertHolder = document.querySelector('.alert__holder');
51
+
52
+ if(element.classList.contains('alert--fixed') && !element.parentNode.classList.contains('alert__wrapper')){
53
+
54
+ alertHolder.appendChild(element);
55
+ }
56
+ }
57
+
58
+ export default alert
@@ -0,0 +1,103 @@
1
+ // @ts-nocheck
2
+ function carousel(carouselElement) {
3
+
4
+ var scrollTimeout;
5
+
6
+ let carouselInner = carouselElement.querySelector('.carousel__inner');
7
+ let itemCount = carouselElement.querySelectorAll('.carousel__item').length;
8
+ let cols = carouselElement.getAttribute('data-cols');
9
+ let smCols = carouselElement.getAttribute('data-sm-cols');
10
+ let mdCols = carouselElement.getAttribute('data-md-cols');
11
+
12
+ carouselElement.querySelector('.carousel__controls a').classList.add('active');
13
+
14
+ // On scroll we need to make sure the buttons get corrected and the next testimonial is shown
15
+ carouselInner.addEventListener('scroll', function(e){
16
+ clearTimeout(scrollTimeout);
17
+ scrollTimeout = setTimeout(function(){
18
+
19
+ let scrollArea = carouselInner.clientWidth;
20
+ let scrollWidth = carouselInner.scrollWidth;
21
+ let scrollLeft = carouselInner.scrollLeft;
22
+ let targetSlide = Math.round((scrollLeft / scrollWidth) * itemCount) + 1;
23
+ let lastItemOffset = carouselElement.querySelector('.carousel__item:last-child').offsetLeft;
24
+
25
+ Array.from(carouselElement.querySelectorAll('.carousel__controls a')).forEach((link, index) => {
26
+ link.classList.remove('active');
27
+ });
28
+
29
+ carouselElement.querySelector('.control-'+targetSlide).classList.add('active');
30
+
31
+ // Disable the previous button
32
+ if(targetSlide == 1)
33
+ carouselElement.querySelector('.btn-prev').setAttribute('disabled','disabled');
34
+ else
35
+ carouselElement.querySelector('.btn-prev').removeAttribute('disabled');
36
+
37
+ // Disable the next button if the last item is in view
38
+ if(carouselInner.scrollLeft + scrollArea > lastItemOffset)
39
+ carouselElement.querySelector('.btn-next').setAttribute('disabled','disabled');
40
+ else
41
+ carouselElement.querySelector('.btn-next').removeAttribute('disabled');
42
+
43
+ }, 100);
44
+
45
+ }, false);
46
+
47
+ // when the buttons are used we need to make sure the carousel scrolls to the correct place
48
+ carouselElement.addEventListener('click', function(e){
49
+
50
+ for (var target = e.target; target && target != this; target = target.parentNode) {
51
+ if (target.matches('.carousel__controls a')) {
52
+
53
+ e.preventDefault();
54
+
55
+ Array.from(carouselElement.querySelectorAll('.carousel__controls a')).forEach((link, index) => {
56
+ link.classList.remove('active');
57
+ });
58
+ target.classList.add('active');
59
+
60
+ const el = document.querySelector(target.getAttribute('href'));
61
+
62
+ carouselInner.scroll({
63
+ top: 0,
64
+ left: el.offsetLeft,
65
+ behavior: 'smooth'
66
+ });
67
+
68
+ break;
69
+ }
70
+ }
71
+ }, false);
72
+
73
+ carouselElement.addEventListener('click', function(e){
74
+
75
+ for (var target = e.target; target && target != this; target = target.parentNode) {
76
+ if (target.matches('.btn-next, .btn-prev')) {
77
+
78
+ e.preventDefault();
79
+ let scrollTo = target.classList.contains('btn-prev') ? carouselInner.scrollLeft - carouselInner.clientWidth : carouselInner.scrollLeft + carouselInner.clientWidth;
80
+
81
+ carouselInner.scroll({
82
+ top: 0,
83
+ left: scrollTo,
84
+ behavior: 'smooth'
85
+ });
86
+ break;
87
+ }
88
+ }
89
+ }, false);
90
+
91
+
92
+ // Add responsive hide button classes
93
+ if(itemCount == 1)
94
+ carouselElement.classList.add('hide-btns');
95
+
96
+ if(smCols >= itemCount)
97
+ carouselElement.classList.add('hide-sm-btns');
98
+
99
+ if(mdCols >= itemCount)
100
+ carouselElement.classList.add('hide-md-btns');
101
+ }
102
+
103
+ export default carousel
@@ -0,0 +1,219 @@
1
+ // @ts-nocheck
2
+ import { ucfirst, unsnake } from './helpers'
3
+
4
+ function chart(chartElement,min,max,type) {
5
+
6
+ let chartKey = chartElement.querySelector('.chart__key');
7
+ let chartYaxis = chartElement.querySelector('.chart__yaxis');
8
+ let chartGuidelines = chartElement.querySelector('.chart__guidelines');
9
+
10
+ // Chart key
11
+ if(chartKey && chartKey.childElementCount == 0){
12
+ createChartKey(chartElement);
13
+ }
14
+
15
+ // Y Axis and Guidelines
16
+ if(chartYaxis && chartYaxis.childElementCount == 0){
17
+ createChartYaxis(chartElement);
18
+ }
19
+ if(chartGuidelines && chartGuidelines.childElementCount == 0){
20
+ createChartGuidelines(chartElement);
21
+ }
22
+
23
+ // Create lines for line graph
24
+ if(type == "line")
25
+ createLines(chartElement,min,max);
26
+
27
+ // Create pies
28
+ if(type == "pie")
29
+ createPies(chartElement);
30
+
31
+ // Add css vars to cells
32
+ Array.from(chartElement.querySelectorAll('tbody tr')).forEach((tr, index) => {
33
+
34
+ let group = tr.querySelector('td:first-child, th:first-child') ? tr.querySelector('td:first-child, th:first-child').innerHTML : '';
35
+
36
+ Array.from(tr.querySelectorAll('td[data-numeric]:not([data-numeric="0"]):not(:first-child)')).forEach((td, index) => {
37
+
38
+ const value = Number.parseFloat(td.getAttribute('data-numeric'));
39
+ let percent = ((value - min)/(max)) * 100;
40
+ const content = td.innerHTML;
41
+ const label = td.getAttribute('data-label');
42
+ let bottom = 0;
43
+
44
+ // If the value is negative the position below the 0 line
45
+ if(min < 0){
46
+ bottom = Math.abs((min)/(max)*100);
47
+ if(value < 0){
48
+ bottom = bottom - percent;
49
+ }
50
+ }
51
+ td.setAttribute("style",`--bottom:${bottom}%;--percent:${percent}%;`);
52
+
53
+
54
+ td.innerHTML = `<span data-group="${group}" data-label="${label}">${content}</span>`;
55
+ });
56
+ });
57
+ }
58
+
59
+ export const createChartKey = function(chartElement){
60
+
61
+ let chartKey = chartElement.querySelector('.chart__key');
62
+
63
+ Array.from(chartElement.querySelectorAll('thead th')).forEach((arrayElement, index) => {
64
+
65
+ chartKey.innerHTML += `<div class="key">${arrayElement.innerText}</div>`;
66
+ });
67
+ }
68
+
69
+ export const createChartGuidelines = function(chartElement){
70
+
71
+ let chartGuidelines = chartElement.querySelector('.chart__guidelines');
72
+ const max = chartElement.getAttribute('data-max');
73
+ const min = chartElement.getAttribute('data-min');
74
+
75
+ chartGuidelines.innerHTML += `<div style="--value: 0;--percent:0%;" class="axis__point"><span>0</span></div>`;
76
+ chartGuidelines.innerHTML += `<div style="--value: ${max};--percent:100%;" class="axis__point"><span>${max}</span></div>`;
77
+ }
78
+
79
+ export const createChartYaxis = function(chartElement){
80
+
81
+ let chartYaxis = chartElement.querySelector('.chart__yaxis');
82
+ const max = chartElement.getAttribute('data-max');
83
+ const min = chartElement.getAttribute('data-min');
84
+
85
+ chartYaxis.innerHTML += `<div style="--value: 0;--percent:0%;" class="axis__point"><span>0</span></div>`;
86
+ chartYaxis.innerHTML += `<div style="--value: ${max};--percent:100%;" class="axis__point"><span>${max}</span></div>`;
87
+ }
88
+
89
+ function getCoordinatesForPercent(percent) {
90
+ const x = Math.cos(2 * Math.PI * percent);
91
+ const y = Math.sin(2 * Math.PI * percent);
92
+ return [x*100, y*100];
93
+ }
94
+
95
+ export const createPies = function(chartElement){
96
+
97
+ let returnString = '';
98
+ let pieWrapper = chartElement.querySelector('.pies');
99
+
100
+ Array.from(chartElement.querySelectorAll('tbody tr')).forEach((item, index) => {
101
+
102
+ let paths = '';
103
+ let tooltips = '';
104
+
105
+ let cumulativePercent = 0;
106
+
107
+ let total = 0;
108
+
109
+ let titleKey = item.querySelectorAll('td')[0]
110
+ let title = titleKey.innerHTML;
111
+
112
+ Array.from(item.querySelectorAll('td')).forEach((cell, subindex) => {
113
+
114
+ if(subindex != 0){
115
+
116
+ let value = cell.getAttribute('data-numeric');
117
+
118
+ value = value.replace('£','');
119
+ value = value.replace('%','');
120
+ value = Number.parseInt(value);
121
+
122
+ total += value;
123
+ }
124
+ });
125
+
126
+ Array.from(item.querySelectorAll('td')).forEach((cell, subindex) => {
127
+
128
+ if(subindex != 0){
129
+
130
+ let value = cell.getAttribute('data-numeric');
131
+
132
+ value = value.replace('£','');
133
+ value = value.replace('%','');
134
+ value = Number.parseInt(value);
135
+
136
+ let percent = value/total;
137
+
138
+ //lines[subindex-1] += `${command} ${spacer * index} ${100-percent} `;
139
+ const [startX, startY] = getCoordinatesForPercent(cumulativePercent);
140
+
141
+ // each slice starts where the last slice ended, so keep a cumulative percent
142
+ cumulativePercent += percent;
143
+
144
+ const [endX, endY] = getCoordinatesForPercent(cumulativePercent);
145
+
146
+ // if the slice is more than 50%, take the large arc (the long way around)
147
+ const largeArcFlag = percent > .5 ? 1 : 0;
148
+
149
+ // create an array and join it just for code readability
150
+ const pathData = [
151
+ `M ${startX} ${startY}`, // Move
152
+ `A 100 100 0 ${largeArcFlag} 1 ${endX} ${endY}`, // Arc
153
+ `L 0 0`, // Line
154
+ ].join(' ');
155
+
156
+ paths += `<path d="${pathData}"></path>`;
157
+ tooltips += `<foreignObject x="-70" y="-70" width="140" height="140" style="transform: rotate(90deg)"><div><span class="h5 mb-0"><span class="total d-block">${ucfirst(unsnake(title))}</span> ${ucfirst(unsnake(cell.getAttribute('data-label')))}<br/> ${cell.innerHTML}</span></div></foreignObject>`;
158
+ }
159
+ });
160
+
161
+ returnString += `<div class="pie"><svg viewBox="-105 -105 210 210" style="transform: rotate(-90deg)" preserveAspectRatio="none">${paths}<foreignObject x="-70" y="-70" width="140" height="140" style="transform: rotate(90deg)"><div><span class="h5 mb-0">${title}</span></div></foreignObject>${tooltips}</svg></div>`
162
+ });
163
+
164
+ pieWrapper.innerHTML = returnString;
165
+ }
166
+
167
+ export const createLines = function(chartElement,min,max){
168
+
169
+ let returnString = '';
170
+ let linesWrapper = chartElement.querySelector('.lines');
171
+
172
+ let items = Array.from(chartElement.querySelectorAll('tbody tr'));
173
+
174
+ let lines = Array();
175
+ let spacer = 200/(items.length - 1);
176
+
177
+ // Creates the lines array from the fields array
178
+ Array.from(chartElement.querySelectorAll('thead th')).forEach((field, index) => {
179
+
180
+ if(index != 0){
181
+
182
+ lines[index-1] = '';
183
+ }
184
+ });
185
+
186
+ // populate the lines array from the items array
187
+ Array.from(chartElement.querySelectorAll('tbody tr')).forEach((item, index) => {
188
+
189
+ Array.from(item.querySelectorAll('td')).forEach((cell, subindex) => {
190
+
191
+ if(subindex != 0){
192
+
193
+ let value = cell.getAttribute('data-numeric');
194
+
195
+ value = value.replace('£','');
196
+ value = value.replace('%','');
197
+ value = Number.parseFloat(value) - min;
198
+
199
+ const percent = (value/max) * 100;
200
+
201
+ let command = index == 0 ? 'M' : 'L';
202
+
203
+ lines[subindex-1] += `${command} ${spacer * index} ${100-percent} `;
204
+ }
205
+ });
206
+ });
207
+
208
+ lines.forEach((line, index) => {
209
+
210
+ returnString += `
211
+ <svg viewBox="0 0 200 100" class="line" preserveAspectRatio="none">
212
+ <path fill="none" d="${line}"></path>
213
+ </svg>`
214
+ });
215
+
216
+ linesWrapper.innerHTML = returnString;
217
+ }
218
+
219
+ export default chart
@@ -0,0 +1,17 @@
1
+ // @ts-nocheck
2
+ const drawer = (element) => {
3
+
4
+ const observer = new IntersectionObserver(
5
+
6
+ function([e]){
7
+ e.target.classList.toggle("in-view", e.intersectionRatio > 0)
8
+ document.getElementById('showDrawer').checked = false
9
+ },
10
+ { threshold: [1] }
11
+ );
12
+
13
+ const el = document.getElementById('drawer-end')
14
+ observer.observe(el);
15
+ }
16
+
17
+ export default drawer
@@ -0,0 +1,49 @@
1
+ // @ts-nocheck
2
+ function fileupload(form, callback) {
3
+
4
+ const input = form.querySelector('[type="file"]');
5
+ const label = form.querySelector(`[for="${input.getAttribute('id')}"]`);
6
+ const add = form.querySelector('.file-upload__add');
7
+
8
+ form.querySelector('button').remove()
9
+
10
+ input.addEventListener("change", function( e ) {
11
+ // prevent default to allow drop
12
+
13
+ let url = form.getAttribute('action');
14
+ let formData = new FormData(form);
15
+
16
+ input.setAttribute('disabled', 'disabled');
17
+
18
+ fetch(url, {
19
+ method: 'POST',
20
+ body: formData
21
+ })
22
+ .then(() => {
23
+
24
+ form.classList.add('file-uploaded')
25
+ label.innerHTML = 'File uploaded';
26
+
27
+ if(typeof callback == "function")
28
+ callback();
29
+ })
30
+
31
+
32
+ }, false);
33
+
34
+
35
+ form.addEventListener("submit", function( e ) {
36
+ // prevent default to allow drop
37
+ e.preventDefault();
38
+ }, false);
39
+
40
+ add.addEventListener("click", function( e ) {
41
+
42
+ form.classList.remove('file-uploaded')
43
+ label.innerHTML = 'Select a file to upload';
44
+ input.removeAttribute('disabled');
45
+
46
+ }, false);
47
+ }
48
+
49
+ export default fileupload;
@@ -0,0 +1,169 @@
1
+ // @ts-nocheck
2
+ // Create a link between two input/selects with one acting as setting a minimum value and the second a maximum
3
+ // The link between the two will prevent the max input field form setting a lower value than the min and vice versa
4
+ function inputRange(inputWrapper){
5
+
6
+ inputWrapper.addEventListener('change', function(e){
7
+
8
+ var min = parseInt(inputWrapper.querySelector('[data-min] select,[data-min] input').value);
9
+ var max = parseInt(inputWrapper.querySelector('[data-max] select,[data-max] input').value);
10
+
11
+ // Set attributes for input fields
12
+ Array.from(inputWrapper.querySelectorAll('[data-min] input')).forEach((input, index) => {
13
+
14
+ input.setAttribute('max',max);
15
+ });
16
+
17
+ Array.from(inputWrapper.querySelectorAll('[data-max] input')).forEach((input, index) => {
18
+
19
+ input.setAttribute('min',min);
20
+ });
21
+
22
+ // Hide select options if they are higher or lower than the min and max values
23
+ Array.from(inputWrapper.querySelectorAll('[data-min] select option')).forEach((option, index) => {
24
+
25
+ if(parseInt(option.getAttribute('value')) > max)
26
+ option.classList.add('d-none');
27
+ else
28
+ option.classList.remove('d-none');
29
+ });
30
+
31
+ Array.from(inputWrapper.querySelectorAll('[data-max] select option')).forEach((option, index) => {
32
+
33
+ if(parseInt(option.getAttribute('value')) < min)
34
+ option.classList.add('d-none');
35
+ else
36
+ option.classList.remove('d-none');
37
+ });
38
+
39
+ }, false);
40
+ }
41
+
42
+ function inputRedirect(inputWrapper){
43
+
44
+
45
+ inputWrapper.addEventListener('change', function(e){
46
+
47
+ if(inputWrapper.matches('[data-value-if]')) {
48
+
49
+ const url = inputWrapper.getAttribute('data-redirect');
50
+ const desiredValue = inputWrapper.getAttribute('data-value-if');
51
+
52
+ if(inputWrapper.value == desiredValue)
53
+ document.location.href = url;
54
+ }
55
+ else {
56
+
57
+ if(typeof inputWrapper.value != "undefined")
58
+ document.location.href = inputWrapper.value;
59
+ }
60
+
61
+ }, false);
62
+ }
63
+
64
+ //
65
+ function multipleFileUploads(wrapper){
66
+
67
+ const fileTenplate = wrapper.querySelector('.row');
68
+ const clone = fileTenplate.cloneNode(true);
69
+ const addButton = wrapper.querySelector('[data-add]');
70
+
71
+ wrapper.addEventListener('click', function(e){
72
+ for (var target = e.target; target && target != this; target = target.parentNode) {
73
+ if (target.matches('[data-add]')) { // Add a new row upload file input fields
74
+
75
+ const tempClone = clone.cloneNode(true);
76
+ wrapper.insertBefore(tempClone,target);
77
+
78
+ if(addButton.matches('[data-maxfiles]') && Array.from(wrapper.querySelectorAll(':scope > .row')).length >= addButton.dataset.maxfiles)
79
+ addButton.setAttribute('disabled','disabled');
80
+
81
+ break;
82
+ }
83
+ if (target.matches('[data-delete]')) { // Delete the current row
84
+
85
+ let row = target.closest('.row');
86
+ row.remove();
87
+
88
+ if(addButton.matches('[data-maxfiles]') && Array.from(wrapper.querySelectorAll(':scope > .row')).length < addButton.dataset.maxfiles)
89
+ addButton.removeAttribute('disabled');
90
+
91
+ break;
92
+ }
93
+ }
94
+
95
+ }, false);
96
+ }
97
+
98
+ // Acts as an overall initialise function to trigger other functions.
99
+ function form(formElement) {
100
+
101
+ // Check for input range groups
102
+ Array.from(formElement.querySelectorAll('[data-input-range]')).forEach((arrayElement, index) => {
103
+ inputRange(arrayElement);
104
+ });
105
+
106
+ Array.from(formElement.querySelectorAll('[data-redirect]')).forEach((arrayElement, index) => {
107
+ inputRedirect(arrayElement);
108
+ });
109
+
110
+ Array.from(formElement.querySelectorAll('.multiple-file-uploads')).forEach((arrayElement, index) => {
111
+ multipleFileUploads(arrayElement);
112
+ });
113
+
114
+
115
+ // Check the file size of a file when uploaded in case it exceeds the max file size set
116
+ formElement.addEventListener('change', function(e){
117
+ for (var target = e.target; target && target != this; target = target.parentNode) {
118
+ if (target.matches('[type="file"][data-filesize]') && target.files && target.files[0]) {
119
+
120
+ const maxAllowedSize = target.dataset.filesize;
121
+ if (target.files[0].size > maxAllowedSize) {
122
+
123
+ target.value = '';
124
+ alert('File too large');
125
+ }
126
+ break;
127
+ }
128
+ }
129
+ }, false);
130
+
131
+
132
+ // When a form is updated we may want to update some of the existing input fields; setting active fields when some data is selected.
133
+ formElement.addEventListener('change', function(e){
134
+
135
+ // Remove disabled attribute when a pre-selected input field equals a certain value
136
+ Array.from(formElement.querySelectorAll('select[data-activeif][data-equals],input[data-activeif][data-equals]')).forEach((arrayElement, index) => {
137
+
138
+ let group = arrayElement.closest('[data-group]') ? arrayElement.closest('[data-group]') : formElement;
139
+ let selector = arrayElement.dataset.activeif;
140
+ let value = arrayElement.dataset.equals;
141
+ let testElement = group.querySelector(`select[data-id="${selector}"],input[data-id="${selector}"]`);
142
+
143
+ if(testElement.value == value){
144
+ arrayElement.removeAttribute('disabled');
145
+ }
146
+ else {
147
+ arrayElement.setAttribute('disabled','disabled');
148
+ arrayElement.value = '';
149
+ }
150
+ });
151
+
152
+ // Show this input wrapper when a pre-selected input field equals a certain value
153
+ Array.from(formElement.querySelectorAll('.form-control__wrapper[data-displayif][data-equals]')).forEach((arrayElement, index) => {
154
+
155
+ let group = arrayElement.closest('[data-group]') ? arrayElement.closest('[data-group]') : formElement;
156
+ let selector = arrayElement.dataset.activeif;
157
+ let value = arrayElement.dataset.equals;
158
+ let testElement = group.querySelector(`select[data-id="${selector}"],input[data-id="${selector}"]`);
159
+
160
+ if(testElement.value == value)
161
+ arrayElement.classList.remove('d-none');
162
+ else
163
+ arrayElement.classList.add('d-none');
164
+ });
165
+
166
+ }, false);
167
+ }
168
+
169
+ export default form