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