web-manager 4.3.1 → 4.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.
@@ -1,56 +0,0 @@
1
- /*
2
- */
3
-
4
- function Debug(utilObj) {
5
- this.debug = utilObj;
6
- }
7
-
8
- Debug.promise = function(status, data, options) {
9
- options = options || {};
10
- options.wait = options.wait || {enabled: false};
11
- return new Promise(function (resolve, reject) {
12
- if (status == 'resolve') {
13
- if (options.wait.enabled) {
14
- Debug.wait(options.wait.msec, options.wait.range)
15
- .then(function () {
16
- // console.log('*** WAIT');
17
- resolve(data);
18
- console.log('[DEBUG] Debug.promise(resolve).');
19
- });
20
- } else {
21
- resolve(data);
22
- console.log('[DEBUG] Debug.promise(resolve).');
23
- }
24
- } else {
25
- if (options.wait.enabled) {
26
- Debug.wait(options.wait.msec, options.wait.range)
27
- .then(function () {
28
- // console.log('*** WAIT');
29
- reject(data);
30
- console.log('[DEBUG] Debug.promise(reject).');
31
- });
32
- } else {
33
- reject(data);
34
- console.log('[DEBUG] Debug.promise(reject).');
35
- }
36
- }
37
- })
38
- }
39
-
40
- Debug.wait = function(msec, range) {
41
- msec = msec || 0;
42
- range = range || 0;
43
-
44
- var min = 0;
45
- var randomNumPlus = (Math.random() * (range - min) + min);
46
- var randomNumMinus = (Math.random() * (range - min) + min);
47
-
48
- msec = msec + randomNumPlus - randomNumMinus;
49
- msec = (msec <= 0) ? 50 : msec;
50
- console.log('[DEBUG] waiting...', msec);
51
- return new Promise(function (resolve, reject) {
52
- setTimeout(resolve, msec);
53
- });
54
- }
55
-
56
- module.exports = Debug;
@@ -1,351 +0,0 @@
1
- /*
2
- https://gist.github.com/joyrexus/7307312
3
-
4
- JQUERY vs vanilla
5
- https://github.com/nefe/You-Dont-Need-jDom#dom-manipulation
6
-
7
- queryselector polyfill
8
- https://gist.github.com/chrisjlee/8960575
9
- * https://github.com/mtsyganov/queryselector-polyfill/blob/master/index.js
10
-
11
- */
12
-
13
-
14
- function Dom(elObj) {
15
- this.elements = elObj;
16
- }
17
-
18
- function _forEach(array, callback, scope) {
19
- for (var i = 0, l = array ? array.length : 0; i < l; i++) {
20
- callback.call(scope, i, array[i]); // passes back stuff we need
21
- }
22
- };
23
-
24
- Dom.prototype.addClass = function(name) {
25
- var elsObj = Object.assign({}, this.elements);
26
- for (var i = 0; i < elsObj.count; i++) {
27
- var element = elsObj.list[i];
28
- if (!validate(element)) { continue; }
29
- element.classList.add(name);
30
- }
31
- return new Dom(elsObj);
32
- }
33
-
34
- Dom.prototype.removeClass = function(name) {
35
- var elsObj = Object.assign({}, this.elements);
36
- for (var i = 0; i < elsObj.count; i++) {
37
- var element = elsObj.list[i];
38
- if (!validate(element)) { continue; }
39
- element.classList.remove(name);
40
- }
41
- return new Dom(elsObj);
42
- }
43
-
44
- Dom.prototype.css = function(ops) {
45
- var elsObj = Object.assign({}, this.elements);
46
- var keys = Object.keys(ops);
47
- for (var i = 0; i < elsObj.count; i++) {
48
- var element = elsObj.list[i];
49
- if (!validate(element)) { continue; }
50
- for (var i = 0; i < keys.length; i++) {
51
- element.style[keys[i]] = ops[keys[i]];
52
- }
53
- }
54
- return new Dom(elsObj);
55
- }
56
-
57
- Dom.prototype.hide = function(options) {
58
- var elsObj = Object.assign({}, this.elements);
59
- options = options || {};
60
- options.type = options.type || 'display' /* display, visibility, both*/
61
- for (var i = 0; i < elsObj.count; i++) {
62
- var element = elsObj.list[i];
63
- if (!validate(element)) { continue; }
64
- if (options.type === 'visibility') {
65
- element.style.visibility = 'hidden';
66
- } else if (options.type === 'display') {
67
- element.style.display = 'none';
68
- element.setAttribute('hidden', true);
69
- element.classList.add('hidden');
70
- } else {
71
- element.style.visibility = 'hidden';
72
- element.style.display = 'none';
73
- element.setAttribute('hidden', true);
74
- element.classList.add('hidden');
75
-
76
- }
77
- }
78
- return new Dom(elsObj);
79
- }
80
-
81
- Dom.prototype.show = function(options) {
82
- var elsObj = Object.assign({}, this.elements);
83
- options = options || {};
84
- options.type = options.type || 'display' /* display, visibility, both*/
85
- for (var i = 0; i < elsObj.count; i++) {
86
- var element = elsObj.list[i];
87
- if (!validate(element)) { continue; }
88
- if (options.type === 'visibility') {
89
- element.style.visibility = 'visible';
90
- } else if (options.type === 'display') {
91
- element.style.display = 'block';
92
- // element.setAttribute('hidden', false);
93
- element.removeAttribute('hidden');
94
- element.classList.remove('hidden');
95
- } else {
96
- element.style.visibility = 'visible';
97
- element.style.display = 'block';
98
- // element.setAttribute('hidden', false);
99
- element.removeAttribute('hidden');
100
- element.classList.remove('hidden');
101
- }
102
- }
103
- return new Dom(elsObj);
104
- }
105
-
106
- Dom.prototype.getAttribute = function(name, options) {
107
- var elsObj = Object.assign({}, this.elements);
108
- options = options || {};
109
- var r;
110
- for (var i = 0; i < elsObj.count; i++) {
111
- var element = elsObj.list[i];
112
- if (!validate(element)) { continue; }
113
- r = element.getAttribute(name);
114
- }
115
- return r;
116
- }
117
-
118
- Dom.prototype.setAttribute = function(name, value, options) {
119
- var elsObj = Object.assign({}, this.elements);
120
- options = options || {};
121
- for (var i = 0; i < elsObj.count; i++) {
122
- var element = elsObj.list[i];
123
- if (!validate(element)) { continue; }
124
- element.setAttribute(name, value);
125
- }
126
- return new Dom(elsObj);
127
- }
128
-
129
- Dom.prototype.removeAttribute = function(name, options) {
130
- var elsObj = Object.assign({}, this.elements);
131
- options = options || {};
132
- for (var i = 0; i < elsObj.count; i++) {
133
- var element = elsObj.list[i];
134
- if (!validate(element)) { continue; }
135
- element.setAttribute(name, 'DELETE');
136
- element.removeAttribute(name);
137
- }
138
- return new Dom(elsObj);
139
- }
140
-
141
- Dom.prototype.getValue = function(options) {
142
- options = options || {};
143
- options.returnType = options.returnType || 'array'; // array, object, single (only for checkbox)
144
- var r;
145
- var elsObj = Object.assign({}, this.elements);
146
- for (var i = 0; i < elsObj.count; i++) {
147
- var element = elsObj.list[i];
148
- if (!validate(element)) { continue; }
149
- if ((element.type === 'checkbox') ) {
150
- if (elsObj.list.length === 1) {
151
- r = element.checked;
152
- break;
153
- } else {
154
- if (options.returnType === 'array') {
155
- r = (r) ? r : [];
156
- if (element.checked) {
157
- r.push(element.value);
158
- }
159
- } else if (options.returnType === 'object') {
160
- r = (r) ? r : {};
161
- r[element.value] = element.checked;
162
- } else {
163
- r = element.checked
164
- }
165
- }
166
- } else if (element.type === 'radio') {
167
- if (element.checked) {
168
- r = element.value;
169
- break;
170
- }
171
- } else {
172
- r = element.type === 'number' ? parseFloat(element.value) : element.value;
173
- break;
174
- }
175
- }
176
- return r;
177
- }
178
-
179
- Dom.prototype.setValue = function(value, options) {
180
- options = options || {};
181
- options.returnType = options.returnType || 'single';
182
- var elsObj = Object.assign({}, this.elements);
183
- for (var i = 0; i < elsObj.count; i++) {
184
- var element = elsObj.list[i];
185
- if (!validate(element)) { continue; }
186
- if (element.type === 'checkbox') {
187
- if (Array.isArray(value)) {
188
- element.checked = !!value.includes(element.value);
189
- } else if (typeof value === 'object') {
190
- element.checked = !!value[element.value];
191
- } else {
192
- element.checked = !!value;
193
- }
194
- } else if (element.type === 'radio') {
195
- element.checked = !!value;
196
- } else {
197
- element.value = value;
198
- }
199
- }
200
- return new Dom(elsObj);
201
- }
202
-
203
- Dom.prototype.setInnerHTML = function(html, options) {
204
- options = options || {};
205
- var elsObj = Object.assign({}, this.elements);
206
- // console.log('SET ', this);
207
- for (var i = 0; i < elsObj.count; i++) {
208
- var element = elsObj.list[i];
209
- if (!validate(element)) { continue; }
210
- element.innerHTML = html;
211
- }
212
- return new Dom(elsObj);
213
- }
214
-
215
- Dom.prototype.each = function(fn, options) {
216
- options = options || {};
217
- var elsObj = Object.assign({}, this.elements);
218
- for (var i = 0; i < elsObj.count; i++) {
219
- var element = elsObj.list[i];
220
- if (!validate(element)) { continue; }
221
- if (fn(element, i) === false) {
222
- break;
223
- };
224
- }
225
- return new Dom(elsObj);
226
- }
227
-
228
- Dom.prototype.on = function(evt, fn) {
229
- var elsObj = Object.assign({}, this.elements);
230
- for (var i = 0; i < elsObj.count; i++) {
231
- var element = elsObj.list[i];
232
- if (!validate(element)) { continue; }
233
- if (document.addEventListener) { // W3C model
234
- element.addEventListener(evt, fn, false);
235
- // return true;
236
- } else if (document.attachEvent) { // Microsoft model
237
- // return element.attachEvent('on' + evt, fn);
238
- element.attachEvent('on' + evt, fn);
239
- }
240
- }
241
- return new Dom(elsObj);
242
- };
243
-
244
- Dom.prototype.get = function(index) {
245
- return (index || 0 <= this.elements.count) ? this.elements.list[index || 0] : null;
246
- }
247
-
248
- Dom.prototype.exists = function() {
249
- return (this.elements.exists);
250
- }
251
-
252
- Dom.loadScript = function(options, callback) {
253
- return new Promise(function(resolve, reject) {
254
- options = options || {};
255
- options.async = typeof options.async === 'undefined' ? false : options.async;
256
- options.crossorigin = typeof options.crossorigin === 'undefined' ? false : options.crossorigin;
257
- options.cacheBreaker = typeof options.cacheBreaker === 'undefined' ? true : options.cacheBreaker;
258
- options.attributes = typeof options.attributes === 'undefined' ? [] : options.attributes;
259
-
260
- var s = document.createElement('script');
261
-
262
- // Set the script cache breaker
263
- if (options.cacheBreaker) {
264
- var src = options.src.split('?');
265
- var query = new URLSearchParams(src[1])
266
- query.set('cb', new Date().getTime());
267
-
268
- options.src = src[0] + '?' + query.toString();
269
- }
270
-
271
- // If crossorigin is set, set the attribute
272
- if (options.crossorigin) {
273
- options.attributes.push({name: 'crossorigin', value: '*'});
274
- }
275
-
276
- // Set the script attributes
277
- options.attributes
278
- .forEach(function (attribute) {
279
- s.setAttribute(attribute.name, attribute.value);
280
- });
281
-
282
- // Set the script source
283
- s.async = options.async;
284
- s.src = options.src;
285
-
286
- s.onload = function() {
287
- if (callback) { callback(); }
288
- return resolve();
289
- };
290
- s.onerror = function() {
291
- var error = new Error('Failed to load script ' + options.src);
292
- if (callback) { callback(error); }
293
- return reject(error);
294
- };
295
- document.head.appendChild(s);
296
- });
297
- }
298
-
299
- Dom.select = function(selector, options) {
300
- options = options || {};
301
-
302
- var elems;
303
- var type = typeof selector;
304
- if (type === 'string') {
305
- elems = document.querySelectorAll(selector);
306
- } else if (type === 'object') {
307
- elems = (selector && selector.tagName) ? [selector] : selector;
308
- }
309
- var r = [];
310
-
311
- _forEach(elems, function (index, value) {
312
- r.push(value);
313
- });
314
-
315
- return new Dom({
316
- list: r,
317
- count: r.length,
318
- exists: (r.length > 0),
319
- });
320
- }
321
-
322
- Dom.onDocumentReady = function(fn) {
323
- if (['complete', 'interactive'].includes(document.readyState)) {
324
- fn();
325
- } else {
326
- document.addEventListener('DOMContentLoaded', fn);
327
- }
328
- }
329
-
330
- Dom.prototype.parent = function(selector) {
331
- var elsObj = Object.assign({}, this.elements);
332
- for (var i = 0; i < elsObj.count; i++) {
333
- var element = elsObj.list[i];
334
- if (!validate(element)) { continue; }
335
- do {
336
- if (element.matches(selector)) {
337
- return element;
338
- } else {
339
- element = element.parentNode;
340
- }
341
- } while (element && element.parentNode)
342
- }
343
- return new Dom(elsObj);
344
- }
345
-
346
- module.exports = Dom;
347
-
348
- // Helpers
349
- function validate(element) {
350
- return (element && element.tagName);
351
- }
@@ -1,5 +0,0 @@
1
- /*
2
- */
3
- module.exports = function (name) {
4
- return require(name);
5
- };
@@ -1,78 +0,0 @@
1
- /*
2
- */
3
- var utilities = require('./utilities.js');
4
- var pseudoStorage = {};
5
-
6
- function Storage(storageObj) {
7
- this.storage = storageObj;
8
- }
9
-
10
- Storage.get = function (path, def) {
11
- // Setup the usable storage object
12
- var usableStorage;
13
-
14
- // Setup the path and default value
15
- path = path || '';
16
- // def = typeof def === 'undefined' ? {} : def;
17
- // Important that defaults to undefined
18
- // Because if default is empty obj, then a path to an undefined value like 'a.b.c' (assuming c is undefined) will return empty obj instead of undefined
19
- def = typeof def === 'undefined' ? undefined : def;
20
-
21
- // Try to parse the localStorage object
22
- try {
23
- usableStorage = JSON.parse(window.localStorage.getItem('_manager') || '{}');
24
- } catch (e) {
25
- usableStorage = pseudoStorage;
26
- }
27
-
28
- // If there's no path, return the entire storage object
29
- if (!path) {
30
- return usableStorage || def;
31
- }
32
-
33
- // Return the value at the path
34
- return utilities.get(usableStorage, path, def);
35
- }
36
-
37
- Storage.set = function (path, value) {
38
- // Setup the usable storage object
39
- var usableStorage;
40
-
41
- // Setup the path and default value
42
- path = path || '';
43
- value = typeof value === 'undefined' ? undefined : value;
44
-
45
- // Try to parse the localStorage object
46
- try {
47
- usableStorage = Storage.get();
48
- } catch (e) {
49
- usableStorage = pseudoStorage;
50
- }
51
-
52
- // If there's no path, return the entire storage object
53
- if (!path) {
54
- usableStorage = value || {};
55
- } else {
56
- // Set the value at the path
57
- utilities.set(usableStorage, path, value);
58
- }
59
-
60
- // Try to set the localStorage object
61
- try {
62
- window.localStorage.setItem('_manager', JSON.stringify(usableStorage));
63
- } catch (e) {
64
- pseudoStorage = usableStorage;
65
- }
66
-
67
- return usableStorage;
68
- }
69
-
70
- Storage.clear = function () {
71
- try {
72
- window.localStorage.setItem('_manager', '{}');
73
- } catch (e) {
74
- pseudoStorage = {};
75
- }
76
- }
77
-
78
- module.exports = Storage;
@@ -1,180 +0,0 @@
1
- /*
2
- */
3
-
4
- var shadow;
5
-
6
- function Utilities(utilObj) {
7
- this.utilities = utilObj;
8
- }
9
-
10
- Utilities.get = function (object, path, defaultValue) {
11
- // If the path is not defined or it has false value
12
- if (!path) {
13
- return defaultValue;
14
- }
15
-
16
- // Check if the path is a string or array. If it is a string, convert it to array
17
- const pathArray = Array.isArray(path) ? path : path.split('.');
18
-
19
- // For each item in the path, dig into the object
20
- let currentObject = object;
21
- for (const key of pathArray) {
22
- if (!currentObject || currentObject[key] === undefined) {
23
- return defaultValue;
24
- }
25
- currentObject = currentObject[key];
26
- }
27
-
28
- // Return the value
29
- return currentObject === undefined ? defaultValue : currentObject;
30
- }
31
-
32
- /* https://stackoverflow.com/questions/54733539/javascript-implementation-of-lodash-set-method */
33
- Utilities.set = function (obj, path, value) {
34
- if (Object(obj) !== obj) {
35
- return obj;
36
- }; // When obj is not an object
37
-
38
- var p = (path || '').split("."); // Get the keys from the path
39
-
40
- p.slice(0, -1).reduce(function (a, c, i) {
41
- return (// Iterate all of them except the last one
42
- Object(a[c]) === a[c] // Does the key exist and is its value an object?
43
- // Yes: then follow that path
44
- ? a[c] // No: create the key. Is the next key a potential array-index?
45
- : a[c] = Math.abs(p[i + 1]) >> 0 === +p[i + 1] ? [] // Yes: assign a new array object
46
- : {}
47
- );
48
- }, // No: assign a new plain object
49
- obj)[p.pop()] = value; // Finally assign the value to the last key
50
-
51
- return obj; // Return the top-level object to allow chaining
52
- }
53
-
54
- /* https://gist.github.com/jeneg/9767afdcca45601ea44930ea03e0febf */
55
- // Utilities.getLegacy = function (obj, path, def) {
56
- // if (!path) {
57
- // return def;
58
- // }
59
- // var fullPath = (path || '')
60
- // .replace(/\[/g, '.')
61
- // .replace(/]/g, '')
62
- // .split('.')
63
- // .filter(Boolean);
64
-
65
- // return fullPath.every(everyFunc) ? obj : def;
66
-
67
- // function everyFunc(step) {
68
- // // return !(step && (obj = obj[step]) === undefined);
69
- // // console.log(' CHECK > ', !(step && (obj = obj[step]) === undefined));
70
- // // console.log('step', step, 'obj', obj, 'objstep', obj[step]);
71
- // // return !(step && (obj = obj[step]) === undefined);
72
- // return !(step && (obj = obj[step]) === undefined);
73
- // }
74
- // }
75
-
76
- // https://dzone.com/articles/cross-browser-javascript-copy-and-paste
77
- // https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
78
- Utilities.clipboardCopy = function (input) {
79
- // Get the text from the input
80
- var text = input && input.nodeType
81
- ? input.value || input.innerText || input.innerHTML
82
- : input;
83
-
84
- // Try to use the modern clipboard API
85
- try {
86
- navigator.clipboard.writeText(text);
87
- } catch (e) {
88
- // Try creating a textarea and copying the text to it
89
- var el = document.createElement('textarea');
90
- el.setAttribute('style','width:1px;border:0;opacity:0;');
91
- el.value = text;
92
- document.body.appendChild(el);
93
- el.select();
94
-
95
- // Try to copy the text
96
- try {
97
- document.execCommand('copy');
98
- } catch (e) {
99
- alert('Please press Ctrl+C/Cmd+C to copy');
100
- }
101
-
102
- // Remove the textarea
103
- document.body.removeChild(el);
104
- }
105
- }
106
-
107
- // Escape HTML
108
- // https://stackoverflow.com/questions/6234773/can-i-escape-html-special-chars-in-javascript
109
- // Utilities.escapeHTML = function (str) {
110
- // shadow = shadow || document.createElement('div');
111
- // shadow.textContent = str;
112
-
113
- // return shadow.textContent.replace(/["']/g, function(m) {
114
- // switch (m) {
115
- // case '"':
116
- // return '&quot;';
117
- // default:
118
- // return '&#039;';
119
- // }
120
- // });
121
- // }
122
-
123
- Utilities.escapeHTML = function (str) {
124
- shadow = shadow || document.createElement('p');
125
- shadow.innerHTML = '';
126
-
127
- // This automatically escapes HTML entities like <, >, &, etc.
128
- shadow.appendChild(document.createTextNode(str));
129
-
130
- // This is needed to escape quotes to prevent attribute injection
131
- return shadow.innerHTML.replace(/["']/g, function(m) {
132
- switch (m) {
133
- case '"':
134
- return '&quot;';
135
- default:
136
- return '&#039;';
137
- }
138
- });
139
- }
140
-
141
- Utilities.getContext = function () {
142
- // Check mobile
143
- function mobile() {
144
- try {
145
- var m = navigator.userAgentData.mobile;
146
- return typeof m === 'undefined' ? _THROW : m === true;
147
- } catch (e) {
148
- try {
149
- // return window.matchMedia('only screen and (max-width: 767px)').matches;
150
- return window.matchMedia('(max-width: 767px)').matches;
151
- } catch (e) {
152
- return false;
153
- }
154
- }
155
- }
156
-
157
- // Return findings
158
- return {
159
- client: {
160
- mobile: mobile(),
161
- },
162
- }
163
- }
164
-
165
- // Navigate fn that takes a url and an object of query params
166
- Utilities.navigate = function (url, params) {
167
- // Should work if the url is a relative path too
168
- var newUrl = new URL(url, window.location.origin);
169
-
170
- // Add the params to the url
171
- Object.keys(params).forEach(function (key) {
172
- newUrl.searchParams.set(key, params[key]);
173
- });
174
-
175
- // Navigate to the new url
176
- window.location.href = newUrl;
177
- }
178
-
179
-
180
- module.exports = Utilities;