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