Skip to content

Commit 813402a

Browse files
committed
embed youtube videos in practice comments
1 parent 725ab03 commit 813402a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

public/stylesheets/practice.css

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ div.game_control {
9797
.underboard .feedback .comment {
9898
display: block;
9999
}
100+
.underboard .feedback .comment iframe {
101+
margin: 10px 0;
102+
}
100103

101104
#practice_app .section {
102105
width: 742px;

ui/analyse/src/study/practice/studyPracticeCtrl.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,32 @@ var readOnlyProp = function(value) {
77
};
88
};
99

10+
var commentYoutubeRegex = /(?:https?:\/\/)(?:www\.)(?:youtube\.com|youtu\.be)\/(?:watch)?(?:\?v=)?([^"&?\/ ]{11})/gi;
11+
1012
module.exports = function(root, studyData, data) {
1113

1214
var goal = m.prop();
1315
var comment = m.prop();
1416
var nbMoves = m.prop(0);
1517
var won = m.prop(false);
1618

19+
var makeComment = function(treeRoot) {
20+
if (!treeRoot.comments) return;
21+
var c = m.trust(treeRoot.comments[0].text.replace(commentYoutubeRegex, function(m, id) {
22+
return '<iframe width="472" height="300" src="https://www.youtube.com/embed/' + id + '" frameborder="0" allowfullscreen></iframe>';
23+
}));
24+
delete treeRoot.comments;
25+
return c;
26+
};
27+
1728
var onLoad = function() {
1829
root.vm.showAutoShapes = readOnlyProp(true);
1930
root.vm.showGauge = readOnlyProp(true);
2031
root.vm.showComputer = readOnlyProp(true);
2132
goal(root.data.practiceGoal);
2233
nbMoves(0);
2334
won(false);
24-
var r = root.tree.root;
25-
if (r.comments) {
26-
comment(r.comments[0].text);
27-
delete r.comments;
28-
}
35+
comment(makeComment(root.tree.root));
2936
};
3037
onLoad();
3138

0 commit comments

Comments
 (0)