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