initial import
[roojs1] / buildSDK / doc_templates / static / doc.js
1 //<script type="text/javascript">
2
3
4 Roo.onReady(function(){
5
6     Roo.QuickTips.init();
7       MainBody.init();
8    
9     
10     
11 });
12 MainBody = {
13     layout: false,
14     cookie: false,
15     init: function() 
16     {
17         
18         this.cookie = new Roo.state.CookieProvider({})
19         
20         MainBody.layout = new Roo.BorderLayout(document.body, {
21             north: {
22                 split:true,
23                 initialSize: 30,
24                 titlebar: false,
25                 collapsible: false
26                 
27             },
28             west: {
29                 split:true,
30                 initialSize: 200,
31                 titlebar: true,
32                 collapsible: true
33                 
34             },
35             center: {
36                 autoScroll: false,
37                 titlebar: true,
38                 resizeTabs:true,
39                 minTabWidth: 100,
40                 preferredTabWidth:250
41             }
42         });
43         var layout = MainBody.layout;
44         MainBody.layout.beginUpdate();
45         var hd = this.layout.getEl().createChild( {
46                 tag:'div' , 
47                 style: 'background-colour:#000; font-weight: bold;' + 
48                     'font-size:16px;'  +
49                     'font-family:Arial,Verdana,\'Bitstream Vera Sans\',Helvetica,sans-serif;', 
50                 html: '<img src="../images/roojs_logo.jpg" height="25" align="right"/>' + 
51                     '<div style="margin-left:10px;margin-top:3px;">Roo Version 1.1.1 - Documentation</div>'
52         });
53         layout.add('north', new Roo.ContentPanel(hd, {fitToFrame:true, closable:false }));
54          
55         //innerLayout.add('south', new Roo.ContentPanel('inner1', "More Information"));
56         //innerLayout.add('center', new Roo.ContentPanel('inner2')); // right bottom Tree
57         
58          
59         //alert("initing");
60        
61         ClassTree.init();
62         
63         //var frame = this.layout.getEl().createChild({ tag:'div' , frameborder: "no"});
64         var frame = this.layout.getEl().createChild({ tag:'iframe' , id:'viewFrame', name:'viewFrame',frameborder: "no"});
65                    
66                    
67      
68         
69         this.preview = new Roo.ContentPanel(frame, {title: 
70             '&nbsp;<a target="viewFrame" href="/roojs1/buildSDK/indexPage.html">Contents / Examples</a>' + 
71             ' | Class Details',
72             fitToFrame:true,
73             autoScroll: true
74         });
75         
76         //// ---- HANLE CLICKS ON OUR CHILD PAGE???
77         /*
78         this.preview.getEl().on('click', function(e, target)
79         {
80             //console.log("click pressed?");
81             
82             if(target = e.getTarget('a:not(.exi)', 3)) {
83                 var cls = Roo.fly(target).getAttributeNS('roo', 'cls');
84                 e.stopEvent();
85                 if(cls){
86                     var member = Roo.fly(target).getAttributeNS('roo', 'member');
87                     //this.loadClass(target.href, cls, member);
88                     
89                     if (/^src\//.test(cls)) {
90                         cls = cls.replace(/.js$/, ''); // get rid of .js for source links..
91                     }
92                     
93                     
94                     MainBody.loadPage("symbols/"+ cls +".html");
95                     return;
96                 }
97                 if(target.className == 'inner-link'){ // go to #
98                     this.getActiveTab().scrollToSection(target.href.split('#')[1]);
99                     return;
100                 }
101                 window.open(target.href);
102                 
103                 return; // no more...
104             }
105             if(target = e.getTarget('.micon', 2)){
106                 
107                 e.stopEvent();
108                 var tr = Roo.fly(target.parentNode);
109                 if(tr.hasClass('expandable')){
110                     tr.toggleClass('expanded');
111                 }
112             }
113           
114         });
115         */
116          
117         window.setInterval(function() {
118             // check 
119             //console.log("check");
120                 if (CommentDialog.showCommentId.length) {
121                     var id  = '' + CommentDialog.showCommentId;
122                     if (Roo.isSafari) {
123                         Roo.get(document.getElementsByTagName('iframe')[0]).setVisible(false);
124                     }
125                    // alert(id);
126                     CommentDialog.showCommentId= '';
127                     
128                     
129                     
130                     CommentDialog.show(id);
131                 }
132             }, 500); // check every half second..
133         
134         
135         
136         
137         var cp = this.layout.add('center',   this.preview);
138         MainBody.loadPage("/roojs1/buildSDK/indexPage.html");
139         
140         
141         MainBody.layout.endUpdate();
142       
143         CommentDialog.build();
144         
145         Roo.get(document.getElementsByTagName('iframe')[0]).setVisibilityMode(Roo.Element.DISPLAY);
146         
147     },
148     
149     
150     loadPage: function(src) {
151         this.preview.el.dom.src = src;
152
153         //this.preview.load(src);
154     } 
155     
156     
157 }
158
159
160 ClassTree = {
161     tree: false,
162     
163     init : function () 
164     {
165         if (this.tree) {
166             return;
167            }
168         
169         var ct = MainBody.layout.getEl().createChild({tag:'div'});
170         var viewEl = ct.createChild({tag:'div'});
171         var folders = MainBody.layout.add('west', 
172             new Roo.ContentPanel(ct, {
173                 title:'Tree', 
174                 fitToFrame:true,
175                 autoScroll:true,
176                 autoCreate:true,
177                // toolbar: tb,
178                 resizeEl:viewEl
179             }));
180         this.tree = new Roo.tree.TreePanel(viewEl, {
181             animate:true, 
182             enableDD:false,
183             containerScroll: true,
184             ddGroup: 'organizerDD',
185             rootVisible:false,
186             listeners : {
187                 
188                 click : function(node, e) {
189                     // do stuff.
190                     // load: 
191                     //console.log(node.attributes.openUrl);
192                     if (!node.attributes.openUrl) {
193                         return;
194                     }
195                     MainBody.loadPage("symbols/"+ node.attributes.openUrl  +".html");
196                      
197                     //MainBody.layout.getRegion('center').getPanel(0).setTitle(ClassTree.getTitleHtml(file)); // methods
198                 }
199                 
200                 
201             }
202         });
203         new Roo.tree.TreeSorter(this.tree, {folderSort:true});
204         var root = new Roo.tree.TreeNode({
205             text: '', 
206             allowDrag:false,
207             allowDrop:false
208         });
209         this.tree.setRootNode(root);
210         // loop through 
211         function addNodes(parent, ar, pref) 
212         {
213             for(var nm in ar) {
214                 if (nm.substring(0,1) == "_") { // skip desc..
215                     continue;
216                 }
217                 //console.log("nm : " + nm + " = isNS:"+ar[nm]._isNS + " ? PN:" + nd.getDepth());
218                 var hasChildNodes = ar[nm]._hasChildren && (ar[nm]._isNS || (parent.getDepth() < 1));
219                     
220                 
221                 var nd = new Roo.tree.TreeNode( {
222                         text:pref +nm, 
223                         cls:  'album-node'  ,  
224                         allowDrag:false,
225                         leaf : !hasChildNodes,
226                         openUrl: ar[nm].hasOwnProperty('_full') ? ar[nm]._full : false,
227                         isNS : ar[nm]._isNS
228                 });
229                 
230                 // add a duplacate reference - if it's got children and 
231                 /*
232                 if (ar[nm]._hasChildren && (!ar[nm]._isNS) {
233                     //console.log("Adding node.." + nm);
234                     var xn = new Roo.tree.TreeNode( {
235                             text:    nm,
236                             cls:  'album-node'  ,  
237                             allowDrag:false,
238                             leaf : true,
239                             openUrl: ar[nm].hasOwnProperty('_full') ? ar[nm]._full : false
240                             
241                             
242                     });    
243                     parent.appendChild(xn);
244                 }
245                 */
246                 parent.appendChild(nd);
247                 
248                 //if (typeof(ar[nm]) == "object") {
249                 
250                 if (ar[nm]._hasChildren) {
251                     //console.log("nm : " + nm + " = isNS:"+ar[nm]._isNS + " ? PN:" + nd.getDepth());
252                     
253                     if (hasChildNodes) {
254                         // namespace -- make a tre..
255                         addNodes(nd, ar[nm],'');
256                         
257                         
258                         
259                     } else {
260                         addNodes(parent, ar[nm],  pref + nm + '.');
261                         
262                         
263                         
264                         
265                         
266                     }
267                     
268                 }
269             }
270              
271             
272         }
273         ClassTree.load();
274         // class tree comes from outside!!!
275         addNodes(root, ClassTree.nodes,'');
276         
277         this.tree.render();
278         
279         
280         root.eachChild(function(n) { n.expand(); });
281         //new Roo.tree.TreeSorter(this.tree);
282         ///this.tree.expand();
283           
284         },
285     nodes : { },
286     load: function(file)
287     {
288         
289         ClassTree.nodes = { _hasChildren: true, _isNameSpace: true };
290            
291         Roo.get('classlist').select('li').each( function(n) {
292             var dvs = n.select('div');
293             
294             var cn = {
295                 name : dvs.item(0).dom.innerHTML,
296                 desc : '', //dvs.item(1).dom.innerHTML
297                 isNS : dvs.item(0).getAttributeNS('roo','isns') == "yes"
298             }
299             //console.log("ADD: " + cn.name);
300             var nbits = cn.name.split(".");
301             
302             // top is where we stick everything in...
303             
304             var top=  ClassTree.nodes;
305             
306             for (var  i = 0; i < nbits.length; i++) {
307                 // is the last one..
308                 var nm = nbits[i];
309                 
310                 if (i == (nbits.length-1)) {
311                     if (top.hasOwnProperty(nm)) {
312                         top[nm]._full = cn.name;
313                         top[nm]._desc = cn.desc;
314                         break; // all done..
315                     }
316                     top._hasChildren =true;
317                     top[nm] = {
318                       ///  _parent : "Object", // not sure abou this bit!!!
319                         _full : cn.name,
320                         _desc : cn.name,
321                         _hasChildren : false ,
322                         _isNS : cn.isNS
323                     }
324                     break;
325                 }
326                 // not the top.
327                 if (top.hasOwnProperty(nm)) {
328                     top = top[nm];
329                     continue;
330                 }
331                 top[nm] = { _hasChildren : false };
332                 top = top[nm];
333             }
334             
335             
336             
337             
338         });
339        
340         //console.log(ClassTree.nodes);
341         
342         
343         
344         // load page into right hand panel....
345     }
346     /*
347     getTitleHtml : function (file)
348     {
349         var bits = file.split(".");
350         // what about 'Gtk/G etc.'
351         if (bits.length < 2) {
352             return file;
353         }
354         // should not really happen..
355         if (!(bits[0] in classtree)) {
356             return file;
357         }
358         if (!(bits[1] in classtree[bits[0]])) {
359             return file;
360         }
361         var parent = classtree[bits[0]][bits[1]]._parent;
362         if (bits.length == 3) {
363             if (!(bits[2] in classtree[bits[0]][bits[1]])) {
364                 return file;
365             }
366             parent = classtree[bits[0]][bits[1]][bits[2]]._parent;
367         }
368         
369         // add parent...
370         var ret = "<u onclick=\"ClassTree.load('"+file+"')\">" + file + "</u>&nbsp;&gt;&nbsp;";
371         return ret + ClassTree.getTitleHtml(parent);
372     }
373     */
374     
375     
376 }
377      
378      
379      
380      
381      
382      
383      
384
385 CommentDialog = {
386     
387     dialog : false,
388     form: false,
389     ids: false,
390     showCommentId: '', /// id of comment to show as scoping on konq/safari is borked
391     show: function (cls) {
392         this.build();
393         this.ids = cls;
394         this.form.reset();
395         this.form.setValues( {
396                 "comment[title]" : "General Comment",
397                 "comment[wikifile]" : cls
398                 });
399         this.form.setValues( MainBody.cookie.state );
400         
401         this.dialog.show();
402         if (this.form.getValues()["comment[author]"].length) {
403             CommentDialog.form.items.items[4].focus();
404         } else {
405             CommentDialog.form.items.items[0].focus();
406         }
407         
408     },
409     build: function ()
410     {
411         
412         if (this.dialog) {
413             return;
414         }
415   
416         this.dialog = new Roo.LayoutDialog(Roo.id(), { 
417                 autoCreate: true,
418                 modal:true,
419                 title: "Add Comment",
420                 //autoTabs:true,
421                 titlebar: true,
422                 
423                 modal:true,
424                 width:550,
425                 height:450,
426                 shadow:true,
427                  
428                 
429                 center:{
430                     autoScroll:false 
431                  
432                 } 
433                
434         });
435              
436         this.dialog.addKeyListener(27, this.hide, this);
437         this.dialog.addButton('Cancel', this.hide, this);
438         this.dialog.addButton('Submit', this.submit, this);
439     
440         var layout = this.dialog.getLayout();
441         var cd = this;
442         // create the dialog....
443         this.form = new Roo.form.Form({
444             labelWidth: 160,
445             
446             listeners : {
447                 actionfailed : function(f, act) {
448                     cd.dialog.el.unmask();    
449                     Roo.MessageBox.alert("Error", "Saving failed = fix errors and try again");
450                     // we dont do loads....
451                     
452                               
453                 },
454                 actioncomplete: function(f, act) {
455                      
456                     cd.dialog.el.unmask();    
457                     cd.hide();
458                     cd.form.reset();
459                     //hopefully this hsould work!
460                     var p = parent;
461                     while (p.parent != p) {
462                         p = p.parent;
463                     }
464                     console.log("trying : " + "comments-" + cd.ids);
465                     p.frames[0].document.getElementById("comments-" + cd.ids).contentDocument.location.reload();
466              
467                     // unmask?? 
468                 }
469             }
470             
471             
472              
473         });
474             // simple array store
475         var ctypes = new Roo.data.SimpleStore({
476             fields: ['value'],
477             data : [
478                 [ "General Comment" ],
479                 [ "Example Code" ],
480                 [ "Introduction" ],
481                 [ "Bug" ]
482             ]
483         });
484         
485        this.form.add( 
486              
487           
488                 new Roo.form.TextField({
489                     fieldLabel: 'Your Name',
490                     name: 'comment[author]',
491                     width: 300,
492                     allowBlank:false,
493                     autoCreate: {tag: "input", type: "text", size: "20", autocomplete: "on"} 
494                 }),
495                 new Roo.form.TextField({
496                     fieldLabel: 'Your Email address',
497                     name: 'comment[email]',
498                     width: 300,
499                     allowBlank:false,
500                     vtype: "email",
501                     autoCreate: {tag: "input", type: "text", size: "20", autocomplete: "on"} 
502                     
503                 }),
504                 new Roo.form.TextField({
505                     fieldLabel: 'Your Web site (optional)',
506                     name: 'comment[url]',
507                     width: 300,
508                     allowBlank:true,
509                     vtype: "url"
510                 }),
511                 new Roo.form.ComboBox({
512                     fieldLabel: 'Type of Comment',
513                     name: 'comment[title]',
514                     editable: false,
515                     forceSelection: true,
516                     store: ctypes,
517                     displayField:'value',
518                     typeAhead: false,
519                     mode: 'local',
520                     triggerAction: 'all',
521                     defaultValue: "General Comment",
522                     allowBlank:false,
523                     selectOnFocus:true
524                     
525                 }),
526                 new Roo.form.TextArea({
527                     fieldLabel: 'Comment',
528                     name: 'comment[body]',
529                     width:300,
530                     growMin:200,
531                     grow: true,
532                     allowBlank:false
533                 }),
534                 new Roo.form.Hidden({
535                     name: 'comment[wikifile]',
536                     value : ''
537                 }),
538                 new Roo.form.Hidden({
539                     name: 'jsonRequest',
540                     value : 'yes'
541                 })
542                 
543                 
544         );
545         
546         
547         var ef = layout.getEl().createChild({tag: 'div', style: 'margin: 5px'});
548         ef.dom.style.margin = 10;
549         ef.dom.style.position = "fixed";
550              
551             //console.log("form container");
552             //console.log(ef);
553             
554             
555         
556         var vp = layout.add('center', new Roo.ContentPanel(ef, {
557             autoCreate : true,
558             fitToFrame:true
559         }));
560         
561         this.form.render(ef.dom);
562        
563        
564         
565     
566     },
567     submit: function()
568     {
569         
570         
571         var cd = typeof(CommentDialog) == "undefined" ? parent.CommentDialog : CommentDialog;
572         if (!cd.form.isValid()) {
573             Roo.MessageBox.alert("Error", "Please Fill in all the details");
574             return;
575         }
576         var p = cd.form.getValues();
577         
578         var mb = typeof(MainBody) == "undefined" ? parent.MainBody : MainBody;
579         
580         mb.cookie.set("comment[author]", p["comment[author]"]);
581         mb.cookie.set("comment[email]", p["comment[email]"]);
582         mb.cookie.set("comment[url]", p["comment[url]"]);
583         cd.dialog.el.mask("Saving Data");    
584         
585         
586         cd.form.doAction('submit', {
587                 url: '/blog.php/GtkDjsComments/' + cd.ids + '.html',
588                 method: 'POST'
589         });
590         
591         
592          
593         
594     },
595     hide : function()
596     {
597         
598         if (Roo.isSafari) {
599             Roo.get(document.getElementsByTagName('iframe')[0]).setVisible(true);  
600         }
601         this.dialog.hide();
602     }
603         
604         
605        
606     
607 }
608
609      
610      
611      
612      
613