Merge "Whitelist the <wbr> element."
[mediawiki.git] / skins / common / IEFixes.js
blobdd999ed4205ac3632e9f1e487eb60c1946022c5a
1 // IE fixes javascript
3 window.isMSIE55 = ( window.showModalDialog && window.clipboardData && window.createPopup );
4 window.doneIETransform = undefined;
5 window.doneIEAlphaFix = undefined;
7 window.hookit = function() {
8         if ( !doneIETransform && document.getElementById && document.getElementById( 'bodyContent' ) ) {
9                 doneIETransform = true;
10                 relativeforfloats();
11                 fixalpha();
12         }
15 if ( document.attachEvent ) {
16         document.attachEvent( 'onreadystatechange', window.hookit );
19 // png alpha transparency fixes
20 window.fixalpha = function( logoId ) {
21         // bg
22         if ( isMSIE55 && !doneIEAlphaFix ) {
23                 var plogo = document.getElementById( logoId || 'p-logo' );
24                 if ( !plogo ) {
25                         return;
26                 }
28                 var logoa = plogo.getElementsByTagName('a')[0];
29                 if ( !logoa ) {
30                         return;
31                 }
33                 var bg = logoa.currentStyle.backgroundImage;
34                 var imageUrl = bg.substring( 5, bg.length - 2 );
36                 doneIEAlphaFix = true;
38                 if ( imageUrl.substr( imageUrl.length - 4 ).toLowerCase() == '.png' ) {
39                         var logospan = logoa.appendChild( document.createElement( 'span' ) );
41                         logoa.style.backgroundImage = 'none';
42                         logospan.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + imageUrl + ')';
43                         logospan.style.height = '100%';
44                         logospan.style.position = 'absolute';
45                         logospan.style.width = logoa.currentStyle.width;
46                         logospan.style.cursor = 'hand';
47                         // Center image with hack for IE5.5
48                         if ( document.documentElement.dir == 'rtl' ) {
49                                 logospan.style.right = '50%';
50                                 logospan.style.setExpression( 'marginRight', '"-" + (this.offsetWidth / 2) + "px"' );
51                         } else {
52                                 logospan.style.left = '50%';
53                                 logospan.style.setExpression( 'marginLeft', '"-" + (this.offsetWidth / 2) + "px"' );
54                         }
55                         logospan.style.top = '50%';
56                         logospan.style.setExpression( 'marginTop', '"-" + (this.offsetHeight / 2) + "px"' );
58                         var linkFix = logoa.appendChild( logoa.cloneNode() );
59                         linkFix.style.position = 'absolute';
60                         linkFix.style.height = '100%';
61                         linkFix.style.width = '100%';
62                 }
63         }
66 if ( isMSIE55 ) {
67         // ondomready
68         $( fixalpha );
71 // fix ie6 disappering float bug
72 window.relativeforfloats = function() {
73         var bc = document.getElementById( 'bodyContent' );
74         if ( bc ) {
75                 var tables = bc.getElementsByTagName( 'table' );
76                 var divs = bc.getElementsByTagName( 'div' );
77                 setrelative( tables );
78                 setrelative( divs );
79         }
82 window.setrelative = function( nodes ) {
83         var i = 0;
84         while ( i < nodes.length ) {
85                 if( ( ( nodes[i].style.float && nodes[i].style.float != ( 'none' ) ||
86                         ( nodes[i].align && nodes[i].align != ( 'none' ) ) ) &&
87                         ( !nodes[i].style.position || nodes[i].style.position != 'relative' ) ) )
88                 {
89                         nodes[i].style.position = 'relative';
90                 }
91                 i++;
92         }
95 // Expand links for printing
96 String.prototype.hasClass = function( classWanted ) {
97         var classArr = this.split(/\s/);
98         for ( var i = 0; i < classArr.length; i++ ) {
99                 if ( classArr[i].toLowerCase() == classWanted.toLowerCase() ) {
100                         return true;
101                 }
102         }
103         return false;
106 window.expandedURLs = undefined;
108 window.onbeforeprint = function() {
109         expandedURLs = [];
111         var contentEl = document.getElementById( 'content' );
113         if ( contentEl ) {
114                 var allLinks = contentEl.getElementsByTagName( 'a' );
116                 for ( var i = 0; i < allLinks.length; i++ ) {
117                         if ( allLinks[i].className.hasClass( 'external' ) && !allLinks[i].className.hasClass( 'free' ) ) {
118                                 var expandedLink = document.createElement( 'span' );
119                                 var expandedText = document.createTextNode( ' (' + allLinks[i].href + ')' );
120                                 expandedLink.appendChild( expandedText );
121                                 allLinks[i].parentNode.insertBefore( expandedLink, allLinks[i].nextSibling );
122                                 expandedURLs[i] = expandedLink;
123                         }
124                 }
125         }
128 window.onafterprint = function() {
129         for ( var i = 0; i < expandedURLs.length; i++ ) {
130                 if ( expandedURLs[i] ) {
131                         expandedURLs[i].removeNode( true );
132                 }
133         }