MDL-8992 Added a simple script from http://mar.anomy.net/entry/2006/11/24/02.12.18...
[moodle.git] / filter / mediaplugin / eolas_fix.js
CommitLineData
2f39c5ef 1// Documentation & updates available at:
2// http://codecentre.eplica.is/js/eolasfix/test.htm
3
4(function( Eolas_Fixed,
5 win, doc,
6 getElementsByTagName,
7 outerHTML,
8 parentNode,
9 tags,
10 elmsToRemoveOnload,
11 x,
12 is_ie,
13 y,z,elm,childNode,HTML,dummy,eolasfix)
14{
15 // run only once!
16 if (win[Eolas_Fixed]) return;
17 win[Eolas_Fixed] = 1;
18
19 eolasfix = function ()
20 {
21 // for each tag name specified in Array t
22 while (tags[++x])
23 {
24 // find all elements of that type in the document
25 // loop through the elements
26 y = 0;
27 while (elm = doc[getElementsByTagName](tags[x])[y++])
28 {
29 if (is_ie)
30 {
31 HTML = '>';
32 z = 0;
33 // <param> elements don't show up in innerHTML IE
34 // so we need to collect their outerHTML.
35 while (childNode = elm.childNodes[z++])
36 HTML += childNode[outerHTML];
37
38 // create a 'dummy' element
39 dummy = doc.createElement('i');
40 // inject it next to `elm`,
41 elm[parentNode].insertBefore(dummy, elm);
42 // and turn it into an `elm` clone
43 dummy[outerHTML] = elm[outerHTML].replace(/>/, HTML);
44 // increment y to skip over it
45 y++;
46
47 // then hide the original elm
48 elm.style.display = 'none';
49 // and save it in 'The List of Elements to Remove Later'.
50 elmsToRemoveOnload[elmsToRemoveOnload.length] = elm;
51 }
52 else
53 {
54 elm[outerHTML] = elm[outerHTML];
55 }
56 }
57 }
58 };
59
60 // For IE run the fix straight away (because the defer="defer"
61 // attribute has delayed execution until the DOM has loaded).
62 // Then assign a window.onload event to purge the old elements.
63 is_ie && !eolasfix() && win.attachEvent('onload', function(){
64 x=0;
65 while(elm = elmsToRemoveOnload[x++])
66 elm[parentNode].removeChild(elm);
67 });
68 // For Opera set an `DOMContentLoaded` event to run the fix.
69 win.opera && doc.addEventListener('DOMContentLoaded', eolasfix, 0);
70
71})( '__Eolas_Fixed',
72 window, document,
73 'getElementsByTagName',
74 'outerHTML',
75 'parentNode',
76 ['object','embed','applet'],
77 [],
78 -1 /*@cc_on,1 @*/
79 );
80