Generate expanded URLs for printing on the client, not server (using CSS, or JS for...
[lhc/web/wiklou.git] / skins / common / IEFixes.js
1 // IE fixes javascript
2
3 var isMSIE55 = (window.showModalDialog && window.clipboardData && window.createPopup);
4 var doneIETransform;
5 var doneIEAlphaFix;
6
7 if (document.attachEvent)
8 document.attachEvent('onreadystatechange', hookit);
9
10 function hookit() {
11 if (!doneIETransform && document.getElementById && document.getElementById('bodyContent')) {
12 doneIETransform = true;
13 relativeforfloats();
14 fixalpha();
15 }
16 }
17
18 // png alpha transparency fixes
19 function fixalpha() {
20 // bg
21 if (!doneIEAlphaFix)
22 {
23 doneIEAlphaFix = true;
24 var plogo = document.getElementById('p-logo');
25 var logoa = plogo.getElementsByTagName('a')[0];
26 var bg = logoa.currentStyle.backgroundImage;
27 var imageUrl = bg.substring(5, bg.length-2);
28
29 if (imageUrl.substr(imageUrl.length-4).toLowerCase() == '.png') {
30 var logospan = logoa.appendChild(document.createElement('span'));
31
32 logoa.style.backgroundImage = 'none';
33 logospan.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + imageUrl + ')';
34 logospan.style.height = '100%';
35 logospan.style.position = 'absolute';
36 logospan.style.width = logoa.currentStyle.width;
37 logospan.style.cursor = 'hand';
38 // Center image with hack for IE5.5
39 if (document.documentElement.dir == "rtl")
40 {
41 logospan.style.right = '50%';
42 logospan.style.setExpression('marginRight', '"-" + (this.offsetWidth / 2) + "px"');
43 }
44 else
45 {
46 logospan.style.left = '50%';
47 logospan.style.setExpression('marginLeft', '"-" + (this.offsetWidth / 2) + "px"');
48 }
49 logospan.style.top = '50%';
50 logospan.style.setExpression('marginTop', '"-" + (this.offsetHeight / 2) + "px"');
51 }
52 }
53 }
54
55 // fix ie6 disappering float bug
56 function relativeforfloats() {
57 var bc = document.getElementById('bodyContent');
58 if (bc) {
59 var tables = bc.getElementsByTagName('table');
60 var divs = bc.getElementsByTagName('div');
61 }
62 setrelative(tables);
63 setrelative(divs);
64 }
65 function setrelative (nodes) {
66 var i = 0;
67 while (i < nodes.length) {
68 if(((nodes[i].style.float && nodes[i].style.float != ('none') ||
69 (nodes[i].align && nodes[i].align != ('none'))) &&
70 (!nodes[i].style.position || nodes[i].style.position != 'relative')))
71 {
72 nodes[i].style.position = 'relative';
73 }
74 i++;
75 }
76 }
77
78
79 // Expand links for printing
80
81 String.prototype.hasClass = function(classWanted)
82 {
83 var classArr = this.split(/\s/);
84 for (var i=0; i<classArr.length; i++)
85 if (classArr[i].toLowerCase() == classWanted.toLowerCase()) return true;
86 return false;
87 }
88
89 var expandedURLs;
90
91 onbeforeprint = function() {
92 expandedURLs = [];
93
94 var contentEl = document.getElementById("content");
95
96 if (contentEl)
97 {
98 var allLinks = contentEl.getElementsByTagName("a");
99
100 for (var i=0; i < allLinks.length; i++) {
101 if (allLinks[i].className.hasClass("external") && !allLinks[i].className.hasClass("free")) {
102 var expandedLink = document.createElement("span");
103 var expandedText = document.createTextNode(" (" + allLinks[i].href + ")");
104 expandedLink.appendChild(expandedText);
105 allLinks[i].parentNode.insertBefore(expandedLink, allLinks[i].nextSibling);
106 expandedURLs[i] = expandedLink;
107 }
108 }
109 }
110 }
111
112 onafterprint = function()
113 {
114 for (var i=0; i < expandedURLs.length; i++)
115 if (expandedURLs[i])
116 expandedURLs[i].removeNode(true);
117 }