-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajaxModules.js
119 lines (108 loc) · 3.63 KB
/
ajaxModules.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'use strict'
import { default as ajaxMap } from "/e107_plugins/ajaxModules/Components/Map/ajaxMaps.js";
import { default as ajaxTable } from "/e107_plugins/ajaxModules/Components/Table/ajaxTables.js";
import { default as ajaxTemplate } from "/e107_plugins/ajaxModules/Components/Template/ajaxTemplates.js";
import { default as ajaxForm } from "/e107_plugins/ajaxModules/Components/Form/ajaxForms.js";
import { default as ajaxMenu } from "/e107_plugins/ajaxModules/Components/Menu/ajaxMenus.js";
(function () {
window["ajaxMaps"] = [];
window["ajaxTables"] = [];
window["ajaxTemplates"] = [];
window["ajaxForms"] = [];
window["ajaxMenus"] = [];
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
var layer = "dark";
} else {
var layer = "light";
}
document.addEventListener('DOMContentLoaded', () => {
const maps = document.querySelectorAll('div[data-ajax="map"]');
maps.forEach((element, key) => {
var mapOptions = {
_defaults: {
lat: parseFloat(element.dataset.lat, 10),
lng: parseFloat(element.dataset.lng, 10),
zoom: parseInt(element.dataset.zoom, 10),
geolocation: true,
// minZoom: parseInt(element.dataset.minZoom, 10),
// maxZoom: parseInt(element.dataset.maxZoom, 10)
},
_baseMaps: {
layers: layer
},
_mapCallback: {
functions: {}
}
}
window["ajaxMaps"][key] = new ajaxMap(element, key, mapOptions);
})
const tables = document.querySelectorAll('table[data-ajax="table"]');
tables.forEach((element, key) => {
var tableOptions = {
parseResponse: function (response) {
const type = response.type;
const data = response.data;
const dataset = response.data.dataset;
const records = data.records;
const totalrecords = data.totalrecords;
return { type, data, dataset, records, totalrecords };
},
_tableCallback: {
functions: {}
}
}
window["ajaxTables"][key] = new ajaxTable(element, key, tableOptions);
})
const templates = document.querySelectorAll('div[data-ajax="template"]');
templates.forEach((element, key) => {
var templateOptions = {
parseResponse: function (response) {
const type = response.type;
const data = response.data;
const dataset = response.data.dataset[0];
const records = data.records;
const totalrecords = data.totalrecords;
return { type, data, dataset, records, totalrecords };
},
_templateCallback: {
functions: {}
}
}
window["ajaxTemplates"][key] = new ajaxTemplate(element, key, templateOptions);
})
const forms = document.querySelectorAll('div[data-ajax="form"]');
forms.forEach((element, key) => {
var formOptions = {
parseResponse: function (response) {
const type = response.type;
const data = response.data;
const dataset = response.data.dataset[0];
const records = data.records;
const totalrecords = data.totalrecords;
return { type, data, dataset, records, totalrecords };
},
_formCallback: {
functions: {}
}
}
window["ajaxForms"][key] = new ajaxForm(element, key, formOptions);
})
const menus = document.querySelectorAll('div[data-ajax="menu"]');
menus.forEach((element, key) => {
var menuOptions = {
parseResponse: function (response) {
const type = response.type;
const data = response.data;
const dataset = response.data.dataset;
const records = data.records;
const totalrecords = data.totalrecords;
return { type, data, dataset, records, totalrecords };
},
_menuCallback: {
functions: {}
}
}
window["ajaxMenus"][key] = new ajaxMenu(element, key, menuOptions);
})
});
})();