0c69bb401d097dd97cac58ec880a0692f7ab7c89
[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     hash : '',
9     
10     onReady : function()
11     {
12        
13         //if (typeof(pagedata) == 'undefined') {
14         //    Site.onReady.defer(100, Roo.docs.init);
15         //    return;
16         //}
17         //Roo.debug = 1;
18         
19         Roo.XComponent.hideProgress = true;
20         Roo.XComponent.build();
21         
22         
23         
24         
25         Roo.XComponent.on('buildcomplete', function() {
26             
27             //Roo.XComponent.modules[0].el.fireEvent('render');
28             this.loadTree();
29         }, this);
30         
31         
32         window.onhashchange = function() { Roo.docs.init.onHashChange(); }
33         
34         
35        
36         
37         //Roo.get(document.body).on('click', this.onClick, this);
38       
39         
40     },
41     
42     loadTree: function()
43     {
44         Roo.docs.doc_body_content.hide();
45         
46         Roo.Ajax.request({
47             url : 'tree.json',
48             method : 'GET',
49             success : function(res, o)
50             {
51                 var d = Roo.decode(res.responseText);
52                 //Roo.log(d);
53                 this.classes = {};
54                 // our classes witch children first..
55                 d.forEach(function(e) {
56                     if (e.cn.length) {
57                         this.addTreeItem(Roo.docs.navGroup, e, 'NavSidebarItem', true);
58                         
59                     }
60                 }, this);
61                 
62                 d.forEach(function(e) {
63                     if (!e.cn.length) {
64                         this.addTreeItem(Roo.docs.navGroup, e, 'NavSidebarItem' ,true);
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                     }
73                 }, this);
74                 
75                 d.forEach(function(e) {
76                     if (!e.cn.length) {
77                         this.addTreeItem(Roo.docs.mobileNavGroup, e, 'NavSidebarItem', false);
78                     }
79                 }, this);
80                 
81                 var roo = Roo.docs.navGroup.items[1].menu;
82                 roo.show(roo.triggerEl, '?', false);
83                 if (location.hash.length) {
84                     this.loadHash();
85                     return;
86                 }
87                 
88                 this.loadIntro();
89                 
90                 
91             },
92             scope : this
93         });
94         
95         
96     },
97     
98     hideChildren : function(c)
99     {
100         if (c.node.menu) {
101             c.node.menu.hide();
102         }
103         for (var i =0; i < c.cn.length; i++) {
104             this.hideChildren(c.cn[i]);
105         }
106         
107     },
108     
109     
110     addTreeItem : function(parent, e, type , parent_e) {
111         
112         this.classes[e.name] = e; 
113         // add a node..
114         var node = parent.addxtypeChild(Roo.factory({
115             html: e.name.split('.').pop(),
116            // id : e.name,
117             xns : Roo.bootstrap,
118             showArrow: false,
119             xtype : type,
120             preventDefault : true,
121           //  cls : type == 'NavSidebarItem' ? 'open' : '',
122             listeners : {
123                 click : (function(mi,ev,c)
124                 {
125                     
126                     ev.stopPropagation();
127                      
128                     if (c.cn.length) {
129                         //Roo.log(ev);
130                         if (mi.menu.el.hasClass('show')) {
131                             this.hideChildren(c); //mi.menu.hide();
132                             // collapse children..
133                             
134                             
135                             
136                         } else {
137                             mi.menu.show(mi.menu.triggerEl,'?', false);
138                         }
139                         
140                     }
141                     location.hash = '#' + c.name;
142                     //Roo.docs.init.loadDoc(c);
143                     
144                 }).createDelegate(this,[e], true)
145                 
146             },
147             fa :  e.cn.length  ? 'chevron-right' : '',
148             menu : !e.cn.length ? false  : Roo.factory({
149                 type : 'treeview',
150                 xns: Roo.bootstrap,
151                 xtype : 'Menu',
152                 listeners : {
153                     beforehide : (function(mi,c)
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 : 'symbols/' + cls.name + '.json',
269             method : 'GET',
270             success : function(res, o)
271             {
272                 var d = Roo.decode(res.responseText);
273                 this.fillDoc(d);
274                 
275             },
276             scope : this
277         });
278         
279         
280     },
281     
282     fillDoc : function(d)
283     {
284         /*{
285             "name" : "Roo.bootstrap.Progress",
286             "augments" : [
287               "Roo.bootstrap.Component",
288               "Roo.Component",
289               "Roo.util.Observable"
290             ],
291             "desc" : "Bootstrap Progress class",
292             "config" : [
293               {
294         */
295         document.body.scrollTop  = 0;
296         Roo.docs.doc_name.el.dom.innerHTML = Roo.docs.template.resolveLinks(d.name);
297         Roo.docs.doc_desc.el.dom.innerHTML = Roo.docs.template.summary(d);
298         Roo.docs.doc_extends.hide();
299         Roo.docs.doc_extends_sep.hide();
300         if (d.augments.length) {
301             Roo.docs.doc_extends.show();
302             Roo.docs.doc_extends_sep.show();
303             Roo.docs.doc_extends.el.dom.innerHTML = d.augments[0];
304         }
305         Roo.docs.doc_source.el.dom.innerHTML = d.name.replace(/\./g,"/") + ".js";
306         
307         if (d.augments.length) {
308             Roo.docs.augments.show();
309             Roo.docs.augments.bodyEl().dom.innerHTML = Roo.docs.template.augments(d);
310         } else {
311             Roo.docs.augments.hide();
312         }
313         
314         
315         
316         Roo.docs.configTableContainer.hide();
317         Roo.docs.methodsTableContainer.hide();
318         Roo.docs.eventsTableContainer.hide();
319         if (d.config.length) {
320             Roo.docs.configTableContainer.show();
321             Roo.docs.configTable.store.load( { params : { data : d.config.sort(Roo.docs.template.makeSortby("name")) }});
322         } 
323         
324         if (d.methods.length) {
325             Roo.docs.methodsTable.store.load( { params : { data : Roo.docs.template.methodsSort(d) }});
326             Roo.docs.methodsTableContainer.show();
327         }
328         if (d.events.length) {
329             Roo.docs.eventsTable.store.load( { params : { data : d.events.sort(Roo.docs.template.makeSortby("name")) }});
330             Roo.docs.eventsTableContainer.show();
331         }
332         
333         
334     },
335     onClick : function(e)
336     {
337         if (e.target.nodeName != 'A') {
338             return;
339         }
340         if (!e.target.href.match(/#/)) {
341             return;
342         }
343         e.stopPropagation();
344         var link = e.target.href.split('#')[1];
345         this.loadClass(link);
346         
347     },
348     
349     onHashChange : function()
350     {
351         if (this.hash == location.hash) {
352             return;
353         }
354         this.loadHash();
355         
356     },
357     loadHash : function()
358     {
359         if (location.hash.length < 2) {
360             this.loadDoc(false);
361         }
362         this.loadClass(location.hash.substring(1));
363         this.hash = location.hash;
364     },
365     
366       
367     loadIntro : function()
368     {
369       
370         
371         Roo.Ajax.request({
372             url : 'summary.txt',
373             method : 'GET',
374             success : function(res)
375             {
376                 this.renderIntro(res.responseText);
377                
378                 
379             },
380             scope : this
381         });
382         
383         
384     },
385     // render the really simple markdown data
386     renderIntro : function(intro)
387     {
388         
389         Roo.docs.doc_body_content.hide();
390
391         
392         var lines = intro.split("\n");
393         var tree = { 'name' : 'root', cn : []};
394         var state = [ tree ];
395         for (var i=0;i< lines.length;i++) {
396             var line = lines[i];
397             if (!line.length || line.match(/^\s+$/)) {
398                 continue;
399             }
400             var sm = line.match(/^(\s+)(.*)/);
401             
402             var sml = sm ? sm[1].length: 0;
403             //Roo.log(sml);
404             sml = sml / 4; // 4 spaces indent?
405             var add = { name : sm ?  sm[2] : line, cn : [] };
406             state[sml].cn.push(add);
407             state[sml+1] = add;
408             
409         }
410         //Roo.log(tree);
411         
412         for(var i = 0; i < tree.cn.length; i++) {
413             // make a container..
414             var treei = tree.cn[i];
415             var ctree = {
416                 
417                 xtype : 'Column',
418                 xns : Roo.bootstrap,
419                 md:4,
420                 sm : 6,
421                 items : [ {
422                     header : treei.name,
423                     xtype : 'Container',
424                     panel : 'info',
425                     xns : Roo.bootstrap,
426                     items : []
427                 }]
428             };
429             for(var ii = 0; ii < treei.cn.length; ii++) {
430                 var treeii = treei.cn[ii];
431                 // another container..
432                var ctreei = {
433                     header : treeii.name,
434                     xtype : 'Container',
435                     panel : 'primary',
436                     xns : Roo.bootstrap,
437                   
438                     items : [
439                          {
440                             xtype : 'Element',
441                             tag :'ul',
442                            
443                             xns : Roo.bootstrap,
444                             items : []
445                          }
446                     ]
447                 };
448                 ctree.items[0].items.push(ctreei);
449                 var footer = '';
450                 for(var iii = 0; iii < treeii.cn.length; iii++) {
451                     var treeiii = treeii.cn[iii];
452                     var ll = treeiii.name.match(/^(\S+)\s*(.*)$/);
453                     //Roo.log(treeiii.name);
454                     if (treeiii.name == 'Examples') {
455                         for (var j =0;j< treeiii.cn.length; j++) {
456                             var exs = treeiii.cn[j].name.match(/^\[([^\]]+)\](.*)$/);
457                             footer += '<li><a target="_blank" href="../' + exs[1] + '">'+exs[2] + '</a></li>';
458                         }
459                         continue;
460                         
461                         
462                     }
463         
464         
465
466                     ctreeii = {
467                             xtype : 'Element',
468                             tag :'li',
469                             xns : Roo.bootstrap,
470                             items : [
471                                 {
472                                    xtype : 'Link',
473                                     href : '#' + ( ll ? ll[1] : treeiii.name ) ,
474                                     html : ll ? ll[1] : treeiii.name,
475                                     
476                                     xns : Roo.bootstrap 
477                                 },
478                                 {
479                                    xtype : 'Element',
480                                     tag : 'span',
481                                     html : ll && ll[2].length ? ' - ' + ll[2] : '',
482                                     xns : Roo.bootstrap 
483                                 }
484                             ]
485                             
486                             
487                             
488                     };
489                     ctreei.items.push(ctreeii);
490                     
491                 }
492                 if (footer.length) {
493                     //Roo.log("footer:"+  footer);
494                     ctreei.footer = '<h5>Examples:</h5><ul>'+footer +'</ul>';
495                 }
496         
497             }
498             
499             
500             
501             
502             
503             Roo.docs.introBody.addxtypeChild(ctree);
504         }
505         
506         
507         
508     }
509     
510     
511     
512 };
513
514
515 Roo.onReady(Roo.docs.init.onReady, Roo.docs.init);
516     
517