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
 
(16 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');
mw.loader.load('mediaWiki.user');
if ($.isEmptyObject(wgUserName)) {
if ($.isEmptyObject(wgUserName)) {
alert("Please Log In To Continue.");
alert("Please Log In To Continue.");
window.location.replace("http://wikidoc.org/index.php?title=Special:UserLogin&returnto=User%3AMatt+Pijoan");
window.location.replace("http://wikidoc.org/index.php?title=Special:UserLogin&returnto=User%3AMatt+Pijoan");
} else {
} else {
curriculumType();
curriculumType();
}
}
}
}
function curriculumType() {
function curriculumType() {
Line 467: Line 467:
}
}
function loadNextQuestion() {
function loadNextQuestion() {
        window.exam.examQuestions = [];
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);
$("#" + exam.currentQuestion).addClass("boxed");
$(".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();
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();
var api = new mw.Api();
api.get({
api.get({
                action : 'firstResponseQuery',
action : 'firstResponseQuery',
                question : window.exam.examQuestions[exam.currentQuestion].PageName,
question : window.exam.examQuestions[exam.currentQuestion].PageName,
format : 'json'
format : 'json'
})
})
.done(function (data) {
.done(function (data) {
                if(data.firstResponseQuery.A===null){
if (data.firstResponseQuery.A === null) {
                      data.firstResponseQuery.A = 0;
data.firstResponseQuery.A = 0;
                }
}
                if(data.firstResponseQuery.B===null){
if (data.firstResponseQuery.B === null) {
                      data.firstResponseQuery.B = 0;
data.firstResponseQuery.B = 0;
                }
}
                if(data.firstResponseQuery.C===null){
if (data.firstResponseQuery.C === null) {
                      data.firstResponseQuery.C = 0;
data.firstResponseQuery.C = 0;
                }
}
                if(data.firstResponseQuery.D===null){
if (data.firstResponseQuery.D === null) {
                      data.firstResponseQuery.D = 0;
data.firstResponseQuery.D = 0;
                }
}
                if(data.firstResponseQuery.E===null){
if (data.firstResponseQuery.E === null) {
                      data.firstResponseQuery.E = 0;
data.firstResponseQuery.E = 0;
                }
}
var firstResponses = "<table><th colspan='5'>First Responses</th><tr><td>A</td><td>B</td><td>C</td><td>D</td><td>E</td></tr><tr><td>" + data.firstResponseQuery.A + "</td><td>"+ data.firstResponseQuery.B + "</td><td>"+ data.firstResponseQuery.C + "</td><td>"+ data.firstResponseQuery.D + "</td><td>"+ data.firstResponseQuery.E + "</td><td></tr></table>";
data.firstResponseSum = parseInt(data.firstResponseQuery.A) + parseInt(data.firstResponseQuery.B) + parseInt(data.firstResponseQuery.C) + parseInt(data.firstResponseQuery.D) + parseInt(data.firstResponseQuery.E);
                $("#examSpace").prepend(firstResponses);
$("#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");
$('input[type=radio]').prop('checked', function () {
 
return this.getAttribute('checked') == 'checked';
$(event.currentTarget).addClass("boxed");
});
$(event.currentTarget.firstChild).prop("checked", true);
$(this).addClass("boxed");
window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer = $("div .boxed").attr("id");
$(this).find("#Ar").prop("checked", true);
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 729: Line 730:
function answerSubmitted(event) {
function answerSubmitted(event) {
$("#submit").remove();
$("#submit").remove();
window.exam.examQuestions[window.exam.currentQuestion].selectedAnswer = $("div .boxed").attr("id");
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 771: Line 771:
}
}
function questionNavigation(event) {
function questionNavigation(event) {
$("#" + window.exam.currentQuestion).removeClass("boxed");
if ($(this).attr("id") === "back") {
if ($(this).attr("id") === "back") {
window.exam.currentQuestion--;
window.exam.currentQuestion--;
Line 779: Line 778:
window.exam.currentQuestion = $(this).attr("id");
window.exam.currentQuestion = $(this).attr("id");
}
}
$("#" + window.exam.currentQuestion).addClass("boxed");
questionDisplay(window.exam);
questionDisplay(window.exam);
}
}
function questionReviewNavigation(event) {
function questionReviewNavigation(event) {
$("#" + window.exam.currentQuestion).removeClass("boxed");
if ($(this).attr("id") === "back") {
if ($(this).attr("id") === "back") {
window.exam.currentQuestion--;
window.exam.currentQuestion--;
Line 791: Line 788:
window.exam.currentQuestion = $(this).attr("id");
window.exam.currentQuestion = $(this).attr("id");
}
}
$("#" + window.exam.currentQuestion).addClass("boxed");
questionReview(window.exam);
questionReview(window.exam);
}
}
Line 1,012: Line 1,008:
}
}
$(document).ready(ensureLoggedIn);
$(document).ready(ensureLoggedIn);
</script>
</script>
<div id="exam">pewp</div>
<div id="exam">pewp</div>
</includeonly>
</includeonly>

Latest revision as of 16:56, 27 June 2014