nexusframework 0.3.0-beta.72 → 0.3.0-beta.74

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 (64) hide show
  1. package/LICENSE.md +55 -55
  2. package/README.md +12 -12
  3. package/about/index.json +5 -5
  4. package/about/index.nhp +4 -4
  5. package/icon.png +0 -0
  6. package/index.d.ts +12 -15
  7. package/index.js +94 -81
  8. package/index.js.map +1 -1
  9. package/index.ts +101 -89
  10. package/indexOfSkeleton.nhp +133 -133
  11. package/legacySkeleton.nhp +22 -22
  12. package/loader/overlay.css +1 -1
  13. package/loader/overlay.html +25 -25
  14. package/loader/overlay.scss +152 -152
  15. package/package.json +102 -89
  16. package/scripts/es5/compat.js +101 -0
  17. package/scripts/es5/compat.js.map +1 -0
  18. package/scripts/es5/compat.min.js +2 -0
  19. package/scripts/es5/compat.min.js.map +1 -0
  20. package/scripts/es5/loader.js +0 -0
  21. package/scripts/es5/loader.js.map +0 -0
  22. package/scripts/es5/loader.min.js +1 -1
  23. package/scripts/es5/loader.min.js.map +0 -0
  24. package/scripts/es5/nexusframeworkclient.js +1092 -1103
  25. package/scripts/es5/nexusframeworkclient.js.map +1 -1
  26. package/scripts/es5/nexusframeworkclient.min.js +1 -1
  27. package/scripts/es5/nexusframeworkclient.min.js.map +1 -1
  28. package/scripts/es6/compat.js +65 -0
  29. package/scripts/es6/compat.js.map +1 -0
  30. package/scripts/es6/compat.min.js +2 -0
  31. package/scripts/es6/compat.min.js.map +1 -0
  32. package/scripts/es6/loader.js +0 -0
  33. package/scripts/es6/loader.js.map +0 -0
  34. package/scripts/es6/loader.min.js +1 -1
  35. package/scripts/es6/loader.min.js.map +0 -0
  36. package/scripts/es6/nexusframeworkclient.js +1026 -1049
  37. package/scripts/es6/nexusframeworkclient.js.map +1 -1
  38. package/scripts/es6/nexusframeworkclient.min.js +1 -1
  39. package/scripts/es6/nexusframeworkclient.min.js.map +1 -1
  40. package/scripts/index.d.ts +259 -251
  41. package/scripts/src/compat.ts +62 -0
  42. package/scripts/src/loader.ts +385 -385
  43. package/scripts/src/nexusframeworkclient.ts +1163 -1185
  44. package/scripts/tsconfig.json +11 -11
  45. package/src/cli.d.ts +1 -0
  46. package/src/cli.js +102 -102
  47. package/src/cli.js.map +1 -1
  48. package/src/cli.ts +101 -101
  49. package/src/compileScripts.d.ts +2 -2
  50. package/src/compileScripts.js +145 -145
  51. package/src/compileScripts.js.map +1 -1
  52. package/src/compileScripts.ts +153 -153
  53. package/src/nexusframework.d.ts +177 -168
  54. package/src/nexusframework.js +3578 -3422
  55. package/src/nexusframework.js.map +1 -1
  56. package/src/nexusframework.ts +3631 -3473
  57. package/templates/basic/package.json +3 -3
  58. package/templates/basic/www/skeleton.nhp +1 -1
  59. package/templates/bootstrap/package.json +2 -2
  60. package/templates/bootstrap/www/skeleton.nhp +1 -1
  61. package/templates/bootstrap-material-design/package.json +2 -2
  62. package/templates/bootstrap-material-design/www/skeleton.nhp +1 -1
  63. package/tsconfig.json +25 -22
  64. package/types.d.ts +612 -564
@@ -1,363 +1,388 @@
1
1
  /// <reference path="../index.d.ts" />
2
- Object.defineProperties(window, {
3
- NexusFrameworkTransport: {
4
- configurable: true,
5
- set: function (instance) {
6
- Object.defineProperty(window, "NexusFrameworkTransport", {
7
- value: instance
8
- });
9
- },
10
- get: function () {
11
- var impl;
12
- if ("XMLHttpRequest" in window) {
13
- class NexusFrameworkXMLHttpRequestResponse {
14
- constructor(request, url, hadData) {
15
- this._url = url;
16
- this.request = request;
17
- this.hadData = hadData;
18
- }
19
- get url() {
20
- return this.request.responseURL || this._url;
21
- }
22
- get code() {
23
- return this.request.status;
24
- }
25
- get contentLength() {
26
- return parseInt(this.request.getResponseHeader("content-length")) || this.request.responseText.length;
27
- }
28
- get contentFromJSON() {
29
- if (!this.parsedJson)
30
- this.parsedJson = JSON.parse(this.request.responseText);
31
- return this.parsedJson;
32
- }
33
- get contentAsString() {
34
- return this.request.responseText;
35
- }
36
- get headers() {
37
- if (!this.processedHeaders) {
38
- const headers = this.processedHeaders = {};
39
- this.request.getAllResponseHeaders().split(/\r?\n/g).forEach(function (header) {
40
- const index = header.indexOf(":");
41
- var key, val;
42
- if (index > 0) {
43
- key = header.substring(0, index).trim().toLowerCase();
44
- val = header.substring(index + 1).trim();
45
- }
46
- else
47
- key = header.trim().toLowerCase();
48
- var list = headers[key];
49
- if (!list)
50
- list = headers[key] = [];
51
- if (val)
52
- list.push(val);
53
- });
2
+ (function (window) {
3
+ const BSON = new window['bson'];
4
+ Object.defineProperties(window, {
5
+ NexusFrameworkTransport: {
6
+ configurable: true,
7
+ set: function (instance) {
8
+ Object.defineProperty(window, "NexusFrameworkTransport", {
9
+ value: instance
10
+ });
11
+ },
12
+ get: function () {
13
+ var impl;
14
+ if ("XMLHttpRequest" in window) {
15
+ class NexusFrameworkXMLHttpRequestResponse {
16
+ constructor(request, url, hadData, abResponse) {
17
+ this._url = url;
18
+ this.request = request;
19
+ this.hadData = hadData;
20
+ this.abResponse = abResponse;
54
21
  }
55
- return this.processedHeaders;
56
- }
57
- }
58
- const execute = function (method, url, data, cb, extraHeaders, progcb) {
59
- const request = new XMLHttpRequest();
60
- request.open(method, url, true);
61
- if (extraHeaders)
62
- Object.keys(extraHeaders).forEach(function (key) {
63
- request.setRequestHeader(key, extraHeaders[key]);
64
- });
65
- if (progcb)
66
- request.onprogress = function (ev) {
67
- if (ev.lengthComputable && ev.total)
68
- progcb(ev.loaded, ev.total);
69
- };
70
- request.onreadystatechange = function (e) {
71
- if (request.readyState === XMLHttpRequest.DONE) {
72
- cb(new NexusFrameworkXMLHttpRequestResponse(request, url, !!data));
22
+ get url() {
23
+ return this.request.responseURL || this._url;
73
24
  }
74
- };
75
- const type = data && data.type;
76
- if (type)
77
- switch (type) {
78
- case "":
79
- case "text/urlencoded":
80
- var dat = "";
81
- for (var entry of data.data) {
82
- if (dat)
83
- dat += "&";
84
- dat += encodeURIComponent(entry[0]);
85
- dat += "=";
86
- dat += encodeURIComponent(entry[1]);
87
- }
88
- request.setRequestHeader("Content-Type", "text/urlencoded");
89
- request.send(dat);
90
- break;
91
- case "multipart/form-data":
92
- request.send(data.data);
93
- break;
94
- default:
95
- request.send(data);
25
+ get code() {
26
+ return this.request.status;
96
27
  }
97
- else
98
- request.send(data);
99
- };
100
- impl = {
101
- get: function (url, cb, extraHeaders, progcb) {
102
- execute("GET", url, undefined, cb, extraHeaders, progcb);
103
- },
104
- head: function (url, cb, extraHeaders, progcb) {
105
- execute("HEAD", url, undefined, cb, extraHeaders, progcb);
106
- },
107
- post: function (url, data, cb, extraHeaders, progcb) {
108
- execute("POST", url, data, cb, extraHeaders, progcb);
109
- },
110
- put: function (url, data, cb, extraHeaders, progcb) {
111
- execute("PUT", url, data, cb, extraHeaders, progcb);
112
- },
113
- execute,
114
- del: function (url, cb, extraHeaders, progcb) {
115
- execute("DELETE", url, undefined, cb, extraHeaders, progcb);
116
- }
117
- };
118
- }
119
- else {
120
- impl = {
121
- get(url, cb, extraHeaders) {
122
- cb({
123
- url,
124
- code: 0,
125
- get contentFromJSON() {
126
- throw new Error("No response to parse.");
127
- },
128
- contentAsString: "",
129
- contentLength: 0,
130
- headers: {}
131
- });
132
- },
133
- head(url, cb, extraHeaders) {
134
- cb({
135
- url,
136
- code: 0,
137
- get contentFromJSON() {
138
- throw new Error("No response to parse.");
139
- },
140
- contentAsString: "",
141
- contentLength: 0,
142
- headers: {}
143
- });
144
- },
145
- put(url, data, cb, extraHeaders) {
146
- cb({
147
- url,
148
- code: 0,
149
- get contentFromJSON() {
150
- throw new Error("No response to parse.");
151
- },
152
- contentAsString: "",
153
- contentLength: 0,
154
- headers: {}
155
- });
156
- },
157
- post(url, data, cb, extraHeaders) {
158
- cb({
159
- url,
160
- code: 0,
161
- get contentFromJSON() {
162
- throw new Error("No response to parse.");
163
- },
164
- contentAsString: "",
165
- contentLength: 0,
166
- headers: {}
167
- });
168
- },
169
- execute(method, url, data, cb, extraHeaders) {
170
- cb({
171
- url,
172
- code: 0,
173
- get contentFromJSON() {
174
- throw new Error("No response to parse.");
175
- },
176
- contentAsString: "",
177
- contentLength: 0,
178
- headers: {}
179
- });
180
- },
181
- del(url, cb, extraHeaders) {
182
- cb({
183
- url,
184
- code: 0,
185
- get contentFromJSON() {
186
- throw new Error("No response to parse.");
187
- },
188
- contentAsString: "",
189
- contentLength: 0,
190
- headers: {}
191
- });
192
- }
193
- };
194
- }
195
- Object.defineProperty(window, "NexusFrameworkTransport", {
196
- value: impl
197
- });
198
- return impl;
199
- }
200
- },
201
- NexusFrameworkImpl: {
202
- configurable: true,
203
- set: function (instance) {
204
- Object.defineProperty(window, "NexusFrameworkImpl", {
205
- value: instance
206
- });
207
- },
208
- get: function () {
209
- const loader = window.NexusFrameworkLoader;
210
- const showError = loader.showError;
211
- const debug = /*function(...args: any[]){};*/ console.log.bind(console);
212
- const GA_ANALYTICS = {
213
- reportError: function (err, fatal) {
214
- if (window.ga)
215
- try {
216
- window.ga('send', 'exception', {
217
- 'exDescription': (err.stack || "" + err).replace(/\n/g, "\n\t"),
218
- 'exFatal': fatal
219
- });
28
+ get contentLength() {
29
+ return parseInt(this.request.getResponseHeader("content-length")) || this.request.responseText.length;
220
30
  }
221
- catch (e) {
222
- console.warn(e);
31
+ get contentFromJSON() {
32
+ if (!this.parsedJson)
33
+ this.parsedJson = JSON.parse(this.request.responseText);
34
+ return this.parsedJson;
223
35
  }
224
- },
225
- reportEvent: function (category, action, label, value) {
226
- if (window.ga)
227
- try {
228
- window.ga('send', 'event', category, action, label, value);
36
+ get contentFromBSON() {
37
+ if (!this.parsedBson) {
38
+ var response = this.request.response;
39
+ if (typeof response === "string")
40
+ response = Buffer.from(response, "utf8");
41
+ else
42
+ response = new Buffer(response);
43
+ this.parsedBson = BSON.deserialize(response, { promoteValues: true });
44
+ }
45
+ return this.parsedBson;
229
46
  }
230
- catch (e) {
231
- console.warn(e);
47
+ get contentAsString() {
48
+ return this.request.responseText;
49
+ }
50
+ get contentAsArrayBuffer() {
51
+ return this.request.response;
232
52
  }
233
- },
234
- reportPage: function (path) {
235
- if (window.ga)
53
+ get headers() {
54
+ if (!this.processedHeaders) {
55
+ const headers = this.processedHeaders = {};
56
+ this.request.getAllResponseHeaders().split(/\r?\n/g).forEach(function (header) {
57
+ const index = header.indexOf(":");
58
+ var key, val;
59
+ if (index > 0) {
60
+ key = header.substring(0, index).trim().toLowerCase();
61
+ val = header.substring(index + 1).trim();
62
+ }
63
+ else
64
+ key = header.trim().toLowerCase();
65
+ var list = headers[key];
66
+ if (!list)
67
+ list = headers[key] = [];
68
+ if (val)
69
+ list.push(val);
70
+ });
71
+ }
72
+ return this.processedHeaders;
73
+ }
74
+ }
75
+ const execute = function (method, url, data, cb, extraHeaders, progcb, wantsBinary) {
76
+ const request = new XMLHttpRequest();
77
+ var responseIsArrayBuffer;
236
78
  try {
237
- if (!path)
238
- path = location.pathname;
239
- window.ga('set', 'page', path);
240
- window.ga('send', 'pageview');
79
+ if (!wantsBinary)
80
+ throw false;
81
+ request.responseType = "arraybuffer";
82
+ if (request.responseType !== "arraybuffer") {
83
+ console.error("Could not request arraybuffer");
84
+ throw false;
85
+ }
86
+ responseIsArrayBuffer = true;
241
87
  }
242
88
  catch (e) {
243
- console.warn(e);
89
+ responseIsArrayBuffer = false;
90
+ }
91
+ request.open(method, url, true);
92
+ if (extraHeaders)
93
+ Object.keys(extraHeaders).forEach(function (key) {
94
+ request.setRequestHeader(key, extraHeaders[key]);
95
+ });
96
+ if (progcb)
97
+ request.onprogress = function (ev) {
98
+ if (ev.lengthComputable && ev.total)
99
+ progcb(ev.loaded, ev.total);
100
+ };
101
+ request.onreadystatechange = function (e) {
102
+ if (request.readyState === XMLHttpRequest.DONE)
103
+ cb(new NexusFrameworkXMLHttpRequestResponse(request, url, !!data, responseIsArrayBuffer));
104
+ };
105
+ const type = data && data.type;
106
+ if (type)
107
+ switch (type) {
108
+ case "":
109
+ case "text/urlencoded":
110
+ var dat = "";
111
+ for (var entry of data.data) {
112
+ if (dat)
113
+ dat += "&";
114
+ dat += encodeURIComponent(entry[0]);
115
+ dat += "=";
116
+ dat += encodeURIComponent(entry[1]);
117
+ }
118
+ request.setRequestHeader("Content-Type", "text/urlencoded");
119
+ request.send(dat);
120
+ break;
121
+ case "text/json":
122
+ request.setRequestHeader("Content-Type", "text/json");
123
+ request.send(JSON.stringify(data.data));
124
+ break;
125
+ case "application/bson":
126
+ request.setRequestHeader("Content-Type", "application/bson");
127
+ request.send(BSON.serialize(data.data));
128
+ break;
129
+ case "multipart/form-data":
130
+ request.send(data.data);
131
+ break;
132
+ default:
133
+ request.send(data);
134
+ }
135
+ else
136
+ request.send(data);
137
+ };
138
+ impl = {
139
+ get: function (url, cb, extraHeaders, progcb, wantsBinary) {
140
+ execute("GET", url, undefined, cb, extraHeaders, progcb, wantsBinary);
141
+ },
142
+ head: function (url, cb, extraHeaders, progcb, wantsBinary) {
143
+ execute("HEAD", url, undefined, cb, extraHeaders, progcb, wantsBinary);
144
+ },
145
+ post: function (url, data, cb, extraHeaders, progcb, wantsBinary) {
146
+ execute("POST", url, data, cb, extraHeaders, progcb, wantsBinary);
147
+ },
148
+ put: function (url, data, cb, extraHeaders, progcb, wantsBinary) {
149
+ execute("PUT", url, data, cb, extraHeaders, progcb, wantsBinary);
150
+ },
151
+ execute,
152
+ del: function (url, cb, extraHeaders, progcb, wantsBinary) {
153
+ execute("DELETE", url, undefined, cb, extraHeaders, progcb, wantsBinary);
244
154
  }
155
+ };
245
156
  }
246
- };
247
- const r = document.createElement("a");
248
- const protocol = location.href.match(/^\w+:/)[0];
249
- const resolveUrl = function (url) {
250
- r.setAttribute("href", url);
251
- var href = r.href;
252
- if (/^\/\//.test(href))
253
- href = protocol + href;
254
- return href;
255
- };
256
- const convertResponse = function (res, url = location.href) {
257
- var storage;
258
- return (typeof res.data === "string" || res.data instanceof String) ? {
259
- url,
260
- code: res.code,
261
- contentAsString: res.data,
262
- get contentLength() {
263
- return parseInt(res.headers['content-length'] && res.headers['content-length'][0]) || res.data.length;
264
- },
265
- get contentFromJSON() {
266
- if (!storage)
267
- storage = JSON.parse(res.data);
268
- return storage;
157
+ else
158
+ throw new Error("No transport implementations");
159
+ Object.defineProperty(window, "NexusFrameworkTransport", {
160
+ value: impl
161
+ });
162
+ return impl;
163
+ }
164
+ },
165
+ NexusFrameworkImpl: {
166
+ configurable: true,
167
+ set: function (instance) {
168
+ Object.defineProperty(window, "NexusFrameworkImpl", {
169
+ value: instance
170
+ });
171
+ },
172
+ get: function () {
173
+ const loader = window.NexusFrameworkLoader;
174
+ const showError = loader.showError;
175
+ const debug = /*function(...args: any[]){};*/ console.log.bind(console);
176
+ const GA_ANALYTICS = {
177
+ reportError: function (err, fatal) {
178
+ if (window.ga)
179
+ try {
180
+ window.ga('send', 'exception', {
181
+ 'exDescription': (err.stack || "" + err).replace(/\n/g, "\n\t"),
182
+ 'exFatal': fatal
183
+ });
184
+ }
185
+ catch (e) {
186
+ console.warn(e);
187
+ }
269
188
  },
270
- headers: res.headers
271
- } : {
272
- url,
273
- code: res.code,
274
- get contentAsString() {
275
- if (!storage)
276
- storage = JSON.stringify(res.data);
277
- return storage;
189
+ reportEvent: function (category, action, label, value) {
190
+ if (window.ga)
191
+ try {
192
+ window.ga('send', 'event', category, action, label, value);
193
+ }
194
+ catch (e) {
195
+ console.warn(e);
196
+ }
278
197
  },
279
- contentFromJSON: res.data,
280
- headers: res.headers,
281
- get contentLength() {
282
- var length = parseInt(res.headers['content-length'] && res.headers['content-length'][0]);
283
- if (length)
284
- return length;
285
- if (!storage)
286
- storage = JSON.stringify(res.data);
287
- return storage.length;
198
+ reportPage: function (path) {
199
+ if (window.ga)
200
+ try {
201
+ if (!path)
202
+ path = location.pathname;
203
+ window.ga('set', 'page', path);
204
+ window.ga('send', 'pageview');
205
+ }
206
+ catch (e) {
207
+ console.warn(e);
208
+ }
288
209
  }
289
210
  };
290
- };
291
- const loaderContainerRegex = /(^|\s)loader\-(progress|error)\-container(\s|$)/;
292
- class NexusFrameworkBase {
293
- constructor(url = "/", io) {
294
- this.activerid = 0;
295
- this.components = {};
296
- this.currentUserID = undefined;
297
- this.progressVisible = false;
298
- this.animationTiming = 500;
299
- this.requestPage = this.defaultRequestPage;
300
- this._listeners = {};
301
- url = resolveUrl(url);
302
- if (!/\/$/.test(url))
303
- url += "/";
304
- Object.defineProperties(this, {
305
- io: {
306
- value: io
211
+ const r = document.createElement("a");
212
+ const protocol = location.href.match(/^\w+:/)[0];
213
+ const resolveUrl = function (url) {
214
+ r.setAttribute("href", url);
215
+ var href = r.href;
216
+ if (/^\/\//.test(href))
217
+ href = protocol + href;
218
+ return href;
219
+ };
220
+ const convertResponse = function (res, url = location.href) {
221
+ var storage;
222
+ return (typeof res.data === "string") ? {
223
+ url,
224
+ code: res.code,
225
+ contentAsString: res.data,
226
+ get contentLength() {
227
+ return parseInt(res.headers['content-length'] && res.headers['content-length'][0]) || res.data.length;
228
+ },
229
+ get contentAsArrayBuffer() {
230
+ throw new Error("Not implemented");
231
+ },
232
+ get contentFromBSON() {
233
+ if (!storage)
234
+ storage = JSON.parse(res.data);
235
+ return storage;
236
+ },
237
+ get contentFromJSON() {
238
+ if (!storage)
239
+ storage = JSON.parse(res.data);
240
+ return storage;
241
+ },
242
+ headers: res.headers
243
+ } : {
244
+ url,
245
+ code: res.code,
246
+ get contentAsString() {
247
+ if (!storage)
248
+ storage = JSON.stringify(res.data);
249
+ return storage;
307
250
  },
308
- url: {
309
- value: url
251
+ get contentAsArrayBuffer() {
252
+ throw new Error("Not implemented");
253
+ },
254
+ contentFromJSON: res.data,
255
+ contentFromBSON: res.data,
256
+ headers: res.headers,
257
+ get contentLength() {
258
+ var length = parseInt(res.headers['content-length'] && res.headers['content-length'][0]);
259
+ if (length)
260
+ return length;
261
+ if (!storage)
262
+ storage = JSON.stringify(res.data);
263
+ return storage.length;
310
264
  }
311
- });
312
- this._analytics = GA_ANALYTICS;
313
- }
314
- resolveUrl(url) {
315
- if (/^\w+\:/.test(url))
316
- return url;
317
- return resolveUrl(this.url + url);
318
- }
319
- disableAll(root = document.body) {
320
- const focusable = root.querySelectorAll("a, input, select, textarea, iframe, button, *[focusable], *[tabindex]");
321
- for (var i = 0; i < focusable.length; i++) {
322
- const child = focusable[i];
323
- const tabindex = child.getAttribute("tabindex");
324
- if (tabindex == "-1")
325
- return;
326
- child.setAttribute("data-tabindex", tabindex ? tabindex : "");
327
- child.setAttribute("data-tabindex", "-1");
265
+ };
266
+ };
267
+ const loaderContainerRegex = /(^|\s)loader\-(progress|error)\-container(\s|$)/;
268
+ class NexusFrameworkBase {
269
+ constructor(url = "/", io) {
270
+ this.activerid = 0;
271
+ this.components = {};
272
+ this.currentUserID = undefined;
273
+ this.progressVisible = false;
274
+ this.animationTiming = 500;
275
+ this.requestPage = this.defaultRequestPage;
276
+ this._listeners = {};
277
+ url = resolveUrl(url);
278
+ if (!/\/$/.test(url))
279
+ url += "/";
280
+ Object.defineProperties(this, {
281
+ io: {
282
+ value: io
283
+ },
284
+ url: {
285
+ value: url
286
+ }
287
+ });
288
+ this._analytics = GA_ANALYTICS;
328
289
  }
329
- }
330
- enableAll(root = document.body) {
331
- const focusable = root.querySelectorAll("*[data-tabindex]");
332
- for (var i = 0; i < focusable.length; i++) {
333
- const child = focusable[i];
334
- child.setAttribute("tabindex", child.getAttribute("data-tabindex"));
335
- child.removeAttribute("data-tabindex");
290
+ resolveUrl(url) {
291
+ if (/^\w+\:/.test(url))
292
+ return url;
293
+ return resolveUrl(this.url + url);
336
294
  }
337
- }
338
- get analytics() {
339
- return this._analytics;
340
- }
341
- set analytics(value) {
342
- this._analytics = value ? value : GA_ANALYTICS;
343
- }
344
- reportError(err, fatal) {
345
- console[fatal ? "error" : "warn"](err.stack);
346
- if (this.errorreporter)
347
- this.errorreporter(err, fatal);
348
- }
349
- installErrorReporter(errorreporter) {
350
- this.errorreporter = errorreporter;
351
- }
352
- registerComponent(selector, impl) {
353
- if (impl) {
354
- this.components[selector] = impl;
355
- this.createComponents(document.head);
356
- this.createComponents(document.body);
295
+ disableAll(root = document.body) {
296
+ const focusable = root.querySelectorAll("a, input, select, textarea, iframe, button, *[focusable], *[tabindex]");
297
+ for (var i = 0; i < focusable.length; i++) {
298
+ const child = focusable[i];
299
+ const tabindex = child.getAttribute("tabindex");
300
+ if (tabindex == "-1")
301
+ return;
302
+ child.setAttribute("data-tabindex", tabindex ? tabindex : "");
303
+ child.setAttribute("data-tabindex", "-1");
304
+ }
305
+ }
306
+ enableAll(root = document.body) {
307
+ const focusable = root.querySelectorAll("*[data-tabindex]");
308
+ for (var i = 0; i < focusable.length; i++) {
309
+ const child = focusable[i];
310
+ child.setAttribute("tabindex", child.getAttribute("data-tabindex"));
311
+ child.removeAttribute("data-tabindex");
312
+ }
313
+ }
314
+ get analytics() {
315
+ return this._analytics;
316
+ }
317
+ set analytics(value) {
318
+ this._analytics = value ? value : GA_ANALYTICS;
319
+ }
320
+ reportError(err, fatal) {
321
+ console[fatal ? "error" : "warn"](err.stack);
322
+ if (this.errorreporter)
323
+ this.errorreporter(err, fatal);
324
+ }
325
+ installErrorReporter(errorreporter) {
326
+ this.errorreporter = errorreporter;
327
+ }
328
+ registerComponent(selector, impl) {
329
+ if (impl) {
330
+ this.components[selector] = impl;
331
+ this.createComponents(document.head);
332
+ this.createComponents(document.body);
333
+ }
334
+ else {
335
+ delete this.components[selector];
336
+ var destroy = (root) => {
337
+ const elements = root.querySelectorAll(selector);
338
+ if (!elements.length)
339
+ return;
340
+ for (var i = 0; i < elements.length; i++) {
341
+ const element = elements[i];
342
+ var components = element['__nf_cmapping__'];
343
+ if (!components)
344
+ components = element['__nf_cmapping__'] = {};
345
+ const component = components[selector];
346
+ if (component) {
347
+ try {
348
+ component.destroy();
349
+ }
350
+ catch (e) {
351
+ this.reportError(e);
352
+ }
353
+ }
354
+ }
355
+ };
356
+ destroy(document.head);
357
+ destroy(document.body);
358
+ }
359
+ }
360
+ unregisterComponent(selector, impl) {
357
361
  }
358
- else {
359
- delete this.components[selector];
360
- var destroy = (root) => {
362
+ createComponents(root) {
363
+ Object.keys(this.components).forEach((selector) => {
364
+ const elements = root.querySelectorAll(selector);
365
+ if (!elements.length)
366
+ return;
367
+ for (var i = 0; i < elements.length; i++) {
368
+ const element = elements[i];
369
+ var components = element['__nf_cmapping__'];
370
+ if (!components)
371
+ components = element['__nf_cmapping__'] = {};
372
+ if (components[selector])
373
+ continue;
374
+ const componentFactory = this.components[selector];
375
+ try {
376
+ (components[selector] = new componentFactory()).create(element);
377
+ }
378
+ catch (e) {
379
+ this.reportError(e);
380
+ }
381
+ }
382
+ });
383
+ }
384
+ destroyComponents(root) {
385
+ Object.keys(this.components).forEach((selector) => {
361
386
  const elements = root.querySelectorAll(selector);
362
387
  if (!elements.length)
363
388
  return;
@@ -376,795 +401,747 @@ Object.defineProperties(window, {
376
401
  }
377
402
  }
378
403
  }
379
- };
380
- destroy(document.head);
381
- destroy(document.body);
404
+ });
382
405
  }
383
- }
384
- unregisterComponent(selector, impl) {
385
- }
386
- createComponents(root) {
387
- Object.keys(this.components).forEach((selector) => {
388
- const elements = root.querySelectorAll(selector);
389
- if (!elements.length)
390
- return;
391
- for (var i = 0; i < elements.length; i++) {
392
- const element = elements[i];
393
- var components = element['__nf_cmapping__'];
394
- if (!components)
395
- components = element['__nf_cmapping__'] = {};
396
- if (components[selector])
397
- continue;
398
- const componentFactory = this.components[selector];
399
- try {
400
- (components[selector] = new componentFactory()).create(element);
401
- }
402
- catch (e) {
403
- this.reportError(e);
404
- }
405
- }
406
- });
407
- }
408
- destroyComponents(root) {
409
- Object.keys(this.components).forEach((selector) => {
410
- const elements = root.querySelectorAll(selector);
411
- if (!elements.length)
412
- return;
413
- for (var i = 0; i < elements.length; i++) {
414
- const element = elements[i];
415
- var components = element['__nf_cmapping__'];
416
- if (!components)
417
- components = element['__nf_cmapping__'] = {};
418
- const component = components[selector];
419
- if (component) {
420
- try {
421
- component.destroy();
422
- }
423
- catch (e) {
424
- this.reportError(e);
425
- }
426
- }
427
- }
428
- });
429
- }
430
- restoreComponents(root, state) {
431
- Object.keys(this.components).forEach((selector) => {
432
- const states = state[selector];
433
- if (!states)
434
- return;
435
- const elements = root.querySelectorAll(selector);
436
- if (!elements.length)
437
- return;
438
- for (var i = 0; i < elements.length; i++) {
439
- const element = elements[i];
440
- if (states.length) {
441
- const _state = states.shift();
442
- if (_state) {
443
- var components = element['__nf_cmapping__'];
444
- if (!components)
445
- components = element['__nf_cmapping__'] = {};
446
- var component = components[selector];
447
- if (!component) {
448
- const componentFactory = this.components[selector];
406
+ restoreComponents(root, state) {
407
+ Object.keys(this.components).forEach((selector) => {
408
+ const states = state[selector];
409
+ if (!states)
410
+ return;
411
+ const elements = root.querySelectorAll(selector);
412
+ if (!elements.length)
413
+ return;
414
+ for (var i = 0; i < elements.length; i++) {
415
+ const element = elements[i];
416
+ if (states.length) {
417
+ const _state = states.shift();
418
+ if (_state) {
419
+ var components = element['__nf_cmapping__'];
420
+ if (!components)
421
+ components = element['__nf_cmapping__'] = {};
422
+ var component = components[selector];
423
+ if (!component) {
424
+ const componentFactory = this.components[selector];
425
+ try {
426
+ (component = components[selector] = new componentFactory()).create(element);
427
+ }
428
+ catch (e) {
429
+ this.reportError(e);
430
+ console.warn(e);
431
+ continue;
432
+ }
433
+ }
449
434
  try {
450
- (component = components[selector] = new componentFactory()).create(element);
435
+ component.restore(_state);
451
436
  }
452
437
  catch (e) {
453
438
  this.reportError(e);
454
439
  console.warn(e);
455
- continue;
456
440
  }
457
441
  }
442
+ }
443
+ else
444
+ break;
445
+ }
446
+ });
447
+ }
448
+ saveComponents(root) {
449
+ var state = {};
450
+ Object.keys(this.components).forEach((selector) => {
451
+ const states = state[selector] = [];
452
+ const elements = root.querySelectorAll(selector);
453
+ if (!elements.length)
454
+ return;
455
+ for (var i = 0; i < elements.length; i++) {
456
+ const element = elements[i];
457
+ var components = element['__nf_cmapping__'];
458
+ if (!components)
459
+ components = element['__nf_cmapping__'] = {};
460
+ var component = components[selector];
461
+ if (!component) {
462
+ const componentFactory = this.components[selector];
458
463
  try {
459
- component.restore(_state);
464
+ (component = components[selector] = new componentFactory).create(element);
460
465
  }
461
466
  catch (e) {
467
+ states.push(undefined);
462
468
  this.reportError(e);
463
469
  console.warn(e);
470
+ continue;
464
471
  }
465
472
  }
466
- }
467
- else
468
- break;
469
- }
470
- });
471
- }
472
- saveComponents(root) {
473
- var state = {};
474
- Object.keys(this.components).forEach((selector) => {
475
- const states = state[selector] = [];
476
- const elements = root.querySelectorAll(selector);
477
- if (!elements.length)
478
- return;
479
- for (var i = 0; i < elements.length; i++) {
480
- const element = elements[i];
481
- var components = element['__nf_cmapping__'];
482
- if (!components)
483
- components = element['__nf_cmapping__'] = {};
484
- var component = components[selector];
485
- if (!component) {
486
- const componentFactory = this.components[selector];
487
473
  try {
488
- (component = components[selector] = new componentFactory).create(element);
474
+ states.push(component.save());
489
475
  }
490
476
  catch (e) {
491
477
  states.push(undefined);
492
478
  this.reportError(e);
493
479
  console.warn(e);
494
- continue;
495
480
  }
496
481
  }
482
+ });
483
+ return state;
484
+ }
485
+ initPageSystem(opts) {
486
+ if (!loader)
487
+ return console.error("The NexusFramework Loader is required for the dynamic Page System to work correctly.");
488
+ if (!history.pushState || !history.replaceState)
489
+ return console.warn("This browser is missing an essential feature required for the dynamic Page System.");
490
+ if (this.pagesyshandler)
491
+ return console.warn("Page System already initialized, ignoring additional requests to initialize.");
492
+ opts = opts || {};
493
+ const self = this;
494
+ var pageStatesSize = 0;
495
+ const pageStates = [];
496
+ this.animationTiming = opts.animationTiming || 500;
497
+ const pageStateCacheSize = opts.pageHistoryCacheSize || 25000000;
498
+ const wrapCB = (cb) => {
499
+ return (res) => {
500
+ const user = res.headers['x-logged-user'];
501
+ if (user)
502
+ self.currentUserID = user[0];
503
+ else
504
+ self.currentUserID = undefined;
505
+ debug("Current UID", self.currentUserID);
506
+ cb(res);
507
+ if (res.code === 200)
508
+ setTimeout(() => {
509
+ self._analytics.reportPage();
510
+ });
511
+ };
512
+ };
513
+ loader.showError = function (error) {
514
+ const match = location.href.match(beforeHash);
515
+ const baseurl = match && match[1] || location.href;
516
+ const length = error.stack.length;
517
+ const tooBig = pageStateCacheSize <= length;
497
518
  try {
498
- states.push(component.save());
519
+ const cPageStates = pageStates.length;
520
+ for (var i = 0; i < cPageStates; i++) {
521
+ const state = pageStates[i];
522
+ if (state.url === baseurl) {
523
+ if (tooBig) {
524
+ pageStates.splice(i, 1);
525
+ pageStatesSize -= state.size;
526
+ }
527
+ else {
528
+ state.data = { error };
529
+ state.updated = +new Date;
530
+ pageStatesSize += length - state.size;
531
+ }
532
+ throw true;
533
+ }
534
+ }
535
+ if (tooBig)
536
+ throw true;
537
+ pageStates.push({
538
+ url: baseurl,
539
+ data: { error },
540
+ updated: +new Date,
541
+ size: length
542
+ });
543
+ pageStatesSize += length;
499
544
  }
500
545
  catch (e) {
501
- states.push(undefined);
502
- this.reportError(e);
503
- console.warn(e);
546
+ if (e !== true)
547
+ throw e;
504
548
  }
505
- }
506
- });
507
- return state;
508
- }
509
- initPageSystem(opts) {
510
- if (!loader)
511
- return console.error("The NexusFramework Loader is required for the dynamic Page System to work correctly.");
512
- if (!history.pushState || !history.replaceState)
513
- return console.warn("This browser is missing an essential feature required for the dynamic Page System.");
514
- if (this.pagesyshandler)
515
- return console.warn("Page System already initialized, ignoring additional requests to initialize.");
516
- opts = opts || {};
517
- const self = this;
518
- var pageStatesSize = 0;
519
- const pageStates = [];
520
- this.animationTiming = opts.animationTiming || 500;
521
- const pageStateCacheSize = opts.pageHistoryCacheSize || 25000000;
522
- const wrapCB = (cb) => {
523
- return (res) => {
524
- const user = res.headers['x-logged-user'];
525
- if (user)
526
- self.currentUserID = user[0];
527
- else
528
- self.currentUserID = undefined;
529
- debug("Current UID", self.currentUserID);
530
- cb(res);
531
- if (res.code === 200)
532
- setTimeout(() => {
533
- self._analytics.reportPage();
534
- });
549
+ return showError(error);
535
550
  };
536
- };
537
- loader.showError = function (error) {
538
- const match = location.href.match(beforeHash);
539
- const baseurl = match && match[1] || location.href;
540
- const length = error.stack.length;
541
- const tooBig = pageStateCacheSize <= length;
542
- try {
543
- const cPageStates = pageStates.length;
544
- for (var i = 0; i < cPageStates; i++) {
545
- const state = pageStates[i];
546
- if (state.url === baseurl) {
547
- if (tooBig) {
548
- pageStates.splice(i, 1);
549
- pageStatesSize -= state.size;
550
- }
551
- else {
552
- state.data = { error };
553
- state.updated = +new Date;
554
- pageStatesSize += length - state.size;
555
- }
556
- throw true;
551
+ const transportPageSystem = {
552
+ requestPage(path, cb, post, rid) {
553
+ if (self.pagesysprerequest && !self.pagesysprerequest(path)) {
554
+ self.defaultRequestPage(path, post);
555
+ return;
557
556
  }
558
- }
559
- if (tooBig)
560
- throw true;
561
- pageStates.push({
562
- url: baseurl,
563
- data: { error },
564
- updated: +new Date,
565
- size: length
566
- });
567
- pageStatesSize += length;
568
- }
569
- catch (e) {
570
- if (e !== true)
571
- throw e;
572
- }
573
- return showError(error);
574
- };
575
- const transportPageSystem = {
576
- requestPage(path, cb, post, rid) {
577
- if (self.pagesysprerequest && !self.pagesysprerequest(path)) {
578
- self.defaultRequestPage(path, post);
579
- return;
580
- }
581
- if (!opts.noprogress) {
582
- self.disableAll();
583
- loader.showProgress();
584
- }
585
- const url = self.resolveUrl(":pagesys/" + path);
586
- const _cb = opts.noprogress ? cb : function (res) {
587
- if (opts.noprogress)
588
- cb(res);
589
- else
590
- loader.showProgress(() => {
557
+ if (!opts.noprogress) {
558
+ self.disableAll();
559
+ loader.showProgress();
560
+ }
561
+ const url = self.resolveUrl(":pagesys/" + path);
562
+ const _cb = opts.noprogress ? cb : function (res) {
563
+ if (opts.noprogress)
591
564
  cb(res);
592
- self.enableAll();
593
- });
594
- };
595
- if (post)
596
- window.NexusFrameworkTransport.post(url, post, wrapCB(_cb));
597
- else
598
- window.NexusFrameworkTransport.get(url, wrapCB(_cb));
599
- }
600
- };
601
- if (!opts.noio && !opts.nopagesysio && this.io) {
602
- const io = this.io;
603
- this.pagesysimpl = {
604
- requestPage(path, cb, post, rid) {
605
- if (io.connected) {
606
- if (self.pagesysprerequest && !self.pagesysprerequest(path)) {
607
- self.defaultRequestPage(path, post);
608
- return;
609
- }
610
- if (!opts.noprogress) {
611
- self.disableAll();
612
- loader.showProgress();
613
- }
614
- const headers = {
615
- "referrer": location.href
616
- };
617
- var val = document.cookie;
618
- if (val)
619
- headers['cookie'] = val;
620
- io.emit("page", post ? "POST" : "GET", path, post, headers, function (res) {
621
- if (rid != self.activerid)
565
+ else
566
+ loader.showProgress(() => {
567
+ cb(res);
568
+ self.enableAll();
569
+ });
570
+ };
571
+ if (post)
572
+ window.NexusFrameworkTransport.post(url, post, wrapCB(_cb), undefined, undefined, true);
573
+ else
574
+ window.NexusFrameworkTransport.get(url, wrapCB(_cb), undefined, undefined, true);
575
+ }
576
+ };
577
+ if (!opts.noio && this.io) {
578
+ const io = this.io;
579
+ this.pagesysimpl = {
580
+ requestPage(path, cb, post, rid) {
581
+ if (io.connected) {
582
+ if (self.pagesysprerequest && !self.pagesysprerequest(path)) {
583
+ self.defaultRequestPage(path, post);
622
584
  return;
623
- const cookies = res.headers['set-cookie'];
624
- if (cookies) {
625
- cookies.forEach(function (cookie) {
626
- document.cookie = cookie;
627
- });
628
585
  }
629
- const _cb = opts.noprogress ? cb : function (res) {
630
- if (!opts.noprogress)
631
- cb(res);
632
- else
633
- loader.showProgress(() => {
634
- cb(res);
635
- self.enableAll();
636
- });
586
+ if (!opts.noprogress) {
587
+ self.disableAll();
588
+ loader.showProgress();
589
+ }
590
+ const headers = {
591
+ "referrer": location.href
637
592
  };
638
- wrapCB(_cb)(convertResponse(res, self.resolveUrl(path)));
639
- });
593
+ var val = document.cookie;
594
+ if (val)
595
+ headers['cookie'] = val;
596
+ io.emit("page", post ? "POST" : "GET", path, post, headers, function (res) {
597
+ if (rid != self.activerid)
598
+ return;
599
+ const cookies = res.headers['set-cookie'];
600
+ if (cookies) {
601
+ cookies.forEach(function (cookie) {
602
+ document.cookie = cookie;
603
+ });
604
+ }
605
+ const _cb = opts.noprogress ? cb : function (res) {
606
+ if (!opts.noprogress)
607
+ cb(res);
608
+ else
609
+ loader.showProgress(() => {
610
+ cb(res);
611
+ self.enableAll();
612
+ });
613
+ };
614
+ wrapCB(_cb)(convertResponse(res, self.resolveUrl(path)));
615
+ });
616
+ }
617
+ else
618
+ transportPageSystem.requestPage(path, cb, post, rid);
640
619
  }
641
- else
642
- transportPageSystem.requestPage(path, cb, post, rid);
643
- }
644
- };
645
- }
646
- else
647
- this.pagesysimpl = transportPageSystem;
648
- var base = document.getElementsByTagName("base");
649
- base = base && base[0];
650
- this.pagesysprerequest = opts.prerequest;
651
- this.pagesyshandler = opts.handler || ((res, pageReady) => {
652
- try {
653
- const contentType = res.headers['content-type'][0];
654
- if (!/\/html(;.+)?$/.test(contentType.toLowerCase())) {
655
- throw new Error("Content type is not html");
656
- }
620
+ };
657
621
  }
658
- catch (e) { }
659
- const content = res.contentAsString;
660
- const bodyindex = content.indexOf("<body");
661
- if (bodyindex == -1)
662
- throw new Error("Could not find start of body tag");
663
- const endbodyindex = content.indexOf("</body>") || content.indexOf("</ body>");
664
- if (endbodyindex == -1)
665
- throw new Error("Could not find end of body tag");
666
- const title = content.match(/<title>([^<]+)<\/\s*title>/);
667
- document.title = title && title[1] || "Title Not Set";
668
- const mockhtml = document.createElement("html");
669
- mockhtml.innerHTML = content.substring(bodyindex, endbodyindex) + "</body>";
670
- var loaderScript;
671
- var childs = mockhtml.children;
672
- const toAdd = [];
673
- for (var i = 0; i < childs.length; i++) {
674
- const child = childs[i];
675
- switch (child.nodeName.toUpperCase()) {
676
- case "HEAD":
677
- break;
678
- case "BODY":
679
- i = -1;
680
- childs = child.children;
681
- break;
682
- case "SCRIPT":
683
- const match = child.innerHTML.match(/^NexusFrameworkLoader\.load\((.+)\);?$/);
684
- if (match)
685
- loaderScript = JSON.parse(match[1]);
686
- break;
687
- default:
688
- if (loaderContainerRegex.test(child.className))
622
+ else
623
+ this.pagesysimpl = transportPageSystem;
624
+ var base = document.getElementsByTagName("base");
625
+ base = base && base[0];
626
+ this.pagesysprerequest = opts.prerequest;
627
+ this.pagesyshandler = opts.handler || ((res, pageReady) => {
628
+ try {
629
+ const contentType = res.headers['content-type'][0];
630
+ if (!/\/html(;.+)?$/.test(contentType.toLowerCase())) {
631
+ throw new Error("Content type is not html");
632
+ }
633
+ }
634
+ catch (e) { }
635
+ const content = res.contentAsString;
636
+ const bodyindex = content.indexOf("<body");
637
+ if (bodyindex == -1)
638
+ throw new Error("Could not find start of body tag");
639
+ const endbodyindex = content.indexOf("</body>") || content.indexOf("</ body>");
640
+ if (endbodyindex == -1)
641
+ throw new Error("Could not find end of body tag");
642
+ const title = content.match(/<title>([^<]+)<\/\s*title>/);
643
+ document.title = title && title[1] || "Title Not Set";
644
+ const mockhtml = document.createElement("html");
645
+ mockhtml.innerHTML = content.substring(bodyindex, endbodyindex) + "</body>";
646
+ var loaderScript;
647
+ var childs = mockhtml.children;
648
+ const toAdd = [];
649
+ for (var i = 0; i < childs.length; i++) {
650
+ const child = childs[i];
651
+ switch (child.nodeName.toUpperCase()) {
652
+ case "HEAD":
653
+ break;
654
+ case "BODY":
655
+ i = -1;
656
+ childs = child.children;
657
+ break;
658
+ case "SCRIPT":
659
+ const match = child.innerHTML.match(/^NexusFrameworkLoader\.load\((.+)\);?$/);
660
+ if (match)
661
+ loaderScript = JSON.parse(match[1]);
689
662
  break;
690
- toAdd.push(child);
663
+ default:
664
+ if (loaderContainerRegex.test(child.className))
665
+ break;
666
+ toAdd.push(child);
667
+ }
691
668
  }
692
- }
693
- if (!toAdd.length)
694
- throw new Error("Nothing found in response to add to page");
695
- if (!loaderScript)
696
- throw new Error("NexusFrameworkLoader script not found...");
697
- childs = document.body.children;
698
- for (var i = childs.length - 1; i >= 0; i--) {
699
- const child = childs[i];
700
- switch (child.nodeName.toUpperCase()) {
701
- case "LINK":
702
- case "SCRIPT":
703
- break;
704
- default:
705
- if (loaderContainerRegex.test(child.className))
669
+ if (!toAdd.length)
670
+ throw new Error("Nothing found in response to add to page");
671
+ if (!loaderScript)
672
+ throw new Error("NexusFrameworkLoader script not found...");
673
+ childs = document.body.children;
674
+ for (var i = childs.length - 1; i >= 0; i--) {
675
+ const child = childs[i];
676
+ switch (child.nodeName.toUpperCase()) {
677
+ case "LINK":
678
+ case "SCRIPT":
706
679
  break;
707
- document.body.removeChild(child);
680
+ default:
681
+ if (loaderContainerRegex.test(child.className))
682
+ break;
683
+ document.body.removeChild(child);
684
+ }
708
685
  }
709
- }
710
- const fragment = document.createDocumentFragment();
711
- toAdd.forEach((el) => {
712
- fragment.appendChild(el);
713
- this.createComponents(el);
714
- });
715
- document.body.appendChild(fragment);
716
- loader.load(loaderScript, function () {
717
- self.progressVisible = true;
718
- loader.resetProgress();
719
- pageReady();
686
+ const fragment = document.createDocumentFragment();
687
+ toAdd.forEach((el) => {
688
+ fragment.appendChild(el);
689
+ this.createComponents(el);
690
+ });
691
+ document.body.appendChild(fragment);
692
+ loader.load(loaderScript, function () {
693
+ self.progressVisible = true;
694
+ loader.resetProgress();
695
+ pageReady();
696
+ });
697
+ return true;
720
698
  });
721
- return true;
722
- });
723
- var forwardPopState;
724
- const beforeHash = /^([^#]+)(#.*)?$/;
725
- var chash = location.href.match(beforeHash)[1];
726
- const startsWith = new RegExp("^" + this.url.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + "(.*)$", "i");
727
- class AnchorElementComponent {
728
- constructor() {
729
- this.handler = (e) => {
730
- if (this.element.hasAttribute("data-nopagesys") || this.element.hasAttribute("data-nodynamic"))
731
- return;
732
- const href = this.element.getAttribute("href");
733
- if (!href || !href.length)
734
- return;
735
- var url = this.element.href;
736
- const bhash = url.match(beforeHash);
737
- if (bhash[2] && chash === bhash[1])
738
- return;
739
- if (startsWith.test(url))
740
- try {
741
- const match = url.match(/^(.+)#.*$/);
742
- if (match)
743
- url = match[1];
744
- self.requestPage(url.substring(self.url.length));
699
+ var forwardPopState;
700
+ const beforeHash = /^([^#]+)(#.*)?$/;
701
+ var chash = location.href.match(beforeHash)[1];
702
+ const startsWith = new RegExp("^" + this.url.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + "(.*)$", "i");
703
+ class AnchorElementComponent {
704
+ constructor() {
705
+ this.handler = (e) => {
706
+ if (this.element.hasAttribute("data-nopagesys") || this.element.hasAttribute("data-nodynamic"))
707
+ return;
708
+ const href = this.element.getAttribute("href");
709
+ if (!href || !href.length)
710
+ return;
711
+ var url = this.element.href;
712
+ const bhash = url.match(beforeHash);
713
+ if (bhash[2] && chash === bhash[1])
714
+ return;
715
+ if (startsWith.test(url))
745
716
  try {
746
- e.stopPropagation();
717
+ const match = url.match(/^(.+)#.*$/);
718
+ if (match)
719
+ url = match[1];
720
+ self.requestPage(url.substring(self.url.length));
721
+ try {
722
+ e.stopPropagation();
723
+ }
724
+ catch (e) { }
725
+ try {
726
+ e.preventDefault();
727
+ }
728
+ catch (e) { }
747
729
  }
748
- catch (e) { }
749
- try {
750
- e.preventDefault();
730
+ catch (e) {
731
+ console.warn(e);
751
732
  }
752
- catch (e) { }
753
- }
754
- catch (e) {
755
- console.warn(e);
756
- }
757
- else
758
- debug("Navigating", url);
759
- };
760
- }
761
- create(element) {
762
- element.addEventListener("click", this.handler);
763
- this.element = element;
764
- }
765
- destroy() {
766
- this.element.removeEventListener("click", this.handler);
733
+ else
734
+ debug("Navigating", url);
735
+ };
736
+ }
737
+ create(element) {
738
+ element.addEventListener("click", this.handler);
739
+ this.element = element;
740
+ }
741
+ destroy() {
742
+ this.element.removeEventListener("click", this.handler);
743
+ }
744
+ restore(data) { }
745
+ save() { }
767
746
  }
768
- restore(data) { }
769
- save() { }
770
- }
771
- class FormElementComponent {
772
- constructor() {
773
- this.handler = (e) => {
774
- if (this.element.hasAttribute("data-nopagesys") || this.element.hasAttribute("data-nodynamic"))
775
- return;
776
- const method = this.element.getAttribute("method") || "get";
777
- const enctype = this.element.getAttribute("enctype") || "text/urlencoded";
778
- const action = this.element.getAttribute("action") || "";
779
- var url = resolveUrl(action);
780
- if (startsWith.test(url)) {
781
- try {
782
- const match = url.match(/^(.+)#.*$/);
783
- if (match)
784
- url = match[1];
785
- const formData = new FormData(this.element);
786
- loader.showProgress(undefined, "Submitting Form", "Your form data is being processed");
787
- if (method.trim().toLowerCase() === "post")
788
- self.requestPage(url.substring(self.url.length), { type: enctype, data: formData });
789
- else {
790
- var first = true;
791
- var reqUrl = url.substring(self.url.length) + "?";
792
- for (var entry of formData) {
793
- if (first)
794
- first = false;
795
- else
796
- reqUrl += "&";
797
- reqUrl += encodeURIComponent(entry[0]);
798
- reqUrl += "=";
799
- reqUrl += encodeURIComponent(entry[1]);
800
- }
801
- self.requestPage(reqUrl);
802
- }
747
+ class FormElementComponent {
748
+ constructor() {
749
+ this.handler = (e) => {
750
+ if (this.element.hasAttribute("data-nopagesys") || this.element.hasAttribute("data-nodynamic"))
751
+ return;
752
+ const method = this.element.getAttribute("method") || "get";
753
+ const enctype = this.element.getAttribute("enctype") || "text/urlencoded";
754
+ const action = this.element.getAttribute("action") || "";
755
+ var url = resolveUrl(action);
756
+ if (startsWith.test(url)) {
803
757
  try {
804
- e.stopPropagation();
758
+ const match = url.match(/^(.+)#.*$/);
759
+ if (match)
760
+ url = match[1];
761
+ const formData = new FormData(this.element);
762
+ loader.showProgress(undefined, "Submitting Form", "Your form data is being processed");
763
+ if (method.trim().toLowerCase() === "post")
764
+ self.requestPage(url.substring(self.url.length), { type: enctype, data: formData });
765
+ else {
766
+ var first = true;
767
+ var reqUrl = url.substring(self.url.length) + "?";
768
+ for (var entry of formData) {
769
+ if (first)
770
+ first = false;
771
+ else
772
+ reqUrl += "&";
773
+ reqUrl += encodeURIComponent(entry[0]);
774
+ reqUrl += "=";
775
+ reqUrl += encodeURIComponent(entry[1]);
776
+ }
777
+ self.requestPage(reqUrl);
778
+ }
779
+ try {
780
+ e.stopPropagation();
781
+ }
782
+ catch (e) { }
783
+ try {
784
+ e.preventDefault();
785
+ }
786
+ catch (e) { }
787
+ Array.prototype.forEach.call(this.element.querySelectorAll("a, input, select, textarea, iframe, button, *[name]"), function (el) {
788
+ el.setAttribute("disabled", "disabled");
789
+ el.className += " disabled";
790
+ });
791
+ Array.prototype.forEach.call(this.element.querySelectorAll("button:not([type]), button[type=submit]"), function (button) {
792
+ button.innerHTML = "Processing Request";
793
+ });
794
+ Array.prototype.forEach.call(this.element.querySelectorAll("input[type=submit]"), function (input) {
795
+ input.value = "Processing Request";
796
+ });
797
+ return;
805
798
  }
806
- catch (e) { }
807
- try {
808
- e.preventDefault();
799
+ catch (e) {
800
+ debug(e);
809
801
  }
810
- catch (e) { }
811
- Array.prototype.forEach.call(this.element.querySelectorAll("a, input, select, textarea, iframe, button, *[name]"), function (el) {
812
- el.setAttribute("disabled", "disabled");
813
- el.className += " disabled";
814
- });
815
- Array.prototype.forEach.call(this.element.querySelectorAll("button:not([type]), button[type=submit]"), function (button) {
816
- button.innerHTML = "Processing Request";
817
- });
818
- Array.prototype.forEach.call(this.element.querySelectorAll("input[type=submit]"), function (input) {
819
- input.value = "Processing Request";
820
- });
821
- return;
822
- }
823
- catch (e) {
824
- debug(e);
825
802
  }
826
- }
827
- debug("Submitting", url);
828
- };
829
- }
830
- create(element) {
831
- element.addEventListener("submit", this.handler);
832
- this.element = element;
833
- }
834
- destroy() {
835
- this.element.removeEventListener("submit", this.handler);
836
- }
837
- restore(data) { }
838
- save() { }
839
- }
840
- const requestPage = this.requestPage = (path, post, replace = false) => {
841
- const match = path.match(/\.([^\/]+)([\?#].*)?$/);
842
- if (match && match[0] !== "htm" && match[0] !== "html") {
843
- this.defaultRequestPage(path, post);
844
- debug("Ignoring navigation", path, match);
803
+ debug("Submitting", url);
804
+ };
805
+ }
806
+ create(element) {
807
+ element.addEventListener("submit", this.handler);
808
+ this.element = element;
809
+ }
810
+ destroy() {
811
+ this.element.removeEventListener("submit", this.handler);
812
+ }
813
+ restore(data) { }
814
+ save() { }
845
815
  }
846
- else {
847
- debug("requestPage", path);
848
- const rid = ++self.activerid;
849
- const baseurl = this.resolveUrl(path);
850
- const fullurl = baseurl + (match && match[2] || "");
851
- if (replace)
852
- history.replaceState(!!post, "Loading...", fullurl);
853
- else {
854
- history.pushState(!!post, "Loading...", fullurl);
855
- chash = fullurl.match(beforeHash)[1];
856
- window.scrollTo(0, 0);
816
+ const requestPage = this.requestPage = (path, post, replace = false) => {
817
+ const match = path.match(/\.([^\/]+)([\?#].*)?$/);
818
+ if (match && match[0] !== "htm" && match[0] !== "html") {
819
+ this.defaultRequestPage(path, post);
820
+ debug("Ignoring navigation", path, match);
857
821
  }
858
- loader.resetError();
859
- loader.resetProgress();
860
- this.pagesysimpl.requestPage(path, (res) => {
861
- try {
862
- if (rid !== self.activerid)
863
- return;
864
- if (!res.code) {
865
- loader.showProgress(undefined, "Connection Issue", "Check your network and try again");
866
- document.title = "Connection Issue";
867
- history.replaceState(res.hadData, "Connection Issue", fullurl);
868
- setTimeout(function () {
869
- if (rid !== self.activerid)
870
- return;
871
- requestPage(path, post, true);
872
- }, 900000);
873
- return;
874
- }
875
- else if (res.code === 502 || res.code === 503) {
876
- loader.showProgress(undefined, "Scheduled Maintenance", "Sorry but this website is undergoing scheduled maintenance");
877
- document.title = "Scheduled Maintenance";
878
- history.replaceState(res.hadData, "Scheduled Maintenance", fullurl);
879
- setTimeout(function () {
880
- if (rid !== self.activerid)
881
- return;
882
- requestPage(path, post, true);
883
- }, 900000);
884
- return;
885
- }
886
- const location = res.headers['x-location'] || res.headers['location'];
887
- if (location) {
888
- const url = resolveUrl(location[0]);
889
- if (startsWith.test(url)) {
890
- this.requestPage(url.substring(this.url.length), undefined, true);
822
+ else {
823
+ debug("requestPage", path);
824
+ const rid = ++self.activerid;
825
+ const baseurl = this.resolveUrl(path);
826
+ const fullurl = baseurl + (match && match[2] || "");
827
+ if (replace)
828
+ history.replaceState(!!post, "Loading...", fullurl);
829
+ else {
830
+ history.pushState(!!post, "Loading...", fullurl);
831
+ chash = fullurl.match(beforeHash)[1];
832
+ window.scrollTo(0, 0);
833
+ }
834
+ loader.resetError();
835
+ loader.resetProgress();
836
+ this.pagesysimpl.requestPage(path, (res) => {
837
+ try {
838
+ if (rid !== self.activerid)
839
+ return;
840
+ if (!res.code) {
841
+ loader.showProgress(undefined, "Connection Issue", "Check your network and try again");
842
+ document.title = "Connection Issue";
843
+ history.replaceState(res.hadData, "Connection Issue", fullurl);
844
+ setTimeout(function () {
845
+ if (rid !== self.activerid)
846
+ return;
847
+ requestPage(path, post, true);
848
+ }, 900000);
891
849
  return;
892
850
  }
893
- console.warn("Requested redirect to external url:", url);
894
- window.location.href = url;
895
- return;
896
- }
897
- const contentDisposition = res.headers['content-disposition'];
898
- if (contentDisposition && contentDisposition[0].toLowerCase() == "attachment")
899
- throw new Error("Attachment disposition");
900
- this.pagesyshandler(res, function () {
901
- if (rid !== self.activerid)
851
+ else if (res.code === 502 || res.code === 503) {
852
+ loader.showProgress(undefined, "Scheduled Maintenance", "Sorry but this website is undergoing scheduled maintenance");
853
+ document.title = "Scheduled Maintenance";
854
+ history.replaceState(res.hadData, "Scheduled Maintenance", fullurl);
855
+ setTimeout(function () {
856
+ if (rid !== self.activerid)
857
+ return;
858
+ requestPage(path, post, true);
859
+ }, 900000);
902
860
  return;
903
- try {
904
- const title = document.title;
905
- const contentType = res.headers['content-type'];
906
- const length = res.contentLength;
907
- const tooBig = pageStateCacheSize <= length;
908
- const stateData = tooBig ? undefined : {
909
- title: title,
910
- user: self.currentUserID,
911
- scroll: [window.scrollX, window.scrollY],
912
- body: self.saveComponents(document.body),
913
- basehref: base ? base['href'] : undefined,
914
- response: res
915
- };
916
- var i;
917
- const cPageStates = pageStates.length;
861
+ }
862
+ const location = res.headers['x-location'] || res.headers['location'];
863
+ if (location) {
864
+ const url = resolveUrl(location[0]);
865
+ if (startsWith.test(url)) {
866
+ this.requestPage(url.substring(this.url.length), undefined, true);
867
+ return;
868
+ }
869
+ console.warn("Requested redirect to external url:", url);
870
+ window.location.href = url;
871
+ return;
872
+ }
873
+ const contentDisposition = res.headers['content-disposition'];
874
+ if (contentDisposition && contentDisposition[0].toLowerCase() == "attachment")
875
+ throw new Error("Attachment disposition");
876
+ this.pagesyshandler(res, function () {
877
+ if (rid !== self.activerid)
878
+ return;
918
879
  try {
919
- for (i = 0; i < cPageStates; i++) {
920
- const state = pageStates[i];
921
- if (state.url === baseurl) {
922
- if (tooBig) {
923
- pageStates.splice(i, 1);
924
- pageStatesSize -= state.size;
925
- }
926
- else {
927
- state.data = stateData;
928
- state.updated = +new Date;
929
- pageStatesSize += length - state.size;
880
+ const title = document.title;
881
+ const length = res.contentLength;
882
+ const tooBig = pageStateCacheSize <= length;
883
+ const stateData = tooBig ? undefined : {
884
+ title: title,
885
+ user: self.currentUserID,
886
+ scroll: [window.scrollX, window.scrollY],
887
+ body: self.saveComponents(document.body),
888
+ basehref: base ? base['href'] : undefined,
889
+ response: res
890
+ };
891
+ var i;
892
+ const cPageStates = pageStates.length;
893
+ try {
894
+ for (i = 0; i < cPageStates; i++) {
895
+ const state = pageStates[i];
896
+ if (state.url === baseurl) {
897
+ if (tooBig) {
898
+ pageStates.splice(i, 1);
899
+ pageStatesSize -= state.size;
900
+ }
901
+ else {
902
+ state.data = stateData;
903
+ state.updated = +new Date;
904
+ pageStatesSize += length - state.size;
905
+ }
906
+ throw true;
930
907
  }
908
+ }
909
+ if (!tooBig) {
910
+ pageStates.push({
911
+ url: baseurl,
912
+ data: stateData,
913
+ updated: +new Date,
914
+ size: length
915
+ });
916
+ pageStatesSize += length;
931
917
  throw true;
932
918
  }
919
+ else
920
+ debug("Response too big to store", baseurl, length);
933
921
  }
934
- if (!tooBig) {
935
- pageStates.push({
936
- url: baseurl,
937
- data: stateData,
938
- updated: +new Date,
939
- size: length
940
- });
941
- pageStatesSize += length;
942
- throw true;
943
- }
944
- else
945
- debug("Response too big to store", baseurl, length);
946
- }
947
- catch (e) {
948
- if (e === true) {
949
- const over = pageStatesSize - pageStateCacheSize;
950
- if (over > 0) {
951
- pageStates.sort(function (a, b) {
952
- return a.updated - b.updated;
953
- });
954
- var found = 0;
955
- for (i = 0; i < cPageStates; i++) {
956
- found += pageStates[i].size;
957
- if (found >= over)
958
- break;
922
+ catch (e) {
923
+ if (e === true) {
924
+ const over = pageStatesSize - pageStateCacheSize;
925
+ if (over > 0) {
926
+ pageStates.sort(function (a, b) {
927
+ return a.updated - b.updated;
928
+ });
929
+ var found = 0;
930
+ for (i = 0; i < cPageStates; i++) {
931
+ found += pageStates[i].size;
932
+ if (found >= over)
933
+ break;
934
+ }
935
+ i++;
936
+ pageStates.splice(0, i);
937
+ debug("Trimmed", i, "items...");
959
938
  }
960
- i++;
961
- pageStates.splice(0, i);
962
- debug("Trimmed", i, "items...");
963
939
  }
940
+ else
941
+ throw e;
964
942
  }
943
+ history.replaceState(res.hadData, document.title, fullurl);
944
+ self.emit("page", baseurl, path);
945
+ }
946
+ catch (e) {
947
+ debug(e);
948
+ if (replace)
949
+ window.location.reload(true);
965
950
  else
966
- throw e;
951
+ try {
952
+ chash = undefined;
953
+ forwardPopState = [path, post];
954
+ debug("Going backwards");
955
+ history.go(-1);
956
+ }
957
+ catch (e) { }
967
958
  }
968
- history.replaceState(res.hadData, document.title, fullurl);
969
- self.emit("page", baseurl, path);
970
- }
971
- catch (e) {
972
- debug(e);
973
- if (replace)
974
- window.location.reload(true);
975
- else
976
- try {
977
- chash = undefined;
978
- forwardPopState = [path, post];
979
- debug("Going backwards");
980
- history.go(-1);
981
- }
982
- catch (e) { }
983
- }
984
- });
959
+ });
960
+ }
961
+ catch (e) {
962
+ debug(e);
963
+ if (replace)
964
+ window.location.reload(true);
965
+ else
966
+ try {
967
+ chash = undefined;
968
+ forwardPopState = [path, post];
969
+ debug("Going backwards");
970
+ history.go(-1);
971
+ }
972
+ catch (e) { }
973
+ }
974
+ }, post, rid);
975
+ }
976
+ };
977
+ this.registerComponent("a", AnchorElementComponent);
978
+ this.registerComponent("form", FormElementComponent);
979
+ window.addEventListener('popstate', (e) => {
980
+ try {
981
+ var state;
982
+ const bhash = location.href.match(beforeHash);
983
+ const cStates = pageStates.length;
984
+ const baseurl = bhash[1];
985
+ for (var i = 0; i < cStates; i++) {
986
+ const _state = pageStates[i];
987
+ if (_state.url === baseurl) {
988
+ state = _state;
989
+ break;
990
+ }
985
991
  }
986
- catch (e) {
987
- debug(e);
988
- if (replace)
989
- window.location.reload(true);
990
- else
991
- try {
992
- chash = undefined;
993
- forwardPopState = [path, post];
994
- debug("Going backwards");
995
- history.go(-1);
996
- }
997
- catch (e) { }
992
+ const hasState = !!state;
993
+ const rid = ++self.activerid;
994
+ const error = hasState && state.data.error;
995
+ if (error) {
996
+ showError(error);
997
+ return;
998
998
  }
999
- }, post, rid);
1000
- }
1001
- };
1002
- this.registerComponent("a", AnchorElementComponent);
1003
- this.registerComponent("form", FormElementComponent);
1004
- window.addEventListener('popstate', (e) => {
1005
- try {
1006
- var state;
1007
- const bhash = location.href.match(beforeHash);
1008
- const cStates = pageStates.length;
1009
- const baseurl = bhash[1];
1010
- for (var i = 0; i < cStates; i++) {
1011
- const _state = pageStates[i];
1012
- if (_state.url === baseurl) {
1013
- state = _state;
1014
- break;
999
+ if (forwardPopState) {
1000
+ debug("forwardPopState", forwardPopState);
1001
+ const forward = forwardPopState;
1002
+ setTimeout(() => {
1003
+ if (rid === self.activerid)
1004
+ self.defaultRequestPage(forward[0], forward[1]);
1005
+ });
1006
+ forwardPopState = undefined;
1007
+ return;
1015
1008
  }
1016
- }
1017
- const hasState = !!state;
1018
- const rid = ++self.activerid;
1019
- const error = hasState && state.data.error;
1020
- if (error) {
1021
- showError(error);
1022
- return;
1023
- }
1024
- if (forwardPopState) {
1025
- debug("forwardPopState", forwardPopState);
1026
- const forward = forwardPopState;
1027
- setTimeout(() => {
1028
- if (rid === self.activerid)
1029
- self.defaultRequestPage(forward[0], forward[1]);
1030
- });
1031
- forwardPopState = undefined;
1032
- return;
1033
- }
1034
- if (chash === baseurl) {
1035
- debug("Only hash has changed...", baseurl);
1036
- return;
1037
- }
1038
- console.log(baseurl, chash, e);
1039
- console.trace();
1040
- chash = bhash[1];
1041
- if (e.state)
1042
- alert("You submitted data to this page, which cannot be re-sent. Because of this, what you're viewing may not be the same now.");
1043
- if (!hasState)
1044
- throw new Error("No state for: " + baseurl + ", reloading...");
1045
- if (state.data.user != self.currentUserID)
1046
- throw new Error("User has changed since state was created, reloading...");
1047
- document.title = state.data.title;
1048
- loader.resetProgress();
1049
- loader.resetError();
1050
- self.pagesyshandler(state.data.response, function (err) {
1051
- if (rid !== self.activerid)
1009
+ if (chash === baseurl) {
1010
+ debug("Only hash has changed...", baseurl);
1052
1011
  return;
1053
- try {
1054
- if (err)
1055
- throw err;
1056
- if (state.data.body)
1057
- self.restoreComponents(document.body, state.data.body);
1058
- if (state.data.scroll)
1059
- window.scrollTo.apply(window, state.data.scroll);
1060
- debug("Used stored page state!", state);
1061
1012
  }
1062
- catch (err) {
1063
- debug(err);
1064
- var url = location.href;
1065
- if (startsWith.test(url)) {
1066
- try {
1067
- if (/reloading\.\.\.$/.test(err.message)) {
1068
- self.requestPage(url.substring(self.url.length), undefined, true);
1069
- return;
1013
+ chash = bhash[1];
1014
+ if (e.state)
1015
+ alert("You submitted data to this page, which cannot be re-sent. Because of this, what you're viewing may not be the same now.");
1016
+ if (!hasState)
1017
+ throw new Error("No state for: " + baseurl + ", reloading...");
1018
+ if (state.data.user != self.currentUserID)
1019
+ throw new Error("User has changed since state was created, reloading...");
1020
+ document.title = state.data.title;
1021
+ loader.resetProgress();
1022
+ loader.resetError();
1023
+ self.pagesyshandler(state.data.response, function (err) {
1024
+ if (rid !== self.activerid)
1025
+ return;
1026
+ try {
1027
+ if (err)
1028
+ throw err;
1029
+ if (state.data.body)
1030
+ self.restoreComponents(document.body, state.data.body);
1031
+ if (state.data.scroll)
1032
+ window.scrollTo.apply(window, state.data.scroll);
1033
+ debug("Used stored page state!", state);
1034
+ }
1035
+ catch (err) {
1036
+ debug(err);
1037
+ var url = location.href;
1038
+ if (startsWith.test(url)) {
1039
+ try {
1040
+ if (/reloading\.\.\.$/.test(err.message)) {
1041
+ self.requestPage(url.substring(self.url.length), undefined, true);
1042
+ return;
1043
+ }
1044
+ console.error("Unknown error occured, actually navigating to page...");
1045
+ }
1046
+ catch (e) {
1047
+ console.error(e);
1070
1048
  }
1071
- console.error("Unknown error occured, actually navigating to page...");
1072
1049
  }
1073
- catch (e) {
1074
- console.error(e);
1050
+ location.reload(true);
1051
+ }
1052
+ });
1053
+ }
1054
+ catch (err) {
1055
+ debug(err);
1056
+ var url = location.href;
1057
+ if (startsWith.test(url)) {
1058
+ try {
1059
+ if (/reloading\.\.\.$/.test(err.message)) {
1060
+ self.requestPage(url.substring(self.url.length), undefined, true);
1061
+ return;
1075
1062
  }
1063
+ console.error("Unknown error occured, actually navigating to page...");
1076
1064
  }
1077
- location.reload(true);
1078
- }
1079
- });
1080
- }
1081
- catch (err) {
1082
- debug(err);
1083
- var url = location.href;
1084
- if (startsWith.test(url)) {
1085
- try {
1086
- if (/reloading\.\.\.$/.test(err.message)) {
1087
- self.requestPage(url.substring(self.url.length), undefined, true);
1088
- return;
1065
+ catch (e) {
1066
+ console.error(e);
1089
1067
  }
1090
- console.error("Unknown error occured, actually navigating to page...");
1091
- }
1092
- catch (e) {
1093
- console.error(e);
1094
1068
  }
1069
+ location.reload(true);
1095
1070
  }
1096
- location.reload(true);
1097
- }
1098
- });
1099
- return true;
1100
- }
1101
- defaultRequestPage(path, post) {
1102
- if (post)
1103
- throw new Error("Posting is not supported without an initialized page system, yet");
1104
- else
1105
- location.href = this.resolveUrl(path);
1106
- }
1107
- on(event, cb) {
1108
- var listeners = this._listeners[event];
1109
- if (listeners)
1110
- listeners.push(cb);
1111
- else
1112
- this._listeners[event] = listeners = [cb];
1113
- }
1114
- off(event, cb) {
1115
- var index;
1116
- var listeners = this._listeners[event];
1117
- if (listeners && (index = listeners.indexOf(cb)) > -1)
1118
- listeners.splice(index, 1);
1119
- }
1120
- emit(event, ...args) {
1121
- const self = this;
1122
- const listeners = this._listeners[event];
1123
- if (listeners)
1124
- listeners.forEach(function (cb) {
1125
- cb.apply(self, args);
1126
- });
1127
- }
1128
- }
1129
- var impl;
1130
- if (window.io)
1131
- impl = class NexusFrameworkWithIO extends NexusFrameworkBase {
1132
- constructor(url) {
1133
- super(url, window.io({
1134
- path: "/:io"
1135
- }));
1136
- const io = this.io;
1137
- io.on("connect", function () {
1138
- io.emit("init", loader.requestedResources());
1139
1071
  });
1072
+ return true;
1140
1073
  }
1141
- };
1142
- else
1143
- impl = class NexusFrameworkNoIO extends NexusFrameworkBase {
1144
- constructor(url) {
1145
- super(url);
1074
+ get currentUser() {
1075
+ return this.currentUserID;
1146
1076
  }
1147
- };
1148
- Object.defineProperty(window, "NexusFrameworkImpl", {
1149
- value: impl
1150
- });
1151
- return impl;
1152
- }
1153
- },
1154
- NexusFrameworkClient: {
1155
- configurable: true,
1156
- set: function (instance) {
1157
- Object.defineProperty(window, "NexusFrameworkClient", {
1158
- value: instance
1159
- });
1077
+ defaultRequestPage(path, post) {
1078
+ if (post)
1079
+ throw new Error("Posting is not supported without an initialized page system, yet");
1080
+ else
1081
+ location.href = this.resolveUrl(path);
1082
+ }
1083
+ on(event, cb) {
1084
+ var listeners = this._listeners[event];
1085
+ if (listeners)
1086
+ listeners.push(cb);
1087
+ else
1088
+ this._listeners[event] = listeners = [cb];
1089
+ }
1090
+ off(event, cb) {
1091
+ var index;
1092
+ var listeners = this._listeners[event];
1093
+ if (listeners && (index = listeners.indexOf(cb)) > -1)
1094
+ listeners.splice(index, 1);
1095
+ }
1096
+ emit(event, ...args) {
1097
+ const self = this;
1098
+ const listeners = this._listeners[event];
1099
+ if (listeners)
1100
+ listeners.forEach(function (cb) {
1101
+ cb.apply(self, args);
1102
+ });
1103
+ }
1104
+ }
1105
+ var impl;
1106
+ if (window.io)
1107
+ impl = class NexusFrameworkWithIO extends NexusFrameworkBase {
1108
+ constructor(url) {
1109
+ super(url, window.io({
1110
+ path: "/:io"
1111
+ }));
1112
+ const io = this.io;
1113
+ io.on("connect", function () {
1114
+ io.emit("init", loader.requestedResources());
1115
+ });
1116
+ }
1117
+ };
1118
+ else
1119
+ impl = class NexusFrameworkNoIO extends NexusFrameworkBase {
1120
+ constructor(url) {
1121
+ super(url);
1122
+ }
1123
+ };
1124
+ Object.defineProperty(window, "NexusFrameworkImpl", {
1125
+ value: impl
1126
+ });
1127
+ return impl;
1128
+ }
1160
1129
  },
1161
- get: function () {
1162
- const instance = new window.NexusFrameworkImpl();
1163
- Object.defineProperty(window, "NexusFrameworkClient", {
1164
- value: instance
1165
- });
1166
- return instance;
1130
+ NexusFrameworkClient: {
1131
+ configurable: true,
1132
+ set: function (instance) {
1133
+ Object.defineProperty(window, "NexusFrameworkClient", {
1134
+ value: instance
1135
+ });
1136
+ },
1137
+ get: function () {
1138
+ const instance = new window.NexusFrameworkImpl();
1139
+ Object.defineProperty(window, "NexusFrameworkClient", {
1140
+ value: instance
1141
+ });
1142
+ return instance;
1143
+ }
1167
1144
  }
1168
- }
1169
- });
1145
+ });
1146
+ })(window);
1170
1147
  //# sourceMappingURL=nexusframeworkclient.js.map