Widget:Sandbox: Difference between revisions
Jump to navigation
Jump to search
Matt Pijoan (talk | contribs) No edit summary |
Matt Pijoan (talk | contribs) No edit summary |
||
(19 intermediate revisions by the same user not shown) | |||
Line 100: | Line 100: | ||
</style> | </style> | ||
<script type="text/javascript">function ensureLoggedIn() { | <script type="text/javascript">function ensureLoggedIn() { | ||
mw.loader.load('mediaWiki.user'); | |||
if ($.isEmptyObject(wgUserName)) { | |||
alert("Please Log In To Continue."); | |||
window.location.replace("http://wikidoc.org/index.php?title=Special:UserLogin&returnto=User%3AMatt+Pijoan"); | |||
} else { | |||
curriculumType(); | |||
} | |||
} | } | ||
function curriculumType() { | function curriculumType() { | ||
Line 467: | Line 467: | ||
} | } | ||
function loadNextQuestion() { | function loadNextQuestion() { | ||
window.exam.examQuestions = []; | |||
if (window.exam.searchMethod === "Category") { | if (window.exam.searchMethod === "Category") { | ||
var api = new mw.Api(window.exam); | var api = new mw.Api(window.exam); | ||
Line 528: | Line 528: | ||
}); | }); | ||
$(".navPaneButton").click(questionNavigation); | $(".navPaneButton").click(questionNavigation); | ||
$(".navPaneButton:odd").css("background-color", "#3338CC"); | $(".navPaneButton:odd").css("background-color", "#3338CC"); | ||
$(".navPaneButton:odd").css("background-color", "#B0B0B0"); | $(".navPaneButton:odd").css("background-color", "#B0B0B0"); | ||
Line 643: | Line 641: | ||
} | } | ||
function addRatyRating() { | function addRatyRating() { | ||
addFirstResponses(); | |||
var ratyLayers = "<center>Rate this question!</center><br /><span style='position:relative; float:left;'>Difficulty: <div id='star1'></div></span><span style='position:relative; float:left;left:33%;'>High Yield: <div id='star2'></div></span><span style='position:relative; float:left;left:66%'>Quality: <div id='star3'></div></span><br /><br /><br />" | var ratyLayers = "<center>Rate this question!</center><br /><span style='position:relative; float:left;'>Difficulty: <div id='star1'></div></span><span style='position:relative; float:left;left:33%;'>High Yield: <div id='star2'></div></span><span style='position:relative; float:left;left:66%'>Quality: <div id='star3'></div></span><br /><br /><br />" | ||
$("#examSpace").prepend(ratyLayers); | $("#examSpace").prepend(ratyLayers); | ||
getRating(window.exam.examQuestions[exam.currentQuestion].PageName, window.exam); | getRating(window.exam.examQuestions[exam.currentQuestion].PageName, window.exam); | ||
} | } | ||
function addFirstResponses(){ | function addFirstResponses() { | ||
var api = new mw.Api(); | |||
api.get({ | api.get({ | ||
action : 'firstResponseQuery', | |||
question : window.exam.examQuestions[exam.currentQuestion].PageName, | |||
format : 'json' | format : 'json' | ||
}) | }) | ||
.done(function (data) { | .done(function (data) { | ||
if (data.firstResponseQuery.A === null) { | |||
data.firstResponseQuery.A = 0; | |||
} | |||
if (data.firstResponseQuery.B === null) { | |||
data.firstResponseQuery.B = 0; | |||
} | |||
if (data.firstResponseQuery.C === null) { | |||
data.firstResponseQuery.C = 0; | |||
} | |||
if (data.firstResponseQuery.D === null) { | |||
data.firstResponseQuery.D = 0; | |||
} | |||
if (data.firstResponseQuery.E === null) { | |||
data.firstResponseQuery.E = 0; | |||
} | |||
data.firstResponseSum = parseInt(data.firstResponseQuery.A) + parseInt(data.firstResponseQuery.B) + parseInt(data.firstResponseQuery.C) + parseInt(data.firstResponseQuery.D) + parseInt(data.firstResponseQuery.E); | |||
$("#Ae").append("<br />Selected as first response:" + parseInt((data.firstResponseQuery.A / data.firstResponseSum) * 100).toString() + "%"); | |||
$("#Be").append("<br />Selected as first response:" + parseInt((data.firstResponseQuery.B / data.firstResponseSum) * 100).toString() + "%"); | |||
$("#Ce").append("<br />Selected as first response:" + parseInt((data.firstResponseQuery.C / data.firstResponseSum) * 100).toString() + "%"); | |||
$("#De").append("<br />Selected as first response:" + parseInt((data.firstResponseQuery.D / data.firstResponseSum) * 100).toString() + "%"); | |||
$("#Ee").append("<br />Selected as first response:" + parseInt((data.firstResponseQuery.E / data.firstResponseSum) * 100).toString() + "%"); | |||
}); | }); | ||
} | } | ||
function answerClicked(event) { | function answerClicked(event) { | ||
$(".answer").removeClass("boxed"); | $(".answer").removeClass("boxed"); | ||
$( | |||
$(event.currentTarget).addClass("boxed"); | |||
$(event.currentTarget.firstChild).prop("checked", true); | |||
$( | window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer = $("div .boxed").attr("id"); | ||
$( | |||
if ($("#exam").find('#submit').length == 0) { | if ($("#exam").find('#submit').length == 0) { | ||
$("#examSpace").append("<div class='noSelect WBRButton' id='submit'><br />Submit</div>"); | $("#examSpace").append("<div class='noSelect WBRButton' id='submit'><br />Submit</div>"); | ||
Line 714: | Line 730: | ||
function answerSubmitted(event) { | function answerSubmitted(event) { | ||
$("#submit").remove(); | $("#submit").remove(); | ||
if (!window.exam.examQuestions[window.exam.currentQuestion].creditRecieved && window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer === window.exam.examQuestions[window.exam.currentQuestion].RightAnswer) { | if (!window.exam.examQuestions[window.exam.currentQuestion].creditRecieved && window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer === window.exam.examQuestions[window.exam.currentQuestion].RightAnswer) { | ||
window.exam.answeredRight += 1; | window.exam.answeredRight += 1; | ||
Line 756: | Line 771: | ||
} | } | ||
function questionNavigation(event) { | function questionNavigation(event) { | ||
if ($(this).attr("id") === "back") { | if ($(this).attr("id") === "back") { | ||
window.exam.currentQuestion--; | window.exam.currentQuestion--; | ||
Line 764: | Line 778: | ||
window.exam.currentQuestion = $(this).attr("id"); | window.exam.currentQuestion = $(this).attr("id"); | ||
} | } | ||
questionDisplay(window.exam); | questionDisplay(window.exam); | ||
} | } | ||
function questionReviewNavigation(event) { | function questionReviewNavigation(event) { | ||
if ($(this).attr("id") === "back") { | if ($(this).attr("id") === "back") { | ||
window.exam.currentQuestion--; | window.exam.currentQuestion--; | ||
Line 776: | Line 788: | ||
window.exam.currentQuestion = $(this).attr("id"); | window.exam.currentQuestion = $(this).attr("id"); | ||
} | } | ||
questionReview(window.exam); | questionReview(window.exam); | ||
} | } | ||
Line 997: | Line 1,008: | ||
} | } | ||
$(document).ready(ensureLoggedIn); | $(document).ready(ensureLoggedIn); | ||
</script> | </script> | ||
<div id="exam">pewp</div> | <div id="exam">pewp</div> | ||
</includeonly> | </includeonly> |