8e6ebf785389c1413df0bf71074719aa8f711e2d
[gnome.introspection-doc-generator] / docs / resources / 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 RooDocsPage = {
28     
29     isIE: function() {
30         var ua = navigator.userAgent.toLowerCase();
31         return ua.indexOf("msie") > -1;
32         
33     },
34     
35     
36     onload : function()
37     {
38         //console.log("loading");
39         
40         this.addEvent(document,'click', function(e) {
41             var ev = e || window.event;
42             var t = ev.target || ev.srcElement;
43             //console.log(t);
44             return RooDocsPage.clicked(t);
45             
46         });
47         
48         
49         
50     },
51     addEvent: function(el, eventName, fn)
52     {
53         
54         if (window.addEventListener) {
55             capture = false;
56             el.addEventListener(eventName, fn, (capture));
57             return;
58         } 
59         if (window.attachEvent) {
60             el.attachEvent("on" + eventName, fn);
61             return;
62          
63         }
64     },
65     clicked : function(t)
66     {
67         
68         
69         var classAr = t.className.split(' ');
70         //console.log(classAr)
71         if ((t.nodeName == 'a') && (classAr.indexOf('exi') < 0) && (classAr.indexOf('micon') < 0)) {
72             // link clicked...
73             return false;
74            
75         }
76             
77            
78         
79         
80         if (classAr.indexOf('exi') > -1 || classAr.indexOf('micon') > -1) {
81             
82             var tr = t;
83             //console.log(tr.parentNode);
84             while (tr.parentNode) {
85                 ///console.log(tr.nodeName);
86                 if (tr.nodeName.toUpperCase() =='TR') {
87                     break;
88                 }
89                 tr = tr.parentNode;
90             }
91             if (tr.nodeName.toUpperCase() != 'TR') { // no tr!
92                 return false;
93             }
94             //console.log(tr.className)
95             if (tr.className.match(/expandable/)) {
96                 
97                 if (!/expanded/.test(tr.className)) {
98                     
99                     tr.className += " expanded";
100                     
101                     //this.loadComments(tr);
102                     
103                   //  console.log("ADDED:"+ tr.className);
104                 } else {
105                     tr.className = tr.className.replace(/ expanded/,'');
106                     //console.log("REMOVED:"+ tr.className);
107                 }
108             }
109             return true;
110             
111             
112             
113         }
114         return false;
115     },
116     
117     getAttributeNS : function(d,ns,name) {
118         if (this.isIE()) {
119             // ie uses attribute stuff...
120             var type = typeof d[ns+":"+name];
121             if(type != 'undefined' && type != 'unknown'){
122                 return d[ns+":"+name];
123             }
124             return d[name];
125             
126         } 
127         return d.getAttributeNS(ns, name) || d.getAttribute(ns+":"+name) || d.getAttribute(name) || d[name];
128     },
129     display : '',       
130  
131     toggle : function () {
132         this.display  = (this.display == 'none' ) ? '': 'none';
133         var display = this.display;
134         
135         Array.prototype.slice.call(
136            document.getElementsByTagName('tr')
137         ).forEach(function(tr) {
138            tr.style.display = ''; 
139            if (tr.className.match(/notInherited/)) return;
140            if (!tr.className.match(/expandable/)) return;
141            tr.style.display = display; 
142         });
143     }
144 }
145
146  /*
147 this.preview.getEl().on('click', function(e, target)
148         {
149             //console.log("click pressed?");
150             
151             if(target = e.getTarget('a:not(.exi)', 3)) {
152                 var cls = Ext.fly(target).getAttributeNS('roo', 'cls');
153                 e.stopEvent();
154                 if(cls){
155                     var member = Ext.fly(target).getAttributeNS('roo', 'member');
156                     //this.loadClass(target.href, cls, member);
157                     
158                     if (/^src\//.test(cls)) {
159                         cls = cls.replace(/.js$/, ''); // get rid of .js for source links..
160                     }
161                     
162                     
163                     MainBody.loadPage("symbols/"+ cls +".html");
164                     return;
165                 }
166                 if(target.className == 'inner-link'){ // go to #
167                     this.getActiveTab().scrollToSection(target.href.split('#')[1]);
168                     return;
169                 }
170                 window.open(target.href);
171                 
172                 return; // no more...
173             }
174             if(target = e.getTarget('.micon', 2)){
175                 
176                 e.stopEvent();
177                 var tr = Ext.fly(target.parentNode);
178                 if(tr.hasClass('expandable')){
179                     tr.toggleClass('expanded');
180                 }
181             }
182           
183         });
184 */