root / trunk / web / dojo / dojox / help / _base.js @ 12
History | View | Annotate | Download (8.22 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.help._base"]){ |
||
9 | dojo._hasResource["dojox.help._base"]=true; |
||
10 | dojo.provide("dojox.help._base");
|
||
11 | dojo.require("dojox.rpc.Service");
|
||
12 | dojo.require("dojo.io.script");
|
||
13 | dojo.experimental("dojox.help");
|
||
14 | console.warn("Script causes side effects (on numbers, strings, and booleans). Call dojox.help.noConflict() if you plan on executing code.");
|
||
15 | dojox.help={locate:function(_1,_2,_3){ |
||
16 | _3=_3||20;
|
||
17 | var _4=[];
|
||
18 | var _5={};
|
||
19 | var _6;
|
||
20 | if(_2){
|
||
21 | if(!dojo.isArray(_2)){
|
||
22 | _2=[_2]; |
||
23 | } |
||
24 | for(var i=0,_7;_7=_2[i];i++){ |
||
25 | _6=_7; |
||
26 | if(dojo.isString(_7)){
|
||
27 | _7=dojo.getObject(_7); |
||
28 | if(!_7){
|
||
29 | continue;
|
||
30 | } |
||
31 | }else{
|
||
32 | if(dojo.isObject(_7)){
|
||
33 | _6=_7.__name__; |
||
34 | }else{
|
||
35 | continue;
|
||
36 | } |
||
37 | } |
||
38 | _4.push(_7); |
||
39 | if(_6){
|
||
40 | _6=_6.split(".")[0]; |
||
41 | if(!_5[_6]&&dojo.indexOf(dojox.help._namespaces,_6)==-1){ |
||
42 | dojox.help.refresh(_6); |
||
43 | } |
||
44 | _5[_6]=true;
|
||
45 | } |
||
46 | } |
||
47 | } |
||
48 | if(!_4.length){
|
||
49 | _4.push({__name__:"window"}); |
||
50 | dojo.forEach(dojox.help._namespaces,function(_8){
|
||
51 | _5[_8]=true;
|
||
52 | }); |
||
53 | } |
||
54 | var _9=_1.toLowerCase();
|
||
55 | var _a=[];
|
||
56 | out: |
||
57 | for(var i=0,_7;_7=_4[i];i++){ |
||
58 | var _b=_7.__name__||""; |
||
59 | var _c=dojo.some(_4,function(_d){ |
||
60 | _d=_d.__name__||"";
|
||
61 | return (_b.indexOf(_d+".")==0); |
||
62 | }); |
||
63 | if(_b&&!_c){
|
||
64 | _6=_b.split(".")[0]; |
||
65 | var _e=[];
|
||
66 | if(_b=="window"){ |
||
67 | for(_6 in dojox.help._names){ |
||
68 | if(dojo.isArray(dojox.help._names[_6])){
|
||
69 | _e=_e.concat(dojox.help._names[_6]); |
||
70 | } |
||
71 | } |
||
72 | }else{
|
||
73 | _e=dojox.help._names[_6]; |
||
74 | } |
||
75 | for(var j=0,_f;_f=_e[j];j++){ |
||
76 | if((_b=="window"||_f.indexOf(_b+".")==0)&&_f.toLowerCase().indexOf(_9)!=-1){ |
||
77 | if(_f.slice(-10)==".prototype"){ |
||
78 | continue;
|
||
79 | } |
||
80 | var obj=dojo.getObject(_f);
|
||
81 | if(obj){
|
||
82 | _a.push([_f,obj]); |
||
83 | if(_a.length==_3){
|
||
84 | break out;
|
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 | dojox.help._displayLocated(_a); |
||
92 | if(!dojo.isMoz){
|
||
93 | return ""; |
||
94 | } |
||
95 | },refresh:function(_10,_11){ |
||
96 | if(arguments.length<2){ |
||
97 | _11=true;
|
||
98 | } |
||
99 | dojox.help._recurse(_10,_11); |
||
100 | },noConflict:function(_12){ |
||
101 | if(arguments.length){ |
||
102 | return dojox.help._noConflict(_12);
|
||
103 | }else{
|
||
104 | while(dojox.help._overrides.length){
|
||
105 | var _13=dojox.help._overrides.pop();
|
||
106 | var _14=_13[0]; |
||
107 | var key=_13[1]; |
||
108 | var _15=_14[key];
|
||
109 | _14[key]=dojox.help._noConflict(_15); |
||
110 | } |
||
111 | } |
||
112 | },init:function(_16,_17){ |
||
113 | if(_16){
|
||
114 | dojox.help._namespaces.concat(_16); |
||
115 | } |
||
116 | dojo.addOnLoad(function(){
|
||
117 | dojo.require=(function(_18){
|
||
118 | return function(){ |
||
119 | dojox.help.noConflict(); |
||
120 | _18.apply(dojo,arguments);
|
||
121 | if(dojox.help._timer){
|
||
122 | clearTimeout(dojox.help._timer); |
||
123 | } |
||
124 | dojox.help._timer=setTimeout(function(){
|
||
125 | dojo.addOnLoad(function(){
|
||
126 | dojox.help.refresh(); |
||
127 | dojox.help._timer=false;
|
||
128 | }); |
||
129 | },500);
|
||
130 | }; |
||
131 | })(dojo.require); |
||
132 | dojox.help._recurse(); |
||
133 | }); |
||
134 | },_noConflict:function(_19){ |
||
135 | if(_19 instanceof String){ |
||
136 | return _19.toString();
|
||
137 | }else{
|
||
138 | if(_19 instanceof Number){ |
||
139 | return +_19;
|
||
140 | }else{
|
||
141 | if(_19 instanceof Boolean){ |
||
142 | return (_19==true); |
||
143 | }else{
|
||
144 | if(dojo.isObject(_19)){
|
||
145 | delete _19.__name__;
|
||
146 | delete _19.help;
|
||
147 | } |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | return _19;
|
||
152 | },_namespaces:["dojo","dojox","dijit","djConfig"],_rpc:new dojox.rpc.Service(dojo.moduleUrl("dojox.rpc.SMDLibrary","dojo-api.smd")),_attributes:["summary","type","returns","parameters"],_clean:function(_1a){ |
||
153 | var obj={};
|
||
154 | for(var i=0,_1b;_1b=dojox.help._attributes[i];i++){ |
||
155 | var _1c=_1a["__"+_1b+"__"]; |
||
156 | if(_1c){
|
||
157 | obj[_1b]=_1c; |
||
158 | } |
||
159 | } |
||
160 | return obj;
|
||
161 | },_displayLocated:function(_1d){ |
||
162 | throw new Error("_displayLocated should be overridden in one of the dojox.help packages"); |
||
163 | },_displayHelp:function(_1e,obj){ |
||
164 | throw new Error("_displayHelp should be overridden in one of the dojox.help packages"); |
||
165 | },_addVersion:function(obj){ |
||
166 | if(obj.name){
|
||
167 | obj.version=[dojo.version.major,dojo.version.minor,dojo.version.patch].join(".");
|
||
168 | var _1f=obj.name.split("."); |
||
169 | if(_1f[0]=="dojo"||_1f[0]=="dijit"||_1f[0]=="dojox"){ |
||
170 | obj.project=_1f[0];
|
||
171 | } |
||
172 | } |
||
173 | return obj;
|
||
174 | },_stripPrototype:function(_20){ |
||
175 | var _21=_20.replace(/\.prototype(\.|$)/g,"."); |
||
176 | var _22=_21;
|
||
177 | if(_21.slice(-1)=="."){ |
||
178 | _22=_21=_21.slice(0,-1); |
||
179 | }else{
|
||
180 | _21=_20; |
||
181 | } |
||
182 | return [_22,_21];
|
||
183 | },_help:function(){ |
||
184 | var _23=this.__name__; |
||
185 | var _24=dojox.help._stripPrototype(_23)[0]; |
||
186 | var _25=[];
|
||
187 | for(var i=0,_26;_26=dojox.help._attributes[i];i++){ |
||
188 | if(!this["__"+_26+"__"]){ |
||
189 | _25.push(_26); |
||
190 | } |
||
191 | } |
||
192 | dojox.help._displayHelp(true,{name:this.__name__}); |
||
193 | if(!_25.length||this.__searched__){ |
||
194 | dojox.help._displayHelp(false,dojox.help._clean(this)); |
||
195 | }else{
|
||
196 | this.__searched__=true; |
||
197 | dojox.help._rpc.get(dojox.help._addVersion({name:_24,exact:true,attributes:_25})).addCallback(this,function(_27){ |
||
198 | if(this.toString===dojox.help._toString){ |
||
199 | this.toString(_27);
|
||
200 | } |
||
201 | if(_27&&_27.length){
|
||
202 | _27=_27[0];
|
||
203 | for(var i=0,_26;_26=dojox.help._attributes[i];i++){ |
||
204 | if(_27[_26]){
|
||
205 | this["__"+_26+"__"]=_27[_26]; |
||
206 | } |
||
207 | } |
||
208 | dojox.help._displayHelp(false,dojox.help._clean(this)); |
||
209 | }else{
|
||
210 | dojox.help._displayHelp(false,false); |
||
211 | } |
||
212 | }); |
||
213 | } |
||
214 | if(!dojo.isMoz){
|
||
215 | return ""; |
||
216 | } |
||
217 | },_parse:function(_28){ |
||
218 | delete this.__searching__; |
||
219 | if(_28&&_28.length){
|
||
220 | var _29=_28[0].parameters; |
||
221 | if(_29){
|
||
222 | var _2a=["function ",this.__name__,"("]; |
||
223 | this.__parameters__=_29;
|
||
224 | for(var i=0,_2b;_2b=_29[i];i++){ |
||
225 | if(i){
|
||
226 | _2a.push(", ");
|
||
227 | } |
||
228 | _2a.push(_2b.name); |
||
229 | if(_2b.types){
|
||
230 | var _2c=[];
|
||
231 | for(var j=0,_2d;_2d=_2b.types[j];j++){ |
||
232 | _2c.push(_2d.title); |
||
233 | } |
||
234 | if(_2c.length){
|
||
235 | _2a.push(": ");
|
||
236 | _2a.push(_2c.join("|"));
|
||
237 | } |
||
238 | } |
||
239 | if(_2b.repeating){
|
||
240 | _2a.push("...");
|
||
241 | } |
||
242 | if(_2b.optional){
|
||
243 | _2a.push("?");
|
||
244 | } |
||
245 | } |
||
246 | _2a.push(")");
|
||
247 | this.__source__=this.__source__.replace(/function[^\(]*\([^\)]*\)/,_2a.join("")); |
||
248 | } |
||
249 | if(this.__output__){ |
||
250 | delete this.__output__; |
||
251 | } |
||
252 | }else{
|
||
253 | dojox.help._displayHelp(false,false); |
||
254 | } |
||
255 | },_toStrings:{},_toString:function(_2e){ |
||
256 | if(!this.__source__){ |
||
257 | return this.__name__; |
||
258 | } |
||
259 | var _2f=(!this.__parameters__); |
||
260 | this.__parameters__=[];
|
||
261 | if(_2e){
|
||
262 | dojox.help._parse.call(this,_2e);
|
||
263 | }else{
|
||
264 | if(_2f){
|
||
265 | this.__searching__=true; |
||
266 | dojox.help._toStrings[dojox.help._stripPrototype(this.__name__)[0]]=this; |
||
267 | if(dojox.help._toStringTimer){
|
||
268 | clearTimeout(dojox.help._toStringTimer); |
||
269 | } |
||
270 | dojox.help._toStringTimer=setTimeout(function(){
|
||
271 | dojox.help.__toString(); |
||
272 | },50);
|
||
273 | } |
||
274 | } |
||
275 | if(!_2f||!this.__searching__){ |
||
276 | return this.__source__; |
||
277 | } |
||
278 | var _30="function Loading info for "+this.__name__+"... (watch console for result) {}"; |
||
279 | if(!dojo.isMoz){
|
||
280 | this.__output__=true; |
||
281 | return _30;
|
||
282 | } |
||
283 | return {toString:dojo.hitch(this,function(){ |
||
284 | this.__output__=true; |
||
285 | return _30;
|
||
286 | })}; |
||
287 | },__toString:function(){ |
||
288 | if(dojox.help._toStringTimer){
|
||
289 | clearTimeout(dojox.help._toStringTimer); |
||
290 | } |
||
291 | var _31=[];
|
||
292 | dojox.help.noConflict(dojox.help._toStrings); |
||
293 | for(var _32 in dojox.help._toStrings){ |
||
294 | _31.push(_32); |
||
295 | } |
||
296 | while(_31.length){
|
||
297 | dojox.help._rpc.batch(dojox.help._addVersion({names:_31.splice(-50,50),exact:true,attributes:["parameters"]})).addCallback(this,function(_33){ |
||
298 | for(var i=0,_34;_34=_33[i];i++){ |
||
299 | var fn=dojox.help._toStrings[_34.name];
|
||
300 | if(fn){
|
||
301 | dojox.help._parse.call(fn,[_34]); |
||
302 | delete dojox.help._toStrings[_34.name];
|
||
303 | } |
||
304 | } |
||
305 | }); |
||
306 | } |
||
307 | },_overrides:[],_recursions:[],_names:{},_recurse:function(_35,_36){ |
||
308 | if(arguments.length<2){ |
||
309 | _36=true;
|
||
310 | } |
||
311 | var _37=[];
|
||
312 | if(_35&&dojo.isString(_35)){
|
||
313 | dojox.help.__recurse(dojo.getObject(_35),_35,_35,_37,_36); |
||
314 | }else{
|
||
315 | for(var i=0,ns;ns=dojox.help._namespaces[i];i++){ |
||
316 | if(window[ns]){
|
||
317 | dojox.help._recursions.push([window[ns],ns,ns]); |
||
318 | window[ns].__name__=ns; |
||
319 | if(!window[ns].help){
|
||
320 | window[ns].help=dojox.help._help; |
||
321 | } |
||
322 | } |
||
323 | } |
||
324 | } |
||
325 | while(dojox.help._recursions.length){
|
||
326 | var _38=dojox.help._recursions.shift();
|
||
327 | dojox.help.__recurse(_38[0],_38[1],_38[2],_37,_36); |
||
328 | } |
||
329 | for(var i=0,_39;_39=_37[i];i++){ |
||
330 | delete _39.__seen__;
|
||
331 | } |
||
332 | },__recurse:function(_3a,_3b,_3c,_3d,_3e){ |
||
333 | for(var key in _3a){ |
||
334 | if(key.match(/([^\w_.$]|__[\w_.$]+__)/)){ |
||
335 | continue;
|
||
336 | } |
||
337 | var _3f=_3a[key];
|
||
338 | if(typeof _3f=="undefined"||_3f===document||_3f===window||_3f===dojox.help._toString||_3f===dojox.help._help||_3f===null||(+dojo.isIE&&_3f.tagName)||_3f.__seen__){ |
||
339 | continue;
|
||
340 | } |
||
341 | var _40=dojo.isFunction(_3f);
|
||
342 | var _41=dojo.isObject(_3f)&&!dojo.isArray(_3f)&&!_3f.nodeType;
|
||
343 | var _42=(_3c)?(_3c+"."+key):key; |
||
344 | if(_42=="dojo._blockAsync"){ |
||
345 | continue;
|
||
346 | } |
||
347 | if(!_3f.__name__){
|
||
348 | var _43=null; |
||
349 | if(dojo.isString(_3f)){
|
||
350 | _43=String; |
||
351 | }else{
|
||
352 | if(typeof _3f=="number"){ |
||
353 | _43=Number; |
||
354 | }else{
|
||
355 | if(typeof _3f=="boolean"){ |
||
356 | _43=Boolean; |
||
357 | } |
||
358 | } |
||
359 | } |
||
360 | if(_43){
|
||
361 | _3f=_3a[key]=new _43(_3f);
|
||
362 | } |
||
363 | } |
||
364 | _3f.__seen__=true;
|
||
365 | _3f.__name__=_42; |
||
366 | (dojox.help._names[_3b]=dojox.help._names[_3b]||[]).push(_42); |
||
367 | _3d.push(_3f); |
||
368 | if(!_40){
|
||
369 | dojox.help._overrides.push([_3a,key]); |
||
370 | } |
||
371 | if((_40||_41)&&_3e){
|
||
372 | dojox.help._recursions.push([_3f,_3b,_42]); |
||
373 | } |
||
374 | if(_40){
|
||
375 | if(!_3f.__source__){
|
||
376 | _3f.__source__=_3f.toString().replace(/^function\b ?/,"function "+_42); |
||
377 | } |
||
378 | if(_3f.toString===Function.prototype.toString){
|
||
379 | _3f.toString=dojox.help._toString; |
||
380 | } |
||
381 | } |
||
382 | if(!_3f.help){
|
||
383 | _3f.help=dojox.help._help; |
||
384 | } |
||
385 | } |
||
386 | }}; |
||
387 | } |