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