@iamproperty/components 2.2.0 → 2.3.3

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 (38) hide show
  1. package/assets/.DS_Store +0 -0
  2. package/assets/css/core.min.css +1 -0
  3. package/assets/css/core.min.css.map +1 -0
  4. package/assets/css/style.min.css +1 -0
  5. package/assets/css/style.min.css.map +1 -0
  6. package/assets/js/main.js +5 -0
  7. package/assets/js/modules/modal.js +19 -1
  8. package/assets/js/modules/table.js +4 -0
  9. package/assets/js/modules/youtubevideo.js +145 -0
  10. package/assets/js/scripts.bundle.js +871 -0
  11. package/assets/js/scripts.bundle.js.map +1 -0
  12. package/assets/js/scripts.bundle.min.js +7 -0
  13. package/assets/js/scripts.bundle.min.js.map +1 -0
  14. package/assets/sass/_corefiles.scss +2 -2
  15. package/assets/sass/_functions/variables.scss +8 -1
  16. package/assets/sass/foundations/circles.scss +10 -0
  17. package/assets/sass/foundations/media.scss +47 -0
  18. package/assets/sass/foundations/reboot.scss +1 -1
  19. package/dist/components.common.js +539 -5736
  20. package/dist/components.common.js.map +1 -1
  21. package/dist/components.css.map +1 -1
  22. package/dist/components.umd.js +537 -5734
  23. package/dist/components.umd.js.map +1 -1
  24. package/dist/components.umd.min.js +1 -1
  25. package/dist/components.umd.min.js.map +1 -1
  26. package/package.json +26 -24
  27. package/src/components/Accordion/AccordionItem.vue +2 -2
  28. package/src/components/Tabs/Tabs.vue +12 -8
  29. package/src/elements/Table/README.md +7 -0
  30. package/src/elements/Table/Table.vue +2 -2
  31. package/src/foundations/YoutubeVideo/README.md +11 -0
  32. package/src/foundations/YoutubeVideo/YoutubeVideo.vue +24 -0
  33. package/src/index.js +1 -0
  34. package/assets/img/.DS_Store +0 -0
  35. package/assets/sass/.DS_Store +0 -0
  36. package/assets/sass/elements/media.scss +0 -3
  37. package/assets/svg/.DS_Store +0 -0
  38. package/assets/svg/flat/.DS_Store +0 -0
@@ -0,0 +1,871 @@
1
+ /*!
2
+ * Bootstrap v2.2.0
3
+ * Copyright 2011-2022 [object Object]
4
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5
+ */
6
+ (function (factory) {
7
+ typeof define === 'function' && define.amd ? define(factory) :
8
+ factory();
9
+ })((function () { 'use strict';
10
+
11
+ /**
12
+ * Global helper functions to help maintain and enhance framework elements.
13
+ * @module Helpers
14
+ */
15
+
16
+ /**
17
+ * Add global classes used by the CSS and later JavaScript.
18
+ * @param {HTMLElement} body Dom element, this doesn't have to be the body but it is recommended.
19
+ */
20
+ var addBodyClasses = body => {
21
+ body.classList.add("js-enabled");
22
+
23
+ if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0) {
24
+ body.classList.add("ie");
25
+ }
26
+
27
+ return null;
28
+ };
29
+ /**
30
+ * 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.
31
+ * @param {HTMLElement} element Dom element, this doesn't have to be the body but it is recommended.
32
+ */
33
+
34
+
35
+ var checkElements = element => {
36
+ // Tables
37
+ Array.from(element.querySelectorAll('table')).forEach((table, index) => {
38
+ tableStacked(table);
39
+ tableWrap(table);
40
+ });
41
+ };
42
+ /**
43
+ * Wrap tables with a table wrapper div to help maintain its responsive design.
44
+ * @param {HTMLElement} table Dom table element
45
+ */
46
+
47
+
48
+ var tableWrap = table => {
49
+ if (!table.parentNode.classList.contains('table__wrapper')) {
50
+ var tableHTML = table.outerHTML;
51
+ table.outerHTML = "<div class=\"table__wrapper\">".concat(tableHTML, "</div>");
52
+ }
53
+ };
54
+ /**
55
+ * Creates data attributes to be used by the CSS for mobile views.
56
+ * @param {HTMLElement} table Dom table element
57
+ */
58
+
59
+
60
+ var tableStacked = table => {
61
+ var colHeadings = Array.from(table.querySelectorAll('thead th'));
62
+ var colRows = Array.from(table.querySelectorAll('tbody tr'));
63
+ colRows.forEach((row, index) => {
64
+ var cells = Array.from(row.querySelectorAll('th, td'));
65
+ cells.forEach((cell, cellIndex) => {
66
+ var heading = colHeadings[cellIndex];
67
+
68
+ if (typeof heading != "undefined") {
69
+ var tempDiv = document.createElement("div");
70
+ tempDiv.innerHTML = heading.innerHTML;
71
+ var headingText = tempDiv.textContent || tempDiv.innerText || "";
72
+ cell.setAttribute('data-label', headingText);
73
+ }
74
+ });
75
+ });
76
+ };
77
+
78
+ var isNumeric = function isNumeric(str) {
79
+ if (typeof str != "string") return false; // we only process strings!
80
+
81
+ return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
82
+ !isNaN(parseFloat(str)); // ...and ensure strings of whitespace fail
83
+ };
84
+
85
+ var zeroPad = (num, places) => String(num).padStart(places, '0');
86
+
87
+ var navbar = element => {
88
+ Array.from(element.querySelectorAll('details')).forEach((detail, index) => {
89
+ detail.addEventListener('mouseenter', function (e) {
90
+ if (window.matchMedia('(min-width: 62em)').matches) detail.setAttribute('open', 'true');
91
+ }, false);
92
+ detail.addEventListener('mouseleave', function (e) {
93
+ if (window.matchMedia('(min-width: 62em)').matches) detail.removeAttribute('open');
94
+ }, false);
95
+ });
96
+ var observer = new IntersectionObserver(_ref => {
97
+ var [e] = _ref;
98
+ return e.target.classList.toggle("is-stuck", e.intersectionRatio < 1);
99
+ }, {
100
+ threshold: [1]
101
+ });
102
+ observer.observe(element);
103
+ };
104
+
105
+ function table(tableElement) {
106
+ if (typeof tableElement != "object") return false;
107
+ var thead = tableElement.querySelector('thead');
108
+ var tbody = tableElement.querySelector('tbody');
109
+ var storedData = tbody.cloneNode(true);
110
+ var sortedEvent = new Event('sorted');
111
+ var filteredEvent = new Event('filtered');
112
+ var randID = 'tabe_' + Math.random().toString(36).substr(2, 9); // Random to make sure IDs created are unique
113
+
114
+ var draggedRow;
115
+ tableElement.setAttribute('id', randID); // #region Sortable
116
+
117
+ var sortTable = function sortTable(sortBy, sort) {
118
+ // Create an array from the table rows, the index created is then used to sort the array
119
+ var tableArr = [];
120
+ Array.from(tbody.querySelectorAll('tr')).forEach((tableRow, index) => {
121
+ var rowIndex = tableRow.querySelector('td[data-label="' + sortBy + '"], th[data-label="' + sortBy + '"]').textContent;
122
+ if (isNumeric(rowIndex)) rowIndex = zeroPad(rowIndex, 10);
123
+ var dataRow = {
124
+ index: rowIndex,
125
+ row: tableRow
126
+ };
127
+ tableArr.push(dataRow);
128
+ }); // Sort array
129
+
130
+ tableArr.sort((a, b) => a.index > b.index ? 1 : -1); // Reverse if descending
131
+
132
+ if (sort == "descending") tableArr = tableArr.reverse(); // Create a string to return and populate the tbody
133
+
134
+ var strTbody = '';
135
+ tableArr.forEach((tableRow, index) => {
136
+ strTbody += tableRow.row.outerHTML;
137
+ });
138
+ tbody.innerHTML = strTbody; // Dispatch the sortable event
139
+
140
+ tableElement.dispatchEvent(sortedEvent);
141
+ }; // Declare event handlers
142
+
143
+
144
+ tableElement.addEventListener('click', function (e) {
145
+ for (var target = e.target; target && target != this; target = target.parentNode) {
146
+ if (target.matches('[data-sortable]')) {
147
+ // Get current sort order
148
+ var sort = target.getAttribute('aria-sort') == "ascending" ? "descending" : "ascending"; // unset sort attributes
149
+
150
+ Array.from(tableElement.querySelectorAll('[data-sortable]')).forEach((col, index) => {
151
+ col.setAttribute('aria-sort', 'none');
152
+ }); // Set the sort order attribute
153
+
154
+ target.setAttribute('aria-sort', sort); // Save the sort options on the table element so that it can be re-sorted later
155
+
156
+ tableElement.setAttribute('data-sort', sort);
157
+ tableElement.setAttribute('data-sortBy', target.textContent); // Sort the table
158
+
159
+ sortTable(target.textContent, sort);
160
+ Array.from(tableElement.querySelectorAll('tr[draggable]')).forEach((tableRow, index) => {
161
+ tableRow.removeAttribute('draggable');
162
+ });
163
+ break;
164
+ }
165
+ }
166
+ }, false); // On page load check if the table should be pre-sorted, if so trigger a click
167
+
168
+ if (tableElement.getAttribute('data-sortBy')) {
169
+ var sort = tableElement.getAttribute('data-sort') == "ascending" ? "descending" : "ascending";
170
+ Array.from(tableElement.querySelectorAll('[data-sortable]')).forEach((col, index) => {
171
+ if (col.textContent == tableElement.getAttribute('data-sortBy')) {
172
+ col.setAttribute('aria-sort', sort);
173
+ col.click();
174
+ }
175
+ });
176
+ } // #endregion Sortable
177
+ // #region Filters
178
+
179
+
180
+ var createFilterForm = function createFilterForm(count) {
181
+ // Create wrapper div
182
+ var form = document.createElement("div");
183
+ form.classList.add('table__filters');
184
+ form.classList.add('row');
185
+ form.classList.add('pt-1');
186
+ form.classList.add('pb-3'); // Create the filter options array
187
+
188
+ var filterColumns = Array.from(tableElement.querySelectorAll('th[data-filterable]')); // Populate a list of searchable terms from the cells of the columns that could be used as a filter
189
+
190
+ var searchableTerms = {};
191
+ filterColumns.forEach((columnHeading, index) => {
192
+ Array.from(tableElement.querySelectorAll('td[data-label="' + columnHeading.textContent + '"]')).forEach((label, index) => {
193
+ searchableTerms[label.textContent] = label.textContent;
194
+ });
195
+ }); // Create the form
196
+
197
+ var filterTitle = filterColumns.length == 1 ? "Filter by " + filterColumns[0].textContent : "Filter"; // Update title if only one filter is chosen
198
+
199
+ var checkboxClass = filterColumns.length == 1 ? "d-none" : "d-sm-flex"; // Hide controls when only one filter is chosen
200
+
201
+ form.innerHTML = "<div class=\"col-sm-6 col-md-4 pb-3\">\n <div class=\"form-control__wrapper form-control-inline mb-0\">\n <label for=\"".concat(randID, "_filter\" class=\"form-label\">").concat(filterTitle, ":</label>\n <input type=\"search\" name=\"").concat(randID, "_filter\" id=\"").concat(randID, "_filter\" class=\"form-control form-control-sm\" placeholder=\"\" list=\"").concat(randID, "_list\" />\n </div>\n <datalist id=\"").concat(randID, "_list\">\n ").concat(Object.keys(searchableTerms).map(term => "<option value=\"".concat(term, "\"></option>")).join(""), "\n </datalist>\n</div>\n<div class=\"col-md-8 align-items-center pb-3 ").concat(checkboxClass, "\">\n ").concat("<span class=\"pe-3 text-nowrap h5 mb-0\">Filter by: </span>" + filterColumns.map(column => "<div class=\"form-check pe-3 mt-0 mb-0\"><input class=\"form-check-input\" type=\"checkbox\" id=\"".concat(randID, "_").concat(column.textContent.replace(' ', '_').toLowerCase(), "\" checked=\"checked\" /><label class=\"form-check-label text-nowrap\" for=\"").concat(randID, "_").concat(column.textContent.replace(' ', '_').toLowerCase(), "\">").concat(column.textContent, "</label></div>")).join(""), "\n</div>"); // Add before the actual table
202
+
203
+ tableElement.prepend(form);
204
+ };
205
+
206
+ var filterTable = function filterTable(searchTerm) {
207
+ // Create an array of rows that match the search term
208
+ var tableArr = [];
209
+ Array.from(storedData.querySelectorAll('tr')).forEach((tableRow, index) => {
210
+ // We want one long search string per row including each filterable table cell
211
+ var rowSearchString = '';
212
+ Array.from(tableElement.querySelectorAll('[type="checkbox"]:checked + label')).forEach((label, index) => {
213
+ rowSearchString += tableRow.querySelector('td[data-label="' + label.textContent + '"]').textContent + ' | ';
214
+ }); // Check if the table row search string contains the search term
215
+
216
+ if (rowSearchString.indexOf(searchTerm) >= 0) {
217
+ var dataRow = {
218
+ row: tableRow
219
+ };
220
+ tableArr.push(dataRow);
221
+ }
222
+ }); // Create a string to return and populate the tbody
223
+
224
+ var strTbody = '';
225
+ tableArr.forEach((tableRow, index) => {
226
+ strTbody += tableRow.row.outerHTML;
227
+ });
228
+ tbody.innerHTML = strTbody; // Dispatch the filter event.
229
+
230
+ tableElement.dispatchEvent(filteredEvent);
231
+ };
232
+
233
+ var createFilterList = function createFilterList() {
234
+ // Check which options are checked
235
+ var filterOptions = [];
236
+ Array.from(tableElement.querySelectorAll('[type="checkbox"]:checked + label')).forEach((label, index) => {
237
+ filterOptions.push(label.textContent);
238
+ }); // Build up the list of searchable terms
239
+
240
+ var searchableTerms = [];
241
+ filterOptions.forEach((option, index) => {
242
+ Array.from(tableElement.querySelectorAll('td[data-label="' + option + '"]')).forEach((label, index) => {
243
+ searchableTerms[label.textContent] = label.textContent;
244
+ });
245
+ }); // Rebuild the list
246
+
247
+ var dataList = tableElement.querySelector('datalist');
248
+ dataList.innerHTML = Object.keys(searchableTerms).map(term => "<option value=\"".concat(term, "\"></option>")).join("");
249
+ }; // On page load check if filters are needed
250
+
251
+
252
+ if (Array.from(tableElement.querySelectorAll('[data-filterable]')).length) {
253
+ // Create the filter options
254
+ createFilterForm(tableElement, Array.from(tableElement.querySelectorAll('[data-filterable]')).length); // Add event handlers for the filter options
255
+
256
+ tableElement.addEventListener('keyup', function (e) {
257
+ for (var target = e.target; target && target != this; target = target.parentNode) {
258
+ if (target.matches('input[type="search"]')) {
259
+ var searchTerm = target.value;
260
+ filterTable(searchTerm);
261
+ }
262
+ }
263
+ });
264
+ tableElement.addEventListener('change', function (e) {
265
+ for (var target = e.target; target && target != this; target = target.parentNode) {
266
+ if (target.matches('input[type="search"]')) {
267
+ var searchTerm = target.value;
268
+ filterTable(searchTerm);
269
+ }
270
+ }
271
+ });
272
+ tableElement.addEventListener('change', function (e) {
273
+ for (var target = e.target; target && target != this; target = target.parentNode) {
274
+ if (target.matches('input[type="checkbox"]')) {
275
+ var searchTerm = tableElement.querySelector('input[type="search"]').value;
276
+ filterTable(searchTerm);
277
+ createFilterList();
278
+ }
279
+ }
280
+ });
281
+ } // #endregion Filters
282
+ // #region Pagination
283
+
284
+
285
+ var paginateRows = function paginateRows(show, page) {
286
+ // Create some inline CSS to control what is viewed on the table, unline the filters we are just hiding the rable rows not removing them from the DOM.
287
+ var style = document.getElementById(randID + '_style');
288
+
289
+ if (style == null) {
290
+ style = document.createElement("style");
291
+ style.setAttribute('id', randID + '_style');
292
+ }
293
+
294
+ var startShowing = show * (page - 1) + 1;
295
+ var stopShowing = show * page;
296
+ style.innerHTML = "\n #".concat(randID, " tbody tr {\n display: none;\n }\n #").concat(randID, " tbody tr:nth-child(").concat(startShowing, "),\n #").concat(randID, " tbody tr:nth-child(").concat(startShowing, ") ~ tr{\n display: table-row;\n }\n #").concat(randID, " tbody tr:nth-child(").concat(stopShowing, ") ~ tr{\n display: none;\n }\n ");
297
+ tableElement.append(style);
298
+ };
299
+
300
+ var createPaginationForm = function createPaginationForm(show, page, totalRows) {
301
+ var form = document.createElement("div");
302
+ form.classList.add('table__pagination');
303
+ form.classList.add('row');
304
+ form.classList.add('pt-3');
305
+ form.classList.add('pb-3'); // Create the form and create a container div to hold the pagination buttons
306
+
307
+ form.innerHTML = "<div class=\"col-6 col-sm-3 col-md-2 mb-3\">\n <div class=\"form-control__wrapper form-control-inline mb-0\">\n <label for=\"".concat(randID, "_showing\" class=\"form-label\">Showing:</label>\n <input type=\"number\" name=\"").concat(randID, "_showing\" id=\"").concat(randID, "_showing\" class=\"form-control form-control-sm\" placeholder=\"\" list=\"").concat(randID, "_pagination\" value=\"").concat(show, "\" min=\"1\" max=\"").concat(totalRows, "\" />\n </div>\n <datalist id=\"").concat(randID, "_pagination\">\n <option value=\"5\">5</option>\n ").concat(totalRows > 10 ? "<option value=\"10\">10</option>" : '', "\n ").concat(totalRows > 20 ? "<option value=\"20\">20</option>" : '', "\n <option value=\"").concat(totalRows, "\">").concat(totalRows, "</option>\n </datalist>\n</div>\n<div class=\"col-6 col-sm-2 col-md-2 d-flex align-items-center mb-3\"><span class=\"label\">per page</span></div>\n<div class=\"col-sm-7 col-md-8 d-sm-flex justify-content-end align-items-center mb-3\" id=\"").concat(randID, "_paginationBtns\"></div>"); // Add after the actual table
308
+
309
+ tableElement.append(form);
310
+ };
311
+
312
+ var createPaginationButttons = function createPaginationButttons(show, page, totalRows) {
313
+ var paginationButtonsWrapper = document.getElementById(randID + '_paginationBtns');
314
+ if (paginationButtonsWrapper == null) return false;
315
+ var numberPages = Math.ceil(totalRows / show);
316
+
317
+ if (numberPages == 1) {
318
+ // Remore the buttons or dont display any if we dont need them
319
+ paginationButtonsWrapper.innerHTML = '';
320
+ } else if (numberPages < 5) {
321
+ // If less than 5 pages (which fits comfortably on mobile) we display buttons
322
+ var strButtons = '';
323
+
324
+ for (var i = 1; i <= numberPages; i++) {
325
+ if (i == page) strButtons += "<li class=\"page-item active\" aria-current=\"page\"><span class=\"page-link\">".concat(i, "</span></li>");else strButtons += "<li class=\"page-item\"><button class=\"page-link\" data-page=\"".concat(i, "\">").concat(i, "</button></li>");
326
+ }
327
+
328
+ paginationButtonsWrapper.innerHTML = "<span class=\"pe-2\">Page: </span><ul class=\"pagination mb-0\">\n ".concat(page == 1 ? "<li class=\"page-item disabled\"><span class=\"page-link\">Previous</span></li>" : "<li class=\"page-item\"><button class=\"page-link\" data-page=\"".concat(parseInt(page) - 1, "\">Previous</button></li>"), "\n ").concat(strButtons, "\n ").concat(page == numberPages ? "<li class=\"page-item disabled\"><span class=\"page-link\">Next</span></li>" : "<li class=\"page-item\"><button class=\"page-link\" data-page=\"".concat(parseInt(page) + 1, "\">Next</button></li>"), "\n </ul>");
329
+ } else {
330
+ // If more than 5 lets show a select field instead so that we dont have loads and loads of buttons
331
+ var strOptions = '';
332
+
333
+ for (var _i = 1; _i <= numberPages; _i++) {
334
+ if (_i == page) strOptions += "<option value=\"".concat(_i, "\" selected>Page ").concat(_i, "</option>");else strOptions += "<option value=\"".concat(_i, "\">Page ").concat(_i, "</option>");
335
+ }
336
+
337
+ paginationButtonsWrapper.innerHTML = "\n<select class=\"form-select mb-3\">\n ".concat(strOptions, "\n</select>\n ");
338
+ }
339
+ }; // On page load check if the table should be paginated
340
+
341
+
342
+ if (tableElement.getAttribute('data-show')) {
343
+ var show = parseInt(tableElement.getAttribute('data-show'));
344
+ var page = parseInt(tableElement.getAttribute('data-page')) ? parseInt(tableElement.getAttribute('data-page')) : 1;
345
+ var totalRows = tableElement.querySelectorAll('tbody tr').length;
346
+
347
+ if (show < totalRows) {
348
+ paginateRows(show, page);
349
+ createPaginationForm(show, page, totalRows);
350
+ createPaginationButttons(show, page, totalRows);
351
+ tableElement.addEventListener('change', function (e) {
352
+ for (var target = e.target; target && target != this; target = target.parentNode) {
353
+ if (target.matches('.table__pagination input[type="number"]')) {
354
+ paginateRows(target.value, page);
355
+ createPaginationButttons(target.value, page, totalRows);
356
+ tableElement.setAttribute('data-show', target.value);
357
+ }
358
+ }
359
+ });
360
+ tableElement.addEventListener('click', function (e) {
361
+ for (var target = e.target; target && target != this; target = target.parentNode) {
362
+ if (target.matches('.page-item:not(.active):not(.disabled) .page-link')) {
363
+ paginateRows(tableElement.getAttribute('data-show'), target.getAttribute('data-page'));
364
+ createPaginationButttons(tableElement.getAttribute('data-show'), target.getAttribute('data-page'), totalRows);
365
+ }
366
+ }
367
+ }, false);
368
+ tableElement.addEventListener('change', function (e) {
369
+ for (var target = e.target; target && target != this; target = target.parentNode) {
370
+ if (target.matches('.table__pagination select')) {
371
+ paginateRows(tableElement.getAttribute('data-show'), target.value);
372
+ createPaginationButttons(tableElement.getAttribute('data-show'), target.value, totalRows);
373
+ }
374
+ }
375
+ });
376
+ }
377
+ } // #endregion Pagination
378
+ // #region Reorderable
379
+ // Set the row thats being dragged and copy the row
380
+
381
+
382
+ function setDraggedRow(e) {
383
+ e.dataTransfer.setData("text/plain", e.target.id);
384
+ draggedRow = e.target;
385
+ e.target.classList.add('tr--dragging');
386
+ } // Create the order column and event handler for rows
387
+
388
+
389
+ var setReorderRows = function setReorderRows() {
390
+ Array.from(tbody.querySelectorAll('tr')).forEach((tableRow, index) => {
391
+ // Create column if not already created
392
+ if (tableRow.querySelector('[data-label="Order"]') == null) {
393
+ var orderColumn = document.createElement('th');
394
+ orderColumn.innerHTML = index + 1;
395
+ orderColumn.setAttribute('data-label', 'Order');
396
+ tableRow.prepend(orderColumn);
397
+ } // Make draggable
398
+
399
+
400
+ tableRow.setAttribute('id', randID + '_row_' + (index + 1));
401
+ tableRow.setAttribute('data-order', index + 1);
402
+ tableRow.setAttribute('draggable', 'true');
403
+ tableRow.addEventListener("dragstart", setDraggedRow);
404
+ });
405
+ };
406
+
407
+ if (tableElement.getAttribute('data-reorder')) {
408
+ // Add column heading
409
+ var orderHeading = document.createElement('th');
410
+ orderHeading.innerHTML = 'Order';
411
+ orderHeading.classList.add('table-order-reset');
412
+ thead.querySelector('tr').prepend(orderHeading);
413
+ setReorderRows(); // Reset order button
414
+
415
+ tableElement.addEventListener('click', function (e) {
416
+ for (var target = e.target; target && target != this; target = target.parentNode) {
417
+ if (target.matches('.table-order-reset')) {
418
+ // unset sort attributes
419
+ Array.from(tableElement.querySelectorAll('[data-sortable]')).forEach((col, index) => {
420
+ col.setAttribute('aria-sort', 'none');
421
+ }); // Save the sort options on the table element so that it can be re-sorted later
422
+
423
+ tableElement.removeAttribute('data-sort');
424
+ tableElement.removeAttribute('data-sortBy'); // Sort the table
425
+
426
+ sortTable('Order', 'ascending');
427
+ Array.from(tableElement.querySelectorAll('tbody tr')).forEach((tableRow, index) => {
428
+ tableRow.setAttribute('draggable', 'true');
429
+ });
430
+ break;
431
+ }
432
+ }
433
+ }, false);
434
+ document.addEventListener("dragover", function (e) {
435
+ // prevent default to allow drop
436
+ e.preventDefault();
437
+ }, false);
438
+ document.addEventListener("dragenter", function (e) {
439
+ // prevent default to allow drop
440
+ e.preventDefault();
441
+ e.dataTransfer.dropEffect = "move";
442
+
443
+ for (var target = e.target; target && target != this; target = target.parentNode) {
444
+ if (target.matches('[data-reorder] tbody tr')) {
445
+ target.classList.add('tr--dropable');
446
+ }
447
+ }
448
+ }, false);
449
+ document.addEventListener("dragleave", function (e) {
450
+ // prevent default to allow drop
451
+ e.preventDefault();
452
+
453
+ for (var target = e.target; target && target != this; target = target.parentNode) {
454
+ if (target.matches('[data-reorder] tbody tr')) {
455
+ target.classList.remove('tr--dropable');
456
+ }
457
+ }
458
+ }, false);
459
+ document.addEventListener("drop", function (e) {
460
+ e.preventDefault();
461
+
462
+ for (var target = e.target; target && target != this; target = target.parentNode) {
463
+ if (target.matches('[data-reorder] tbody tr')) {
464
+ if (target.parentNode != null && draggedRow.parentNode != null && target != draggedRow) {
465
+ draggedRow.parentNode.removeChild(draggedRow);
466
+ if (draggedRow.getAttribute('data-order') > target.getAttribute('data-order')) target.parentNode.insertBefore(draggedRow, target);else target.parentNode.insertBefore(draggedRow, target.nextElementSibling); // Re label the rows
467
+
468
+ Array.from(tbody.querySelectorAll('tr')).forEach((tableRowOrder, index) => {
469
+ tableRowOrder.classList.remove('tr--dragging');
470
+ tableRowOrder.classList.remove('tr--dropable');
471
+ tableRowOrder.querySelector('th').innerHTML = index + 1;
472
+ tableRowOrder.setAttribute('data-order', index + 1);
473
+ });
474
+ }
475
+
476
+ break;
477
+ }
478
+ }
479
+ }, false);
480
+ } // #endregion Reorderable
481
+ // Watch for the filterable event and re-sort the tbody
482
+
483
+
484
+ tableElement.addEventListener('filtered', function (e) {
485
+ if (tableElement.getAttribute('data-sortBy') && tableElement.getAttribute('data-sort')) sortTable(tableElement.getAttribute('data-sortBy'), tableElement.getAttribute('data-sort'));
486
+
487
+ if (tableElement.getAttribute('data-show')) {
488
+ var _show = parseInt(tableElement.getAttribute('data-show'));
489
+
490
+ var _totalRows = tableElement.querySelectorAll('tbody tr').length;
491
+ var tablePagination = tableElement.querySelector('.table__pagination');
492
+ if (tablePagination != null) tablePagination.remove();
493
+
494
+ if (_show < _totalRows) {
495
+ paginateRows(_show, 1);
496
+ createPaginationForm(_show, 1, _totalRows);
497
+ createPaginationButttons(_show, 1, _totalRows);
498
+ }
499
+ }
500
+
501
+ if (tableElement.getAttribute('data-reorder')) {
502
+ setReorderRows();
503
+ }
504
+ }, false);
505
+ tableElement.addEventListener('sorted', function (e) {
506
+ if (tableElement.getAttribute('data-reorder')) {
507
+ setReorderRows();
508
+ }
509
+ }, false);
510
+ tableElement.addEventListener('populated', function (e) {
511
+ var tableFilter = tableElement.querySelector('.table__filters');
512
+ tableFilter.remove();
513
+ var tablePagination = tableElement.querySelector('.table__pagination');
514
+ tablePagination.remove();
515
+ var newTable = tableElement.cloneNode(true);
516
+ tableElement.parentNode.replaceChild(newTable, tableElement);
517
+ table(newTable);
518
+ }, false);
519
+ }
520
+
521
+ function accordion(accordionElement) {
522
+ // Fetch all the details element.
523
+ if (!accordionElement.classList.contains('accordion--keep-open')) {
524
+ var details = accordionElement.querySelectorAll(":scope > details"); // Add the onclick listeners.
525
+
526
+ details.forEach(targetDetail => {
527
+ targetDetail.addEventListener("click", () => {
528
+ // Close all the details that are not targetDetail.
529
+ details.forEach(detail => {
530
+ if (detail !== targetDetail) {
531
+ detail.removeAttribute("open");
532
+ }
533
+ });
534
+ });
535
+ });
536
+ }
537
+
538
+ if (window.location.hash && document.querySelector(window.location.hash + ':not([open]) summary')) {
539
+ var detail = document.querySelector(window.location.hash + ' summary');
540
+ detail.click();
541
+ }
542
+
543
+ window.addEventListener('hashchange', function () {
544
+ if (window.location.hash && document.querySelector(window.location.hash + ' summary')) {
545
+ var _detail = document.querySelector(window.location.hash + ' summary');
546
+
547
+ _detail.click();
548
+ }
549
+ });
550
+ }
551
+
552
+ function testimonial(testimonialElement) {
553
+ var scrollTimeout;
554
+ var imagesCarousel = testimonialElement.querySelector('.testimonial__images');
555
+ var itemCount = imagesCarousel.querySelectorAll('img').length; // If we only have 1 item lets not bother doing anything else
556
+
557
+ if (itemCount == 1) {
558
+ return false;
559
+ }
560
+
561
+ testimonialElement.classList.add('testimonial--multi'); // Set where the buttons go to
562
+
563
+ var setButtons = function setButtons(scrollTo) {
564
+ var nextButton = testimonialElement.querySelector('.btn-next');
565
+ var prevButton = testimonialElement.querySelector('.btn-prev');
566
+ nextButton.setAttribute('data-go', scrollTo + 1);
567
+ prevButton.setAttribute('data-go', scrollTo - 1);
568
+ nextButton.removeAttribute('disabled');
569
+ prevButton.removeAttribute('disabled');
570
+ if (scrollTo == 1) prevButton.setAttribute('disabled', true);else if (scrollTo == itemCount) nextButton.setAttribute('disabled', true);
571
+ }; // On scroll we need to make sure the buttons get corrected and the next testimonial is shown
572
+
573
+
574
+ imagesCarousel.addEventListener('scroll', function (e) {
575
+ clearTimeout(scrollTimeout);
576
+ scrollTimeout = setTimeout(function () {
577
+ var scrollWidth = imagesCarousel.scrollWidth;
578
+ var scrollHeight = imagesCarousel.scrollHeight;
579
+ var scrollLeft = imagesCarousel.scrollLeft;
580
+ var scrollDown = imagesCarousel.scrollTop;
581
+ var scrollTo = Math.round(scrollLeft / scrollWidth * itemCount) + 1; // Change in scroll direction
582
+
583
+ if (scrollLeft == 0 && scrollDown != 0) scrollTo = Math.round(scrollDown / scrollHeight * itemCount) + 1;
584
+ testimonialElement.setAttribute('data-show', scrollTo);
585
+ setButtons(scrollTo);
586
+ }, 300);
587
+ }, false); // when the buttons are used we need to make sure the carousel scrolls to the correct place
588
+
589
+ testimonialElement.addEventListener('click', function (e) {
590
+ for (var target = e.target; target && target != this; target = target.parentNode) {
591
+ if (target.matches('[data-go]')) {
592
+ var scrollTo = parseInt(target.getAttribute('data-go'));
593
+ var scrollDown = 0;
594
+ var scrollLeft = 0;
595
+ var scrollWidth = imagesCarousel.scrollWidth;
596
+ var scrollHeight = imagesCarousel.scrollHeight;
597
+ if (scrollWidth > scrollHeight) scrollLeft = Math.floor(scrollWidth * ((scrollTo - 1) / itemCount));else scrollDown = Math.floor(scrollHeight * ((scrollTo - 1) / itemCount)); // Trigger the scroll
598
+
599
+ imagesCarousel.scroll({
600
+ top: scrollDown,
601
+ left: scrollLeft,
602
+ behavior: 'smooth'
603
+ });
604
+ break;
605
+ }
606
+ }
607
+ }, false);
608
+ }
609
+
610
+ function carousel(carouselElement) {
611
+ var scrollTimeout;
612
+ var carouselInner = carouselElement.querySelector('.carousel__inner');
613
+ var itemCount = carouselElement.querySelectorAll('.carousel__item').length;
614
+ carouselElement.getAttribute('data-cols');
615
+ var smCols = carouselElement.getAttribute('data-sm-cols');
616
+ var mdCols = carouselElement.getAttribute('data-md-cols');
617
+ carouselElement.querySelector('.carousel__controls a').classList.add('active'); // On scroll we need to make sure the buttons get corrected and the next testimonial is shown
618
+
619
+ carouselInner.addEventListener('scroll', function (e) {
620
+ clearTimeout(scrollTimeout);
621
+ scrollTimeout = setTimeout(function () {
622
+ var scrollArea = carouselInner.clientWidth;
623
+ var scrollWidth = carouselInner.scrollWidth;
624
+ var scrollLeft = carouselInner.scrollLeft;
625
+ var targetSlide = Math.round(scrollLeft / scrollWidth * itemCount) + 1;
626
+ var lastItemOffset = carouselElement.querySelector('.carousel__item:last-child').offsetLeft;
627
+ Array.from(carouselElement.querySelectorAll('.carousel__controls a')).forEach((link, index) => {
628
+ link.classList.remove('active');
629
+ });
630
+ carouselElement.querySelector('.control-' + targetSlide).classList.add('active'); // Disable the previous button
631
+
632
+ if (targetSlide == 1) carouselElement.querySelector('.btn-prev').setAttribute('disabled', 'disabled');else carouselElement.querySelector('.btn-prev').removeAttribute('disabled'); // Disable the next button if the last item is in view
633
+
634
+ if (carouselInner.scrollLeft + scrollArea > lastItemOffset) carouselElement.querySelector('.btn-next').setAttribute('disabled', 'disabled');else carouselElement.querySelector('.btn-next').removeAttribute('disabled');
635
+ }, 100);
636
+ }, false); // when the buttons are used we need to make sure the carousel scrolls to the correct place
637
+
638
+ carouselElement.addEventListener('click', function (e) {
639
+ for (var target = e.target; target && target != this; target = target.parentNode) {
640
+ if (target.matches('.carousel__controls a')) {
641
+ e.preventDefault();
642
+ Array.from(carouselElement.querySelectorAll('.carousel__controls a')).forEach((link, index) => {
643
+ link.classList.remove('active');
644
+ });
645
+ target.classList.add('active');
646
+ var el = document.querySelector(target.getAttribute('href'));
647
+ carouselInner.scroll({
648
+ top: 0,
649
+ left: el.offsetLeft,
650
+ behavior: 'smooth'
651
+ });
652
+ break;
653
+ }
654
+ }
655
+ }, false);
656
+ carouselElement.addEventListener('click', function (e) {
657
+ for (var target = e.target; target && target != this; target = target.parentNode) {
658
+ if (target.matches('.btn-next, .btn-prev')) {
659
+ e.preventDefault();
660
+ var scrollTo = target.classList.contains('btn-prev') ? carouselInner.scrollLeft - carouselInner.clientWidth : carouselInner.scrollLeft + carouselInner.clientWidth;
661
+ carouselInner.scroll({
662
+ top: 0,
663
+ left: scrollTo,
664
+ behavior: 'smooth'
665
+ });
666
+ break;
667
+ }
668
+ }
669
+ }, false); // Add responsive hide button classes
670
+
671
+ if (itemCount == 1) carouselElement.classList.add('hide-btns');
672
+ if (smCols >= itemCount) carouselElement.classList.add('hide-sm-btns');
673
+ if (mdCols >= itemCount) carouselElement.classList.add('hide-md-btns');
674
+ }
675
+
676
+ // Create a link between two input/selects with one acting as setting a minimum value and the second a maximum
677
+ // The link between the two will prevent the max input field form setting a lower value than the min and vice versa
678
+ function inputRange(inputWrapper) {
679
+ inputWrapper.addEventListener('change', function (e) {
680
+ var min = parseInt(inputWrapper.querySelector('[data-min] select,[data-min] input').value);
681
+ var max = parseInt(inputWrapper.querySelector('[data-max] select,[data-max] input').value); // Set attributes for input fields
682
+
683
+ Array.from(inputWrapper.querySelectorAll('[data-min] input')).forEach((input, index) => {
684
+ input.setAttribute('max', max);
685
+ });
686
+ Array.from(inputWrapper.querySelectorAll('[data-max] input')).forEach((input, index) => {
687
+ input.setAttribute('min', min);
688
+ }); // Hide select options if they are higher or lower than the min and max values
689
+
690
+ Array.from(inputWrapper.querySelectorAll('[data-min] select option')).forEach((option, index) => {
691
+ if (parseInt(option.getAttribute('value')) > max) option.classList.add('d-none');else option.classList.remove('d-none');
692
+ });
693
+ Array.from(inputWrapper.querySelectorAll('[data-max] select option')).forEach((option, index) => {
694
+ if (parseInt(option.getAttribute('value')) < min) option.classList.add('d-none');else option.classList.remove('d-none');
695
+ });
696
+ }, false);
697
+ } // Acts as an overall initialise function to trigger other functions.
698
+
699
+
700
+ function form(formElement) {
701
+ // Check for input range groups
702
+ Array.from(formElement.querySelectorAll('[data-input-range]')).forEach((arrayElement, index) => {
703
+ inputRange(arrayElement);
704
+ });
705
+ }
706
+
707
+ /**
708
+ * Integrate YouTube videos as a way of hosting videos without the overhead and worry surrounding hosting vides. i.e. file sizes, performance and accessibility.
709
+ */
710
+ class youtubeVideo {
711
+ /** @param {HTMLElement} embed dom element */
712
+ constructor(embed) {
713
+ var createEmbed = this.createEmbed; // If the scripts is already loaded then lets just create the embed
714
+
715
+ if (document.body.classList.contains('youtubeLoaded')) {
716
+ embed.addEventListener('click', function (e) {
717
+ // loop parent nodes from the target to the delegation node
718
+ for (var target = e.target; target && target != this; target = target.parentNode) {
719
+ if (target.matches('a:not([data-modal-youtube]')) {
720
+ e.preventDefault();
721
+ createEmbed(embed, target);
722
+ break;
723
+ }
724
+ }
725
+ }, false);
726
+ } else {
727
+ this.loadScripts(embed, this.createEmbed);
728
+ }
729
+ }
730
+ /**
731
+ * Load the YouTube scripts before trying to create the embed
732
+ * @param {HTMLElement} embed dom element
733
+ * @param {Function} createEmbed function to create the embed after script loaded.
734
+ */
735
+
736
+
737
+ loadScripts(embed, createEmbed) {
738
+ return new Promise((resolve, reject) => {
739
+ var image = new Image();
740
+
741
+ image.onload = function () {
742
+ // This code loads the IFrame Player API code asynchronously.
743
+ var tag = document.createElement('script');
744
+ tag.src = "https://www.youtube.com/iframe_api";
745
+ var firstScriptTag = document.getElementsByTagName('script')[0];
746
+ firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
747
+ document.body.classList.add('youtubeLoaded');
748
+ resolve(true); // script has loaded, you can now use it safely
749
+
750
+ tag.onload = () => {
751
+ embed.addEventListener('click', function (e) {
752
+ // loop parent nodes from the target to the delegation node
753
+ for (var target = e.target; target && target != this; target = target.parentNode) {
754
+ if (target.matches('a:not([data-modal-youtube]')) {
755
+ e.preventDefault();
756
+ createEmbed(embed, target);
757
+ break;
758
+ }
759
+ }
760
+ }, false);
761
+ };
762
+ };
763
+
764
+ image.onerror = function () {
765
+ reject(false);
766
+ };
767
+
768
+ image.src = "https://youtube.com/favicon.ico";
769
+ });
770
+ }
771
+ /**
772
+ * Create the YouTube embed after the user has clicked on it.
773
+ * @param {HTMLElement} embed dom element
774
+ */
775
+
776
+
777
+ createEmbed(embed, target) {
778
+ // If there is more than one video lets make sure there is only one playing at a time.
779
+ if (typeof window.player != "undefined" && typeof window.player.pauseVideo == "function") window.player.pauseVideo();
780
+ var video_id = target.getAttribute('data-id');
781
+ var link_id = target.getAttribute('id'); // create an id to pass t the script if one isn't present
782
+
783
+ if (typeof link_id == 'undefined' || link_id == null) {
784
+ var randLetter = String.fromCharCode(65 + Math.floor(Math.random() * 26));
785
+ link_id = randLetter + Date.now();
786
+ target.setAttribute('id', link_id);
787
+ } // This function creates an <iframe> (and YouTube player) after the API code downloads.
788
+
789
+
790
+ function onYouTubeIframeAPIReady() {
791
+ window.player = new YT.Player(link_id, {
792
+ height: '100%',
793
+ width: '100%',
794
+ videoId: video_id,
795
+ playerVars: {
796
+ 'modestbranding': 1,
797
+ 'playsinline': 1,
798
+ 'rel': 0,
799
+ 'showinfo': 0
800
+ },
801
+ events: {
802
+ 'onReady': onPlayerReady,
803
+ 'onStateChange': onPlayerStateChange
804
+ }
805
+ });
806
+ }
807
+
808
+ onYouTubeIframeAPIReady(); // The API will call this function when the video player is ready.
809
+
810
+ function onPlayerReady(event) {
811
+ // Play the video straight away
812
+ event.target.playVideo();
813
+ } // The API calls this function when the player's state changes.
814
+ // The function indicates that when playing a video (state=1)
815
+
816
+
817
+ var done = false;
818
+
819
+ function onPlayerStateChange(event) {
820
+ if (event.data == YT.PlayerState.PLAYING && !done) {
821
+ var link = document.getElementById(link_id);
822
+ link.classList.add('player-ready');
823
+ done = true;
824
+ }
825
+ }
826
+ }
827
+
828
+ }
829
+
830
+ // Bootstrap modules
831
+
832
+ document.addEventListener("DOMContentLoaded", function () {
833
+ addBodyClasses(document.body);
834
+ checkElements(document.body);
835
+ console.log('test.js'); // ANav
836
+
837
+ Array.from(document.querySelectorAll('.nav')).forEach((arrayElement, index) => {
838
+ navbar(arrayElement);
839
+ }); // Advanced tables
840
+
841
+ Array.from(document.querySelectorAll('.table__wrapper')).forEach((arrayElement, index) => {
842
+ table(arrayElement);
843
+ }); // Accordions
844
+
845
+ Array.from(document.querySelectorAll('.accordion')).forEach((arrayElement, index) => {
846
+ accordion(arrayElement);
847
+ }); // Testimonial
848
+
849
+ Array.from(document.querySelectorAll('.testimonial')).forEach((arrayElement, index) => {
850
+ testimonial(arrayElement);
851
+ }); // Carousel
852
+
853
+ Array.from(document.querySelectorAll('.carousel')).forEach((arrayElement, index) => {
854
+ carousel(arrayElement);
855
+ }); // Form
856
+
857
+ Array.from(document.querySelectorAll('form')).forEach((arrayElement, index) => {
858
+ form(arrayElement);
859
+ }); // Modal
860
+
861
+ Array.from(document.querySelectorAll('.modal')).forEach((arrayElement, index) => {
862
+ modal(arrayElement);
863
+ }); // YouTube videos
864
+
865
+ Array.from(document.querySelectorAll('.youtube-embed')).forEach((arrayElement, index) => {
866
+ new youtubeVideo(arrayElement);
867
+ });
868
+ });
869
+
870
+ }));
871
+ //# sourceMappingURL=scripts.bundle.js.map