Skip to content
This repository was archived by the owner on Jun 13, 2022. It is now read-only.

Commit 8b58e3a

Browse files
authored
Merge pull request #44 from karx1/dev
#43 - FIX: Optimize resources script
2 parents 9f1d68a + 73390f1 commit 8b58e3a

File tree

2 files changed

+17
-33
lines changed

2 files changed

+17
-33
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ media/media/
77
.idea/
88
venv/
99
__pycache__
10+
.vscode/
11+
jsconfig.json

notes/static/js/resources.js

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ https://github.com/The-Domecode/domecode-opensource/issues/3#issuecomment-685106
33
for 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.
78
if (!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

Comments
 (0)