Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / lang / observable.js @ 12

History | View | Annotate | Download (3.57 KB)

1 9 andrej.cim
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6
7
8
if(!dojo._hasResource["dojox.lang.observable"]){
9
dojo._hasResource["dojox.lang.observable"]=true;
10
dojo.provide("dojox.lang.observable");
11
dojo.experimental("dojox.lang.observable");
12
dojox.lang.observable=function(_1,_2,_3,_4){
13
return dojox.lang.makeObservable(_2,_3,_4)(_1);
14
};
15
dojox.lang.makeObservable=function(_5,_6,_7,_8){
16
_8=_8||{};
17
_7=_7||function(_9,_a,_b,_c){
18
return _a[_b].apply(_9,_c);
19
};
20
function _d(_e,_f,i){
21
return function(){
22
return _7(_e,_f,i,arguments);
23
};
24
};
25
if(dojox.lang.lettableWin){
26
var _10=dojox.lang.makeObservable;
27
_10.inc=(_10.inc||0)+1;
28
var _11="gettable_"+_10.inc;
29
dojox.lang.lettableWin[_11]=_5;
30
var _12="settable_"+_10.inc;
31
dojox.lang.lettableWin[_12]=_6;
32
var _13={};
33
return function(_14){
34
if(_14.__observable){
35
return _14.__observable;
36
}
37
if(_14.data__){
38
throw new Error("Can wrap an object that is already wrapped");
39
}
40
var _15=[],i,l;
41
for(i in _8){
42
_15.push(i);
43
}
44
var _16={type:1,event:1};
45
for(i in _14){
46
if(i.match(/^[a-zA-Z][\w\$_]*$/)&&!(i in _8)&&!(i in _16)){
47
_15.push(i);
48
}
49
}
50
var _17=_15.join(",");
51
var _18,_19=_13[_17];
52
if(!_19){
53
var _1a="dj_lettable_"+(_10.inc++);
54
var _1b=_1a+"_dj_getter";
55
var _1c=["Class "+_1a,"\tPublic data__"];
56
for(i=0,l=_15.length;i<l;i++){
57
_18=_15[i];
58
var _1d=typeof _14[_18];
59
if(_1d=="function"||_8[_18]){
60
_1c.push("  Public "+_18);
61
}else{
62
if(_1d!="object"){
63
_1c.push("\tPublic Property Let "+_18+"(val)","\t\tCall "+_12+"(me.data__,\""+_18+"\",val)","\tEnd Property","\tPublic Property Get "+_18,"\t\t"+_18+" = "+_11+"(me.data__,\""+_18+"\")","\tEnd Property");
64
}
65
}
66
}
67
_1c.push("End Class");
68
_1c.push("Function "+_1b+"()","\tDim tmp","\tSet tmp = New "+_1a,"\tSet "+_1b+" = tmp","End Function");
69
dojox.lang.lettableWin.vbEval(_1c.join("\n"));
70
_13[_17]=_19=function(){
71
return dojox.lang.lettableWin.construct(_1b);
72
};
73
}
74
var _1e=_19();
75
_1e.data__=_14;
76
try{
77
_14.__observable=_1e;
78
}
79
catch(e){
80
}
81
for(i=0,l=_15.length;i<l;i++){
82
_18=_15[i];
83
try{
84
var val=_14[_18];
85
}
86
catch(e){
87
}
88
if(typeof val=="function"||_8[_18]){
89
_1e[_18]=_d(_1e,_14,_18);
90
}
91
}
92
return _1e;
93
};
94
}else{
95
return function(_1f){
96
if(_1f.__observable){
97
return _1f.__observable;
98
}
99
var _20=_1f instanceof Array?[]:{};
100
_20.data__=_1f;
101
for(var i in _1f){
102
if(i.charAt(0)!="_"){
103
if(typeof _1f[i]=="function"){
104
_20[i]=_d(_20,_1f,i);
105
}else{
106
if(typeof _1f[i]!="object"){
107
(function(i){
108
_20.__defineGetter__(i,function(){
109
return _5(_1f,i);
110
});
111
_20.__defineSetter__(i,function(_21){
112
return _6(_1f,i,_21);
113
});
114
})(i);
115
}
116
}
117
}
118
}
119
for(i in _8){
120
_20[i]=_d(_20,_1f,i);
121
}
122
_1f.__observable=_20;
123
return _20;
124
};
125
}
126
};
127
if(!{}.__defineGetter__){
128
if(dojo.isIE){
129
var frame;
130
if(document.body){
131
frame=document.createElement("iframe");
132
document.body.appendChild(frame);
133
}else{
134
document.write("<iframe id='dj_vb_eval_frame'></iframe>");
135
frame=document.getElementById("dj_vb_eval_frame");
136
}
137
frame.style.display="none";
138
var doc=frame.contentWindow.document;
139
dojox.lang.lettableWin=frame.contentWindow;
140
doc.write("<html><head><script language=\"VBScript\" type=\"text/VBScript\">"+"Function vb_global_eval(code)"+"ExecuteGlobal(code)"+"End Function"+"</script>"+"<script type=\"text/javascript\">"+"function vbEval(code){ \n"+"return vb_global_eval(code);"+"}"+"function construct(name){ \n"+"return window[name]();"+"}"+"</script>"+"</head><body>vb-eval</body></html>");
141
doc.close();
142
}else{
143
throw new Error("This browser does not support getters and setters");
144
}
145
}
146
dojox.lang.ReadOnlyProxy=dojox.lang.makeObservable(function(obj,i){
147
return obj[i];
148
},function(obj,i,_22){
149
});
150
}