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