5fef56b2a14aa8e61c738ee1f083ccff77f670ae
[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                 
275                 if (typeof(d.augments) == 'undefined') {
276                     d.augments = [];
277                     d.config = []; // props for ctor?
278                     d.isFlutter  = true;
279                     this.fillAugments(d, d.extends, Roo.docs.init.fillDoc);
280                     return;
281                 }
282                 this.fillDoc(d);
283                 
284                 
285                 
286             },
287             scope : this
288         });
289         
290     },
291     n : 0,
292     fillAugments : function(d, ext, cb )
293     {
294         Roo.docs.init.n++;
295         if (Roo.docs.init.n > 20) {
296             return;
297         }
298         if (!ext.length) {
299             cb(d);
300             return;
301         }
302         var next = ext.shift();
303         d.augments.push(next);
304         var ax =   new Roo.data.Connection({});
305         ax.request({
306             url : this.prefix + 'symbols/' + next + '.json',
307             method : 'GET',
308             success : function(res, o)
309             {
310                 
311                 var r = Roo.decode(res.responseText);
312                 
313                 if (!r.isAbstract) {
314                     
315                     
316                     // copy methods that are not constructors..
317                     r.methods.forEach(function(m) {
318                         if (m.isConstructor || m.static) {
319                             return;
320                         }
321                         d.methods.push(m);  
322                     });
323                 }    
324                 r.props.forEach(function(m) {
325                     if (m.isConstant) {
326                         return;
327                     }
328                     d.props.push(m);  
329                 });
330                 
331                 r.events.forEach(function(m) {
332                     
333                     d.events.push(m);  
334                 });
335             
336                 this.fillAugments(d,ext, cb)
337                 
338             },
339             scope : this
340         });
341         
342     },
343     
344     
345     
346     fillDoc : function(d)
347     {
348         /*{
349             "name" : "Roo.bootstrap.Progress",
350             "augments" : [
351               "Roo.bootstrap.Component",
352               "Roo.Component",
353               "Roo.util.Observable"
354             ],
355             "desc" : "Bootstrap Progress class",
356             "config" : [
357               {
358         */
359         document.body.scrollTop  = 0;
360         Roo.docs.doc_name.el.dom.innerHTML = Roo.docs.template.resolveLinks(d.name);
361         Roo.docs.doc_desc.el.dom.innerHTML = Roo.docs.template.summary(d);
362         Roo.docs.doc_extends.hide();
363         Roo.docs.doc_extends_sep.hide();
364         if (d.augments.length) {
365             Roo.docs.doc_extends.show();
366             Roo.docs.doc_extends_sep.show();
367             Roo.docs.doc_extends.el.dom.innerHTML = d.augments[0];
368         }
369         Roo.docs.doc_source.el.dom.innerHTML = d.name.replace(/\./g,"/") + ".js";
370         
371         if (d.augments.length) {
372             Roo.docs.augments.show();
373             Roo.docs.augments.bodyEl().dom.innerHTML = Roo.docs.template.augments(d);
374         } else {
375             Roo.docs.augments.hide();
376         }
377         
378         
379         
380         Roo.docs.configTableContainer.hide();
381         Roo.docs.methodsTableContainer.hide();
382         Roo.docs.eventsTableContainer.hide();
383         if (d.config.length) {
384             Roo.docs.configTableContainer.show();
385             Roo.docs.configTable.store.load( { params : { data : d.config.sort(Roo.docs.template.makeSortby("name")) }});
386         } 
387         
388         if (d.methods.length) {
389             Roo.docs.methodsTable.store.load( { params : { data : Roo.docs.template.methodsSort(d) }});
390             Roo.docs.methodsTableContainer.show();
391         }
392         if (d.events.length) {
393             Roo.docs.eventsTable.store.load( { params : { data : d.events.sort(Roo.docs.template.makeSortby("name")) }});
394             Roo.docs.eventsTableContainer.show();
395         }
396         
397         
398     },
399     onClick : function(e)
400     {
401         if (e.target.nodeName != 'A') {
402             return;
403         }
404         if (!e.target.href.match(/#/)) {
405             return;
406         }
407         e.stopPropagation();
408         var link = e.target.href.split('#')[1];
409         this.loadClass(link);
410         
411     },
412     
413     onHashChange : function()
414     {
415         if (this.hash == location.hash) {
416             return;
417         }
418         this.loadHash();
419         
420     },
421     loadHash : function()
422     {
423         if (location.hash.length < 2) {
424             this.loadDoc(false);
425         }
426         this.loadClass(location.hash.substring(1));
427         this.hash = location.hash;
428     },
429     
430       
431     loadIntro : function()
432     {
433       
434         
435         Roo.Ajax.request({
436             url : 'summary.txt',
437             method : 'GET',
438             success : function(res)
439             {
440                 this.renderIntro(res.responseText);
441                
442                 
443             },
444             scope : this
445         });
446         
447         
448     },
449     // render the really simple markdown data
450     renderIntro : function(intro)
451     {
452         
453         Roo.docs.doc_body_content.hide();
454
455         
456         var lines = intro.split("\n");
457         var tree = { 'name' : 'root', cn : []};
458         var state = [ tree ];
459         for (var i=0;i< lines.length;i++) {
460             var line = lines[i];
461             if (!line.length || line.match(/^\s+$/)) {
462                 continue;
463             }
464             var sm = line.match(/^(\s+)(.*)/);
465             
466             var sml = sm ? sm[1].length: 0;
467             //Roo.log(sml);
468             sml = sml / 4; // 4 spaces indent?
469             var add = { name : sm ?  sm[2] : line, cn : [] };
470             state[sml].cn.push(add);
471             state[sml+1] = add;
472             
473         }
474         //Roo.log(tree);
475         
476         for(var i = 0; i < tree.cn.length; i++) {
477             // make a container..
478             var treei = tree.cn[i];
479             var ctree = {
480                 
481                 xtype : 'Column',
482                 xns : Roo.bootstrap,
483                 md:4,
484                 sm : 6,
485                 items : [ {
486                     header : treei.name,
487                     xtype : 'Container',
488                     panel : 'info',
489                     xns : Roo.bootstrap,
490                     items : []
491                 }]
492             };
493             for(var ii = 0; ii < treei.cn.length; ii++) {
494                 var treeii = treei.cn[ii];
495                 // another container..
496                var ctreei = {
497                     header : treeii.name,
498                     xtype : 'Container',
499                     panel : 'primary',
500                     xns : Roo.bootstrap,
501                   
502                     items : [
503                          {
504                             xtype : 'Element',
505                             tag :'ul',
506                            
507                             xns : Roo.bootstrap,
508                             items : []
509                          }
510                     ]
511                 };
512                 ctree.items[0].items.push(ctreei);
513                 var footer = '';
514                 for(var iii = 0; iii < treeii.cn.length; iii++) {
515                     var treeiii = treeii.cn[iii];
516                     var ll = treeiii.name.match(/^(\S+)\s*(.*)$/);
517                     //Roo.log(treeiii.name);
518                     if (treeiii.name == 'Examples') {
519                         for (var j =0;j< treeiii.cn.length; j++) {
520                             var exs = treeiii.cn[j].name.match(/^\[([^\]]+)\](.*)$/);
521                             footer += '<li><a target="_blank" href="../' + exs[1] + '">'+exs[2] + '</a></li>';
522                         }
523                         continue;
524                         
525                         
526                     }
527         
528         
529
530                     ctreeii = {
531                             xtype : 'Element',
532                             tag :'li',
533                             xns : Roo.bootstrap,
534                             items : [
535                                 {
536                                    xtype : 'Link',
537                                     href : '#' + ( ll ? ll[1] : treeiii.name ) ,
538                                     html : ll ? ll[1] : treeiii.name,
539                                     
540                                     xns : Roo.bootstrap 
541                                 },
542                                 {
543                                    xtype : 'Element',
544                                     tag : 'span',
545                                     html : ll && ll[2].length ? ' - ' + ll[2] : '',
546                                     xns : Roo.bootstrap 
547                                 }
548                             ]
549                             
550                             
551                             
552                     };
553                     ctreei.items.push(ctreeii);
554                     
555                 }
556                 if (footer.length) {
557                     //Roo.log("footer:"+  footer);
558                     ctreei.footer = '<h5>Examples:</h5><ul>'+footer +'</ul>';
559                 }
560         
561             }
562             
563             
564             
565             
566             
567             Roo.docs.introBody.addxtypeChild(ctree);
568         }
569         
570         
571         
572     }
573     
574     
575     
576 };
577
578
579 Roo.onReady(Roo.docs.init.onReady, Roo.docs.init);
580     
581