-
Notifications
You must be signed in to change notification settings - Fork 1
/
Objects.js
122 lines (107 loc) · 3.94 KB
/
Objects.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
(function(win) {
//Checks if the Classes exist on the page
if (!win.Object_Document_flag) {
win.Object_Document_flag = true;
win.Object_Document = Object_Document;
win.New = New;
}
//Used to combine/extend objects
function extend(destination, source) {
for (var k in source) {
if (source.hasOwnProperty(k)) {
destination[k] = source[k];
}
}
return destination;
}
function ShaiObject() {
var id = parseInt(Math.random()*10000);
Object.defineProperty(this,'id',{
get: function () {
return id;
}
});
this.children = [];
this.dispatched_list = [];
this.listener_list = [];
this.callback_list = [];
this.stop = false;
}
ShaiObject.prototype.New = New;
ShaiObject.prototype.Dispatch = Dispatch;
ShaiObject.prototype.Detach = Detach;
ShaiObject.prototype.Listen = Listen;
ShaiObject.prototype.addChild = addChild;
ShaiObject.prototype.stopBubble = function() {
this.stop = true;
}
//Main Document Class
function Object_Document() {
ShaiObject.call(this);
this.constructor = Object_Document;
}
Object_Document.prototype = Object.create(ShaiObject.prototype);
Object_Document.prototype.Logger = function() {
var s;
for (var i in arguments ) {
s = arguments[i];
var s= new Date().toLocaleString()+" : " +s;
this.log = (this.log ? this.log+"<br/>"+(s.toString()) : s);
}
}
//Object_Document.prototype = Object.create(ShaiObject.prototype);
//Objec creation Class
function New(_obj){
//var T = this;
//_obj.prototype = Object.create(ShaiObject.prototype);
// _obj.prototype.Document = (this.constructor == Object_Document ? this : this.Document);
/*_obj.prototype.New = this.New;
_obj.prototype.id = parseInt(Math.random()*10000);
_obj.prototype.children = [];
extend(_obj.prototype,Eventor.prototype);*/
/*T.Obj = new (Function.prototype.bind.apply(_obj, arguments));
return T.Obj;*/
//ShaiObject.call(_obj);
//ShaiObjectInitiator(_obj)
//var o = new (Function.prototype.bind.apply(_obj, arguments));
/*var o = new ShaiObject()
o.constructor = _obj;*/
_obj.prototype = new ShaiObject()
_obj.prototype.Document = (this.constructor == Object_Document ? this : this.Document);
_obj.prototype.constructor = _obj
var o = new (Function.prototype.bind.apply(_obj, arguments));
return o;
}
//Methods
function Dispatch(event_name,args) {
this.dispatched_list.push(event_name+"."+this.id);
var idx = this.listener_list.indexOf(event_name+"."+this.id);
while (idx!=-1) {
//this.callback_list[idx]();
this.callback_list[idx].apply(this,[args]);
idx = this.listener_list.indexOf(event_name+"."+this.id,idx+1);
}
//trigger event on parent unless the "stop" flag is raised from inside the child hadler
if (this.parent && !this.stop)
this.parent.Dispatch(event_name,args);
else
this.stop = false;
}
function Detach(event_name) {
var idx = this.listener_list.indexOf(event_name+"."+this.id);
while (idx!=-1) {
this.listener_list.splice(idx,1);
this.callback_list.splice(idx,1);
idx = this.listener_list.indexOf(event_name+"."+this.id,idx+1);
}
}
function Listen(event_name,callback) {
this.listener_list.push(event_name+"."+this.id)
this.callback_list.push(callback)
}
function addChild(_obj) {
//this.children=[];
_obj.parent = this;
this.children.push(_obj);
}
})(window);