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