sync
[roojs1] / docs.old / page.js
1 //<script type="text/javascript">
2 /* -- IE kludge as usual! */
3 if (!Array.prototype.indexOf)
4 {
5   Array.prototype.indexOf = function(elt /*, from*/)
6   {
7     var len = this.length;
8
9     var from = Number(arguments[1]) || 0;
10     from = (from < 0)
11          ? Math.ceil(from)
12          : Math.floor(from);
13     if (from < 0)
14       from += len;
15
16     for (; from < len; from++)
17     {
18       if (from in this &&
19           this[from] === elt)
20         return from;
21     }
22     return -1;
23   };
24 }
25
26
27
28 RooDocsPage = {
29     
30     isIE: function() {
31         var ua = navigator.userAgent.toLowerCase();
32         return ua.indexOf("msie") > -1;
33         
34     },
35     
36     
37     onload : function()
38     {
39         //console.log("loading");
40         
41         this.addEvent(document,'click', function(e) {
42             var ev = e || window.event;
43             var t = ev.target || ev.srcElement;
44             //console.log(t);
45             return RooDocsPage.clicked(t);
46             
47         });
48         
49         
50         
51     },
52     addEvent: function(el, eventName, fn)
53     {
54         
55         if (window.addEventListener) {
56             capture = false;
57             el.addEventListener(eventName, fn, (capture));
58             return;
59         } 
60         if (window.attachEvent) {
61             el.attachEvent("on" + eventName, fn);
62             return;
63          
64         }
65     },
66     clicked : function(t)
67     {
68         
69         
70         var classAr = t.className.split(' ');
71         //console.log(classAr)
72         if ((t.nodeName == 'a') && (classAr.indexOf('exi') < 0) && (classAr.indexOf('micon') < 0)) {
73             // link clicked...
74             return false;
75             /*
76             var cls  = this.getAttributeNS(t,'roo', 'cls');
77             if (cls) {
78                 
79                 var member = this.getAttributeNS(t,'roo', 'member');
80                 //this.loadClass(target.href, cls, member);
81                 
82                 if (/^src\//.test(cls)) {
83                     cls = cls.replace(/.js$/, ''); // get rid of .js for source links..
84                 }
85                 
86                 
87                 document.location = "symbols/"+ cls +".html";
88                 return;
89             }
90             */
91         }
92             
93            
94         
95         
96         if (classAr.indexOf('exi') > -1 || classAr.indexOf('micon') > -1) {
97             
98             var tr = t;
99             //console.log(tr.parentNode);
100             while (tr.parentNode) {
101                 ///console.log(tr.nodeName);
102                 if (tr.nodeName.toUpperCase() =='TR') {
103                     break;
104                 }
105                 tr = tr.parentNode;
106             }
107             if (tr.nodeName.toUpperCase() != 'TR') { // no tr!
108                 return false;
109             }
110             //console.log(tr.className)
111             if (tr.className.match(/expandable/)) {
112                 
113                 if (!/expanded/.test(tr.className)) {
114                     
115                     tr.className += " expanded";
116                     
117                     this.loadComments(tr);
118                     
119                   //  console.log("ADDED:"+ tr.className);
120                 } else {
121                     tr.className = tr.className.replace(/ expanded/,'');
122                     //console.log("REMOVED:"+ tr.className);
123                 }
124             }
125             return true;
126             
127             
128             
129         }
130         return false;
131     },
132     
133     getAttributeNS : function(d,ns,name) {
134         if (this.isIE()) {
135             // ie uses attribute stuff...
136             var type = typeof d[ns+":"+name];
137             if(type != 'undefined' && type != 'unknown'){
138                 return d[ns+":"+name];
139             }
140             return d[name];
141             
142         } 
143         return d.getAttributeNS(ns, name) || d.getAttribute(ns+":"+name) || d.getAttribute(name) || d[name];
144     },
145     loadComments: function(tr)
146     {
147         // first look for  'a' tag with id -
148         var a_s = tr.getElementsByTagName('a');
149         
150         if (a_s.length < 2) return; 
151         var id = a_s[1].getAttribute('id');
152         
153         
154         
155         // then see if we have a comment-{id}
156         
157         if (document.getElementById('comments-' + id)) {
158             // we already have it... assume it's loaded and does not need refeshing...
159             return;
160         }
161         
162         // then if not create it....
163         var div_s = tr.getElementsByTagName('div');
164         var pdiv = false;
165         for (var i=0;i<div_s.length;i++) {
166             
167             if (div_s[i].className != "long") {
168                 continue
169             }
170             pdiv = div_s[i].parentNode; // parent of the <div class="long"
171             
172         }
173         if (!pdiv) { // we dont have a parent to add it to...
174             return; 
175         }
176         
177         var cdiv = document.createElement("div");
178         cdiv.className = "comments";
179         var cb = document.createElement("b");
180         cb.appendChild(document.createTextNode("Element Comment / Notes"));
181         cdiv.appendChild(cb);
182         cdiv.appendChild(document.createTextNode(" => "));
183         var cu = document.createElement("u");
184         cu.appendChild(document.createTextNode("[Add Your comment/notes about this element]"));
185         
186         cu.setAttribute("onclick", "parent.CommentDialog.showCommentId = '" +   id  + "';");
187         cdiv.appendChild(cu);
188         cdiv.appendChild(document.createElement("br"));
189         var ciframe = document.createElement("iframe");
190         ciframe.setAttribute('height', '50');
191         ciframe.setAttribute('frameborder', '50');
192         ciframe.setAttribute('src', '/blog.php/GtkDjsComments/' + id + '.html');
193         ciframe.setAttribute('style', 'border: medium none ; width: 100%;');
194         ciframe.setAttribute('id', 'comments-' + id);
195         cdiv.appendChild(ciframe);
196         pdiv.appendChild(cdiv);
197         
198     }
199     
200     
201 }
202
203
204  /*
205 this.preview.getEl().on('click', function(e, target)
206         {
207             //console.log("click pressed?");
208             
209             if(target = e.getTarget('a:not(.exi)', 3)) {
210                 var cls = Ext.fly(target).getAttributeNS('roo', 'cls');
211                 e.stopEvent();
212                 if(cls){
213                     var member = Ext.fly(target).getAttributeNS('roo', 'member');
214                     //this.loadClass(target.href, cls, member);
215                     
216                     if (/^src\//.test(cls)) {
217                         cls = cls.replace(/.js$/, ''); // get rid of .js for source links..
218                     }
219                     
220                     
221                     MainBody.loadPage("symbols/"+ cls +".html");
222                     return;
223                 }
224                 if(target.className == 'inner-link'){ // go to #
225                     this.getActiveTab().scrollToSection(target.href.split('#')[1]);
226                     return;
227                 }
228                 window.open(target.href);
229                 
230                 return; // no more...
231             }
232             if(target = e.getTarget('.micon', 2)){
233                 
234                 e.stopEvent();
235                 var tr = Ext.fly(target.parentNode);
236                 if(tr.hasClass('expandable')){
237                     tr.toggleClass('expanded');
238                 }
239             }
240           
241         });
242 */