EditPage::newSectionSummary should return a value in all code paths
[lhc/web/wiklou.git] / skins / common / IEFixes.js
1 /**
2 * IE fixes javascript loaded by wikibits.js for IE <= 6.0
3 */
4 /*global isMSIE55:true, doneIETransform:true, doneIEAlphaFix:true */
5 /*global hookit:true, fixalpha:true */
6 ( function ( mw, $ ) {
7
8 var expandedURLs, hasClass;
9
10 // Also returns true for IE6, 7, 8, 9 and 10. createPopup is removed in IE11.
11 // Good thing this is only loaded for IE <= 6 by wikibits.
12 // Might as well set it to true.
13 isMSIE55 = ( window.showModalDialog && window.clipboardData && window.createPopup );
14 doneIETransform = false;
15 doneIEAlphaFix = false;
16
17 hookit = function () {
18 if ( !doneIETransform && document.getElementById && document.getElementById( 'bodyContent' ) ) {
19 doneIETransform = true;
20 fixalpha();
21 }
22 };
23
24 if ( document.attachEvent ) {
25 document.attachEvent( 'onreadystatechange', hookit );
26 }
27
28 // png alpha transparency fixes
29 fixalpha = function ( logoId ) {
30 // bg
31 if ( isMSIE55 && !doneIEAlphaFix ) {
32 var bg, imageUrl, linkFix, logoa, logospan, plogo;
33 plogo = document.getElementById( logoId || 'p-logo' );
34 if ( !plogo ) {
35 return;
36 }
37
38 logoa = plogo.getElementsByTagName('a')[0];
39 if ( !logoa ) {
40 return;
41 }
42
43 bg = logoa.currentStyle.backgroundImage;
44 imageUrl = bg.substring( 5, bg.length - 2 );
45
46 doneIEAlphaFix = true;
47
48 if ( imageUrl.substr( imageUrl.length - 4 ).toLowerCase() === '.png' ) {
49 logospan = logoa.appendChild( document.createElement( 'span' ) );
50
51 logoa.style.backgroundImage = 'none';
52 logospan.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + imageUrl + ')';
53 logospan.style.height = '100%';
54 logospan.style.position = 'absolute';
55 logospan.style.width = logoa.currentStyle.width;
56 logospan.style.cursor = 'hand';
57 // Center image with hack for IE5.5
58 if ( document.documentElement.dir === 'rtl' ) {
59 logospan.style.right = '50%';
60 logospan.style.setExpression( 'marginRight', '"-" + (this.offsetWidth / 2) + "px"' );
61 } else {
62 logospan.style.left = '50%';
63 logospan.style.setExpression( 'marginLeft', '"-" + (this.offsetWidth / 2) + "px"' );
64 }
65 logospan.style.top = '50%';
66 logospan.style.setExpression( 'marginTop', '"-" + (this.offsetHeight / 2) + "px"' );
67
68 linkFix = logoa.appendChild( logoa.cloneNode() );
69 linkFix.style.position = 'absolute';
70 linkFix.style.height = '100%';
71 linkFix.style.width = '100%';
72 }
73 }
74 };
75
76 if ( isMSIE55 ) {
77 // ondomready
78 $( fixalpha );
79 }
80
81 // Expand links for printing
82 hasClass = function ( classText, classWanted ) {
83 var i = 0, classArr = classText.split(/\s/);
84 for ( i = 0; i < classArr.length; i++ ) {
85 if ( classArr[i].toLowerCase() === classWanted.toLowerCase() ) {
86 return true;
87 }
88 }
89 return false;
90 };
91
92 window.onbeforeprint = function () {
93 var allLinks, contentEl, expandedLink, expandedText, i;
94
95 expandedURLs = [];
96 contentEl = document.getElementById( 'content' );
97
98 if ( contentEl ) {
99 allLinks = contentEl.getElementsByTagName( 'a' );
100
101 for ( i = 0; i < allLinks.length; i++ ) {
102 if ( hasClass( allLinks[i].className, 'external' ) && !hasClass( allLinks[i].className, 'free' ) ) {
103 expandedLink = document.createElement( 'span' );
104 expandedText = document.createTextNode( ' (' + allLinks[i].href + ')' );
105 expandedLink.appendChild( expandedText );
106 allLinks[i].parentNode.insertBefore( expandedLink, allLinks[i].nextSibling );
107 expandedURLs[i] = expandedLink;
108 }
109 }
110 }
111 };
112
113 window.onafterprint = function () {
114 for ( var i = 0; i < expandedURLs.length; i++ ) {
115 if ( expandedURLs[i] ) {
116 expandedURLs[i].removeNode( true );
117 }
118 }
119 };
120
121 }( mediaWiki, jQuery ) );