@@ -3,7 +3,8 @@ https://github.com/The-Domecode/domecode-opensource/issues/3#issuecomment-685106
33for more info. */
44
55
6- // polyfill "String.includes" function. required for bowsers without ES6 support, like Internet Explorer.
6+ // polyfill "String.includes" function.
7+ // Required for bowsers without ES6 support, like Internet Explorer.
78if ( ! String . prototype . includes ) {
89 String . prototype . includes = function ( search , start ) {
910 'use strict' ;
@@ -19,40 +20,21 @@ if (!String.prototype.includes) {
1920 } ;
2021}
2122
22- var all = document . getElementsByTagName ( "*" ) ;
23+ // Polyfill HTMLCollection.forEach from Array.forEach
24+ if ( ! HTMLCollection . prototype . forEach ) HTMLCollection . prototype . forEach = Array . prototype . forEach ;
2325
24- var name ;
25- var elements = [ ] ;
26+ // Gather all video frames
27+ const frames = document . getElementsByTagName ( "IFRAME" ) ;
2628
27- // loop through all elements on page to find all the iframes
28- for ( var i = 0 , max = all . length ; i < max ; i ++ ) {
29- // get element name
30- var el = all [ i ] ;
31- var name = el . nodeName . toLowerCase ( ) ;
32- if ( name == "iframe" ) {
33- // if it's an iframe, push it to the list.
34- elements . push ( el ) ;
35- }
36- }
37-
38- // loop through all the iframes we found
39- for ( var i = 0 , max = elements . length ; i < max ; i ++ ) {
40- // get the frame to work on
41- var frame = elements [ i ] ;
42- // Skip trinket python editor
43- if ( frame . src . includes ( "trinket" ) ) {
44- continue ;
45- }
46- // Wrap the video inside the video-wrapper class
47-
48- // get the frame's current parent
49- var parent = frame . parentNode ;
50- // create the wrapper div and set its class
51- var wrapper = document . createElement ( "div" ) ;
52- wrapper . className = "video-container"
29+ // Loop over each frame we got
30+ frames . forEach ( ( frame ) => {
31+ // Get the frame's parent
32+ let parent = frame . parentNode ;
33+ // Create the wrapper div and set its class
34+ let wrapper = document . createElement ( "div" ) ;
35+ wrapper . className = "video-container" ;
5336
54- // set the wrapper as the parent's child instead of the frame
37+ // Wrap the frame in the wrapper
5538 parent . replaceChild ( wrapper , frame ) ;
56- // set the frame as the child of the wrapper
5739 wrapper . appendChild ( frame ) ;
58- }
40+ } )
0 commit comments