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

Commit c6db3cc

Browse files
committed
2 parents 629552a + 6b119c0 commit c6db3cc

File tree

4 files changed

+97
-3
lines changed

4 files changed

+97
-3
lines changed

notes/static/js/resources.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*This script is for implementing the mobile fix for resources. See
2+
https://github.com/The-Domecode/domecode-opensource/issues/3#issuecomment-685106802
3+
for more info. */
4+
5+
6+
// polyfill "String.includes" function. required for bowsers without ES6 support, like Internet Explorer.
7+
if (!String.prototype.includes) {
8+
String.prototype.includes = function(search, start) {
9+
'use strict';
10+
if (typeof start !== 'number') {
11+
start = 0;
12+
}
13+
14+
if (start + search.length > this.length) {
15+
return false;
16+
} else {
17+
return this.indexOf(search, start) !== -1;
18+
}
19+
};
20+
}
21+
22+
var all = document.getElementsByTagName("*");
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);
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"
53+
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+
}

notes/static/notes/dark.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,18 @@ p {
371371
background-position: 0% 50%;
372372
}
373373
}
374+
375+
.video-container {
376+
position: relative;
377+
padding-bottom: 56.25%;
378+
padding-top: 30px;
379+
height: 0;
380+
overflow: hidden;
381+
}
382+
383+
.video-container iframe, .video-container object, .video-container embed {
384+
position: absolute;
385+
top: 0;
386+
width: 100%;
387+
height: 100%;
388+
}

notes/static/notes/light.css

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ body {
118118
left: 0;
119119
bottom: 0;
120120
width: 100%;
121-
height: 18px;
121+
height: auto;
122+
min-height: 18px;
122123
background: #000000;
123124
color: white;
124125
text-align: center;
@@ -189,4 +190,19 @@ body {
189190
color: white;
190191
border: none;
191192
outline: none;
192-
}
193+
}
194+
195+
.video-container {
196+
position: relative;
197+
padding-bottom: 56.25%;
198+
padding-top: 30px;
199+
height: 0;
200+
overflow: hidden;
201+
}
202+
203+
.video-container iframe, .video-container object, .video-container embed {
204+
position: absolute;
205+
top: 0;
206+
width: 100%;
207+
height: 100%;
208+
}

resources/templates/resources/resources_detail_python.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{% extends "notes/base.html" %}
1+
{% extends 'notes/base.html' %}
2+
{% load static %}
23
{% block content %}
34

45
<!--Add navigation to other resources-->
@@ -62,4 +63,8 @@ <h2 class="article-title">{{ object.title }}</h2>
6263
<p>Optional Python Editor for your use</p>
6364
<iframe src="https://trinket.io/embed/python3/9d578a67e3" width="90%" height="400" frameborder="0" marginwidth="0"
6465
marginheight="0"></iframe>
66+
67+
<!-- Run video fix. Has to be at the bottom for this to work. -->
68+
<script src="{% static 'js/resources.js' %}"></script>
69+
6570
{% endblock content %}

0 commit comments

Comments
 (0)