-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathQCObjects.js
4290 lines (4044 loc) · 147 KB
/
QCObjects.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* QCObjects 2.3
* ________________
*
* Author: Jean Machuca <[email protected]>
*
* Cross Browser Javascript Framework for MVC Patterns
* QuickCorp/QCObjects is licensed under the
* GNU Lesser General Public License v3.0
* [LICENSE] (https://github.com/QuickCorp/QCObjects/blob/master/LICENSE.txt)
*
* Permissions of this copyleft license are conditioned on making available
* complete source code of licensed works and modifications under the same
* license or the GNU GPLv3. Copyright and license notices must be preserved.
* Contributors provide an express grant of patent rights. However, a larger
* work using the licensed work through interfaces provided by the licensed
* work may be distributed under different terms and without source code for
* the larger work.
*
* Copyright (C) 2015 Jean Machuca,<[email protected]>
*
* Everyone is permitted to copy and distribute verbatim copies of this
* license document, but changing it is not allowed.
*/
/*eslint no-unused-vars: "off"*/
/*eslint no-redeclare: "off"*/
/*eslint no-empty: "off"*/
/*eslint strict: "off"*/
/*eslint no-mixed-operators: "off"*/
(function(_top) {
"use strict";
var _protected_code_ = function(_) {
var __oldtoString = (typeof _.prototype !== "undefined") ? (_.prototype.toString) : (function() {
return "";
});
_.prototype.toString = function() {
var _protected_symbols = ["ComplexStorageCache",
"css",
"append",
"attachIn",
"debug",
"info",
"warn",
"QC_Append",
"set",
"get",
"done",
"componentDone",
"_new_",
"__new__",
"Class",
"ClassFactory",
"New",
"Export",
"Package",
"Import",
"subelements",
"componentLoader",
"buildComponents",
"Controller",
"View",
"VO",
"Service",
"serviceLoader",
"JSONService",
"ConfigService",
"SourceJS",
"SourceCSS",
"ArrayList",
"ArrayCollection",
"Effect",
"Timer",
"sum",
"avg",
"table",
"max",
"min",
"range",
"matrix",
"matrix2d",
"matrix3d",
"unique",
"uniqueId",
"shortCode",
"NamespaceRef"
];
var _ret_;
if (_protected_symbols.includes(this.name)) {
_ret_ = this.name + "{ [QCObjects native code] }";
} else {
_ret_ = __oldtoString.call(this);
}
return _ret_;
};
};
(_protected_code_)(Function);
var _methods_ = function(_) {
var _m = [];
for (var i in _) {
if ((typeof _[i]).toLowerCase() === "function") {
_m.push(_[i]);
}
}
return _m;
};
String.prototype.__mAll__ = function (regex) {
// This is an alternative to old browsers that dont support String.prototype.matchAll
// https://github.com/tc39/proposal-string-matchall
var matches = [];
this.replace(regex, function () {
var match = Array.prototype.slice.call(arguments, 0, -2);
match.input = arguments[arguments.length - 1];
match.index = arguments[arguments.length - 2];
matches.push(match);
});
return matches;
};
if (typeof String.prototype.matchAll === "undefined"){
String.prototype.matchAll = String.prototype.__mAll__;
}
var isBrowser = typeof window !== "undefined" && typeof window.self !== "undefined" && window === window.self;
var _DOMCreateElement = function(elementName) {
var _ret_;
if (isBrowser) {
_ret_ = document.createElement(elementName);
} else {
_ret_ = {};
}
return _ret_;
};
if (!isBrowser) {
const fs = require("fs");
}
var _DataStringify = function(data) {
var getCircularReplacer = function() {
var seen = new WeakSet();
var _level = 0;
return function(key, value) {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
_level += 1;
return (_level <= 3) ? (_LegacyCopy(value)) : (null);
}
seen.add(value);
}
return value;
};
};
return JSON.stringify(data, getCircularReplacer());
};
if (isBrowser) {
var _subelements = function subelements(selector) {
return [...this.querySelectorAll(selector)];
};
Element.prototype.subelements = _subelements;
HTMLDocument.prototype.subelements = _subelements;
HTMLElement.prototype.subelements = _subelements;
if (typeof ShadowRoot !== "undefined"){
ShadowRoot.prototype.subelements = _subelements;
}
}
if (isBrowser) {
try {
_top = (typeof window.top !== "undefined") ? (window.top) : (window);
_top["_allowed_"] = true;
} catch (e) {
try {
_top = document;
_top["_allowed_"] = true;
} catch (e2) {
try {
_top = global;
_top["_allowed_"] = true;
} catch (e3) {
_top = {};
_top["_allowed_"] = true;
}
}
}
} else if (typeof global !== "undefined") {
_top = global;
}
var basePath = (
function() {
var _basePath = "";
if (isBrowser) {
var baseURI = _top.document.baseURI.split("?")[0].split("/");
baseURI.pop();
_basePath = baseURI.join("/") + "/";
} else {
var process;
try {
process = require("process");
} catch (e) {
// not a process module
}
if (typeof process !== "undefined") {
_basePath = `${process.cwd()}/`;
} else {
_basePath = "";
}
}
return _basePath;
}
)();
if (isBrowser) {
/**
* Polyfilling Promise
*/
if (!("Promise" in _top)) {
_top.Promise = function(_f) {
var _p = {
then: function() {},
catch: function() {},
_then: function(response) {
this.then.call(_p, response);
},
_catch: function(response) {
this.catch.call(_p, response);
}
};
_f.call(_p, _p._then, _p._catch);
return _p;
};
}
if (typeof _top.console === "undefined") {
_top.console = function() {};
_top.console.prototype.log = function(message) {};
}
var domain = (
function() {
return (typeof document !== "undefined" && document.domain !== "") ? (document.domain) : ("localhost");
}
)();
var _secretKey = (
function() {
var __secretKey = _top[(![] + [])[((+!+[]) + (+!+[]))] + (typeof ![])[(+!+[])] + (typeof [])[((+!+[]) + (+!+[])) * ((+!+[]) + (+!+[]))] + (![] + [])[(+!+[])] + (!![] + [])[(+[])] + ([] + [] + [][
[]
])[(+[+!+[] + [+[]]]) / ((+!+[]) + (+!+[]))] + (typeof ![])[(+!+[])] + ([] + [] + [][
[]
])[(+!+[])]]["h" + (typeof ![])[(+!+[])] + (![] + [])[(+!+[] + ((+!+[]) + (+!+[])))] + (!![] + [])[(+[])]].toLowerCase();
return __secretKey;
}
)();
var is_phonegap = (
function() {
return (typeof cordova !== "undefined") ? (true) : (false);
}
)();
} else {
// This is only for code integrity purpose using non-browser implementations
// like using node.js
var _secretKey = "secret";
var domain = "localhost";
}
_top._asyncLoad = [];
var asyncLoad = function(callback, args) {
var asyncCallback = {
"func": callback,
"args": args,
"dispatch": function() {
this.func.apply(null, this.args);
}
};
_top._asyncLoad.push(asyncCallback);
return asyncCallback;
};
if (isBrowser) {
var _fireAsyncLoad = function() {
if (document.readyState === "complete") {
_top._asyncLoad.map(function (fc){
fc.dispatch.call(fc);
});
}
};
document.onreadystatechange = _fireAsyncLoad;
} else if (typeof global !== "undefined") {
global._fireAsyncLoad = function() {
_top._asyncLoad.map(function (fc){
fc.dispatch.call(fc);
});
};
}
_top.asyncLoad = asyncLoad;
var Logger = function() {
return {
debugEnabled: true,
infoEnabled: true,
warnEnabled: true,
debug: function(message) {
if (this.debugEnabled) {
console.log("\x1b[35m%s\x1b[0m","[DEBUG] " + message);
}
},
info: function(message) {
if (this.infoEnabled) {
console.info("\x1b[33m%s\x1b[0m","[INFO] " + message);
}
},
warn: function(message) {
if (this.warnEnabled) {
console.warn("\x1b[31m%s\x1b[0m","[WARN] " + message);
}
}
};
};
var logger = new Logger();
logger.debugEnabled = false;
logger.infoEnabled = false;
_top.logger = logger;
var Base64 = {
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encode: function(e) {
var t = "";
var n, r, i, s, o, u, a;
var f = 0;
e = Base64._utf8_encode(e);
while (f < e.length) {
n = e.charCodeAt(f++);
r = e.charCodeAt(f++);
i = e.charCodeAt(f++);
s = n >> 2;
o = (n & 3) << 4 | r >> 4;
u = (r & 15) << 2 | i >> 6;
a = i & 63;
if (isNaN(r)) {
u = a = 64;
} else if (isNaN(i)) {
a = 64;
}
t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a);
}
return t;
},
decode: function(e) {
var t = "";
var n, r, i;
var s, o, u, a;
var f = 0;
e = e.replace(/[^A-Za-z0-9+/=]/g, "");
while (f < e.length) {
s = this._keyStr.indexOf(e.charAt(f++));
o = this._keyStr.indexOf(e.charAt(f++));
u = this._keyStr.indexOf(e.charAt(f++));
a = this._keyStr.indexOf(e.charAt(f++));
n = s << 2 | o >> 4;
r = (o & 15) << 4 | u >> 2;
i = (u & 3) << 6 | a;
t = t + String.fromCharCode(n);
if (u !== 64) {
t = t + String.fromCharCode(r);
}
if (a !== 64) {
t = t + String.fromCharCode(i);
}
}
t = Base64._utf8_decode(t);
return t;
},
_utf8_encode: function(e) {
e = e.replace(/rn/g, "n");
var t = "";
for (var n = 0; n < e.length; n++) {
var r = e.charCodeAt(n);
if (r < 128) {
t += String.fromCharCode(r);
} else if (r > 127 && r < 2048) {
t += String.fromCharCode(r >> 6 | 192);
t += String.fromCharCode(r & 63 | 128);
} else {
t += String.fromCharCode(r >> 12 | 224);
t += String.fromCharCode(r >> 6 & 63 | 128);
t += String.fromCharCode(r & 63 | 128);
}
}
return t;
},
_utf8_decode: function(e) {
var t = "";
var n = 0;
var r = 0;
var c1 = 0;
var c2 = 0;
var c3;
while (n < e.length) {
r = e.charCodeAt(n);
if (r < 128) {
t += String.fromCharCode(r);
n++;
} else if (r > 191 && r < 224) {
c2 = e.charCodeAt(n + 1);
t += String.fromCharCode((r & 31) << 6 | c2 & 63);
n += 2;
} else {
c2 = e.charCodeAt(n + 1);
c3 = e.charCodeAt(n + 2);
t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
n += 3;
}
}
return t;
}
};
var waitUntil = function(func, exp) {
var _waitUntil = function(func, exp) {
var maxWaitCycles = 2000;
var _w = 0;
var _t = setInterval(function() {
if (exp.call()) {
clearInterval(_t);
func.call();
logger.debug("Ejecuting " + func.name + " after wait");
} else {
if (_w < maxWaitCycles) {
_w += 1;
logger.debug("WAIT UNTIL " + func.name + " is true, " + _w.toString() + " cycles");
} else {
logger.debug("Max execution time for " + func.name + " expression until true");
clearInterval(_t);
}
}
}, 1);
};
setTimeout(function() {
_waitUntil(func, exp);
}, 1);
};
if (typeof localStorage === "undefined"){
/* Polyfill for localStorage */
var localStorage = {
getItem (name) {
return (Object.hasOwnProperty.call(this, name))?(this[name]):(null);
},
setItem (name, value) {
this[name] = value;
},
removeItem (name) {
delete this[name];
}
};
/* end Polyfill for localStorage */
}
var ComplexStorageCache = function(params) {
var object, load, alternate;
object = params.index;
load = params.load;
alternate = params.alternate;
var cachedObjectID = this.getID(object);
var cachedResponse = localStorage.getItem(cachedObjectID);
if (this.isEmpty(cachedResponse)) {
var cachedNewResponse = load.call(null, {
"cachedObjectID": cachedObjectID,
"cachedResponse": cachedResponse,
"cache": this
});
this.save(object, cachedNewResponse);
logger.debug("RESPONSE OF {{cachedObjectID}} CACHED".replace("{{cachedObjectID}}", cachedObjectID));
} else {
var alternateResponse = alternate.call(null, {
"cachedObjectID": cachedObjectID,
"cachedResponse": cachedResponse,
"cache": this
});
logger.debug("RESPONSE OF {{cachedObjectID}} IS ALREADY CACHED ".replace("{{cachedObjectID}}", cachedObjectID));
}
return this;
};
ComplexStorageCache.prototype.getItem = function(cachedObjectID) {
var retrievedObject = localStorage.getItem(cachedObjectID);
if (!this.isEmpty(retrievedObject)) {
return JSON.parse(retrievedObject);
} else {
return null;
}
};
ComplexStorageCache.prototype.setItem = function(cachedObjectID, value) {
localStorage.setItem(cachedObjectID, _DataStringify(value));
};
ComplexStorageCache.prototype.isEmpty = function(object) {
var r = false;
switch (true) {
case (typeof object === "undefined"):
case (typeof object === "string" && object === ""):
case (typeof object === "string" && object === "undefined"):
case (typeof object === "number" && object === 0):
case (object === null):
r = true;
break;
default:
r = false;
}
return r;
};
ComplexStorageCache.prototype.getID = function(object) {
var cachedObjectID = "cachedObject_" + Base64.encode(_DataStringify(object).replace(/\{|\}|,/g, "_"));
return cachedObjectID;
};
ComplexStorageCache.prototype.save = function(object, cachedNewResponse) {
var cachedObjectID = this.getID(object);
logger.debug("CACHING THE RESPONSE OF {{cachedObjectID}} ".replace("{{cachedObjectID}}", cachedObjectID));
this.setItem(cachedObjectID, cachedNewResponse);
};
ComplexStorageCache.prototype.getCached = function(object) {
var cachedObjectID = this.getID(object);
return this.getItem(cachedObjectID);
};
ComplexStorageCache.prototype.clear = function() {
Object.keys(localStorage).filter ( function (k) {return k.startsWith("cachedObject_");} ).map ( function (c) {localStorage.removeItem(c);});
};
/**
* Detecting passive events feature
*
* https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection
**/
// Test via a getter in the options object to see if the passive property is accessed
if (isBrowser) {
var supportsPassive = false;
try {
var opts = Object.defineProperty({}, "passive", {
get: function() {
supportsPassive = true;
return supportsPassive;
}
});
window.addEventListener("testPassive", null, opts);
window.removeEventListener("testPassive", null, opts);
} catch (e) {}
var captureFalse = function() {
return (supportsPassive) ? ({
passive: true
}) : (false);
};
// Use our detect's results. passive applied if supported, capture will be false either way.
//elem.addEventListener('touchstart', fn, captureFalse);
}
/**
* Basic Type of all elements
*/
if (isBrowser){
Element.prototype.find = function(tag) {
var _oo = [];
var _tags = document.subelements(tag);
_tags.map(function (_tt,_t){
if ((typeof _tags[_t] !== "undefined") && _tags[_t].parentNode.tagName === this.parentNode.tagName) {
_oo.push(_Cast(_tt, (new Object())));
}
});
return _oo;
};
}
/**
* Primary instance ID of all objects
*/
var __instanceID;
// Adaptation of Production steps of ECMA-262, Edition 5, 15.2.3.5
// Reference: http://es5.github.io/#x15.2.3.5
var _Object_Create = (function() {
// make a safe reference to Object.prototype.hasOwnProperty
var hasOwn = Object.prototype.hasOwnProperty;
return function(O) {
// 1. If Type(O) is not Object or Null throw a TypeError exception.
if (typeof O !== "object") {
throw TypeError("Object prototype may only be an Object or null. The type is " + typeof(O));
}
// 2. Let obj be the result of creating a new object as if by the
// expression new Object() where Object is the standard built-in
// constructor with that name
// 3. Set the [[Prototype]] internal property of obj to O.
var QCObjects = function() {};
QCObjects.prototype = O;
var obj = new QCObjects();
// Let's not keep a stray reference to O...
// 4. If the argument Properties is present and not undefined, add
// own properties to obj as if by calling the standard built-in
// function Object.defineProperties with arguments obj and
// Properties.
if (arguments.length > 1) {
// Object.defineProperties does ToObject on its first argument.
var Properties = Object(arguments[1]);
for (var prop in Properties) {
if (hasOwn.call(Properties, prop)) {
obj[prop] = Properties[prop];
}
}
}
// 5. Return obj
return obj;
};
})();
// Object.assign Polyfilling
// Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill
if (typeof Object.assign !== "function") {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
value: function assign(target, varArgs) { // .length of function is 2
"use strict";
if (target === null) { // TypeError if undefined or null
throw new TypeError("Cannot convert undefined or null to object");
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource !== null) { // Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true
});
}
var _LegacyCopy = function(obj) {
var _ret_;
switch (typeof obj) {
case "string":
_ret_ = obj;
break;
case "number":
_ret_ = obj;
break;
case "object":
_ret_ = Object.assign({}, obj);
break;
case "function":
_ret_ = Object.assign({}, obj);
break;
default:
break;
}
return _ret_;
};
var _QC_CLASSES = {};
var _QC_PACKAGES = {};
var _QC_PACKAGES_IMPORTED = [];
var _QC_READY_LISTENERS = [];
/**
* Returns the object or function name
*
* @param Object or function
*/
var ObjectName = function(o) {
var ret = "";
if (typeof o.constructor === "function") {
ret = o.constructor.name;
} else if (typeof o.constructor === "object") {
ret = o.constructor.toString().replace(/\[(.*?)\]/g, "$1").split(" ").slice(1).join("");
}
return ret;
};
/**
* Casts an object to another object class type
*
* @param {Object} obj_source
* @param {Object} obj_dest
*/
var _Cast = function(obj_source, obj_dest) {
for (var v in obj_source) {
if (typeof obj_source[v] !== "undefined") {
try {
obj_dest[v] = obj_source[v];
} catch (e) {
}
}
}
return obj_dest;
};
/**
* Casts an object to another object class type. Only properties
*
* @param {Object} obj_source
* @param {Object} obj_dest
*/
var _CastProps = function(obj_source, obj_dest) {
for (var v in obj_source) {
if (typeof obj_source[v] !== "undefined" && typeof obj_source[v] !== "function") {
try {
obj_dest[v] = obj_source[v];
} catch (e) {
}
} else if (typeof obj_source[v] === "function"){
try {
obj_dest[v] = obj_source[v].bind(obj_dest);
} catch (e) {
}
}
}
return obj_dest;
};
/**
* Internal use to determine the forbidden names for classes
* Reserved words
*
* @param {String} name
* @param {Object} type
* @param {Object} definition
*/
var __is__forbidden_name__ = function (){
return (["__proto__", "prototype", "Object", "Map", "defineProperty", "indexOf", "toString", "__instanceID"].indexOf(arguments[0])!== -1)?(true):(false);
};
/**
* Determine the type of the Object for any QCObjects Object
*
* @param {Object} object
*/
var __getType__ = function __getType__(o_c) {
return (o_c.hasOwnProperty.call(o_c,"__classType")) ? (o_c.__classType) : ((o_c.hasOwnProperty.call(o_c,"__definition")) ? (o_c.__definition.__classType) : (ObjectName(o_c)));
};
/**
* Returns if a class or object is from a determinated type
* @param {Object} object
* @param {String} typeName
*/
var is_a = function is_a(obj, typeName) {
return (typeof obj !== "undefined" && obj !== null &&
(((isQCObjects_Class(obj) || isQCObjects_Object(obj)) && (obj.hierarchy().includes(typeName)))
|| __getType__(obj) === typeName
|| ObjectName(obj) === typeName
|| typeof obj === typeName))?(true):(false);
};
/**
* Creates new object class of another object
*
* @param {String} name
* @param {Object} type
* @param {Object} definition
*/
var Class = function(name, type, definition) {
var o;
var name = arguments[0];
if (__is__forbidden_name__.call(this, name)){
throw new Error(`${name} is not an allowed word in the name of a class`);
}
if (isBrowser) {
var type = (arguments.length > 2) ? (arguments[1]) : (HTMLElement);
} else {
var type = (arguments.length > 2) ? (arguments[1]) : (Object);
}
var definition = (arguments.length > 2) ? (arguments[2]) : (
(arguments.length > 1) ? (arguments[1]) : ({})
);
if (typeof type === "undefined") {
if (isBrowser) {
type = HTMLElement; // defaults to HTMLElement type
} else {
type = Object;
}
} else {
definition = _Cast(
(typeof definition === "undefined") ? ({}) : (definition),
(typeof type["__definition"] !== "undefined") ? (_LegacyCopy(type.__definition)) : ({})
);
}
type = (type.hasOwnProperty.call(type,"prototype")) ? (type.prototype) : (_LegacyCopy(type));
if (typeof definition !== "undefined" && !definition.hasOwnProperty.call(definition,"__new__")) {
definition["__new__"] = function(properties) {
_CastProps(properties, this);
};
}
if (typeof definition !== "undefined" && !definition.hasOwnProperty.call(definition,"css")) {
definition["css"] = function QC_CSS3(_css) {
if (typeof this["body"] !== "undefined" && this["body"]["style"] !== "undefined") {
logger.debug("body style");
this["body"]["style"] = _Cast(_css, this["body"]["style"]);
}
};
}
if (typeof definition !== "undefined" && !definition.hasOwnProperty.call(definition,"hierarchy")) {
definition["hierarchy"] = function hierarchy() {
var __classType = function(o_c) {
return __getType__.call(this, o_c);
};
var __hierarchy = [];
__hierarchy.push(__classType(this));
if (this.hasOwnProperty.call(this,"__definition")) {
__hierarchy = __hierarchy.concat(this.__definition.hierarchy.call(this.__definition));
}
return __hierarchy;
};
}
if (typeof definition !== "undefined" && !definition.hasOwnProperty.call(definition,"append")) {
definition["append"] = function QC_Append() {
var child = (arguments.length > 0) ? (arguments[0]) : (this["body"]);
if (typeof this["body"] !== "undefined") {
logger.debug("append element");
if (arguments.lenght > 0) {
logger.debug("append to element");
this["body"].append(child);
if (typeof this["childs"] === "undefined") {
this["childs"] = [];
}
this["childs"].push(child);
} else {
if (isBrowser) {
logger.debug("append to body");
document.body.append(child);
}
}
}
};
}
if (typeof definition !== "undefined" && !definition.hasOwnProperty.call(definition,"attachIn")) {
definition["attachIn"] = function QC_AttachIn(tag) {
if (isBrowser) {
var tags = document.subelements(tag);
for (var i = 0, j = tags.length; i < j; i++) {
tags[i].append(this);
}
} else {
// not yet implemented.
}
};
}
// hack to prevent pre-population of __instanceID into the class definition
if (typeof definition !== "undefined" && definition.hasOwnProperty.call(definition,"__instanceID")){
delete definition.__instanceID;
}
o = _Object_Create(type, definition);
o["__definition"] = definition;
o["__definition"]["__classType"] = name;
_QC_CLASSES[name] = o;
_top[name] = _QC_CLASSES[name];
return _top[name];
};
Class.prototype.toString = function() {
return "Class(name, type, definition) { [QCObjects native code] }";
};
/**
* Returns the QCObjects Class Factory of a given ClassName
*
* @param {String} name
*/
var ClassFactory = function(className) {
var _classFactory;
if (className !== null && className.indexOf(".")>-1){
var packageName = className.split(".").slice(0,className.split(".").length-1).join(".");
var _className = className.split(".").slice(-1).join("");
var _package = Package(packageName);
var packageClasses = (typeof _package !== "undefined")?(_package.filter(classFactory=>{
return typeof classFactory !== "undefined"
&& classFactory.hasOwnProperty.call(classFactory,"__definition")
&& isQCObjects_Class(classFactory)
&& classFactory.__definition.__classType===_className
&& !classFactory.hasOwnProperty.call(classFactory,"__instanceID");}).reverse()):([]);
if (packageClasses.length>0){
_classFactory = packageClasses[0];
}
} else if (className !== null && _QC_CLASSES.hasOwnProperty.call(_QC_CLASSES,className)) {
_classFactory = _QC_CLASSES[className];
}
return _classFactory;
};
if (isBrowser) {
Element.prototype.append = function QC_Append(child) {
if (typeof child.__definition !== "undefined" && typeof child.__definition.__classType !== "undefined" && typeof child.body) {
this.appendChild(child.body);
} else {
this.appendChild(child);
}
};
/**
* A replacement for direct using of innerHTML
* use: [element].render('content') where 'content' is the string corresponding
* to the DOM to insert in the element
**/
Element.prototype.render = function QC_Render(content) {
var _self = this;
var _appendVDOM = function (_self,content){
if (typeof document.implementation.createHTMLDocument !== "undefined"){
var doc = document.implementation.createHTMLDocument("");
doc.innerHTML = content;
doc.body.subelements("*").map(function (element){
return _self.append(element);
});
}
};
if (typeof this.innerHTML !== "undefined"){
try {
this.innerHTML += content;
}catch (e){
_appendVDOM(_self,content);
}
} else {
_appendVDOM(_self,content);
}
};
}
/**
* Returns a method from a superior QCObjects Class
* It is useful for Class Inheritance in the _new_ and __new__ method constructors
* @example _super_('MySuperClass','MySuperMethod').call(this,params) #where this is the current instance and params are method parameters
*
* @param {String} className
* @param {String} classMethodName
* @param {Object} params
*/
var _super_ = function(className, classMethodName, params) {
return ClassFactory(className)[classMethodName];
};
_super_.prototype.toString = function() {
return "_super_(className,classMethodName,params) { [QCObjects native code] }";
};
/**
* Creates an object from a Class definition
*
* @param {QC_Object} o
* @param {Object} args
*/
var New = function(c, args) {
var args = (arguments.length > 1) ? (arguments[1]) : ({});
__instanceID = (typeof __instanceID === "undefined" || __instanceID === null) ? (0) : (__instanceID + 1);
var c_new = (typeof c === "undefined") ? (_Object_Create(({}).constructor.prototype, {})) : (_Object_Create(c.constructor.prototype, c.__definition));
c_new.__definition = _Cast({
"__instanceID": __instanceID
}, (typeof c !== "undefined") ? (c.__definition) : ({}));
c_new["__instanceID"] = __instanceID;
if (c_new.hasOwnProperty.call(c_new,"definition") && typeof c_new.__definition !== "undefined" && c_new.__definition !== null) {
c_new.__definition["__instanceID"] = __instanceID;
}
if (c_new.hasOwnProperty.call(c_new,"__new__")) {
if (typeof c_new !== "undefined" && !c_new.__definition.hasOwnProperty.call(c_new.__definition,"body")) {
try {
if (isBrowser) {
c_new["body"] = _Cast(c_new["__definition"], _DOMCreateElement(c_new.__definition.__classType));
c_new["body"]["style"] = _Cast(c_new.__definition, c_new["body"]["style"]);
} else {
c_new["body"] = {};
c_new["body"]["style"] = {};
}
} catch (e) {
c_new["body"] = {};
c_new["body"]["style"] = {};
}
} else if (c_new.__definition.hasOwnProperty.call(c_new.__definition,"body")) {
c_new["body"] = c_new.__definition.body;
}
c_new.__new__(args);
if (c_new.hasOwnProperty.call(c_new,"_new_")) {
c_new._new_(args);
}