af4a155acfe9ce3ca7eaf626e4a6ac0e079cddf6
[roojs1] / docs / Roo.docs.init.js
1
2
3 Roo.docs.init = {
4     
5     classes : false, // flat version of list of classes 
6     currentClass : '--none--', // currently viewed class name
7     
8     prefix : '',
9     hash : '',
10     
11     onReady : function()
12     {
13        
14         
15         Roo.XComponent.hideProgress = true;
16         Roo.XComponent.build();
17          
18         
19         Roo.XComponent.on('buildcomplete', function() {
20             
21             //Roo.XComponent.modules[0].el.fireEvent('render');
22             this.loadTree();
23         }, this);
24         if (window.location.search.length > 0) {
25             this.prefix = window.location.search.substring(1);
26         }
27         
28         window.onhashchange = function() { Roo.docs.init.onHashChange(); }
29          
30         
31     },
32     
33     loadTree: function()
34     {
35         Roo.docs.doc_body_content.hide();
36         
37         Roo.Ajax.request({
38             url : this.prefix + 'tree.json',
39             method : 'GET',
40             success : function(res, o)
41             {
42                 var d = Roo.decode(res.responseText);
43                 //Roo.log(d);
44                 this.classes = {};
45                 // our classes witch children first..
46                 d.forEach(function(e) {
47                     if (e.cn.length) {
48                         this.addTreeItem(Roo.docs.navGroup, e, 'NavSidebarItem', true );
49                         
50                     }
51                 }, this);
52                 
53                 d.forEach(function(e) {
54                     if (!e.cn.length) {
55                         this.addTreeItem(Roo.docs.navGroup, e, 'NavSidebarItem' ,true);
56                     }
57                 }, this);
58                 
59                 // mobile....
60                 
61                 d.forEach(function(e) {
62                     if (e.cn.length) {
63                         this.addTreeItem(Roo.docs.mobileNavGroup, e, 'NavSidebarItem', false);
64                         
65                     }
66                 }, this);
67                 
68                 d.forEach(function(e) {
69                     if (!e.cn.length) {
70                         this.addTreeItem(Roo.docs.mobileNavGroup, e, 'NavSidebarItem', false);
71                     }
72                 }, this);
73                 
74                 var roo = Roo.docs.navGroup.items[1].menu;
75                 if (!Roo.docs.init.prefix.length) {
76                     roo.show(roo.triggerEl, '?', false);
77                 }
78                 
79                 if (location.hash.length) {
80                     this.loadHash();
81                     return;
82                 }
83                 
84                 this.loadIntro();
85                 
86                 
87             },
88             scope : this
89         });
90         
91         
92     },
93     
94     hideChildren : function(c)
95     {
96         if (c.node.menu) {
97             c.node.menu.hide();
98         }
99         for (var i =0; i < c.cn.length; i++) {
100             this.hideChildren(c.cn[i]);
101         }
102         
103     },
104     
105     
106     addTreeItem : function(parent, e, type , parent_e) {
107         
108         this.classes[e.name] = e; 
109         // add a node..
110         var node = parent.addxtypeChild(Roo.factory({
111             html: e.name.split('.').pop(),
112            // id : e.name,
113             xns : Roo.bootstrap,
114             showArrow: false,
115             xtype : type,
116             preventDefault : true,
117           //  cls : type == 'NavSidebarItem' ? 'open' : '',
118             listeners : {
119                 click : (function(mi,ev,c)
120                 {
121                     
122                     ev.stopEvent();
123                      
124                     if (c.cn.length && !Roo.docs.init.prefix.length) {
125                         //Roo.log(ev);
126                         if (mi.menu.el.hasClass('show')) {
127                             this.hideChildren(c); //mi.menu.hide();
128                             // collapse children..
129                             
130                             
131                             
132                         } else {
133                             mi.menu.show(mi.menu.triggerEl,'?', false);
134                         }
135                         
136                     }
137                     location.hash = '#' + c.name;
138                     //Roo.docs.init.loadDoc(c);
139                     
140                 }).createDelegate(this,[e], true)
141                 
142             },
143             fa :  e.cn.length  ? 'chevron-right' : '',
144             menu : !e.cn.length ? false  : Roo.factory({
145                 type : 'treeview',
146                 xns: Roo.bootstrap,
147                 xtype : 'Menu',
148                 listeners : {
149                     beforehide : (function(mi,c)
150                     {
151                         if (Roo.docs.init.prefix.length) {
152                             return;
153                         }
154                         
155                         if (c.name.split('.').length < 2)  {
156                             return false;
157                         }
158                         return true;
159                         
160                     }).createDelegate(this,[e], true)
161                     
162                 }
163                 
164             })
165         }));
166         
167         // mobile nodes..?
168         
169        
170         
171         
172         
173         
174         if (parent_e !== false) {
175             e.node = node;
176             e.parent_menu = parent;
177             e.parent = parent_e == true ? null : parent_e;
178         }
179         
180         parent.items.push(node);
181         if (e.cn.length  && type == 'NavSidebarItem') {
182             this.topm = node.menu;
183         }
184         
185         
186         if (!e.cn.length) {
187             return;
188         }
189         e.cn.forEach(function(ec) {
190             var cn = ec.name.split('.').pop();
191             //Roo.log(cn);
192             if (cn == cn.toLowerCase()) {
193                 this.addTreeItem(node.menu, ec,'MenuItem', parent_e !== false ? e : false);
194             }
195             
196         }, this);
197         e.cn.forEach(function(ec) {
198             var cn = ec.name.split('.').pop();
199             if (cn != cn.toLowerCase()) {
200                 this.addTreeItem(node.menu, ec,'MenuItem', parent_e !== false ? e : false);
201             }
202         }, this);
203         
204     },
205     
206     loadClass : function(name)
207     {
208         if(typeof(this.classes[name]) != 'undefined' && this.classes[name].is_class ) {
209             this.loadDoc(this.classes[name]);
210         }
211         
212         
213         
214     },
215     
216     loadSource : function( )
217     {
218         
219        
220         Roo.Ajax.request({
221             url : 'src/' +this.currentClass.replace(/\./g,'_') + '.js.html',
222             method : 'GET',
223             success : function(res, o)
224             {
225                 Roo.docs.ViewSource.show({
226                         source : res.responseText,
227                         fname : this.currentClass.replace(/\./g,'/') + ".js"
228                 });
229                 
230             },
231             scope : this
232         });
233         
234         
235     },
236     
237     loadDoc : function(cls)
238     {
239         if (this.currentClass == cls.name) {
240             return;
241         }
242         //Roo.docs.mobileNavGroup.hide();
243         Roo.log("loadDoc?");
244         Roo.docs.doc_body_content.hide();
245         Roo.docs.navHeaderBar.collapse();
246         this.currentClass = cls.name;
247         if (!cls ) {
248             Roo.docs.introBody.show();
249             return;
250         }
251         
252         // expand parents..
253         
254         var m = cls.parent_menu;
255         m.show(m.triggerEl,'?', false);
256         var mp = cls;
257         while ((mp = mp.parent)) {
258             m = mp.parent_menu;
259             m.show(m.triggerEl,'?', false);
260         }
261         cls.node.el.scrollIntoView(Roo.docs.sidebar.el,false);
262         Roo.docs.sidebar.el.select('.active').removeClass('active');
263         cls.node.el.addClass('active');
264         
265         Roo.docs.introBody.hide();
266         Roo.docs.doc_body_content.show();
267         Roo.Ajax.request({
268             url : this.prefix + 'symbols/' + cls.name + '.json',
269             method : 'GET',
270             success : function(res, o)
271             {
272                 
273                 var d = Roo.decode(res.responseText);
274                 if (this.prefix.length) {
275                     this.fillAugments(d, Roo.docs.init.fillDoc);
276                     return;
277                 }
278                 this.fillDoc(d);
279                 
280                 
281                 
282             },
283             scope : this
284         });
285         
286     },
287     fillAugments : function(d, cb)
288     {
289         if (!d.extends.lenght) {
290             cb(d)
291         }
292         Roo.Ajax.request({
293             url : this.prefix + 'symbols/' + d.extends + '.json',
294             method : 'GET',
295             success : function(res, o)
296             {
297                 
298                 var r = Roo.decode(res.responseText);
299                 // copy methods that are not constructors..
300                 r.methods.forEach(function(m) {
301                     if (m.isConstructor || m.static) {
302                         return;
303                     }
304                     d.methods.push(m);  
305                 })
306                 
307                 
308                 
309                 
310                 
311             },
312             scope : this
313         });
314         
315     }
316     
317     
318     
319     fillDoc : function(d)
320     {
321         /*{
322             "name" : "Roo.bootstrap.Progress",
323             "augments" : [
324               "Roo.bootstrap.Component",
325               "Roo.Component",
326               "Roo.util.Observable"
327             ],
328             "desc" : "Bootstrap Progress class",
329             "config" : [
330               {
331         */
332         document.body.scrollTop  = 0;
333         Roo.docs.doc_name.el.dom.innerHTML = Roo.docs.template.resolveLinks(d.name);
334         Roo.docs.doc_desc.el.dom.innerHTML = Roo.docs.template.summary(d);
335         Roo.docs.doc_extends.hide();
336         Roo.docs.doc_extends_sep.hide();
337         if (d.augments.length) {
338             Roo.docs.doc_extends.show();
339             Roo.docs.doc_extends_sep.show();
340             Roo.docs.doc_extends.el.dom.innerHTML = d.augments[0];
341         }
342         Roo.docs.doc_source.el.dom.innerHTML = d.name.replace(/\./g,"/") + ".js";
343         
344         if (d.augments.length) {
345             Roo.docs.augments.show();
346             Roo.docs.augments.bodyEl().dom.innerHTML = Roo.docs.template.augments(d);
347         } else {
348             Roo.docs.augments.hide();
349         }
350         
351         
352         
353         Roo.docs.configTableContainer.hide();
354         Roo.docs.methodsTableContainer.hide();
355         Roo.docs.eventsTableContainer.hide();
356         if (d.config.length) {
357             Roo.docs.configTableContainer.show();
358             Roo.docs.configTable.store.load( { params : { data : d.config.sort(Roo.docs.template.makeSortby("name")) }});
359         } 
360         
361         if (d.methods.length) {
362             Roo.docs.methodsTable.store.load( { params : { data : Roo.docs.template.methodsSort(d) }});
363             Roo.docs.methodsTableContainer.show();
364         }
365         if (d.events.length) {
366             Roo.docs.eventsTable.store.load( { params : { data : d.events.sort(Roo.docs.template.makeSortby("name")) }});
367             Roo.docs.eventsTableContainer.show();
368         }
369         
370         
371     },
372     onClick : function(e)
373     {
374         if (e.target.nodeName != 'A') {
375             return;
376         }
377         if (!e.target.href.match(/#/)) {
378             return;
379         }
380         e.stopPropagation();
381         var link = e.target.href.split('#')[1];
382         this.loadClass(link);
383         
384     },
385     
386     onHashChange : function()
387     {
388         if (this.hash == location.hash) {
389             return;
390         }
391         this.loadHash();
392         
393     },
394     loadHash : function()
395     {
396         if (location.hash.length < 2) {
397             this.loadDoc(false);
398         }
399         this.loadClass(location.hash.substring(1));
400         this.hash = location.hash;
401     },
402     
403       
404     loadIntro : function()
405     {
406       
407         
408         Roo.Ajax.request({
409             url : 'summary.txt',
410             method : 'GET',
411             success : function(res)
412             {
413                 this.renderIntro(res.responseText);
414                
415                 
416             },
417             scope : this
418         });
419         
420         
421     },
422     // render the really simple markdown data
423     renderIntro : function(intro)
424     {
425         
426         Roo.docs.doc_body_content.hide();
427
428         
429         var lines = intro.split("\n");
430         var tree = { 'name' : 'root', cn : []};
431         var state = [ tree ];
432         for (var i=0;i< lines.length;i++) {
433             var line = lines[i];
434             if (!line.length || line.match(/^\s+$/)) {
435                 continue;
436             }
437             var sm = line.match(/^(\s+)(.*)/);
438             
439             var sml = sm ? sm[1].length: 0;
440             //Roo.log(sml);
441             sml = sml / 4; // 4 spaces indent?
442             var add = { name : sm ?  sm[2] : line, cn : [] };
443             state[sml].cn.push(add);
444             state[sml+1] = add;
445             
446         }
447         //Roo.log(tree);
448         
449         for(var i = 0; i < tree.cn.length; i++) {
450             // make a container..
451             var treei = tree.cn[i];
452             var ctree = {
453                 
454                 xtype : 'Column',
455                 xns : Roo.bootstrap,
456                 md:4,
457                 sm : 6,
458                 items : [ {
459                     header : treei.name,
460                     xtype : 'Container',
461                     panel : 'info',
462                     xns : Roo.bootstrap,
463                     items : []
464                 }]
465             };
466             for(var ii = 0; ii < treei.cn.length; ii++) {
467                 var treeii = treei.cn[ii];
468                 // another container..
469                var ctreei = {
470                     header : treeii.name,
471                     xtype : 'Container',
472                     panel : 'primary',
473                     xns : Roo.bootstrap,
474                   
475                     items : [
476                          {
477                             xtype : 'Element',
478                             tag :'ul',
479                            
480                             xns : Roo.bootstrap,
481                             items : []
482                          }
483                     ]
484                 };
485                 ctree.items[0].items.push(ctreei);
486                 var footer = '';
487                 for(var iii = 0; iii < treeii.cn.length; iii++) {
488                     var treeiii = treeii.cn[iii];
489                     var ll = treeiii.name.match(/^(\S+)\s*(.*)$/);
490                     //Roo.log(treeiii.name);
491                     if (treeiii.name == 'Examples') {
492                         for (var j =0;j< treeiii.cn.length; j++) {
493                             var exs = treeiii.cn[j].name.match(/^\[([^\]]+)\](.*)$/);
494                             footer += '<li><a target="_blank" href="../' + exs[1] + '">'+exs[2] + '</a></li>';
495                         }
496                         continue;
497                         
498                         
499                     }
500         
501         
502
503                     ctreeii = {
504                             xtype : 'Element',
505                             tag :'li',
506                             xns : Roo.bootstrap,
507                             items : [
508                                 {
509                                    xtype : 'Link',
510                                     href : '#' + ( ll ? ll[1] : treeiii.name ) ,
511                                     html : ll ? ll[1] : treeiii.name,
512                                     
513                                     xns : Roo.bootstrap 
514                                 },
515                                 {
516                                    xtype : 'Element',
517                                     tag : 'span',
518                                     html : ll && ll[2].length ? ' - ' + ll[2] : '',
519                                     xns : Roo.bootstrap 
520                                 }
521                             ]
522                             
523                             
524                             
525                     };
526                     ctreei.items.push(ctreeii);
527                     
528                 }
529                 if (footer.length) {
530                     //Roo.log("footer:"+  footer);
531                     ctreei.footer = '<h5>Examples:</h5><ul>'+footer +'</ul>';
532                 }
533         
534             }
535             
536             
537             
538             
539             
540             Roo.docs.introBody.addxtypeChild(ctree);
541         }
542         
543         
544         
545     }
546     
547     
548     
549 };
550
551
552 Roo.onReady(Roo.docs.init.onReady, Roo.docs.init);
553     
554