JavaScript Snippets

Feel free to reuse wherever desired. I had to pick goldenrod as background color for the code blocks because all other major colours made at least one type of code operator / keyword invisible or hard to read.

.ogg sound files are not supported in Trident / Microsoft Edge, Internet Explorer and Safari. This code detects those browsers and if they are used, replaces Ogg Sound Players with a message informing them of the situation.

```
var msIE = /\*@cc\_on!@\*/0; //Internet Explorer
var isSafari = /^((?!chrome|android).)\*safari/i.test(navigator.userAgent);
var msEdge = /Edge/.test(navigator.userAgent);
var trident = navigator.userAgent.match(/Trident\/7\./); //Certain Edge versions
 $(".ogg\_player").replaceWith("<span class='NoOggText'>We're sorry, but .ogg sound files are not supported in Safari, Internet Explorer and Microsoft Edge. If you want to hear the sounds nonetheless, please consider using Opera Browser, Google Chrome or Mozilla Firefox instead.</span>");
}

```

Internet Explorer is the bane of webdesign, in that many features from other browsers are unsupported in it and that it is home to dozens of glitches, bugs and other oddities as result due to its primitive and different structure when compared to other browsers. This code fixes some of these oversights.

```
$('head').append('<!--[if lt IE 9]><link rel="stylesheet" type="text/css" '+
 'href="http://admintools.wikia.com/index.php?title=MediaWiki:Common.js/IE.js/IE6-png.css' +
 '&action=raw&ctype=text/css" media="screen" /><![endif]-->');

if (window.showModalDialog && document.compatMode) {
 var oldWidth;
 var docEl = document.documentElement;
 function fixIEScroll() {
 if (!oldWidth || docEl.clientWidth > oldWidth) {doFixIEScroll();}
 else {setTimeout(doFixIEScroll, 1);} oldWidth = docEl.clientWidth;}
 function doFixIEScroll() {docEl.style.overflowX = (docEl.scrollWidth -
 docEl.clientWidth < 4) ? 'hidden' : '';}
 try {document.attachEvent('onreadystatechange', fixIEScroll);
 attachEvent('onresize', fixIEScroll);
 }catch(e){}}

/\* Fix an overflow bug where the scrollbar would wrongly appear and function
in pre elements and code blocks in Internet Explorer 6 and 7, breaking them \*/
//Documented at https://remysharp.com/2008/01/21/fixing-ie-overflow-problem

;(function ($) {
 $.fn.fixOverflow = function() {
 if ($.browser.msie) {return this.each(function () {
 if (this.scrollWidth > this.offsetWidth) {
 $(this).css({
 'padding-bottom': '20px',
 'overflow-y': 'hidden'});}});} else {return this;}};
})(jQuery); $(
 'pre',
 'syntaxhighlight',
 'source',
 '.mw-geshi',
 '.source-lua',
 '.source-css',
 '.source-javascript').fixOverflow();

 window.onload = function () {
 // only apply to IE
 if (!/\*@cc\_on!@\*/0) return;

 // find every element to test
 var all = document.getElementsByTagName('\*'), i = all.length;

 // fast reverse loop
 while (i--) {
 // if the scrollWidth (the real width) is greater than
 // the visible width, then apply style changes
 if (all[i].scrollWidth > all[i].offsetWidth) {
 all[i].style['.paddingBottom'] = '20px';
 all[i].style['.overflowY'] = 'hidden';}}
};

//°°°°°°°°°°°°°°°°°°°°°°°°
//Fixing PNG images bug

/\*IE 6, 7 and 8\*/

function msieversion() {
 var ua = window.navigator.userAgent;
 var msie = ua.indexOf("MSIE ");
 if (msie > 0) {mw.util.addCSS
 ("img {\
 background: transparent;\
 -ms-filter: progid:DXImageTransform.Microsoft.gradient" +
 "(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF);" + //IE 8
 "filter: progid:DXImageTransform.Microsoft.gradient" +
 "(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF);" + //IE 6 & 7
 "zoom: 1;}")}
}

/\*IE 11\*/

function msieversion() {
 var ua = window.navigator.userAgent;
 var msie = ua.indexOf("MSIE ");
 if (msie > 0 || !!navigator.userAgent.match(/Trident.\*rv\:11\./))
 {mw.util.addCSS
 ("img {\
 background: transparent;\
 -ms-filter: progid:DXImageTransform.Microsoft.gradient" +
 "(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF);" +
 "filter: progid:DXImageTransform.Microsoft.gradient" +
 "(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF);" +
 "zoom: 1;}")}
}

```

There are still some browser versions that don't support `getElementsByTagName` (somehow). Here we fix that and make the function for those grandpas.

```
function getElementsByTagName (name, root) {
 if (root === undefined) root = document;
 var e = root.getElementsByTagName('\*'); var r = new Array();
 for (var i = 0; i < e.length; i++) {if (e[i].getAttribute('name') == name)
 r[r.length] = e[i];} return r;}

```