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