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