-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow javascript in attempts and small demo
- Loading branch information
1 parent
340be86
commit d827cdf
Showing
13 changed files
with
250 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
console.log("Hello world!"); | ||
define(function () { | ||
return { | ||
initButton: function(attempt) { | ||
attempt.getElementById("mybutton").addEventListener("click", function (event) { | ||
event.target.disabled = true; | ||
attempt.getElementById("hiddenInput").value = "secret"; | ||
}) | ||
}, | ||
hello: function(attempt, param) { | ||
console.log("hello " + param);}, | ||
} | ||
}); |
13 changes: 12 additions & 1 deletion
13
examples/static-files/python/local/static_files_example/question_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
examples/static-files/python/local/static_files_example/templates/formulation.xhtml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<div xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:qpy="http://questionpy.org/ns/question"> | ||
<div class="my-custom-class">I have custom styling!</div> | ||
<input type="hidden" name="hidden_value" id="hiddenInput" /> | ||
<input type="button" id="mybutton" value="click here for a 1.0 score" /> | ||
</div> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* This file is part of the QuestionPy SDK. (https://questionpy.org) | ||
* The QuestionPy SDK is free software released under terms of the MIT license. See LICENSE.md. | ||
* (c) Technische Universität Berlin, innoCampus <info@isis.tu-berlin.de> | ||
*/ | ||
|
||
/** | ||
* Unescape and replace HTML entities. | ||
* | ||
* @param {string} input | ||
* @returns {string} | ||
*/ | ||
function htmlDecode(input) { | ||
var txt = document.createElement("textarea"); | ||
txt.innerHTML = input; | ||
return txt.value; | ||
} | ||
|
||
class Attempt { | ||
#formulation; | ||
#generalFeedback; | ||
#specificFeedback; | ||
#rightAnswer; | ||
|
||
/** | ||
* @param {Element} formulationElement | ||
* @param {Element} generalFeedbackElement | ||
* @param {Element} specificFeedbackElement | ||
* @param {Element} rightAnswer | ||
*/ | ||
constructor(formulationElement, generalFeedbackElement, specificFeedbackElement, rightAnswer) { | ||
this.#formulation = formulationElement; | ||
this.#generalFeedback = generalFeedbackElement; | ||
this.#specificFeedback = specificFeedbackElement; | ||
this.#rightAnswer = rightAnswer; | ||
} | ||
|
||
/** | ||
* Get the top html element where the question's formulation xhtml was inserted. | ||
* | ||
* @returns {Element} | ||
*/ | ||
get formulationElement() { | ||
return this.#formulation; | ||
} | ||
|
||
/** | ||
* Get the top html element where the question's general feedback xhtml was inserted. | ||
* | ||
* @returns {Element} | ||
*/ | ||
get generalFeedbackElement() { | ||
return this.#generalFeedback; | ||
} | ||
|
||
/** | ||
* Get the top html element where the question's specific feedback xhtml was inserted. | ||
* | ||
* @returns {Element} | ||
*/ | ||
get specificFeedbackElement() { | ||
return this.#specificFeedback; | ||
} | ||
|
||
/** | ||
* Get the top html element where the question's right answer xhtml was inserted. | ||
* | ||
* @returns {Element} | ||
*/ | ||
get rightAnswerElement() { | ||
return this.#rightAnswer; | ||
} | ||
|
||
/** | ||
* Get an element by the id that was given in the question's xhtml. | ||
* | ||
* @param {string} id | ||
* @return {?Element} | ||
*/ | ||
getElementById(id) { | ||
return document.getElementById(id); | ||
} | ||
|
||
/** | ||
* Get an element by the name that was given in the question's xhtml. | ||
* | ||
* @param {string} name | ||
* @return {NodeListOf<Element>} | ||
*/ | ||
getElementsByName(name) { | ||
return document.getElementsByName(name); | ||
} | ||
} |
Oops, something went wrong.