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