1
1
2
+ const youtubeEmbedSchema = / ^ h t t p s : \/ \/ w w w \. y o u t u b e \. c o m \/ e m b e d \/ .+ / ;
3
+ const youtubeWatchSchema = / ^ h t t p s : \/ \/ w w w \. y o u t u b e \. c o m \/ w a t c h \? v = ( .+ ) / ;
4
+ const slideshareSchema = / ^ \/ \/ w w w \. s l i d e s h a r e \. n e t \/ s l i d e s h o w \/ e m b e d _ c o d e \/ k e y \/ .+ / ;
5
+
2
6
const initializeOptions =
3
7
new InitializeOptions ( )
4
8
. plugins ( [ "cl-exercise" ] )
@@ -80,18 +84,23 @@ function createMediaIframe() {
80
84
}
81
85
82
86
function embedMedia ( src ) {
83
- const youtubeEmbedSchema = / ^ h t t p s : \/ \/ w w w .y o u t u b e .c o m \/ e m b e d \/ .+ / ;
84
- const youtubeWatchSchema = / ^ h t t p s : \/ \/ w w w .y o u t u b e .c o m \/ w a t c h \? v = ( .+ ) / ;
85
87
let mediaElement = document . getElementById ( "media-area" ) ;
86
88
let watchSchemaResult = null ;
87
89
if ( src . match ( youtubeEmbedSchema ) ) {
88
90
let frame = createMediaIframe ( ) ;
91
+ mediaElement . classList . add ( "youtube" )
89
92
mediaElement . appendChild ( frame ) ;
90
93
frame . src = src ;
91
94
} else if ( watchSchemaResult = src . match ( youtubeWatchSchema ) ) {
92
95
let frame = createMediaIframe ( ) ;
96
+ mediaElement . classList . add ( "youtube" )
93
97
mediaElement . appendChild ( frame ) ;
94
98
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 ;
95
104
} else {
96
105
console . error ( "Unknown media" ) ;
97
106
}
@@ -117,7 +126,7 @@ window.onload = () => {
117
126
lineNumbers : true ,
118
127
tabSize : 2 ,
119
128
matchBrackets : true ,
120
- autofocus : true ,
129
+ autofocus : false ,
121
130
viewportMargin : Infinity
122
131
} ) ;
123
132
codeMirror . setSize ( "100%" , "auto" ) ;
0 commit comments