-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathessence.js
4709 lines (4450 loc) · 154 KB
/
essence.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
"use strict";
/* global Essence:false, $G, Sys, base64, UnitTest, modules, debugging */
/* eslint no-unused-vars: 0 */
/* eslint no-undef: 0 */
/**
* @module essence
* @description Core module of the framework
* @license MIT
* @author Maximilian Berkmann <[email protected]>
* @copyright Maximilian Berkmann 2016
* @typedef {(number|string)} NumberLike
* @typedef {(number|number[])} Nums
* @typedef {(string|string[])} Str
* @typedef {(number|boolean)} Bool
* @typedef {(Array|Object|string)} Iterable
* @typedef {(Array|Object)} Dict
* @typedef {(XML|string)} Code
* @typedef {(Node|TreeNode|NTreeNode|Vertex)} Node
* @requires modules/Files
* @requires modules/DOM
* @requires modules/UI
* @requires modules/Web
* @requires modules/Misc
* @requires modules/Ajax
* @requires modules/DataStruct
* @requires modules/Maths
* @requires modules/Security
* @requires modules/QTest
*/
/**
* @description This is the main object of the library as well as being the core module of the framework.
* @type {{version: string, author: string, description: string, source: string, element: $n, handleError: module:essence.handleError, say: module:essence.say, applyCSS: module:essence.applyCSS, addCSS: module:essence.addCSS, addJS: module:essence.addJS, update: module:essence.update, eps: number, emptyDoc: module:essence.emptyDoc, editor: module:essence.editor, processList: Array, global: null, addProcess: module:essence.addProcess, processSize: number, serverList: Array, addServer: module:essence.addServer, serverSize: number, toString: module:essence.toString, txt2print: string, addToPrinter: module:essence.addToPrinter, print: module:essence.print, preInit: module:essence.preInit, init: module:essence.init, time: module:essence.time, sayClr: module:essence.sayClr, ask: module:essence.ask, isComplete: module:essence.isComplete, loadedModules: Array, updateAll: module:essence.updateAll}}
* @this Essence
* @namespace
* @exports essence
* @since 1.0
* @property {NumberLike} Essence.version EssenceJS' version
* @property {string} Essence.author Author
* @property {string} Essence.description Description of EssenceJS
* @property {string} Essence.source Source of the script
* @property {HTMLElement} Essence.element $n element
* @property {function((string|Error), (URL|string), NumberLike)} Essence.handleError Error handler
* @property {function(...string)} Essence.say EssenceJS's console logger
* @property {function(boolean)} Essence.applyCSS Apply EssenceJS's CSS
* @property {function(Code)} Essence.addCSS Add CSS rules
* @property {function(string)} Essence.addJS Add JS commands
* @property {Function} Essence.update EssenceJS' self update's mechanism
* @property {number} Essence.eps Matlab's epsilon
* @property {function(string, string)} Essence.emptyDoc Empty the document
* @property {function(Code)} Essence.editor In-browser editor
* @property {process[]} Essence.processList Process list
* @property {Object} Essence.global $G
* @property {function(process)} Essence.addProcess Process adder
* @property {number} Essence.processSize Total process size
* @property {server[]} Essence.serverList Server list
* @property {function(server)} Essence.addServer Server adder
* @property {number} Essence.serverSize Total server size
* @property {function(): string} Essence.toString String representation of EssenceJS's namespace
* @property {string} Essence.txt2print Text to print
* @property {function(string, string)} Essence.addToPrinter Add text to the printer and print them
* @property {function(string, string)} Essence.print Print stuff to the screen
* @property {Function} Essence.preInit Pre-initialisation
* @property {Function} Essence.init Initialisation
* @property {function(...string)} Essence.time Say something with the time stamped
* @property {function(NumberLike[])} Essence.sayClr Log the colour
* @property {function(string, function(string))} Essence.ask Ask something to the user
* @property {function(): boolean} Essence.isComplete Module inclusion completeness check
* @property {string[]} Essence.loadedModules List of loaded modules
* @property {Function} Essence.updateAll Update all modules
*/
var Essence = {
version: "1.1b",
author: "Maximilian Berkmann",
description: "library used for DHTML connexions, maths, database management and cryptography",
source: "http://berkmann18.github.io/rsc/essence.js",
element: $n,
handleError: function (msg, url, line) {
isType(msg, "Error")? alert("[Essence.js] An error has occurred (line/column " + msg.lineNumber + "/" + msg.columnNumber + " of " + msg.fileName + ").\n\nMessage: " + msg.stack): alert("[Essence.js] An error has occurred (line " + line + " of " + url + ").\n\nMessage: " + msg)
}, say: function (msg, type, style, style0, style1, style2) { //Say something in the console
type = isNon(type)? "": type.slice(0, 4).toLowerCase();
if (style && !style0) {
if (type === "info") console.info("%c[EssenceJS]%c " + msg, "color: #00f; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style);
else if (type === "erro") console.error("%c[EssenceJS]%c " + msg, "color: #f00; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style);
else if (type === "warn") console.warn("%c[EssenceJS]%c " + msg, "color: #fc0; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style);
else if (type === "succ") console.log("%c[EssenceJS]%c " + msg, "color: #0f0; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style);
else console.log("%c[EssenceJS]%c " + msg, "color: #808080; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style);
} else if (style && style0 && !style1) {
if (type === "info") console.info("%c[EssenceJS]%c " + msg, "color: #00f; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0);
else if (type === "erro") console.error("%c[EssenceJS]%c " + msg, "color: #f00; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0);
else if (type === "warn") console.warn("%c[EssenceJS]%c " + msg, "color: #fc0; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0);
else if (type === "succ") console.log("%c[EssenceJS]%c " + msg, "color: #0f0; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0);
else console.log("%c[EssenceJS]%c " + msg, "color: #808080; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0);
} else if (style && style0 && style1 && !style2) {
if (type === "info") console.info("%c[EssenceJS]%c " + msg, "color: #00f; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0, style1);
else if (type === "erro") console.error("%c[EssenceJS]%c " + msg, "color: #f00; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0, style1);
else if (type === "warn") console.warn("%c[EssenceJS]%c " + msg, "color: #fc0; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0, style1);
else if (type === "succ") console.log("%c[EssenceJS]%c " + msg, "color: #0f0; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0, style1);
else console.log("%c[EssenceJS]%c " + msg, "color: #808080; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0, style1);
} else if (style && style0 && style1 && style2) {
if (type === "info") console.info("%c[EssenceJS]%c " + msg, "color: #00f; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0, style1, style2);
else if (type === "erro") console.error("%c[EssenceJS]%c " + msg, "color: #f00; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0, style1, style2);
else if (type === "warn") console.warn("%c[EssenceJS]%c " + msg, "color: #fc0; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0, style1, style2);
else if (type === "succ") console.log("%c[EssenceJS]%c " + msg, "color: #0f0; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0, style1, style2);
else console.log("%c[EssenceJS]%c " + msg, "color: #808080; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000", style, style0, style1, style2);
} else {
if (type === "info") console.info("%c[EssenceJS]%c " + msg, "color: #00f; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000");
else if (type === "erro") console.error("%c[EssenceJS]%c " + msg, "color: #f00; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000");
else if (type === "warn") console.warn("%c[EssenceJS]%c " + msg, "color: #fc0; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000");
else if (type === "succ") console.log("%c[EssenceJS]%c " + msg, "color: #0f0; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000");
else console.log("%c[EssenceJS]%c " + msg, "color: #808080; text-decoration: bold;-webkit-text-decoration: bold;-moz-text-decoration: bold;", "color: #000");
}
},
applyCSS: function (nonMinify) {
include_once(getExtPath(getDirectoryPath(gatherScripts()[gatherScripts()["essence.min.js"]? "essence.min.js": "essence.js"])) + (nonMinify? "essence.css": "essence.min.css"), "link", getDirectoryPath());
/*if ($end("html").val(true).indexOf("<body></body>") > -1) { //A bit of cleaning
var ix = $end("html").val(true).indexOf("<body></body>");
var bfr = $end("html").val(true).slice(0, ix), aft = $end("html").val(true).slice(ix + 13, $end("html").val(true).length);
$end("html").write(bfr + aft, true);
}*/
},
addCSS: function (nstyle) {
if ($n("style", true) === null) {
var s = document.createElement("style");
s.innerText = nstyle;
//start.media = "all";
s.type = "text/css";
s.id = "EssenceCSS";
$n("head").appendChild(s);
} else if ($e("style[type='text/css']", true) != null) $e("style[type='text/css']").after(nstyle);
else $e("style").after(nstyle);
}, addJS: function (nscript) {
if ($n("script", true) === null) {
var s = document.createElement("script");
s.innerText = nscript;
s.type = "text/javascript";
$n("head").appendChild(s);
} else $e("script[type='text/javascript']").after(nscript);
}, update: function () { //To keep the script updated !!
var $s = $n("*script").toArray();
var scripts = filenameList($s.map(function (script) {
return script.src;
}));
for (var i = 0; i < scripts.length; i++) {
if (stripPath(scripts[i]) === "essence.js" || stripPath(scripts[i]) === "essence.min.js") $s[i].src = Essence.source;
}
Essence.say("%cEssence(.min).js%c has been updated", "succ", "text-decoration: underline", "text-decoration: none");
},
/** @const {number} Essence.eps Epsilon */
eps: Math.pow(2, -52), //Matlab'sepsilon (useful when dealing with null values to keep them in the real range or just not null
emptyDoc: function (title, author) { //Empty the document and fill it with a basic structure
$e("html").write("<head><title>" + (title || document.title) + "</title><meta charset='UTF-8' /><meta name='author' content=" + (author || "unknown") + " /><script type='text/javascript' src=" + Essence.source + "></script></head><body></body>", true);
}, editor: function (ctt) {
location.href = "data:text/html, <html contenteditable>" + (ctt? ctt + "</html>": "</html>");
}, processList: [["Name (signature)", "Author", "Size"]],
global: null,
addProcess: function (pcs) {
pcs.update();
Essence.processList.push([pcs.name + " (" + pcs.sig + ")", pcs.author, pcs.bitsize]);
pcs.id = Essence.processList.length - 1;
Essence.processSize += pcs.bitsize;
}, processSize: 0, serverList: [["Name", "Author", "Maximum size"]],
addServer: function (serv) {
serv.update();
Essence.serverList.push([serv.name, serv.author, serv.maxsize]);
Essence.serverSize += serv.maxsize;
}, serverSize: 0,
toString: function () {
return "[object Essence]"
}, txt2print: "",
addToPrinter: function (txt, type) { //Allow the usage of print without having to directly touch to txt2print
txt.has("\n\r")? this.print(txt, type): this.txt2print += txt;
}, print: function (txt, type) { //Works like the print in Java
if (txt) this.txt2print += txt;
//noinspection JSValidateTypes
this.txt2print = this.txt2print.split("\b");
for (var i = 0; i < this.txt2print.length; i++) {
this.say(this.txt2print[i], type);
}
this.txt2print = "";
}, preInit: function () {
//noinspection JSValidateTypes
$G.t1 = $G.t1.getTime();
}, init: function () {
//noinspection JSValidateTypes
$G.t2 = new Date();
$G.t2 = $G.t2.getTime();
$G.t = ($G.t2 - $G.t1 > 1000)? ($G.t2 - $G.t1) / 1000 + "s": ($G.t2 - $G.t1) + "ms";
if (debugging) Essence.say("Page loaded in %c" + $G.t + "%c", "succ", "font-style: italic", "font-style: none");
}, time: function(msg, style, style0) { //Like Essence.say(msg) but with the timestamp
console.log("[%c" + getTimestamp(true) + "%c] "+msg, "color: #00f;", "color: #000;", style || "", style0 || "")
}, sayClr: function (clrs) { //Display a RGB(A) coloured console log
clrs.length === 4? console.log("%cr%cg%cb%ca(%c" + clrs.join(", %c") + "%c)", "color: #f00", "color: #0f0", "color: #00f", "color: #00f", "color: #000", "color: #f00", "color: #0f0", "color: #00f", "color: #00f", "color: #000"): console.log("%cr%cg%cb%c(%c" + clrs.join(", %c") + "%c)", "color: #f00", "color: #0f0", "color: #00f", "color: #00f", "color: #000", "color: #f00", "color: #0f0", "color: #00f", "color: #00f", "color: #000");
}, ask: function (label, callback) { //Ask something to the user
Sys.in.recording = true;
Essence.say((label || "Is there a problem") + " ? (please type in the window and not the console)", "quest");
while ($G["lastKeyPair"][1] != 96 /*$G["lastKeyPair"][1] != 13*/ && $G["lastKeyPair"][1] != 10) { //Quits on enter and `
//Essence.say("waiting for an enter");
}
alert("OUT !!");
Sys.in.recording = false;
if(callback) callback(Sys.in.data.join(""));
return Sys.in.data.join("");
}, isComplete: function () {
var complete = true;
this.loadedModules = [];
for (var i = 0; i < modules.length; i++) {
try {
eval(window[modules[i]].loaded);
} catch (e) {
Essence.say("The module " + modules[i] + " is not right !", "warn");
init(modules[i]);
} finally {
complete &= window[modules[i]].loaded;
}
if (window[modules[i]].loaded) this.loadedModules.push(window[modules[i]]);
}
//noinspection PointlessBooleanExpressionJS
return !!complete;
}, loadedModules: [],
updateAll: function () {
this.update();
this.isComplete();
this.loadedModules.map(function (m) {
m.update();
});
},
listModules: function () {
var list = moduleList(true);
var weights = list.line(4).get(1);
}
},
/**
* @description List of modules
* @global
* @type {string[]}
* @since 1.1
*/
modules = [],
/**
* @description Debugging flag
* @global
* @type {boolean}
* @since 1.1
*/
debugging = false,
/**
* @description Empty function
* @global
* @type {Function}
* @since 1.1
* @readonly
* @returns {undefined}
*/
$f = function () {},
/**
* @description Test mode on/off
* @type {boolean}
* @global
* @since 1.1
*/
testMode = false,
/**
* @description Performance/profiling mode on/off
* @type {boolean}
* @global
* @since 1.1
*/
perfMod = true;
/**
* @description EssenceJS Module
* @param {string} [name="Module"] Name
* @param {string} [desc=""] Description
* @param {string[]} [dpc=[]] Dependencies
* @param {number} [ver=1] Version
* @param {Function} [rn=function () {}] Run method
* @param {string} [pathVer=Essence.version.substr(0, 3)] Path's version
* @constructor
* @this Module
* @returns {Module} Module
* @property {string} Module.name Name of the module
* @property {number} Module.version Version of the module
* @property {string[]} Module.dependency Dependencies
* @property {string} Module.description Description of the module
* @property {Function} Module.run Runner method
* @property {boolean} Module.loaded Loading flag
* @property {string} Module.path Path of the module
* @property {Function} Module.load Load the module as well as initializing its dependencies
* @property {function(): string} Module.toString String representation
* @property {function(): number} Module.getWeight Weight of the module on EssenceJS's module ecosystem
* @property {Function} Module.update Update the module
* @property {function(): String} Module.getUsage List of modules dependent on this one
* @since 1.1
*/
function Module (name, desc, dpc, ver, rn, pathVer) {
this.name = name || "Module";
this.version = ver || 1;
this.dependency = dpc || [];
this.description = desc || "";
this.run = rn || $f;
this.loaded = false;
this.path = (pathVer? pathVer : Essence.version.substr(0, 3)) + "/modules/" + this.name + ".js";
this.load = function () {
if (perfMod) console.timeStamp("Loading module:" + this.name);
if (debugging) Essence.say("Loading " + this.name);
if (this.dependency.length > 0) {
if (debugging) Essence.say("Initiating dependencies for %c" + this.name + "%c", "info", "color: #f0f", "color: #000");
//For less redundancy here: this.dependency -> complement(this.dependency, modules)
init(this.dependency, false, false, pathVer);
}
/*if (gatherExternalScripts(true).has(this.path) || filenameList(gatherExternalScripts(true)).has(this.path)) */this.loaded = true;
if (perfMod) console.timeStamp("Loaded module:" + this.name);
};
this.toString = function () {
return "Module(name='" + this.name + "', version=" + this.version + ", dependency=[" + this.dependency + "], description='" + this.description + "', loaded=" + this.loaded + ", run=" + this.run + ", path='" + this.path + "')";
};
this.getWeight = function () {
var dpcs = moduleList(false, true).line(3).get(1), weight = 0, names = moduleList(false, true).line().get(1); //List of dependencies of all loaded modules
for (var i = 0; i < dpcs.length; i++) {
if (dpcs[i].has(this.name) && names[i] != this.name && dpcs[i].count(this.name) < 2) weight++;
else if (names[i] === this.name && dpcs[i].has(this.name)) weight--; //Penalty
}
return weight;
};
this.update = function () { //This method should not be used before EssenceJS is fully implemented onto the environment using it
if (perfMod) console.timeStamp("Updated module:" + this.name);
var $s = $n("*script").toArray();
var scripts = filenameList($s.map(function (script) {
return script.src;
}));
for (var i = 0; i < scripts.length; i++) {
if (stripPath(scripts[i]) === this.name + ".js") $s[i].src = "http://berkmann18.github.io/rsc/modules/" + this.name + ".js";
else if (stripPath(scripts[i]) === this.name + ".min.js") $s[i].src = "http://berkmann18.github.io/rsc/modules/" + this.name + ".min.js";
}
Essence.say(this.name.capitalize() + "(.min).js has been updated", "succ");
if (perfMod) console.timeStamp("Updated module:" + this.name);
};
this.getUsage = function () {
var dpcs = moduleList(false, true).line(3).get(1), usage = "", names = moduleList(false, true).line().get(1); //List of dependencies of all loaded modules
for (var i = 0; i < dpcs.length; i++) {
if (dpcs[i].has(this.name) && names[i] != this.name && dpcs[i].count(this.name) < 2) usage += names[i] + ", ";
}
return usage.get(-2);
};
return this;
}
/**
* @description ES6-like module loader
* @func
* @param {Str} mdl Module
* @param {NumberLike} [ver] Version of the directory containing it
* @param {string} [extpath] External path
* @returns {undefined}
* @since 1.1
* @example <caption>Example 1:</caption>
* require("myModule"); //It will import the script located at "modules/myModule.js"
* require(["moduleA", "moduleB", "moduleC"]); //It will import "modules/moduleA.js", "modules/moduleB.js" and "modules/moduleC.js"
* @example <caption>Example 2:</caption>
* require("myModule", 1.1); //It will import the script located at "1.1/modules/myModule.js"
* @see module:essence~$require
* @deprecated
*/
function require (mdl, ver, extpath) {
if (perfMod) console.timeStamp("Start of require(" + mdl + ", " + ver + ")");
if (isType(mdl, "Array")) {
for (var i = 0; i < mdl.length; i++) { //noinspection JSDeprecatedSymbols
require(mdl[i], ver);
}
} else if (modules.indexOf(mdl) === -1) {
include_once((ver? ver + "/": "") + "modules/" + mdl + ".js", "script", extpath || getDirectoryPath());
modules.push(mdl);
if (debugging) console.log("The module %c%start%c is now included into %c%start " + getTimestamp(true), "color: red; text-decoration: bold; -webkit-text-decoration: bold; -moz-text-decoration: bold;", mdl, "color: #000; text-decoration: none;", " text-decoration: bold; -webkit-text-decoration: bold; -moz-text-decoration: bold;", getFilename());
} else if (debugging) console.log("The module %c%start%c is already included into %c%start " + getTimestamp(true), "color: red; text-decoration: bold; -webkit-text-decoration: bold; -moz-text-decoration: bold;", mdl, "color: #000; text-decoration: none;", " text-decoration: bold; -webkit-text-decoration: bold; -moz-text-decoration: bold;", getFilename());
if (perfMod) console.timeStamp("End of require(" + mdl + ", " + version + ")");
}
/**
* @description ES6-like module loader
* @func
* @param {Str} mdl Module
* @returns {undefined}
* @since 1.1
* @example <caption>Example 1:</caption>
* require("myModule"); //It will import the script located at "modules/myModule.js"
* require(["moduleA", "moduleB", "moduleC"]); //It will import "modules/moduleA.js", "modules/moduleB.js" and "modules/moduleC.js"
*/
function $require (mdl) {
if (perfMod) console.timeStamp("Start of $require(" + mdl + ")");
var toND = function (x, n) {
var i = this + ""; //Because it won't work with other types than strings
n = n || 2;
if (parseFloat(i) < Math.pow(10, n - 1)) {
while (i.split(".")[0].length < n) i = "0" + i;
}
return i
}, getT = function () {
var d = new Date();
return getDate() + " " + toND(d.getHours(), 2) + ":" + toND(d.getMinutes(), 2) + ":" + toND(d.getSeconds(), 2) + "." + toND(d.getMilliseconds(), 2)
}, stripP = function (p) {
return p.split("/")[p.split("/").length - 1]
}, _g = function (x, start, end) {
var res = "";
if (start < 0 && !end) {
end = start;
start = 0;
}
if (end < 0) end = x.length + end - 1;
for (var i = (start || 0); i <= (end || x.length - 1); i++) res += x[i];
return res
},getFn = function () {
return _g(stripP(location.pathname), (-stripP(location.pathname).lastIndexOf(".") - 1));
};
if (isType(mdl, "Array")) {
for (var i = 0; i < mdl.length; i++) $require(mdl[i]);
} else if (modules.indexOf(mdl) === -1) {
gatherScripts()["essence.min.js"]? include_once(getExtPath(getDirectoryPath(gatherScripts()["essence.min.js"])) + "modules/" + mdl + ".min.js", "script"): include_once(getExtPath(getDirectoryPath(gatherScripts()["essence.js"])) + "modules/" + mdl + ".js", "script");
modules.push(mdl);
if (debugging) console.log("The module %c%start%c is now included into %c%start " + getT(), "color: red; text-decoration: bold; -webkit-text-decoration: bold; -moz-text-decoration: bold;", mdl, "color: #000; text-decoration: none;", " text-decoration: bold; -webkit-text-decoration: bold; -moz-text-decoration: bold;", getFn());
} else if (debugging) console.log("The module %c%start%c is already included into %c%start " + getT(), "color: red; text-decoration: bold; -webkit-text-decoration: bold; -moz-text-decoration: bold;", mdl, "color: #000; text-decoration: none;", " text-decoration: bold; -webkit-text-decoration: bold; -moz-text-decoration: bold;", getFn());
if (perfMod) console.timeStamp("End of $require(" + mdl + ")");
}
/**
* @description Run a module that was already imported (see {@link require}) after initiating its dependencies
* @func
* @since 1.1
* @param {Str} module Module
* @param {NumberLike} [ver] Directory version
* @returns {undefined}
* @example
* run("myModule"); //will run myModule.run()
* run(["moduleA", "moduleB"]); //will run moduleA.run() then moduleB.run() (unless module is a dependency of moduleA in which case it will be ran before)
*/
function run (module, ver) {
if (perfMod) console.timeStamp("Start of run(" + module + ", " + ver + ")");
if (isType(module, "Array")) {
for (var i = 0; i < module.length; i++) run(module[i], ver);
} else if (modules.indexOf(module) > -1) {
/**
* @description Go onto the running phase of the module
* @inner
* @func
* @returns {undefined}
*/
var go = function () {
if (perfMod) console.timeStamp("Go in run(" + module + ", " + ver + ")");
try {
if (debugging) Essence.say("Running " + module + " " + getTimestamp(true), "info");
/*init(window[module].dependency, false, function (x) {
if (debugging) Essence.say("%c" + x + "%c from %c" + module + "%c's dependency has been initiated !! " + getTimestamp(true), "info", "color: #c0f", "color: #000", "color: #f0c", "color: #000");
//console.info("")
}, ver);*/
if (!window[module].loaded) window[module].load();
window[module].run();
} catch (e) {
Essence.time("The module %c" + module + "%c have problems regarding it's run method.", "color: #c0f", "color: #000");
}
}, /**
* @description Retry to get the module to be usable and launch go()
* @inner
* @func
* @param {number} [stackLayer=0] Stack layer
* @returns {undefined}
*/
retry = function (stackLayer) {
if (perfMod) console.timeStamp("Retry in run(" + module + ", " + ver + ")");
if (!stackLayer) stackLayer = 0;
Essence.say("The module %c" + module + "%c isn't available ! " + getTimestamp(true), "erro", "color: #c0f", "color: #000");
if (debugging) Essence.say("Retrying to run %c" + module + "%c " + getTimestamp(true), "info", "color: #c0f", "color: #000");
if (window[module]) go();
else if (stackLayer <= 2) setTimeout(retry(stackLayer + 1), 1);
else Essence.say("It's not possible to run %c" + module + "%c :( ! " + getTimestamp(true) + "\nModule: " + window[module], "info", "color: #c0f", "color: #000");
init(module);
};
window[module]? go(): retry();
} else Essence.say("The module %c" + module + "%c isn't in the list !! " + getTimestamp(true), "erro", "color: #c0f", "color: #000");
if (perfMod) console.timeStamp("End of $require(" + module + ", " + ver + ")");
}
/**
* @description Initiate a module
* @param {Str} mdls Module(start)
* @param {function(*)|boolean} [mid] Mid-execution function
* @param {function(*)|boolean} [cb] Callback function
* @param {NumberLike} [ver] Version (if the modules are in a version based partitioning (end.g: 1.0/modules/ModuleA.js, 1.1/modules/ModuleA.js, beta/modules/ModuleA.js)
* @param {*} [argsMid] Arguments for the mid()
* @param {*} [argsCB] Arguments for the cb()
* @since 1.0
* @returns {undefined}
* @func
* @example <caption>Example 1:</caption>
* init("myModule"); //Initiate the module myModule
* init(["moduleA", "moduleB"]); //Initiate the modules moduleA and moduleB
* @example <caption>Example 2:</caption>
* init("myModule", function () {}, function () {
* Essence.say("myModule has been fully initiated !", "info");
* }, "alpha"); //Initiate the myModule.js module located at alpha/modules/ and with a callback
* init(["moduleA", "moduleB"], function (mdl) {
* Essence.say("Midway through " + mdl, "info");
* }, function (mdl) {
* Essence.say("Finished initiating " + mdl, "succ");
* });
*/
function init (mdls, mid, cb, ver, argsMid, argsCB) {
if (perfMod) console.timeStamp("Start of init(" + mdls + ")");
if (isType(mdls, "Array")) {
for (var i = 0; i < mdls.length; i++) init(mdls[i], mid, cb, ver, mdls[i], mdls[i]);
} else {
if (debugging) Essence.say("Initiating " + mdls);
if (modules.indexOf(mdls) === -1) $require(mdls);
else if (debugging) Essence.say("The module %c" + mdls + "%c was already initiated !!", "info", "color: #c0f", "color: #000");
if (mid) mid(argsMid || mdls); //Used when initiating a module that has dependencies
setTimeout(function () { //Delayed running to leave some time for the module to be fully available to this page
//if (!window[mdls].loaded) window[mdls].load();
run(mdls);
if (cb) cb(argsCB || mdls);
}, 1);
}
if (perfMod) console.timeStamp("End of init(" + mdls + ")");
}
/**
* @ignore
* @external module/File~getDirectoryPath
* @inheritdoc
* @param {string} [path=location.href] Path
* @returns {string} Directory path
* @since 1.1
*/
var getDirectoryPath = function (path) {
if(!path) path = location.href;
return path.substring(0, path.indexOf(path.split("/")[path.split("/").length - 1]))
}, /**
* @ignore
* @external module/DOM~gatherScripts
* @inheritdoc
* @param {boolean} [asList=false] Result should be a list or an object
* @returns {*} List/dictionary of scripts
*/
gatherScripts = function (asList) {
var $s = $n("*script"), res = asList? []: {};
for(var i = 0; i < $s.length; i++) asList? res.push($s[i].src): res[$s[i].src.split("/")[$s[i].src.split("/").length - 1]] = $s[i].src;
return res
}, /**
* @ignore
* @external module/DOM~gatherStylesheets
* @inheritdoc
* @param {boolean} [asList=false] Result should be a list or an object
* @returns {*} List/dictionary of stylesheets
*/
gatherStylesheets = function (asList) {
var $l = $n("*link"), res = asList? []: {};
for(var i = 0; i<$l.length; i++) asList? res.push($l[i].href): res[$l[i].href.split("/")[$l[i].href.split("/").length - 1]] = $l[i].href;
return res
},/**
* @ignore
* @inheritdoc
* @external module/File~getCurrentPath
* @param {string} path Path
* @param {string} [localPath="file:///"] Local path
* @returns {string} Current path
*/
getCurrentPath = function (path, localPath) {
if (!localPath) localPath = "file:///";
var parts = path.split("/"), res, pParts = localPath.split("/"), i = 0, j = 0, _get = function (o, start, end) {
var r = [];
if (start < 0 && !end) {
end = start;
start = 0;
}
if (end < 0) end = o.length + end - 1;
for (var i = (start || 0); i <= (end || o.length - 1); i++) r.push(o[i]);
return r.filter(function (x) {
return x != undefined;
});
};
while (localPath.indexOf(parts[i]) > -1) i++;
res = _get(parts, i).join("/");
while (res.indexOf(pParts[j]) > -1) {
console.log("Gone through " + pParts[j]);
j++;
}
if (j > 0) {
for(i = 0; i < j; i++) res = "../" + res;
}
return res
}, /**
* @ignore
* @inheritdoc
* @external module/File:getExtPath
* @param {string} path Full path
* @returns {string} External path
*/
getExtPath = function (path) {
var cp = location.href, sF = function (s0, s1) {
var sf = "", pos = -1;
while (pos <= Math.min(s0.length, s1.length)) {
pos++;
if (s0[pos] === s1[pos]) sf += s0[pos];
else break;
}
return sf;
}, ct = function (o, c) {
var n = 0;
for (var i = 0; i < o.length; i++) {
if (o[i] === c) n++;
}
return n
};
var parentPath = sF(cp, path);
return "../".repeat(ct(getCurrentPath(cp, parentPath), "/")) + getCurrentPath(path, parentPath);
}, /**
* @ignore
* @inheritdoc
* @external module/File:filenameList
* @returns {Array} File name list
*/ filenameList = function (list) {
var res = [];
for(var i = 0; i < list.length; i++) res.push(stripPath(list[i]));
return res.remove()
};
/**
* @summary Module Loading section
* @since 1.1
* @returns {undefined}
* @func
*/
(function () {
//document.scripts[i].ownerDocument may be useful to correct the link of the included modules
if (perfMod) console.timeStamp("Module Loader init");
if (debugging) Essence.say("Initiating the Module Loader");
$require(["Files", "DOM", "UI", "Web", "Maths", "Ajax", "DataStruct", "Security", "Misc", "QTest"]);
/* init(["Web", "Maths", "Ajax", "DataStruct", "Security", "Misc", "QTest"], function (mdl) {
Essence.say(mdl + " on the way!", "info");
}, function (mdl) {
Essence.say(mdl + " is ready!", "succ");
}, 1.1); */
setTimeout(function () {
run(modules, Essence.version.substr(0, 3));
if (perfMod) console.timeStamp("Modules ran!");
}, 690);
setTimeout(function () {
if (debugging) {
//noinspection JSValidateTypes
if (Essence.isComplete()) Essence.say("Essence is complete !", "succ");
else Essence.time("List of loaded modules: " + Essence.loadedModules.map(function (m) {
return m.name;
}).toStr(true));
}
if (!filenameList(gatherExternalScripts(true)).has("essence.js")) Essence.source = Essence.source.replace(".js", ".min.js");
UnitTest.libTests = [
//essence
//Ajax
/*[GET("_ijt"), function () {
var val = null;
parseURL("_ijt", function (x) {
val = x;
});
return val;
}, "GET],*/
//DataStruct
[binarySearch(["hi", " ", "dude"], " ", "BinarySearch"), true],
//[binarySearch(["hi", " ", "dude"], "!", "BinarySearch"), false],
//[search(["hi", " ", "dude"], "!", "Search"), -1],
[Perm("abc"), ["abc", "acb", "cab", "cba", "bac", "bca"], "Perm"],
//DOM
[unescapeHTML(escapeHTML("<p>Hi</p>")), "<p>Hi</p>", "Un(escape)"],
[escapeHTML(unescapeHTML("<p>Hi</p>")), "<p>Hi</p>", "Es(unescape)"],
//Files
[getDirectoryPath() + stripPath(location.href), location.href, "Path"],
//Maths
[min2dec(dec2min(.56)), .56, "min<->dec"],
[toS(s2t(75.23)), 75.23, "start<->time"],
[isPrime(23), true, "Prime"],
[isPrime(25), false, "!Prime"],
//Misc
[rmDuplicates("hello world !"), "helo wrd!", "NoDuplic"],
[unRegExpify(RegExpify("Hi ${name}")), "Hi ${name}", "RE<->"],
//QTest
//Security
[decrypt(encrypt("Hello", 5), -5), "Hello"," de(encrypt)"],
[encrypt(decrypt("Hello", -5), 5), "Hello", "en(decrypt)"],
[abcDecode(abcEncode("Lorem")), "Lorem", "de(encode)"],
[abcEncode(abcDecode("6415180513")), "6415180513", "en(decode)"],
[ilDecrypt(ilEncrypt("Hello")), "Hello", "il-De(En)"],
[ilEncrypt(ilDecrypt("Hello")), "Hello", "il-En(De)"], //Result: £¡¡«
//[RSA(RSA("Secrete", keys), ??), "Secrete", "RSA"],
[fromFSHA(toFSHA("password")), "password", "fromFSHA(to)"],
[toFSHA(fromFSHA("password")), "password", "toFSHA(from)"]
//UI
//Web
];
if (testMode) {
UnitTest.basicTests();
UnitTest.multiTest(UnitTest.libTests);
}
if (debugging && !Essence.loadedModules.map(function (m) {
return m.name;
}).equals(modules)
) Essence.say("The following modules weren't loaded: " + complement(modules, Essence.loadedModules.map(function (m) {
return m.name;
}))
);
if (Essence.source.has("essence.min")) { //If it's the minimised version, change the modules to their minimised version as well
var $s = $n("*script").toArray();
for (var i = 0; i < $s.length; i++) {
if (!$s[i].src.has(".min.js")) $s[i].src.replace(".js", ".min.js");
}
}
if (perfMod) console.timeStamp("Module edit");
}, 1e3);
if (perfMod) console.timeStamp("Module Loading done");
})();
/**
* @description Globals won't be globals !!
* @type {{t1: Date, t2: number, t: ?number, lastKeyPair: Array}}
* @default
* @since 1.0
* @global
*/
var $G = {
t1: new Date(),
t2: 0,
t: null,
lastKeyPair: [],
lorem: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,"
};
//noinspection JSValidateTypes
Essence.global = $G;
/**
* @description Element selector
* @param {string} selector A CSS selector
* @param {boolean} [silence=false] Flag to use when <code>selector</code> doesn't exist yet (end.g: a particular selector used by a JS object/function which may not be in the page yet).
* @returns {?Element} Element
* @since 1.0
* @func
*/
function $e (selector, silence) { //THE selector !!
if (silence) {
try {
return new Element(selector)
} catch (e) {
if (debugging) Essence.say("%c$e(\"" + selector + "\")%c isn't there (yet).", "warn", "color: #f00", "color: #000");
return null;
}
} else return new Element(selector);
}
/**
* @description Element's node
* @param {string} selector A CSS selector
* @param {boolean} [silence=false] Flag to use when <code>selector</code> doesn't exist yet (end.g: a particular selector used by a JS object/function which may not be in the page yet).
* @returns {HTMLElement} Element node
* @since 1.0
* @func
*/
function $n (selector, silence) { //To get directly the node without having to use $end(selector).node
return (silence && isNon($e(selector, silence)))? null: $e(selector).node;
}
/**
* @description Element
* @param {string} selector A CSS selector
* @this Element
* @returns {Element} Element object
* @constructor
* @since 1.0
* @throws {InvalidParamError} Invalid parameter
* @property {HTMLElement} Element.node Node
* @property {String} Element.selector Selector
* @property {function(boolean, boolean): (NumberLike|XML)} Element.val Get the node's value
* @property {function(): number} Element.size Get the node's value's size
* @property {function(): boolean} Element.isEmpty Check if the node's value is empty
* @property {function(*, boolean, boolean)} Element.write Write something to the node
* @property {function(*, boolean, boolean)} Element.before Write something to the node before its value
* @property {function(*, boolean, boolean)} Element.after Write something to the node after its value
* @property {function(string, ?string)} Element.remove Remove a character/string from the node's value and optionally insert jointers
* @property {function(string, string)} Element.setCSS Set a CSS rule or change a CSS property
* @property {function(string, string)} Element.setInlineCSS Set a CSS rule or change a CSS property inline to a righty of elements
* @property {function(string[])} Element.setStyles Set multiple CSS rules
* @property {function(string): NumberLike} Element.css Get the value of a CSS property
* @property {function(string): boolean} Element.hasClass Check if the node is affiliated to a class
* @property {function(string): boolean} Element.hasCSS Check if the node's CSS include a particular rule
* @property {function(string)} Element.addClass Affiliate the node to a particular class
* @property {function(string)} Element.rmClass Disjoin the node from a particular class
* @property {function(string, (Str|Nums), number)} Element.toggleCSS Toggle a CSS property
* @property {Function} Element.show Show the node
* @property {Function} Element.hide Hide the node
* @property {function(string)} Element.on Event handler
* @property {function(): string} Element.toString String representation of the element
* @property {function(): string} Element.tagName Tagname of the element
* @property {Function} Element.scrollBottom Scroll to the bottom of the node
* @property {Function} Element.scrollTop Scroll to the top of the node
* @property {Function} Element.scrollLeft Scroll to the left of the node
* @property {Function} Element.scrollRight Scroll to the right of the node
* @property {function(number, number)} Element.scroll Scroll in any directions
* @property {function(string, number)} Element.autoScroll Auto scrolling animation
* @property {function(string, *): *} Element.attr Get/set the attribute of the node
* @property {function(string)} Element.rmAttr Remove an attribute from the node
* @property {Function} Element.invColour Invert the colour and background colour (by negation)
* @property {function(): string[]} Element.classes Get an array of classes of the element
* @property {function(function(HTMLElement))} Element.multi Execute a callback on all nodes of a $e("*...") element
* @property {function(string, Array)} Element.multiElm Execute a method on all elements of a $e("*...") element
* @property {function()} Element.delete Self-destruction of the element by self-removal of the DOM
* @property {function(String, String, boolean, boolean)} Element.replace Replace a string in the element's value by a new one
* @todo All the CSS implementations on $e("*..") must always be wrote in a CSS place and not inline (like now)
* @property {function()} Element.moveCSS Move the inline-CSS into the current stylesheet
*/
function Element (selector) {
if (/^([#.*_-`~&]\W*|\S|undefined|null|)$/.test(selector)) throw new InvalidParamError("Element cannot accept the selector '" + selector + "' as its invalid."); //Reject invalid selectors
if (selector[0] === "#") this.node = document.querySelector(selector) || document.getElementById(selector.slice(1, selector.length)); //Id
else if (selector[0] === ".") this.node = document.querySelector(selector) || document.getElementByClassName(selector.slice(1, selector.length)); //Class
else if (selector[0] === "*") this.node = document.querySelectorAll(selector.slice(1, selector.length)) || document.getElementsByTagName(selector.slice(1, selector.length)); //Node list
else this.node = document.querySelector(selector);
if (this.node === null) throw new Error("The node $n(\"" + selector + "\") doesn't exist !!");
this.selector = selector;
this.val = function (getHTML, withTags) {
if (isType(this.node, "Array")) {
var arr = [];
for (var i = 0; i < this.node.length; i++) {
if (this.node[i].value && !getHTML && !withTags) arr.push(this.node[i].value);
else if (this.node[i].innerHTML && getHTML && !withTags) arr.push(this.node[i].innerHTML);
else if (this.node[i].innerText && !getHTML && !withTags) arr.push(this.node[i].innerText);
else if (this.node[i].outerHTML && !getHTML && withTags) arr.push(this.node[i].outerHTML);
else arr.push(this.node[i].value? this.node[i].value: this.node[i].innerText);
}
return arr
}
if (this.node.value && !getHTML && !withTags) return this.node.value;
else if (this.node.innerHTML && getHTML && !withTags) return this.node.innerHTML;
else if (this.node.innerText && !getHTML && !withTags) return this.node.innerText;
else if (this.node.outerHTML && !getHTML && withTags) return this.node.outerHTML;
else return this.node.value? this.node.value: this.innerText
};
this.size = function () {
return this.val().length
};
this.isEmpty = function () {
return isNon(this.val());
};
this.write = function (nval, parseToHTML, incTags) {
if (typeof this.val(true) == "undefined") this.node.innerText = "?";
if (isType(this.node, "Array")) {
for (var i = 0; i < this.node.length; i++) {
if (this.node[i].value && !parseToHTML && !incTags) this.node[i].value = isType(nval, "Array")? nval[i]: nval;
else if (this.node[i].innerHTML && parseToHTML && !incTags) this.node[i].innerHTML = isType(nval, "Array")? nval[i]: nval;
else if (this.node[i].innerText && !parseToHTML && !incTags)this.node[i].innerText = isType(nval, "Array")? nval[i]: nval;
else if (this.node[i].outerHTML && !parseToHTML && incTags) this.node[i].outerHTML = isType(nval, "Array")? nval[i]: nval;
else this.node[i].value? (this.node[i].value = isType(nval, "Array")? nval[i]: nval): (this.node[i].innerText = isType(nval, "Array")? nval[i]: nval);
}
}
if (this.node.value && !parseToHTML && !incTags) this.node.value = nval;
else if (this.node.innerHTML && parseToHTML && !incTags) this.node.innerHTML = nval;
else if (this.node.innerText && !parseToHTML && !incTags) this.node.innerText = nval;
else if (this.node.outerHTML && incTags && !parseToHTML) this.node.outerHTML = nval;
else this.node.value? this.node.value = nval: this.innerText = nval;
};
this.before = function (nval, parseToHTML, incTags) {
if (typeof this.val(true) == "undefined") this.node.innerText = "?";
if (isType(this.node, "Array")) {
for (var i = 0; i < this.node.length; i++) {
if (this.node[i].value && !parseToHTML && !incTags) this.node[i].value = isType(nval, "Array")? nval[i] + this.node[i].value: nval + this.node[i].value;
else if (this.node[i].innerHTML && parseToHTML && !incTags) this.node[i].innerHTML = isType(nval, "Array")? nval[i] + this.node[i].innerHTML: nval+ this.node[i].innerHTML;
else if (this.node[i].innerText && !parseToHTML && !incTags) this.node[i].innerText = isType(nval, "Array")? nval[i] + this.node[i].innerText: nval + this.node[i].innerText;
else if (this.node[i].outerHTML && !parseToHTML && incTags) this.node[i].outerHTML = isType(nval, "Array")? nval[i] + this.node[i].outerHTML: nval + this.node[i].outerHTML;
else this.node[i].value? (this.node[i].value = isType(nval, "Array")? nval[i] + this.node[i].value: nval + this.node[i].value): (this.node[i].innerText = isType(nval, "Array")? nval[i] + this.node[i].innerText: nval + this.node[i].innerText);
}
}
if (this.node.value && !parseToHTML && !incTags) this.node.value = nval + this.node.value;
else if (this.node.innerHTML && parseToHTML && !incTags) this.node.innerHTML = nval + this.node.innerHTML;
else if (this.node.innerText && !parseToHTML && !incTags) this.node.innerText = nval + this.node.innerText;
else if (this.node.outerHTML && incTags && !parseToHTML) this.node.outerHTML = nval + this.node.outerHTML;
else this.node.value? this.node.value = nval + this.node.value: this.innerText = nval + this.innerText;
};
this.after = function (nval, parseToHTML, incTags) {
if (typeof this.val(true) == "undefined") this.node.innerText = "?";
if (isType(this.node, "Array")) {
for (var i = 0; i < this.node.length; i++) {
if (this.node[i].value && !parseToHTML && !incTags) this.node[i].value += isType(nval, "Array")? nval[i]: nval;
else if (this.node[i].innerHTML && parseToHTML && !incTags) this.node[i].innerHTML += isType(nval, "Array")? nval[i]: nval;
else if (this.node[i].innerText && !parseToHTML && !incTags)this.node[i].innerText += isType(nval, "Array")? nval[i]: nval;
else if (this.node[i].outerHTML && !parseToHTML && incTags) this.node[i].outerHTML += isType(nval, "Array")? nval[i]: nval;
else this.node[i].value? (this.node[i].value += isType(nval, "Array")? nval[i]: nval): (this.node[i].innerText += isType(nval, "Array")? nval[i]: nval);
}
}
if (this.node.value && !parseToHTML && !incTags) this.node.value += nval;
else if (this.node.innerHTML && parseToHTML && !incTags) this.node.innerHTML += nval;
else if (this.node.innerText && !parseToHTML && !incTags) this.node.innerText += nval;
else if (this.node.outerHTML && incTags && !parseToHTML) this.node.outerHTML += nval;
else this.node.value? this.node.value += nval: this.innerText += nval;
};
this.remove = function (c, r) { //Remove the character from the string/array/number and return it with the r character as a joiner or a blank when r isn't specified
if (isType(this.val(), "Array")) {
for (var i = 0; i < this.size(); i++) {
if (this.val()[i] == c) this.write(this.val().slice(0, i).concat(this.val().slice(i + 1, this.size())));
}
}
this.write(this.val().split(c).join(r || "")); //Silent removing
};
this.setCSS = function (prop, val) { //Change the css property
if (isType(this.node, "NodeList")) addCSSRule(/\*\S/.test(selector)? selector.get(1): selector, camelCaseTo(prop, "hyphen") + ": " + val)
else this.node.style[prop] = val;
};
this.setInlineCSS = function (prop, vals) {
for (var i = 0; i < this.node.length; i++) this.node[i].style[prop] = isType(vals, "Array")? vals[i]: vals;
};
this.setStyles = function (sAndV) { //Style and vals: [style0, val0, style1, val1, ...]
for(var i = 0; i < sAndV.length - 1; i += 2) this.setCSS(sAndV[i], sAndV[i + 1]);
};
this.css = function (prop) { //Get the CSS property of the element's node
if (isType(this.node, "Array")) {
var arr = [];
for(var i = 0; i < this.node.length; i++) arr.push(this.node[i].style[prop]);
return arr
}
return isType(this.node, "NodeList")? this.node.toArray().map(function (currentNode) {
return currentNode.style[prop];
}): this.node.style[prop]
};
this.hasClass = function (className) { //Check if the element's node has the specified CSS class
if (isType(this.node, "Array")) {
var arr = [];
for(var i = 0; i < this.node.length; i++) arr.push(new RegExp(" " + className + " ").test(" " + this.node[i].className + " ") || new RegExp(" " + className + " ").test(" " + this.node[i][className] + " ") || this.node[i].style.clasName == className);
}
return new RegExp(" " + className + " ").test(" " + this.node.className + " ") || new RegExp(" " + className + " ").test(" " + this.node[className] + " ") || this.node.style.className == className
};
this.hasCSS = function (prop) { //Check if the element's node has the specified CSS property
if (isType(this.node, "Array")) {
var arr = [];
for(var i = 0; i < this.node.length; i++) arr.push(new RegExp(" " + prop + " ").test(" " + this.node[i].style[prop] + " ") || new RegExp(" " + prop + " ").test(" " + this.node[i][prop] + " "));
}
return new RegExp(" " + prop + " ").test(" " + this.node.style[prop] + " ") || new RegExp(" " + prop + " ").test(" " + this.node[prop] + " ")
};
this.addClass = function (className) { //Add a class to the element's node
if (isType(this.node, "Array")) {
for (var i = 0; i < this.node.length; i++) {
if (!this.node[i].hasClass(className)) this.node[i].className += " " + className;
}
} else if (!this.hasClass(className)) this.node.className += " " + className;
};
this.rmClass = function (className) { //Remove the class from the element's node
var newClass = " " + this.node.className.replace(/[\t\r\n]/g, " ") + " ";
if (isType(this.node, "Array")) {
for (var i = 0; i < this.node.length; i++) {
newClass = " " + this.node[i].className.replace(/[\t\r\n]/g, " ") + " ";
if (this.node[i].hasClass(className)) {
while(newClass.indexOf(" " + className + " ") >= 0) newClass = newClass.replace(" " + className + " ", " ");
this.node[i].className = newClass.replace(/^\s+|\s+$/g, "");
}
}
} else if (this.hasClass(className)) {
while (newClass.indexOf(" " + className + " ") >= 0) newClass = newClass.replace(" " + className + " ", " ");
this.node.className = newClass.replace(/^\s+|\s+$/g, "");
}
};
this.toggleCSS = function (prop, params, stackLayer) { //Toggle between two or more values
if (!stackLayer) stackLayer = 0;
if (this.css(prop) === "" && stackLayer < 1) this.toggleCSS(prop, params, stackLayer + 1);
if (prop === "visibility") {
(this.css("visibility") === "visible")? this.setCSS("visibility", "hidden"): this.setCSS("visibility", "visible");
} else if (prop === "enabled") {
(this.css("enabled") === "enabled")? this.setCSS("enabled", "disabled"): this.setCSS("enabled", "enabled");
} else if (prop === "display") {