3da5727c87a38041b006ab2bbf4157e954681d06
[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', 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         Roo.docs.mobileNavGroup.hide()
240         Roo.docs.doc_body_content.hide();
241         this.currentClass = cls.name;
242         if (!cls ) {
243             Roo.docs.introBody.show();
244             return;
245         }
246         
247         // expand parents..
248         
249         var m = cls.parent_menu;
250         m.show(m.triggerEl,'?', false);
251         var mp = cls;
252         while ((mp = mp.parent)) {
253             m = mp.parent_menu;
254             m.show(m.triggerEl,'?', false);
255         }
256         cls.node.el.scrollIntoView(Roo.docs.sidebar.el,false);
257         Roo.docs.sidebar.el.select('.active').removeClass('active');
258         cls.node.el.addClass('active');
259         
260         Roo.docs.introBody.hide();
261         Roo.docs.doc_body_content.show();
262         Roo.Ajax.request({
263             url : 'symbols/' + cls.name + '.json',
264             method : 'GET',
265             success : function(res, o)
266             {
267                 var d = Roo.decode(res.responseText);
268                 this.fillDoc(d);
269                 
270             },
271             scope : this
272         });
273         
274         
275     },
276     
277     fillDoc : function(d)
278     {
279         /*{
280             "name" : "Roo.bootstrap.Progress",
281             "augments" : [
282               "Roo.bootstrap.Component",
283               "Roo.Component",
284               "Roo.util.Observable"
285             ],
286             "desc" : "Bootstrap Progress class",
287             "config" : [
288               {
289         */
290         document.body.scrollTop  = 0;
291         for (var k in d) {
292             if (typeof(Roo.docs['doc_' + k])  !=  'undefined') {
293                 Roo.docs['doc_' + k].el.dom.innerHTML = Roo.docs.template.resolveLinks(d[k]);;
294             }
295         }
296         Roo.docs.doc_extends.hide();
297         Roo.docs.doc_extends_sep.hide();
298         if (d.augments.length) {
299             Roo.docs.doc_extends.show();
300             Roo.docs.doc_extends_sep.show();
301             Roo.docs.doc_extends.el.dom.innerHTML = d.augments[0];
302         }
303         Roo.docs.doc_source.el.dom.innerHTML = d.name.replace(/\./g,"/") + ".js";
304         
305         if (d.augments.length) {
306             Roo.docs.augments.show();
307             Roo.docs.augments.bodyEl().dom.innerHTML = Roo.docs.template.augments(d);
308         } else {
309             Roo.docs.augments.hide();
310         }
311         
312         
313         
314         Roo.docs.configTableContainer.hide();
315         Roo.docs.methodsTableContainer.hide();
316         Roo.docs.eventsTableContainer.hide();
317         if (d.config.length) {
318             Roo.docs.configTableContainer.show();
319             Roo.docs.configTable.store.load( { params : { data : d.config.sort(Roo.docs.template.makeSortby("name")) }});
320         } 
321         
322         if (d.methods.length) {
323             Roo.docs.methodsTable.store.load( { params : { data : Roo.docs.template.methodsSort(d) }});
324             Roo.docs.methodsTableContainer.show();
325         }
326         if (d.events.length) {
327             Roo.docs.eventsTable.store.load( { params : { data : d.events.sort(Roo.docs.template.makeSortby("name")) }});
328             Roo.docs.eventsTableContainer.show();
329         }
330         
331         
332     },
333     onClick : function(e)
334     {
335         if (e.target.nodeName != 'A') {
336             return;
337         }
338         if (!e.target.href.match(/#/)) {
339             return;
340         }
341         e.stopPropagation();
342         var link = e.target.href.split('#')[1];
343         this.loadClass(link);
344         
345     },
346     
347     onHashChange : function()
348     {
349         if (this.hash == location.hash) {
350             return;
351         }
352         this.loadHash();
353         
354     },
355     loadHash : function()
356     {
357         if (location.hash.length < 2) {
358             this.loadDoc(false);
359         }
360         this.loadClass(location.hash.substring(1));
361         this.hash = location.hash;
362     },
363     
364       
365     loadIntro : function()
366     {
367       
368         
369         Roo.Ajax.request({
370             url : 'summary.txt',
371             method : 'GET',
372             success : function(res)
373             {
374                 this.renderIntro(res.responseText);
375                
376                 
377             },
378             scope : this
379         });
380         
381         
382     },
383     // render the really simple markdown data
384     renderIntro : function(intro)
385     {
386         
387         Roo.docs.doc_body_content.hide();
388
389         
390         var lines = intro.split("\n");
391         var tree = { 'name' : 'root', cn : []};
392         var state = [ tree ];
393         for (var i=0;i< lines.length;i++) {
394             var line = lines[i];
395             if (!line.length || line.match(/^\s+$/)) {
396                 continue;
397             }
398             var sm = line.match(/^(\s+)(.*)/);
399             
400             var sml = sm ? sm[1].length: 0;
401             //Roo.log(sml);
402             sml = sml / 4; // 4 spaces indent?
403             var add = { name : sm ?  sm[2] : line, cn : [] };
404             state[sml].cn.push(add);
405             state[sml+1] = add;
406             
407         }
408         //Roo.log(tree);
409         
410         for(var i = 0; i < tree.cn.length; i++) {
411             // make a container..
412             var treei = tree.cn[i];
413             var ctree = {
414                 
415                 xtype : 'Column',
416                 xns : Roo.bootstrap,
417                 md:4,
418                 sm : 6,
419                 items : [ {
420                     header : treei.name,
421                     xtype : 'Container',
422                     panel : 'info',
423                     xns : Roo.bootstrap,
424                     items : []
425                 }]
426             };
427             for(var ii = 0; ii < treei.cn.length; ii++) {
428                 var treeii = treei.cn[ii];
429                 // another container..
430                var ctreei = {
431                     header : treeii.name,
432                     xtype : 'Container',
433                     panel : 'primary',
434                     xns : Roo.bootstrap,
435                   
436                     items : [
437                          {
438                             xtype : 'Element',
439                             tag :'ul',
440                            
441                             xns : Roo.bootstrap,
442                             items : []
443                          }
444                     ]
445                 };
446                 ctree.items[0].items.push(ctreei);
447                 var footer = '';
448                 for(var iii = 0; iii < treeii.cn.length; iii++) {
449                     var treeiii = treeii.cn[iii];
450                     var ll = treeiii.name.match(/^(\S+)\s*(.*)$/);
451                     //Roo.log(treeiii.name);
452                     if (treeiii.name == 'Examples') {
453                         for (var j =0;j< treeiii.cn.length; j++) {
454                             var exs = treeiii.cn[j].name.match(/^\[([^\]]+)\](.*)$/);
455                             footer += '<li><a target="_blank" href="../' + exs[1] + '">'+exs[2] + '</a></li>';
456                         }
457                         continue;
458                         
459                         
460                     }
461         
462         
463
464                     ctreeii = {
465                             xtype : 'Element',
466                             tag :'li',
467                             xns : Roo.bootstrap,
468                             items : [
469                                 {
470                                    xtype : 'Link',
471                                     href : '#' + ( ll ? ll[1] : treeiii.name ) ,
472                                     html : ll ? ll[1] : treeiii.name,
473                                     
474                                     xns : Roo.bootstrap 
475                                 },
476                                 {
477                                    xtype : 'Element',
478                                     tag : 'span',
479                                     html : ll && ll[2].length ? ' - ' + ll[2] : '',
480                                     xns : Roo.bootstrap 
481                                 }
482                             ]
483                             
484                             
485                             
486                     };
487                     ctreei.items.push(ctreeii);
488                     
489                 }
490                 if (footer.length) {
491                     //Roo.log("footer:"+  footer);
492                     ctreei.footer = '<h5>Examples:</h5><ul>'+footer +'</ul>';
493                 }
494         
495             }
496             
497             
498             
499             
500             
501             Roo.docs.introBody.addxtypeChild(ctree);
502         }
503         
504         
505         
506     }
507     
508     
509     
510 };
511
512
513 Roo.onReady(Roo.docs.init.onReady, Roo.docs.init);
514     
515