-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsClass.js
More file actions
1395 lines (1361 loc) · 41.9 KB
/
JsClass.js
File metadata and controls
1395 lines (1361 loc) · 41.9 KB
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
/*
Copyright 2013 LN(Lucman and Nawal) Enterprise Solution
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Implemented Functions:
-Include
-getURLParameter
-Logger
-Log
-Debug
-Warning
-Error
-__FILE__
-__LINE__
-__DIR__
*/
var _ = _ || {};
_.AttachEvent = function AttachEvent(element, type, handler) {
if (element.addEventListener) {
element.addEventListener(type, handler, false);
}
else if (element.attachEvent) {
element.attachEvent('on' + type, handler)
} else {
element['on' + type] = handler;
}
};
_.DettachEvent = function(el, ev, fn) {
if (!el) return false;
if (window.removeEventListener) { // Standard
el.removeEventListener(ev, fn, false)
} else if (window.detachEvent) { // IE
var iefn = function() {
fn.call(el);
};
el.detachEvent('on' + ev, iefn)
} else { return false };
};
var Include = _.Include = (function(){
var scripts = [];
var curr = 0;
var currScriptElem = null;
var loadTimeout = null;
var busy = false;
var inited = false;
var head = null;
_.AttachEvent(window, 'load', init);
function init(){
head = document.getElementsByTagName('head')[0];
inited = true;
next();
};
function next(e){
busy = true;
if(e){
window.clearTimeout(loadTimeout);
_.DettachEvent(e.target, 'load', next);
//e.target.removeEventListener('load',next);
var callbacks = scripts[curr-1].callbacks;
scripts[curr-1].loaded = true;
if(callbacks.length > 0){
var i = callbacks.length;
while(i--){
callbacks[i]();
}
}
}
if(scripts.length > curr){
var currentScript = scripts[curr].path;
curr++;
var script;
if(currentScript.indexOf('.css') > 0){
script = document.createElement("link");
script.setAttribute("type", "text/css");
script.setAttribute("rel", "stylesheet");
script.setAttribute("href", currentScript);
} else {
script = document.createElement('script');
var suffix = currentScript.substring(currentScript.lastIndexOf('.')+1);
var type;
switch(suffix){
case 'js': type ='text/javascript';break;
case 'rb': type ='text/ruby';break;
case 'py': type ='text/python';break;
case 'php': type ='text/php';break;
default: type = 'text/javascript';
}
script.setAttribute('type', type);
script.setAttribute('src', currentScript);
}
_.AttachEvent(script, 'load', next );
currScriptElem = script;
Log("loading.." + scripts.length + "-" + curr +" "+ currentScript)
loadTimeout = window.setTimeout(skip,10000);
head.appendChild(script);
} else {
busy = false;
if(e && _.Ready){
_.Ready("idle");
}
}
};
function skip(){
_.DettachEvent(currScriptElem, 'load', next);
//currScriptElem.removeEventListener('load',next);
head.removeChild(currScriptElem);
next();
};
function include(scriptPath,optCallback){
var dup = false;
var i = scripts.length;
while (i--) {
if(scripts[i].path == scriptPath){
dup = true;
if (optCallback) {
if(scripts[i].loaded){
optCallback();
} else {
scripts[i].callbacks.unshift(optCallback);
}
}
break;
}
}
if(!dup){
var cbs = [];
if(optCallback) cbs.unshift(optCallback);
scripts.push({path:scriptPath,callbacks:cbs,loaded:false});
}
if(!busy && inited) next();
};
for (var nIndex = 0; nIndex < arguments.length; nIndex++) {
include(arguments[nIndex]);
};
return include
})();
var Ajax = (function(){
function getHttpRequestObject()
{
// Define and initialize as false
var xmlHttpRequst = false;
// Mozilla/Safari/Non-IE
if (window.XMLHttpRequest)
{
xmlHttpRequst = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject)
{
xmlHttpRequst = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlHttpRequst;
}
// Does the AJAX call to URL specific with rest of the parameters
function doAjax(url, method, async, responseHandler, data, mimeType)
{
// Set the variables
url = url || "";
method = method || "GET";
async = (typeof async === 'undefined') ? true : async;
data = data || null;
mimeType = mimeType || 'application/x-www-form-urlencoded';
if(url == "")
{
alert("URL can not be null/blank");
return false;
}
var xmlHttpRequst = getHttpRequestObject();
var readyStateHandler = (function(ajax, callback){
return function(){
if((ajax.readyState === 4) && (ajax.status === 200)
&& (typeof callback === 'function')) {
callback(ajax.responseText);
}
};
})(xmlHttpRequst, responseHandler);
// If AJAX supported
if(xmlHttpRequst != false)
{
// Open Http Request connection
if(method == "GET")
{
url = url + (data ? ("?" + data) : "");
data = null;
}
xmlHttpRequst.open(method, url, async);
// Set request header (optional if GET method is used)
if(method == "POST")
{
xmlHttpRequst.setRequestHeader('Content-Type', mimeType);
}
// Assign (or define) response-handler/callback when ReadyState is changed.
xmlHttpRequst.onreadystatechange = readyStateHandler;
// Send data
xmlHttpRequst.send(data);
}
else
{
alert("Please use browser with Ajax support.!");
}
}
return doAjax;
})();
var Require = (function(){
function responseHandler(script, callback){
return function(data){
try{
eval(data);
}catch(e){};
if(typeof callback === 'function'){
callback(data);
}
};
};
function require(script, callback){
Ajax(script, 'GET', false, responseHandler(script, callback), null, 'application/javascript');
};
return require;
})();
_.getURLParameter = function (name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
);
}
_.__DEBUG__ = _.getURLParameter("debug") == "true";
_.__LOG_LEVEL__ = _.getURLParameter("log");
_.__LOG_LEVEL__ = (_.__LOG_LEVEL__ != "null") ? parseInt(_.__LOG_LEVEL__) : 0;
_.LOG_LEVELS = { ERROR: 1, DEBUG : 2, WARNING : 4, INFO : 8 };
_.__LOG_LEVEL__ = _.__DEBUG__ ? (_.__LOG_LEVEL__|_.LOG_LEVELS.DEBUG) : _.__LOG_LEVEL__;
_.logger = function(log) { console.log(log); };
function Log(msg,level){
var level = level || "INFO";
if((_.__LOG_LEVEL__ & _.LOG_LEVELS[level]) || (typeof level === 'number' && (_.__LOG_LEVEL__ & level))){
var now = new Date();
var log = "[" + now.toTimeString().slice(0,8) + "." + now.getMilliseconds() +"] ";
var caller = arguments.callee.caller;
if(caller){
log += "[" + (caller.name || "anonymous") + "] ";
}
caller = null;
log += msg;
_.logger(log);
log = null;
now = null;
}
};
var Trace = Log;
function Debug(msg){
Log(msg, "DEBUG");
}
function Warning(msg){
Log(msg, "WARNING");
}
var origError = Error || function(){};
/*Error = function(msg){
Log(msg, "ERROR");
if(this.__proto__){
this.__proto__ = origError.prototype;
}
return new origError(msg + '\r\nLine:' + __LINE().slice(0,-1).slice(0, 3).join(':'));
};*/
/*_.defineProperty = function(obj, propName, descriptor){
if (!(/MSIE (\d+\.\d+);/.test(navigator.userAgent))){
return Object.defineProperty(obj, propName, descriptor);
}
}*/
var __LINE = (function(){
var scriptSource = function() {
var scripts = document.getElementsByTagName('script');
return scripts[scripts.length - 1].src;
};
var stackAvailable = !!((new origError()).stack);
function getLine(stack){
var error = (new origError());
var line = error.stack.split("\n")[3 + (stack || 0)];
var fileArr = (line.indexOf('@') > 0) ? line.split("@") :
(line.indexOf(' at ')?line.split(" at "):line.split("("));
var fileName = fileArr[fileArr.length - 1];
fileArr = null;
line = null;
error = null;
if (fileName.indexOf(' ') >= 0) {
fileName = fileName.substr(fileName.lastIndexOf(' ') + 1);
}
if((fileName.indexOf('file:///') == 0)){
fileName = fileName.substr(('file:///').length);
}
return fileName.split(":");
};
Object.defineProperty(window, "__FILE__",
{
get : function() {
if(stackAvailable) {
return getLine().slice(0,-1).slice(0, 2).join(':');
}
else {
return scriptSource();
}
}
}
);
Object.defineProperty(window, "__LINE__",
{
get : function() {
return getLine().slice(2,-1).join();
}
}
);
Object.defineProperty(window, "__DIR__",
{
get : function() {
var path = getLine().slice(0,-1).slice(0, 2).join(':');
return path.substr(0, path.lastIndexOf('/') + 1);
}
}
);
return getLine;
})();
/*
Implemented Functions:
-Namespacing
-Using function
-Class Encapsulation (support static, private, protected, public acccess modifiers)
-Inheritance (Multiple)
-Casting Classes from JsClass to JsClass
-Property Referencing
-Method/Event Delegation
-Class Destroy
-Class Instance Extension from External Source File
*/
//Namespace: Object Namespacing
/*IE Support Dependencies*/
if ( typeof Object.getPrototypeOf !== "function" ) {
if ( typeof "test".__proto__ === "object" ) {
Object.getPrototypeOf = function(object){
return object.__proto__;
};
} else {
Object.getPrototypeOf = function(object){
return object.constructor.prototype;
};
}
}
if(typeof Array.prototype.indexOf !== 'function') {
Array.prototype.indexOf = function(item){
var index = 0;
while(index < this.length) {
if(this[index] === item) return index;
}
return -1;
};
}
/*IE SUpport*/
var Namespace = function(ns, nsObj, callback) {
if (!ns || (typeof ns !== 'string')) {
throw new Error('Supplied namespace is not valid');
}
if (nsObj === null) {
throw new Error('Supplied namespace object is not valid');
}
var names = ns.split('.');
var top = (names[0] != 'this' || !names.splice(0,1)) ? window : nsObj;
if(ns.indexOf('this.') == 0){
nsObj = undefined;
}
var name = '';
var _ns = '';
for (var i = 0; i < names.length - 1; i++) {
name = names[i];
_ns += ((_ns ? '.' :'') + name);
top = top[name] = top[name] || (nsObj && (top[name] || {}));
if(!top) {
throw new Error('Supplied namespace does not exist');
}
top.Namespace = _ns;
}
name = names[names.length-1];
if (top.hasOwnProperty(name)) {
if((typeof nsObj === 'undefined') || (nsObj === null)){
return top[name];
}else if(top[name] !== nsObj) {
throw new Error('Supplied namespace is already defined');
}
return nsObj;
}
else if ((typeof nsObj !== 'undefined') && (nsObj !== null)){
(top[name] = nsObj || {}).Namespace = ns;
}else{
throw new Error('Supplied namespace object is not valid');
}
if(callback && typeof callback === 'function'){
callback.call(nsObj, ns);
}
return nsObj;
};
function Using(nameSpace) {
return (function(/*arg0,arg1,...*/) {
for (var nArg = 0; nArg < arguments.length; nArg++) {
var constructor = arguments[nArg];
var name = JsClass.getFnName(constructor);
if(typeof constructor !== 'function') {
new constructor();
}
else if (name.length == 0) {
constructor.bind((typeof nameSpace === 'string') ? Namespace(nameSpace) : nameSpace)();
continue;
}
if (typeof nameSpace === 'string') {
Namespace((nameSpace + ('.' + name)), constructor);
}
else if(nameSpace) {
nameSpace[name] = constructor;
}
};
});
};
//JsClass
var JsClass = (function(){
var Core;
var Consts = {
ReserveFields : ['$','base','Fields','_self','StaticFields','Implements','Inherits'],
ReserveMethods : ['$', 'Is', 'Prop', '$private'],
AccessModifiers : {
'public' : 0,
'private' : 1,
'protected' : 3,
'static' : 4,
'override' : 8,
'overload' : 16
}
};
// var _privates = {};
var _scope_counter = {};
function _scope($_this, $key){
$key = $key || ('$this');
var $THIS;
if($_this){
$THIS = window[$key];
window[$key] = $_this;
return (function($THIS, $key){
var $_THIS = $THIS;
return function(scope, thisArg, args) {
var ret;
if(typeof scope === 'function'){
ret = scope.apply(thisArg, args);
}
window[$key] = $_THIS;
if($_THIS === undefined){
delete window[$key];
}
$_THIS = null;
return ret;
};
})($THIS, $key);
}
else{
return false;
}
};
function _validateModifier(jsclass, propName, access_modifier){
if((access_modifier & Consts.AccessModifiers.private) &&
((Object.getPrototypeOf(this).constructor != window['$this']) && (window['$this'] != jsclass))) {
throw new Error("Cannot Access Private Member "+propName);
}else if ((access_modifier & Consts.AccessModifiers.protected) && (this.Is && !this.Is(jsclass))) {
throw new Error("Cannot Access Protected Member"+propName);
};
}
var _ = function JsClass(){
var arg0 = arguments[0],
args = arguments, className = '', instanceFields, staticFields, constructor;
if(arg0 instanceof Array){
arg0 = (args = arg0)[0];
}
if(typeof arg0 === 'function'){
className = arg0.name || _.getFnName(arg0);
constructor = arg0;
}
else if (typeof arg0 === 'string') {
className = arg0;
constructor = function(){};
}
if (className.length == 0) {
throw new Error('Class Name is not defined');;
}
staticFields = args[1] || {};
var body = function body(){
Core.$(this);
var ClassDec = Object.getPrototypeOf(this).constructor;
var $privates = { _self : this };
var prop = { prototype : this };
Core.Prop(prop, '$privates',
null,
function(val){},
function(){ return $privates; },
'protected');
delete prop.prototype;
prop = null;
var Implements = ClassDec.Inherits || ClassDec.Implements || [];
var hasBase = ((Implements) instanceof Array) || ((Implements) instanceof Object);
var inherits = (Implements instanceof Array) ? Implements : [Implements];
if(hasBase){
for(var i=0; i < inherits.length;i++){
var base = (inherits[i] instanceof Array) ? inherits[i][0] : inherits[i];
var args =!(inherits[i] instanceof Array) ? [] : inherits[i][1];
var passArgs = [];
var counter = 0;
_scope(ClassDec)(function(){
for (var j = 0; j < args.length; j++) {
var arg = args[j];
if(typeof arg === 'string'){
if((arg.substr(0, 1) == "{") && (arg.substr(arg.length-1) == "}")){
var ndex = parseInt(arg.substr(1, arg.length - 2));
arg = !isNaN(ndex) ? arguments[ndex] : arguments[counter++];
}else if((arg.substr(0, 5) == "eval(") && (arg.substr(arg.length-1) == ")")) {
arg = eval(arg.substr(5, arg.length - 6));
}
}
passArgs[0] = arg;
};
},this, arguments);
_scope(base)(base.$constructor, this, passArgs);
};
};
_scope(ClassDec)(ClassDec.$constructor, this, arguments);
if(this.base){
for (var nBase = this.base.length - 1; nBase >= 0; nBase--) {
var base = this.base[nBase];
var afterConstruct = this.As(base).afterConstruct;
if((typeof afterConstruct === 'function')){
_scope(base)(afterConstruct, this);
};
afterConstruct = null;
};
};
};
var Constructor = (new Function('body','return function '+ className +'(){body.apply(this, arguments);};'))(body);
Constructor.$constructor = constructor;
var base = function base() {};
var commonProps = function(){};
commonProps.prototype = new base();
var $commonProps = commonProps.prototype;
var $base = base.prototype;
Constructor.prototype = new commonProps();
Constructor.prototype.constructor = Constructor;
Core.$(Constructor);
Core.Prop(Constructor, 'self', null, function(){}, undefined ,'protected');
var StaticObject = { prototype : Constructor };
for(var key in staticFields){
var propName = key;
var access_modifier = Consts.AccessModifiers.public;
var isStatic = false;
if(propName.indexOf('$') > 0) {
var identifers = propName.split('$');
propName = identifers[identifers.length-1];
for (var nId = identifers.length - 1; nId >= 0; nId--) {
access_modifier |= Consts.AccessModifiers[identifers[nId]];
};
isStatic = access_modifier & Consts.AccessModifiers.static;
} else if (['Implements', 'Inherits'].indexOf(propName) >= 0) {
isStatic = true;
Constructor[propName] = staticFields[key];
continue;
}
if(typeof staticFields[key] === 'function'){ if (propName == 'constructor') continue;
if (isStatic) {
Core.method(StaticObject, propName, staticFields[key], access_modifier);
}
else {
Core.method(Constructor, propName, staticFields[key], access_modifier);
}
}
else if (isStatic) {
var desc = Object.getOwnPropertyDescriptor(staticFields, key);
if (desc && (desc.set || desc.get)) {
Core.Prop(StaticObject, propName, null,
desc.set, desc.get, access_modifier);
}else{
Constructor[propName] = staticFields[key];
}
}else {
var desc = Object.getOwnPropertyDescriptor(staticFields, key);
if(desc && (desc.set || desc.get)){
Core.Prop(Constructor, propName, null,
desc.set, desc.get, access_modifier);
}else{
Core.Prop(Constructor, propName, staticFields[key], undefined, undefined, access_modifier);
}
}
}
var $privates = { };
Core.Prop(StaticObject, '$privates',
null,
function(val){},
function(){
if(Constructor.prototype.base && (Constructor.prototype.base.length > 0)) {
var _privExtended = $privates;
for (var nBase = 0; nBase < Constructor.prototype.base.length; nBase++) {
Core.extend(_privExtended, Constructor.prototype.base[nBase].$privates);
};
return _privExtended;
}
return $privates;
},
'protected');
delete StaticObject.prototype;
StaticObject = null;
var parents = [];
Core.extend(
$commonProps,
{ base : parents },
{
toString : function(){
return ((this.Namespace || Object.getPrototypeOf(this).constructor.Namespace || "") + "{") + Object.keys(this).toString() + "}";
},
toLocaleString: function(){
return this.Namespace || Object.getPrototypeOf(this).constructor.Namespace || Object.keys(this).toString();
},
Is : Core.Is,
As : Core.As,
ExtendObject : _.ExtendObject,
destroy : _.Destroyer
});
var Implements = Constructor.Inherits || Constructor.Implements || [];
var hasBase = ((Implements) instanceof Array) || ((Implements) instanceof Object);
var inherits = (Implements instanceof Array) ? Implements : [Implements];
if(hasBase){
for(var i=0; i < inherits.length;i++){
var base = (inherits[i] instanceof Array) ? inherits[i][0] : inherits[i];
if(typeof base === 'undefined') throw new Error("Base Undefined");
Implements = base.Inherits || base.Implements || null;
if (Implements instanceof Array) {
for (var nBaseNdx = 0; nBaseNdx < Implements.length; nBaseNdx++) {
if(inherits.indexOf(Implements[nBaseNdx]) < 0) {
inherits.splice(i + nBaseNdx, 0, Implements[nBaseNdx]);
}
};
base = (inherits[i] instanceof Array) ? inherits[i][0] : inherits[i];
}
for(var key in base.prototype){
if (constructor.prototype.hasOwnProperty(key) || $base.hasOwnProperty(key)) {
continue;
}
var descriptor = Object.getOwnPropertyDescriptor(base.prototype, key);
if(descriptor && (descriptor.set || descriptor.get)) {
Object.defineProperty($base, key, {
set : descriptor.set,
get : descriptor.get,
enumerable : true,
configurable : true
});
}else {
//$base[key] = base.prototype[key];
}
descriptor = null;
}
for(var key in base){
if (Constructor.hasOwnProperty(key)) {
continue;
}
var descriptor = Object.getOwnPropertyDescriptor(base, key);
if(descriptor && (descriptor.set || descriptor.get)) {
Object.defineProperty(Constructor, key, {
set : descriptor.set,
get : descriptor.get,
enumerable : true,
configurable : true
});
}else{
Object.defineProperty(Constructor, key, {
set : (function(b,k){
return function(val){ b[k] = val; };
})(base, key),
get : (function(b,k){
return function(){ return b[k]; };
})(base, key),
enumerable : true,
configurable : true
});
}
descriptor = null;
}
parents.push(base);
base = null;
};
};
$base = null;
parents = null;
return Constructor;
};
_.getFnName = function getFnName(fn) {
return fn.name || (fn.toString().match(/function (.+?)\(/)||[,''])[1];
};
var cls2type = {},
_push = Array.prototype.push,
_slice = Array.prototype.slice,
_indexOf = Array.prototype.indexOf,
_toString = Object.prototype.toString,
_hasOwn = Object.prototype.hasOwnProperty,
_trim = String.prototype.trim;
var rawTypes = ("Boolean Number String Function Array Date RegExp Object").split(" ");
for(var nType = 0; nType < rawTypes.length; nType++) {
var n = rawTypes[nType];
cls2type["[object "+ n +"]"] = n.toLowerCase();
};
Core = {
$: (function(){
var $ = 1;
var dict = {};
return function(obj, keep){
keep = ((keep === undefined) && window['record']) ? true : keep;
if((typeof obj === 'string') && (dict[obj])){
return dict[obj];
}else{
if(obj && (typeof obj !== 'undefined')) {
if (!obj.$ && !keep) {
obj.$ = obj.$ || ("$"+($++));
}
else if(keep === true){
obj.$ = obj.$ || ("$"+($++));
dict[obj.$] = obj;
}else{
return false;
}
}
}
return obj;
}
})(),
Is: function(type){
if(this instanceof type){
return true;
}
var base = (this.base);
if (base instanceof Array) {
for(var i in base){
var bs = base[i];
if((bs instanceof type) || (type === bs)){
i = null; bs = null;
return true;
}
}
}
return false;
},
As : function(inhertedOf){
if(!inhertedOf) {//Copy
return _scope(Object.getPrototypeOf(this).constructor)(
function(){
var as = {};
for(key in this) {
as[key] = this[key];
}
as.__proto__ = this.__proto__;//Ignore Not so Important
as.Is = function(type){
return (type === _.Alias) || Core.Is.call(this);
};
return as;
},
this
);
}
else if(typeof inhertedOf !== 'function'){
throw new Error("Cast Error: Invalid JsClass Type");
}
if(inhertedOf === Object.getPrototypeOf(this).constructor){
return this;
}
var base = this.base;
for(i in base){
var bs = base[i];
var priv = _scope(Object.getPrototypeOf(this).constructor)(Object.getOwnPropertyDescriptor(this,'$privates').get,this);
if((bs instanceof inhertedOf) || (inhertedOf === bs)){
return (priv[bs.$] || (priv[bs.$] = (new _.Alias(this, bs))));
}
}
return null;
},
Prop : function(constructor, name, val, setterCallback, getterCallback, access_modifier){
var TheClass = constructor;
if (typeof TheClass !== 'function') {
if(typeof TheClass.constructor === 'function'){
TheClass = TheClass.constructor;
}
else if(typeof TheClass.prototype === 'function'){
TheClass = TheClass.prototype;
}
else{
TheClass = TheClass.prototype.constructor;
}
}
var setterProp, getterProp;
var proto = constructor.prototype
|| (getterCallback && constructor)
|| (function(){
throw new Error('Invalid Reference Object');
})();
if(proto.hasOwnProperty(name)) {
return;
};
setterProp = (function(propName, $hash_callBack, access_mod, clss){
return function $propSetter(val){
_validateModifier.call(this, clss, propName, access_mod);
if(typeof $hash_callBack === 'function') {
$hash_callBack(propName, val);
}
else {
var priv = _scope(Object.getPrototypeOf(this).constructor)(Object.getOwnPropertyDescriptor(this,'$privates').get,this);
var oldVal = priv['_' + propName];
priv['_' + propName] = val;
var retVal;
//observable
var delegates = priv['d_' + propName];
for (var i = 0;(delegates instanceof Array) && (i < delegates.length); i++) {
var ret = (delegates[i]).call(this, val, propName, oldVal);
retVal = (typeof retVal === 'undefined') ? ret : retVal;
};
if (typeof retVal !== 'undefined'){
priv['_'+propName] = retVal;
}
oldVal = null;
}
priv = null;
};
})(name, setterCallback, access_modifier, TheClass);
getterProp = (function(propName, $hash_callBack, defaultVal, access_mod, clss){
return function $propGetter(){
_validateModifier.call(this, clss, propName, access_mod);
var descriptor;
if(typeof $hash_callBack === 'function'){
return $hash_callBack.call(this, propName);
}
else if (descriptor = Object.getOwnPropertyDescriptor(this,'$privates')) {
var val;
return ((val = (_scope(Object.getPrototypeOf(this).constructor)(descriptor.get,this))['_' + propName]) !== undefined) ? val : defaultVal;
}
}
})(name, getterCallback, val, access_modifier, TheClass);
Object.defineProperty(proto, name, {
set : setterProp,
get : getterProp,
enumerable : true,
configurable : true
});
setterProp = null;
getterProp = null;
proto = null;
},
observe: function observe(object, propName, callback, mArgs){
if(!object || !(object instanceof Object)){
throw new Error("Invalid Object for referencing");
}
if( !propName || (undefined === object[propName]) ){
throw new Error("Invalid Object Property for referencing");
}
if(!callback || (typeof callback !== 'function')){
throw new Error("Invalid Callback for referencing");
}
Debug("Bind " + propName + " " + (typeof object[propName]));
if((typeof object[propName]) === 'function'){
Debug("Binding method?");
}
var setter;
var privates;
var proto = Object.getPrototypeOf(object);
var commonProto = Object.getPrototypeOf(proto);
var leafProto = (commonProto && Object.getPrototypeOf(commonProto)) || commonProto;
var leafDesc;
var descriptor = Object.getOwnPropertyDescriptor(proto, propName) || Object.getOwnPropertyDescriptor(object, propName);
var scope = _scope(proto.constructor);
if((setter = (descriptor && descriptor.set)
|| ((leafDesc = Object.getOwnPropertyDescriptor(leafProto, propName)) && (setter = leafDesc.set)))
&& (privates = object.$privates)) {
var bindSetter;
proto = null; commonProto = null; leafProto = null; leafDesc = null; descriptor = null;
bindSetter = (function(obj, propName, callback){
var oldVal = obj[propName];
return function observer(val) {
var ret = _scope((obj && obj.constructor) || obj)(
callback, obj, [val, oldVal, propName]
);
oldVal = obj[propName];
return ret;
};
})(object, propName, callback);
setter._delegates = (privates['d_' + propName]) || (privates['d_' + propName] = []);
Core.method.prototype.push.call(setter, bindSetter);
delete setter._delegates;
return callback;
}
scope();
scope = null;
},
method : (function(){
function SimulateMethod(constructor, name, func, access){
var TheClass = constructor;
if (typeof TheClass !== 'function') {
if(typeof TheClass.prototype === 'function'){
TheClass = TheClass.prototype;
}
else{
TheClass = TheClass.prototype.constructor;
}
}
var m = (function(f, accs, clss){
var method = function Method() {
var scope_base = _scope((function(ThisArg, n, m){
return (function(){
var ret;
if (Object.getPrototypeOf(this).base instanceof Array){
for (var nBase = 0; nBase < Object.getPrototypeOf(this).base.length; nBase++) {
if(Object.getPrototypeOf(this).base[nBase].prototype.hasOwnProperty(n)) {
var bMethod = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this).base[nBase].prototype,n).get;
bMethod = (bMethod && bMethod(true)) || Object.getPrototypeOf(this).base[nBase].prototype[n];
if(bMethod === m){
return ret;
}
if(typeof bMethod === 'function'){
ret = _scope(Object.getPrototypeOf(this).base[nBase])(bMethod, this, arguments);
}
}
};
}
return ret;
}).bind(ThisArg);
})(this, name, f),'base');
var ThisClass = (!this.prototype && Object.getPrototypeOf(this).constructor) || this;
var ret = _scope(clss)(f, this.self || this, arguments);
scope_base(); scope_base = null;
var _$privates = [];
var descriptor = Object.getOwnPropertyDescriptor(this, '$privates');
var $privates = _scope(ThisClass)((descriptor && descriptor.get) || function(){} ,this);
if($privates) {
_$privates.push($privates);
$privates = null;
}
var sDescriptor = Object.getOwnPropertyDescriptor(ThisClass, '$privates');
var s$privates = _scope(ThisClass)((sDescriptor && sDescriptor.get) || function(){} ,ThisClass);
if(s$privates && (s$privates !== $privates)) {
_$privates.push(s$privates);
s$privates = null;
}
for (var nPriv = 0; nPriv < _$privates.length; nPriv++) {
var priv = _$privates[nPriv];
var delegates = priv['d_' + name];
if(!(arguments.callee.caller) || !(delegates) || (delegates.indexOf(arguments.callee.caller) < 0)) {
for (var i = 0;(delegates instanceof Array) && (i < delegates.length); i++) {
if(delegates[i] !== arguments.callee) {
var bMethod = delegates[i];
_scope(ThisClass)(bMethod, this, arguments);
if(bMethod.callCount) {
bMethod.callCount--;
if(bMethod.callCount <= 0) {
delegates.splice(delegates.indexOf(bMethod), 1);