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

Commit db4bacb

Browse files
committed
2 parents 326cd3c + ea1d582 commit db4bacb

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-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: 22 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,28 @@ 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 = [];
2626

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-
}
27+
// List of elements to work on. To add new types of elements, just add mroe tag names to this array.
28+
const elements = ["IFRAME", "IMG"];
29+
let frames = [];
30+
31+
// Grab all the elements
32+
elements.forEach((element) => {
33+
frames = frames.concat(Array.from(document.getElementsByTagName(element)));
34+
});
35+
36+
// Apply our modifications
37+
frames.forEach((frame) => {
38+
// Get the frame's parent
39+
let parent = frame.parentNode;
40+
// Create the wrapper div and set its class
41+
let wrapper = document.createElement("div");
42+
wrapper.className = "video-container";
3743

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"
53-
54-
// set the wrapper as the parent's child instead of the frame
44+
// Wrap the frame in the wrapper
5545
parent.replaceChild(wrapper, frame);
56-
// set the frame as the child of the wrapper
5746
wrapper.appendChild(frame);
58-
}
47+
})

0 commit comments

Comments
 (0)