| 8 | | * by Emmanuel Blot <emmanuel.blot@free.fr> 2006-2007 |
|---|
| | 8 | * by Emmanuel Blot <emmanuel.blot@free.fr> 2006-2008 |
|---|
| | 9 | * |
|---|
| | 10 | * You might wonder why the hell regular Javascript functions are mixed with |
|---|
| | 11 | * jQuery ones... The trouble is that JQuery exhibits many difficulties with |
|---|
| | 12 | * XML documents for now (jQuery 1.2.3) and is sometimes unable to cope with |
|---|
| | 13 | * XML+SVG document. The funny part is that code that works on some browsers |
|---|
| | 14 | * (Presto, Webkit for ex.) does not work with the lastest releases of Gecko, |
|---|
| | 15 | * and vice-versa. |
|---|
| | 21 | |
|---|
| | 22 | window.JT_get_svganchors = function() { |
|---|
| | 23 | if ( (jQuery.browser.mozilla && |
|---|
| | 24 | (parseFloat(jQuery.browser.version) < 1.9)) || |
|---|
| | 25 | (jQuery.browser.safari && |
|---|
| | 26 | (parseFloat(jQuery.browser.version) < 523)) ) { |
|---|
| | 27 | // Firefox 1.x, 2.x, OmniWeb 5.x |
|---|
| | 28 | var vanchors = []; |
|---|
| | 29 | jQuery.each($('a[@id^=rev]'), function(index, value) { |
|---|
| | 30 | vanchors.push(value); |
|---|
| | 31 | }); |
|---|
| | 32 | return vanchors; |
|---|
| | 33 | } |
|---|
| | 34 | else { |
|---|
| | 35 | // Firefox 3.x, Opera, Safari, ... |
|---|
| | 36 | var anchors; |
|---|
| | 37 | anchors = document.getElementsByTagNameNS('http://www.w3.org/2000/svg', |
|---|
| | 38 | 'a'); |
|---|
| | 39 | var vanchors = []; |
|---|
| | 40 | for(var i in anchors) { |
|---|
| | 41 | if ( anchors[i].id && anchors[i].id.substring(0, 3) == 'rev' ) { |
|---|
| | 42 | vanchors.push(anchors[i]); |
|---|
| | 43 | } |
|---|
| | 44 | } |
|---|
| | 45 | return vanchors; |
|---|
| | 46 | } |
|---|
| | 47 | } |
|---|
| 16 | | $('a[@id^=rev]').hover(function(){JT_show(this)}, |
|---|
| 17 | | function(){jttimer=setTimeout("JT_remove();", 250);}); |
|---|
| | 50 | var anchors = JT_get_svganchors(); |
|---|
| | 51 | for (var n = 0; n < anchors.length; n++){ |
|---|
| | 52 | jQuery(anchors[n]).hover( |
|---|
| | 53 | function(){JT_show(this)}, |
|---|
| | 54 | function(){jttimer=setTimeout("JT_remove();", 250);} |
|---|
| | 55 | ); |
|---|
| | 56 | } |
|---|
| 130 | | // The following loop could be simplified to use JQuery |
|---|
| 131 | | // JQuery has some trouble with XML documents for now |
|---|
| 132 | | var svg = document.getElementsByTagName('svg')[0]; |
|---|
| 133 | | var anodes = svg.getElementsByTagName('a'); |
|---|
| 134 | | var object; |
|---|
| 135 | | for ( var e = 0; e < anodes.length; e++ ) { |
|---|
| 136 | | if ( anodes[e].getAttribute('id') == objectId ) { |
|---|
| 137 | | object = anodes[e]; |
|---|
| 138 | | break; |
|---|
| 139 | | } |
|---|
| 140 | | } |
|---|
| 141 | | var cnodes = object.childNodes |
|---|
| 142 | | var elem; |
|---|
| 143 | | for ( var n = 0; n < cnodes.length; n++ ) { |
|---|
| 144 | | if ( cnodes[n].tagName == "svg:g" ) { |
|---|
| 145 | | elem = cnodes[n] |
|---|
| 146 | | break; |
|---|
| 147 | | } |
|---|
| 148 | | } |
|---|
| | 169 | var svg = document.getElementById('svgbox'); |
|---|
| | 170 | var anodes = JT_get_svganchors(); |
|---|
| | 171 | var object; |
|---|
| | 172 | for ( var e = 0; e < anodes.length; e++ ) { |
|---|
| | 173 | if ( anodes[e].getAttribute('id') == objectId ) { |
|---|
| | 174 | object = anodes[e]; |
|---|
| | 175 | break; |
|---|
| | 176 | } |
|---|
| | 177 | } |
|---|
| | 178 | var cnodes = object.childNodes |
|---|
| | 179 | var elem; |
|---|
| | 180 | for ( var n = 0; n < cnodes.length; n++ ) { |
|---|
| | 181 | if ( cnodes[n].tagName == "svg:g" ) { |
|---|
| | 182 | elem = cnodes[n] |
|---|
| | 183 | break; |
|---|
| | 184 | } |
|---|
| | 185 | } |
|---|
| 150 | | var r = Object(); |
|---|
| 151 | | var mx = svg.getScreenCTM(); |
|---|
| 152 | | var box = elem.getBBox(); |
|---|
| 153 | | var svgpos = findPos(svg); |
|---|
| 154 | | |
|---|
| 155 | | // Not sure who's right or wrong here: Opera, Gecko ? |
|---|
| 156 | | // Anyway the following hack seems to work. Javascript, oh my... |
|---|
| 157 | | if ( jQuery.browser.opera || jQuery.browser.safari ) { |
|---|
| 158 | | r.x = Math.floor(box.x*mx.a)+svgpos[0]; |
|---|
| 159 | | r.y = Math.floor(box.y*mx.d)+svgpos[1]; |
|---|
| 160 | | r.w = Math.floor(box.width*mx.a); |
|---|
| 161 | | r.h = Math.floor(box.height*mx.d); |
|---|
| 162 | | return r; |
|---|
| 163 | | } |
|---|
| 164 | | else { |
|---|
| 165 | | var p1 = svg.createSVGPoint(); |
|---|
| 166 | | var p2 = svg.createSVGPoint(); |
|---|
| 167 | | p1.x = box.x; |
|---|
| 168 | | p1.y = box.y; |
|---|
| 169 | | p2.x = p1.x + box.width; |
|---|
| 170 | | p2.y = p1.y + box.height; |
|---|
| 171 | | p1 = p1.matrixTransform(mx); |
|---|
| 172 | | p2 = p2.matrixTransform(mx); |
|---|
| 173 | | r.x = Math.floor(p1.x)+posLeft(); |
|---|
| 174 | | r.y = Math.floor(p1.y)+posTop(); |
|---|
| 175 | | r.w = Math.floor(p2.x-p1.x); |
|---|
| 176 | | r.h = Math.floor(p2.y-p1.y); |
|---|
| 177 | | return r; |
|---|
| 178 | | } |
|---|
| | 187 | var r = Object(); |
|---|
| | 188 | var mx = svg.getScreenCTM(); |
|---|
| | 189 | var box = elem.getBBox(); |
|---|
| | 190 | var svgpos = findPos(svg); |
|---|
| | 191 | |
|---|
| | 192 | // Not sure who's right or wrong here: Gecko, Webkit, Presto, ...? |
|---|
| | 193 | // Anyway the following hack seems to work. Javascript, oh my... |
|---|
| | 194 | if ( jQuery.browser.opera || jQuery.browser.safari ) { |
|---|
| | 195 | r.x = Math.floor(box.x*mx.a)+svgpos[0]; |
|---|
| | 196 | r.y = Math.floor(box.y*mx.d)+svgpos[1]; |
|---|
| | 197 | r.w = Math.floor(box.width*mx.a); |
|---|
| | 198 | r.h = Math.floor(box.height*mx.d); |
|---|
| | 199 | return r; |
|---|
| | 200 | } |
|---|
| | 201 | else { |
|---|
| | 202 | var p1 = svg.createSVGPoint(); |
|---|
| | 203 | var p2 = svg.createSVGPoint(); |
|---|
| | 204 | p1.x = box.x; |
|---|
| | 205 | p1.y = box.y; |
|---|
| | 206 | p2.x = p1.x + box.width; |
|---|
| | 207 | p2.y = p1.y + box.height; |
|---|
| | 208 | p1 = p1.matrixTransform(mx); |
|---|
| | 209 | p2 = p2.matrixTransform(mx); |
|---|
| | 210 | r.x = Math.floor(p1.x)+posLeft(); |
|---|
| | 211 | r.y = Math.floor(p1.y)+posTop(); |
|---|
| | 212 | r.w = Math.floor(p2.x-p1.x); |
|---|
| | 213 | r.h = Math.floor(p2.y-p1.y); |
|---|
| | 214 | return r; |
|---|
| | 215 | } |
|---|
| 195 | | return typeof window.pageXOffset != 'undefined' ? |
|---|
| 196 | | window.pageXOffset : |
|---|
| 197 | | document.documentElement && |
|---|
| 198 | | document.documentElement.scrollLeft ? |
|---|
| 199 | | document.documentElement.scrollLeft : |
|---|
| 200 | | document.body.scrollLeft ? document.body.scrollLeft : 0; |
|---|
| | 232 | return typeof window.pageXOffset != 'undefined' ? |
|---|
| | 233 | window.pageXOffset : |
|---|
| | 234 | document.documentElement && |
|---|
| | 235 | document.documentElement.scrollLeft ? |
|---|
| | 236 | document.documentElement.scrollLeft : |
|---|
| | 237 | document.body.scrollLeft ? document.body.scrollLeft : 0; |
|---|
| 204 | | return typeof window.pageYOffset != 'undefined' ? |
|---|
| 205 | | window.pageYOffset : |
|---|
| 206 | | document.documentElement && |
|---|
| 207 | | document.documentElement.scrollTop ? |
|---|
| 208 | | document.documentElement.scrollTop : |
|---|
| 209 | | document.body.scrollTop ? document.body.scrollTop : 0; |
|---|
| | 241 | return typeof window.pageYOffset != 'undefined' ? |
|---|
| | 242 | window.pageYOffset : |
|---|
| | 243 | document.documentElement && |
|---|
| | 244 | document.documentElement.scrollTop ? |
|---|
| | 245 | document.documentElement.scrollTop : |
|---|
| | 246 | document.body.scrollTop ? document.body.scrollTop : 0; |
|---|