flutter changes
[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         if (d.is_enum) {
392             Roo.docs.classType.el.dom.firstChild.textContent  = 'enum ';
393         }
394         if (d.is_mixin) {
395             Roo.docs.classType.el.dom.firstChild.textContent  = 'mixin ';
396         }
397         document.body.scrollTop  = 0;
398         Roo.docs.doc_name.el.dom.innerHTML = Roo.docs.template.resolveLinks(d.name);
399         Roo.docs.doc_desc.el.dom.innerHTML = Roo.docs.template.summary(d);
400         Roo.docs.doc_extends.hide();
401         Roo.docs.doc_extends_sep.hide();
402         if (d.augments.length) {
403             Roo.docs.doc_extends.show();
404             Roo.docs.doc_extends_sep.show();
405             Roo.docs.doc_extends.el.dom.innerHTML = d.augments[0];
406             Roo.docs.doc_extends.el.dom.href= '#' + d.augments[0];
407         }
408         Roo.docs.doc_source.el.dom.innerHTML = d.name.replace(/\./g,"/") + ".js";
409         if (Roo.docs.init.prefix.length) {
410             Roo.docs.doc_source_row.hide();
411         }
412         
413         
414         if (d.augments.length) {
415             Roo.docs.augments.show();
416             Roo.docs.augments.bodyEl().dom.innerHTML = Roo.docs.template.augments(d);
417         } else {
418             Roo.docs.augments.hide();
419         }
420         
421         if (d.realImplementors.length) {
422             Roo.docs.implementors.show();
423             Roo.docs.implementors.bodyEl().dom.innerHTML = Roo.docs.template.implementors(d);
424         } else {
425             Roo.docs.implementors.hide();
426         }
427         
428         
429         Roo.docs.configTableContainer.hide();
430         Roo.docs.methodsTableContainer.hide();
431         Roo.docs.eventsTableContainer.hide();
432         if (d.config.length) {
433             Roo.docs.configTableContainer.show();
434             Roo.docs.configTable.store.load( { params : { data : d.config.sort(Roo.docs.template.makeSortby("name")) }});
435         } 
436         
437         if (d.methods.length) {
438             Roo.docs.methodsTable.store.load( { params : { data : Roo.docs.template.methodsSort(d) }});
439             Roo.docs.methodsTableContainer.show();
440         }
441         if (d.events.length) {
442             Roo.docs.eventsTable.store.load( { params : { data : d.events.sort(Roo.docs.template.makeSortby("name")) }});
443             Roo.docs.eventsTableContainer.show();
444         }
445         
446         
447     },
448     onClick : function(e)
449     {
450         if (e.target.nodeName != 'A') {
451             return;
452         }
453         if (!e.target.href.match(/#/)) {
454             return;
455         }
456         e.stopPropagation();
457         var link = e.target.href.split('#')[1];
458         this.loadClass(link);
459         
460     },
461     
462     onHashChange : function()
463     {
464         if (this.hash == location.hash) {
465             return;
466         }
467         this.loadHash();
468         
469     },
470     loadHash : function()
471     {
472         if (location.hash.length < 2) {
473             this.loadDoc(false);
474         }
475         this.loadClass(location.hash.substring(1));
476         this.hash = location.hash;
477     },
478     
479       
480     loadIntro : function()
481     {
482       
483         
484         Roo.Ajax.request({
485             url : 'summary.txt',
486             method : 'GET',
487             success : function(res)
488             {
489                 this.renderIntro(res.responseText);
490                
491                 
492             },
493             scope : this
494         });
495         
496         
497     },
498     // render the really simple markdown data
499     renderIntro : function(intro)
500     {
501         
502         Roo.docs.doc_body_content.hide();
503
504         
505         var lines = intro.split("\n");
506         var tree = { 'name' : 'root', cn : []};
507         var state = [ tree ];
508         for (var i=0;i< lines.length;i++) {
509             var line = lines[i];
510             if (!line.length || line.match(/^\s+$/)) {
511                 continue;
512             }
513             var sm = line.match(/^(\s+)(.*)/);
514             
515             var sml = sm ? sm[1].length: 0;
516             //Roo.log(sml);
517             sml = sml / 4; // 4 spaces indent?
518             var add = { name : sm ?  sm[2] : line, cn : [] };
519             state[sml].cn.push(add);
520             state[sml+1] = add;
521             
522         }
523         //Roo.log(tree);
524         
525         for(var i = 0; i < tree.cn.length; i++) {
526             // make a container..
527             var treei = tree.cn[i];
528             var ctree = {
529                 
530                 xtype : 'Column',
531                 xns : Roo.bootstrap,
532                 md:4,
533                 sm : 6,
534                 items : [ {
535                     header : treei.name,
536                     xtype : 'Container',
537                     panel : 'info',
538                     xns : Roo.bootstrap,
539                     items : []
540                 }]
541             };
542             for(var ii = 0; ii < treei.cn.length; ii++) {
543                 var treeii = treei.cn[ii];
544                 // another container..
545                var ctreei = {
546                     header : treeii.name,
547                     xtype : 'Container',
548                     panel : 'primary',
549                     xns : Roo.bootstrap,
550                   
551                     items : [
552                          {
553                             xtype : 'Element',
554                             tag :'ul',
555                            
556                             xns : Roo.bootstrap,
557                             items : []
558                          }
559                     ]
560                 };
561                 ctree.items[0].items.push(ctreei);
562                 var footer = '';
563                 for(var iii = 0; iii < treeii.cn.length; iii++) {
564                     var treeiii = treeii.cn[iii];
565                     var ll = treeiii.name.match(/^(\S+)\s*(.*)$/);
566                     //Roo.log(treeiii.name);
567                     if (treeiii.name == 'Examples') {
568                         for (var j =0;j< treeiii.cn.length; j++) {
569                             var exs = treeiii.cn[j].name.match(/^\[([^\]]+)\](.*)$/);
570                             footer += '<li><a target="_blank" href="../' + exs[1] + '">'+exs[2] + '</a></li>';
571                         }
572                         continue;
573                         
574                         
575                     }
576         
577         
578
579                     ctreeii = {
580                             xtype : 'Element',
581                             tag :'li',
582                             xns : Roo.bootstrap,
583                             items : [
584                                 {
585                                    xtype : 'Link',
586                                     href : '#' + ( ll ? ll[1] : treeiii.name ) ,
587                                     html : ll ? ll[1] : treeiii.name,
588                                     
589                                     xns : Roo.bootstrap 
590                                 },
591                                 {
592                                    xtype : 'Element',
593                                     tag : 'span',
594                                     html : ll && ll[2].length ? ' - ' + ll[2] : '',
595                                     xns : Roo.bootstrap 
596                                 }
597                             ]
598                             
599                             
600                             
601                     };
602                     ctreei.items.push(ctreeii);
603                     
604                 }
605                 if (footer.length) {
606                     //Roo.log("footer:"+  footer);
607                     ctreei.footer = '<h5>Examples:</h5><ul>'+footer +'</ul>';
608                 }
609         
610             }
611             
612             
613             
614             
615             
616             Roo.docs.introBody.addxtypeChild(ctree);
617         }
618         
619         
620         
621     }
622     
623     
624     
625 };
626
627
628 Roo.onReady(Roo.docs.init.onReady, Roo.docs.init);
629     
630