diff -r 02c04d2c8fd8 -r ac1eacb3aa33 src/widgets/Quiz.js
--- a/src/widgets/Quiz.js Sun Nov 12 22:07:33 2017 +0100
+++ b/src/widgets/Quiz.js Wed Sep 04 17:32:50 2024 +0200
@@ -1,388 +1,543 @@
-IriSP.Widgets.Quiz = function(player, config) {
- IriSP.Widgets.Widget.call(this, player, config);
-}
-
-IriSP.Widgets.Quiz.prototype = new IriSP.Widgets.Widget();
-
-IriSP.Widgets.Quiz.prototype.defaults = {
- // annotation_type: "at_quiz",
- quiz_activated: true,
- api_serializer: "ldt_annotate",
- analytics_api: "",
- api_method: "POST",
- user: "",
- userid:""
-}
-
-IriSP.Widgets.Quiz.prototype.template = '
"
+ )
+ .on("click", function () {
+ _this.player.trigger("QuizCreator.create");
+ })
+ .appendTo($("#" + _this.container));
+ _this.overlay.html(this.template);
- // Add Ldt-Quiz-Overlay widget on top of video player
- _this.overlay = $("
").appendTo($('#' + _this.container));
- _this.PauseAddQuestion = $("
")
- .on("click", function() { _this.player.trigger("QuizCreator.create"); })
- .appendTo($('#' + _this.container));
- _this.overlay.html(this.template);
+ $(".Ldt-Quiz-Overlay").hide();
- $(".Ldt-Quiz-Overlay").hide();
+ $(".Ldt-Quiz-Submit input").click(function () {
+ _this.answer();
+ });
- $(".Ldt-Quiz-Submit input").click(function() {
- _this.answer();
- });
+ //In case we click on the first "Skip" link
+ $(".Ldt-Quiz-Submit-Skip-Link").click(
+ { media: this.media },
+ function (event) {
+ _this.submit(
+ _this.user,
+ _this.userid,
+ _this.annotation.id,
+ "skipped_answer",
+ 0
+ );
+ _this.hide();
+ _this.player.trigger("QuizCreator.skip");
+ event.data.media.play();
+ }
+ );
- //In case we click on the first "Skip" link
- $(".Ldt-Quiz-Submit-Skip-Link").click({ media: this.media }, function(event) {
- _this.submit(_this.user, _this.userid, _this.annotation.id, "skipped_answer", 0);
- _this.hide();
- _this.player.trigger("QuizCreator.skip");
- event.data.media.play();
- });
+ $(
+ '.Ldt-Quiz-Votes-Buttons input[type="button"], .Ldt-Quiz-Votes-Buttons a'
+ ).click({ media: this.media }, function (event) {
+ var vote_prop, vote_val;
- $(".Ldt-Quiz-Votes-Buttons input[type=\"button\"], .Ldt-Quiz-Votes-Buttons a").click({media: this.media}, function(event) {
- var vote_prop, vote_val;
+ if ($(this).hasClass("Ldt-Quiz-Vote-Useful")) {
+ vote_prop = "useful";
+ vote_val = 1;
+ } else if ($(this).hasClass("Ldt-Quiz-Vote-Useless")) {
+ vote_prop = "useless";
+ vote_val = -1;
- if ($(this).hasClass("Ldt-Quiz-Vote-Useful")) {
- vote_prop = "useful";
- vote_val = 1;
- } else if ($(this).hasClass("Ldt-Quiz-Vote-Useless")) {
- vote_prop = "useless";
- vote_val = -1;
-
- $(".Ldt-Ctrl-Quiz-Create").addClass("button_highlight").delay(5000).queue(function() {
- $(this).removeClass("button_highlight").dequeue();
+ $(".Ldt-Ctrl-Quiz-Create")
+ .addClass("button_highlight")
+ .delay(5000)
+ .queue(function () {
+ $(this).removeClass("button_highlight").dequeue();
});
- }else{
- vote_prop = "skipped_vote";
- vote_val = 0;
- }
+ } else {
+ vote_prop = "skipped_vote";
+ vote_val = 0;
+ }
- _this.submit(_this.user, _this.userid, _this.annotation.id, vote_prop, vote_val);
+ _this.submit(
+ _this.user,
+ _this.userid,
+ _this.annotation.id,
+ vote_prop,
+ vote_val
+ );
- //Resume the current video
- event.data.media.play();
+ //Resume the current video
+ event.data.media.play();
+
+ _this.hide();
+ $(".Ldt-Pause-Add-Question").hide();
- _this.hide();
- $(".Ldt-Pause-Add-Question").hide();
+ _this.player.trigger("QuizCreator.skip");
+ });
- _this.player.trigger("QuizCreator.skip");
- });
-
- _this.refresh();
+ _this.refresh();
+ }
+ };
};
-//Generates uid
-//source : http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
-IriSP.Widgets.Widget.prototype.generateUid = function () {
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
- var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
- return v.toString(16);
- });
-}
+const UniqueChoiceQuestion = function (ns) {
+ return class extends ns.Widgets.Widget {
+ constructor(annotation) {
+ this.annotation = annotation;
+ }
-//UniqueChoice Question
-IriSP.Widgets.UniqueChoiceQuestion = function(annotation) {
- this.annotation = annotation;
-}
-
-IriSP.Widgets.UniqueChoiceQuestion.prototype = new IriSP.Widgets.Widget();
+ renderQuizTemplate(answer, identifier) {
+ return (
+ ''
+ );
+ }
-IriSP.Widgets.UniqueChoiceQuestion.prototype.renderQuizTemplate = function(answer, identifier) {
- return '';
-}
+ renderTemplate(answer, identifier) {
+ var id = this.generateUid();
+ return (
+ ''
+ );
+ }
-IriSP.Widgets.UniqueChoiceQuestion.prototype.renderTemplate = function(answer, identifier) {
- var id = this.generateUid();
- return '';
-}
+ renderFullTemplate(answer, identifier) {
+ var correct = answer && answer.correct ? "checked" : "";
+ var id = this.generateUid();
+ return (
+ ''
+ );
+ }
+ };
+};
-IriSP.Widgets.UniqueChoiceQuestion.prototype.renderFullTemplate = function(answer, identifier) {
- var correct = (answer && answer.correct) ? "checked" : "";
- var id = this.generateUid();
- return '';
-}
-
+const MultipleChoiceQuestion = function (ns) {
+ return class extends ns.Widgets.Widget {
+ constructor(annotation) {
+ this.annotation = annotation;
+ }
-//MultipleChoice Question
-IriSP.Widgets.MultipleChoiceQuestion = function(annotation) {
- this.annotation = annotation;
-}
-
-IriSP.Widgets.MultipleChoiceQuestion.prototype = new IriSP.Widgets.Widget();
+ renderQuizTemplate(answer, identifier) {
+ return (
+ ' '
+ );
+ }
-IriSP.Widgets.MultipleChoiceQuestion.prototype.renderQuizTemplate = function(answer, identifier) {
- return ' ';
-}
-
-IriSP.Widgets.MultipleChoiceQuestion.prototype.renderTemplate = function(answer, identifier) {
- var id = this.generateUid();
- return '';
-}
+ renderTemplate(answer, identifier) {
+ var id = this.generateUid();
+ return (
+ ''
+ );
+ }
-IriSP.Widgets.MultipleChoiceQuestion.prototype.renderFullTemplate = function(answer, identifier) {
- var correct = (answer && answer.correct) ? "checked" : "";
- var id = this.generateUid();
- return ' ';
-}
+ renderFullTemplate(answer, identifier) {
+ var correct = answer && answer.correct ? "checked" : "";
+ var id = this.generateUid();
+ return (
+ ' '
+ );
+ }
-IriSP.Widgets.Quiz.prototype.submit = function(user,user_id,question,prop,val) {
- var _this = this;
- var _url = Mustache.to_html(this.analytics_api, {id: this.source.projectId}),
- donnees = {
- "username": user,
- "useruuid": user_id,
- "subject": question,
- "property": prop,
- "value": val,
- "session": _this.session_id
- };
+ submit(user, user_id, question, prop, val) {
+ var _this = this;
+ var _url = Mustache.render(this.analytics_api, {
+ id: this.source.projectId,
+ }),
+ donnees = {
+ username: user,
+ useruuid: user_id,
+ subject: question,
+ property: prop,
+ value: val,
+ session: _this.session_id,
+ };
- IriSP.jQuery.ajax({
+ jQuery.ajax({
url: _url,
type: this.api_method,
- contentType: 'application/json',
+ contentType: "application/json",
data: JSON.stringify(donnees),
- success: function(_data) {
+ success: function (_data) {},
+ error: function (_xhr, _error, _thrown) {
+ ns.log("Error when sending annotation", _thrown);
},
- error: function(_xhr, _error, _thrown) {
- IriSP.log("Error when sending annotation", _thrown);
- }
- });
-}
+ });
+ }
+ };
+};
+
+export { Quiz, UniqueChoiceQuestion, MultipleChoiceQuestion, quizStyles };
\ No newline at end of file