Skip to content

Commit 3a1ba4d

Browse files
committed
Support embedding SlideShare as a media
1 parent 1fe4ce4 commit 3a1ba4d

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

static/main.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
const youtubeEmbedSchema = /^https:\/\/www\.youtube\.com\/embed\/.+/;
3+
const youtubeWatchSchema = /^https:\/\/www\.youtube\.com\/watch\?v=(.+)/;
4+
const slideshareSchema = /^\/\/www\.slideshare\.net\/slideshow\/embed_code\/key\/.+/;
5+
26
const initializeOptions =
37
new InitializeOptions()
48
.plugins(["cl-exercise"])
@@ -80,18 +84,23 @@ function createMediaIframe() {
8084
}
8185

8286
function embedMedia(src) {
83-
const youtubeEmbedSchema = /^https:\/\/www.youtube.com\/embed\/.+/;
84-
const youtubeWatchSchema = /^https:\/\/www.youtube.com\/watch\?v=(.+)/;
8587
let mediaElement = document.getElementById("media-area");
8688
let watchSchemaResult = null;
8789
if (src.match(youtubeEmbedSchema)) {
8890
let frame = createMediaIframe();
91+
mediaElement.classList.add("youtube")
8992
mediaElement.appendChild(frame);
9093
frame.src = src;
9194
} else if (watchSchemaResult = src.match(youtubeWatchSchema)) {
9295
let frame = createMediaIframe();
96+
mediaElement.classList.add("youtube")
9397
mediaElement.appendChild(frame);
9498
frame.src = `https://www.youtube.com/embed/${watchSchemaResult[1]}`;
99+
} else if (src.match(slideshareSchema)) {
100+
let frame = createMediaIframe();
101+
mediaElement.classList.add("slideshare");
102+
mediaElement.appendChild(frame);
103+
frame.src = src;
95104
} else {
96105
console.error("Unknown media");
97106
}
@@ -117,7 +126,7 @@ window.onload = () => {
117126
lineNumbers: true,
118127
tabSize: 2,
119128
matchBrackets: true,
120-
autofocus: true,
129+
autofocus: false,
121130
viewportMargin: Infinity
122131
});
123132
codeMirror.setSize("100%", "auto");

templates/exercise.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
<button class="modal-close is-large" aria-label="close"></button>
4444
</div>
4545
<style>
46-
#media-area{position:relative;padding-top:56.25%;margin-bottom:24px;}
46+
#media-area{position:relative;margin-bottom:24px;}
47+
#media-area.youtube{padding-top:56.25%;}
48+
#media-area.slideshare{padding-top:56.25%;}
4749
#media-area .media{position:absolute;top:0;right:0;width:100% !important;height:100% !important;}
4850
</style>
4951
<section class="section" style="flex: 1;">

0 commit comments

Comments
 (0)