@@ -3,7 +3,8 @@ https://github.com/The-Domecode/domecode-opensource/issues/3#issuecomment-685106
3
3
for more info. */
4
4
5
5
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.
7
8
if ( ! String . prototype . includes ) {
8
9
String . prototype . includes = function ( search , start ) {
9
10
'use strict' ;
@@ -19,40 +20,21 @@ if (!String.prototype.includes) {
19
20
} ;
20
21
}
21
22
22
- var all = document . getElementsByTagName ( "*" ) ;
23
23
24
- var name ;
25
- var elements = [ ] ;
26
-
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 ) ;
24
+ // Gather all video frames
25
+ var frames = $ ( "iframe" ) . map ( function ( ) {
26
+ if ( this . src . includes ( "trinket" ) ) {
27
+ // This is a trinket frame, skip
28
+ return ;
29
+ } else {
30
+ // This is not a trinket frame, return this
31
+ return this ;
35
32
}
36
- }
33
+ } ) ;
37
34
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"
35
+ // Loop over each frame we got
36
+ frames . each ( function ( ) {
37
+ // Create our wrapper div and wrap the frame
38
+ $ ( "<div/>" , { "class" : "video-container" } ) . wrap ( $ ( this ) ) ;
53
39
54
- // set the wrapper as the parent's child instead of the frame
55
- parent . replaceChild ( wrapper , frame ) ;
56
- // set the frame as the child of the wrapper
57
- wrapper . appendChild ( frame ) ;
58
- }
40
+ } ) ;
0 commit comments