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

Commit 4017977

Browse files
committed
Convert resource fix script to jQuery
1 parent 05258c8 commit 4017977

File tree

1 file changed

+16
-34
lines changed

1 file changed

+16
-34
lines changed

notes/static/js/resources.js

Lines changed: 16 additions & 34 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("*");
2323

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;
3532
}
36-
}
33+
});
3734

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));
5339

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

Comments
 (0)