summaryrefslogtreecommitdiff
path: root/skins/common/IEFixes.js
blob: 7f3b9c0fb7cf35bee365091738c6f4a469f3f006 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// IE fixes javascript

window.isMSIE55 = ( window.showModalDialog && window.clipboardData && window.createPopup );
window.doneIETransform = undefined;
window.doneIEAlphaFix = undefined;

window.hookit = function() {
	if ( !doneIETransform && document.getElementById && document.getElementById( 'bodyContent' ) ) {
		doneIETransform = true;
		relativeforfloats();
		fixalpha();
	}
};

if ( document.attachEvent ) {
	document.attachEvent( 'onreadystatechange', window.hookit );
}

// png alpha transparency fixes
window.fixalpha = function( logoId ) {
	// bg
	if ( isMSIE55 && !doneIEAlphaFix ) {
		var plogo = document.getElementById( logoId || 'p-logo' );
		if ( !plogo ) {
			return;
		}

		var logoa = plogo.getElementsByTagName('a')[0];
		if ( !logoa ) {
			return;
		}

		var bg = logoa.currentStyle.backgroundImage;
		var imageUrl = bg.substring( 5, bg.length - 2 );

		doneIEAlphaFix = true;

		if ( imageUrl.substr( imageUrl.length - 4 ).toLowerCase() == '.png' ) {
			var logospan = logoa.appendChild( document.createElement( 'span' ) );

			logoa.style.backgroundImage = 'none';
			logospan.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + imageUrl + ')';
			logospan.style.height = '100%';
			logospan.style.position = 'absolute';
			logospan.style.width = logoa.currentStyle.width;
			logospan.style.cursor = 'hand';
			// Center image with hack for IE5.5
			if ( document.documentElement.dir == 'rtl' ) {
				logospan.style.right = '50%';
				logospan.style.setExpression( 'marginRight', '"-" + (this.offsetWidth / 2) + "px"' );
			} else {
				logospan.style.left = '50%';
				logospan.style.setExpression( 'marginLeft', '"-" + (this.offsetWidth / 2) + "px"' );
			}
			logospan.style.top = '50%';
			logospan.style.setExpression( 'marginTop', '"-" + (this.offsetHeight / 2) + "px"' );

			var linkFix = logoa.appendChild( logoa.cloneNode() );
			linkFix.style.position = 'absolute';
			linkFix.style.height = '100%';
			linkFix.style.width = '100%';
		}
	}
};

// fix ie6 disappering float bug
window.relativeforfloats = function() {
	var bc = document.getElementById( 'bodyContent' );
	if ( bc ) {
		var tables = bc.getElementsByTagName( 'table' );
		var divs = bc.getElementsByTagName( 'div' );
		setrelative( tables );
		setrelative( divs );
	}
};

window.setrelative = function( nodes ) {
	var i = 0;
	while ( i < nodes.length ) {
		if( ( ( nodes[i].style.float && nodes[i].style.float != ( 'none' ) ||
			( nodes[i].align && nodes[i].align != ( 'none' ) ) ) &&
			( !nodes[i].style.position || nodes[i].style.position != 'relative' ) ) )
		{
			nodes[i].style.position = 'relative';
		}
		i++;
	}
};

// Expand links for printing
String.prototype.hasClass = function( classWanted ) {
	var classArr = this.split(/\s/);
	for ( var i = 0; i < classArr.length; i++ ) {
		if ( classArr[i].toLowerCase() == classWanted.toLowerCase() ) {
			return true;
		}
	}
	return false;
};

window.expandedURLs = undefined;

window.onbeforeprint = function() {
	expandedURLs = [];

	var contentEl = document.getElementById( 'content' );

	if ( contentEl ) {
		var allLinks = contentEl.getElementsByTagName( 'a' );

		for ( var i = 0; i < allLinks.length; i++ ) {
			if ( allLinks[i].className.hasClass( 'external' ) && !allLinks[i].className.hasClass( 'free' ) ) {
				var expandedLink = document.createElement( 'span' );
				var expandedText = document.createTextNode( ' (' + allLinks[i].href + ')' );
				expandedLink.appendChild( expandedText );
				allLinks[i].parentNode.insertBefore( expandedLink, allLinks[i].nextSibling );
				expandedURLs[i] = expandedLink;
			}
		}
	}
};

window.onafterprint = function() {
	for ( var i = 0; i < expandedURLs.length; i++ ) {
		if ( expandedURLs[i] ) {
			expandedURLs[i].removeNode( true );
		}
	}
};