Widget:WJG Sandbox: Difference between revisions

Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
<includeonly>
<includeonly>
<script src="http://wikidoc.org/includes/jquery.timer.js"></script>
<script src="http://www.wikidoc.org/includes/raty/jquery.timer.js"></script>
<script type="text/javascript" src="http://wikidoc.org/includes/raty/jquery.raty.js"></script>
<script type="text/javascript" src="http://www.wikidoc.org/includes/raty/jquery.raty.js"></script>
<style type="text/css">
<style type="text/css">
.boxed{
.boxed{
border:2px solid black !important;
border:0px solid black !important;
}
}
.redBoxed{
.redBoxed{
border:2px solid #F00 !important;
border:0px solid #F00 !important;
}
}


Line 47: Line 47:
#examSpace{
#examSpace{
position:relative;
position:relative;
float:left;
float:right;
width:600px;
width:94%;
margin-left:20px
}
}
#navBar{
#navBar{
Line 65: Line 64:
}
}
div.answerNoBorder{
div.answerNoBorder{
border:5px solid #FFF;
border:0px solid #FFF;
}
}
div.answerBorder{
div.answerBorder{
border:5px solid #000;
border:0px solid #000;
}
}
div.explanationHide{
div.explanationHide{
Line 311: Line 310:
for (var i = 0; i < categories['sub'].length; i++) {
for (var i = 0; i < categories['sub'].length; i++) {
if (categories['main'][i]) {
if (categories['main'][i]) {
table += "<tr><td><input type='checkbox' name='MainCat' value='" + categories['main'][i] + "' />" + categories['main'][i] + " ( " + exam.arrCounts['category']['main'][categories['main'][i]] + " ) </td><td><input type='checkbox' name='SubCat' value='" + categories['sub'][i] + "' />" + categories['sub'][i] + " ( " + exam.arrCounts['category']['sub'][categories['sub'][i]] + " )</td></tr>";
table += "<tr><td><input type='checkbox' name='MainCat' value='" + categories['main'][i] + "' />" + categories['main'][i] + " ( " + exam.arrCounts['category']['main'][categories['main'][i]] + " ) </td><td><input type='checkbox' name='SubCat' value='" + categories['sub'][i] + "' />" + categories['sub'][i] + " ( " + exam.arrCounts['category']['sub'][categories['sub'][i]]+ " )</td></tr>";
} else {
} else {
table += "<tr><td></td><td><input type='checkbox' name='SubCat' value='" + categories['sub'][i] + "' />" + categories['sub'][i] + " ( " + exam.arrCounts['category']['sub'][categories['sub'][i]] + " ) </td></tr>";
table += "<tr><td></td><td><input type='checkbox' name='SubCat' value='" + categories['sub'][i] + "' />" + categories['sub'][i] + " ( " + exam.arrCounts['category']['sub'][categories['sub'][i]] + " ) </td></tr>";
Line 475: Line 474:
});
});
$("#" + exam.currentQuestion).addClass("boxed");
$("#" + exam.currentQuestion).addClass("boxed");
$(".navPaneButton:odd").css("background-color", "#B0B0B0");
$(".navPaneButton:odd").css("background-color", "#3338CC");
$(".navPaneButton").click(exam, questionNavigation);
        $(".navPaneButton:odd").css("background-color", "#B0B0B0");
questionDisplay(exam);
questionDisplay(exam);
}
}
Line 491: Line 490:
}
}
if (obj.AnswerAExp && obj.AnswerAExp.length > 0 && exam.examType === "Tutor") {
if (obj.AnswerAExp && obj.AnswerAExp.length > 0 && exam.examType === "Tutor") {
htmlStuff += "<div class='answerExp explanationHide' id='Ae'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp" + obj.AnswerAExp + "</div>";
htmlStuff += "<div class='answerExp explanationHide' id='Ae'>" + trimP(obj.AnswerAExp) + "</div>";
}
}
if (obj.AnswerB && obj.AnswerB.length > 0) {
if (obj.AnswerB && obj.AnswerB.length > 0) {
Line 497: Line 496:
}
}
if (obj.AnswerBExp && obj.AnswerBExp.length > 0 && exam.examType === "Tutor") {
if (obj.AnswerBExp && obj.AnswerBExp.length > 0 && exam.examType === "Tutor") {
htmlStuff += "<div class='answerExp explanationHide' id='Be'><i>&nbsp;&nbsp;&nbsp;&nbsp;" + obj.AnswerBExp + "</i></div>";
htmlStuff += "<div class='answerExp explanationHide' id='Be'>" + trimP(obj.AnswerBExp) + "</div>";
}
}
if (obj.AnswerC && obj.AnswerC.length > 0) {
if (obj.AnswerC && obj.AnswerC.length > 0) {
Line 503: Line 502:
}
}
if (obj.AnswerCExp && obj.AnswerCExp.length > 0 && exam.examType === "Tutor") {
if (obj.AnswerCExp && obj.AnswerCExp.length > 0 && exam.examType === "Tutor") {
htmlStuff += "<div class='answerExp explanationHide' id='Ce'><i>&nbsp;&nbsp;&nbsp;&nbsp;" + obj.AnswerCExp + "</i></div>";
htmlStuff += "<div class='answerExp explanationHide' id='Ce'>" + trimP(obj.AnswerCExp) + "</div>";
}
}
if (obj.AnswerD && obj.AnswerD.length > 0) {
if (obj.AnswerD && obj.AnswerD.length > 0) {
Line 509: Line 508:
}
}
if (obj.AnswerDExp && obj.AnswerDExp.length > 0 && exam.examType === "Tutor") {
if (obj.AnswerDExp && obj.AnswerDExp.length > 0 && exam.examType === "Tutor") {
htmlStuff += "<div class='answerExp explanationHide' id='De'><i>&nbsp;&nbsp;&nbsp;&nbsp;" + obj.AnswerDExp + "</i></div>";
htmlStuff += "<div class='answerExp explanationHide' id='De'>" + trimP(obj.AnswerDExp) + "</div>";
}
}
if (obj.AnswerEExp && obj.AnswerE.length > 0) {
if (obj.AnswerEExp && obj.AnswerE.length > 0) {
Line 515: Line 514:
}
}
if (obj.AnswerEExp && obj.AnswerEExp.length > 0 && exam.examType === "Tutor") {
if (obj.AnswerEExp && obj.AnswerEExp.length > 0 && exam.examType === "Tutor") {
htmlStuff += "<div class='answerExp explanationHide' id='Ee'><i>&nbsp;&nbsp;&nbsp;&nbsp;" + obj.AnswerEExp + "</i></div>";
htmlStuff += "<div class='answerExp explanationHide' id='Ee'>" + trimP(obj.AnswerEExp) + "</div>";
}
}
$("#examSpace").html(htmlStuff);
$("#examSpace").html(htmlStuff);
Line 523: Line 522:
$("div.answer").mouseover(function () {
$("div.answer").mouseover(function () {
$(this).css({
$(this).css({
'border' : '5px solid #000'
'border' : '0px solid #000'
})
})
}).mouseout(function () {
}).mouseout(function () {
$(this).css({
$(this).css({
'border' : '5px solid #FFF'
'border' : '0px solid #FFF'
})
})
});
});
Line 551: Line 550:
}
}
if (obj.AnswerAExp && obj.AnswerAExp.length > 0 && exam.examType === "Tutor") {
if (obj.AnswerAExp && obj.AnswerAExp.length > 0 && exam.examType === "Tutor") {
htmlStuff += "<div class='answerExp explanationHide' id='Ae'><i>&nbsp;&nbsp;&nbsp;&nbsp&nbsp;" + obj.AnswerAExp + "</i></div>";
htmlStuff += "<div class='answerExp explanationHide' id='Ae'><i>&nbsp;&nbsp;&nbsp;&nbsp;" + obj.AnswerAExp + "</i></div>";
}
}
if (obj.AnswerB && obj.AnswerB.length > 0) {
if (obj.AnswerB && obj.AnswerB.length > 0) {
Line 588: Line 587:
$("#" + exam.examQuestions[exam.currentQuestion].selectedAnswer).removeClass("answerNoBorder");
$("#" + exam.examQuestions[exam.currentQuestion].selectedAnswer).removeClass("answerNoBorder");
}
}
$("#examSpace").append("<br /><br />The correct answer is: " + exam.examQuestions[exam.currentQuestion].RightAnswer + "<br /><br /><i>" + exam.examQuestions[exam.currentQuestion].Explanation + "</i><br />");
$("#examSpace").append("<br /><br />The correct answer is: " + exam.examQuestions[exam.currentQuestion].RightAnswer + "<br /><br /><b>" + exam.examQuestions[exam.currentQuestion].Explanation + "</b><br />");
}
}
}
}
Line 594: Line 593:
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(exam.examQuestions[exam.currentQuestion].PageName);
}
function answerClicked(event){
$(".answer").removeClass("boxed");
$('input[type=radio]').prop('checked', function () {
    return this.getAttribute('checked') == 'checked';
});
$(this).addClass("boxed");
$(this).find("#Ar").prop("checked",true);
if($("#exam").find('#submit').length == 0){
$("#examSpace").append("<div class='noSelect WBRButton' id='submit'><br />Submit</div>");
                $("#submit").click(event.data, answerSubmitted);
}
}
function getRating(page) {
var api = new mw.Api();
api.get({
action : 'wbrgetrating',
question : page,
format : 'json'
}, {
ok : function (res) {
$("#star1").raty({
$("#star1").raty({
path : 'http://www.wikidoc.org/includes/raty/img/',
path : 'http://www.wikidoc.org/includes/raty/img/',
click : function (score, event) {
click : function (score, event) {
submitRating("difficulty", score, "Buh")
submitRating("difficulty", score, exam.examQuestions[exam.currentQuestion].PageName)
},
score : function (event) {
getRating("difficulty", exam.examQuestions[exam.currentQuestion].PageName);
},
},
                score: res.wbrgetrating.difficulty,
hints : ['Very Poor', 'Poor', 'Average', 'Good', 'Very Good']
hints : ['Very Poor', 'Poor', 'Average', 'Good', 'Very Good']
});
});
Line 607: Line 629:
path : 'http://www.wikidoc.org/includes/raty/img/',
path : 'http://www.wikidoc.org/includes/raty/img/',
click : function (score, event) {
click : function (score, event) {
submitRating("yield", score, "Buh")
submitRating("yield", score, exam.examQuestions[exam.currentQuestion].PageName)
},
score : function (event) {
getRating("yield", exam.examQuestions[exam.currentQuestion].PageName);
},
},
score: res.wbrgetrating.yield,
hints : ['Very Poor', 'Poor', 'Average', 'Good', 'Very Good']
hints : ['Very Poor', 'Poor', 'Average', 'Good', 'Very Good']
});
});
Line 617: Line 637:
path : 'http://www.wikidoc.org/includes/raty/img/',
path : 'http://www.wikidoc.org/includes/raty/img/',
click : function (score, event) {
click : function (score, event) {
submitRating("quality", score, "Buh")
submitRating("quality", score, exam.examQuestions[exam.currentQuestion].PageName)
},
score : function (event) {
getRating("quality", exam.examQuestions[exam.currentQuestion].PageName);
},
},
score: res.wbrgetrating.quality,
hints : ['Very Poor', 'Poor', 'Average', 'Good', 'Very Good']
hints : ['Very Poor', 'Poor', 'Average', 'Good', 'Very Good']
});
}); }
 
});}
}
function answerClicked(event){
$(".answer").removeClass("boxed");
$('input[type=radio]').prop('checked', function () {
    return this.getAttribute('checked') == 'checked';
});
$(this).addClass("boxed");
$(this).find("#Ar").prop("checked",true);
console.log($(this).children());         
if($("#exam").find('#submit').length == 0){
$("#examSpace").append("<div class='noSelect WBRButton' id='submit'><br />Submit</div>");
                $("#submit").click(event.data, answerSubmitted);
}
}
function answerSubmitted(event) {
function answerSubmitted(event) {
         $("#submit").remove();
         $("#submit").remove();
Line 649: Line 653:
$(".answerExp").css("height", "auto");
$(".answerExp").css("height", "auto");
$(".answerExp").css("visibility", "visible");
$(".answerExp").css("visibility", "visible");
                $(".answerExp").each(function(){
                              if($(this).attr('id') === event.data.examQuestions[event.data.currentQuestion].RightAnswer+"e"){
                                      $(this).prepend("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Correct:</b> ");
                              } else {
                                      $(this).prepend("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Incorrect:</b> ");
                              }
                });
}
}
$("div.answer").unbind('click');
$("div.answer").unbind('click');
Line 724: Line 735:
$(".navPaneButton").click(event.data, questionReviewNavigation);
$(".navPaneButton").click(event.data, questionReviewNavigation);
}
}
function submitRating(type, score, page) {
function submitRating(ratingType, score, page) {
      if(ratingType === "difficulty"){
var api = new mw.Api();
var api = new mw.Api();
api.get({
api.get({
Line 730: Line 742:
username : mw.user.getName(),
username : mw.user.getName(),
question : page,
question : page,
quality : 5,
difficulty : score,
format : 'json'
}, {
ok : function (res) {}
});
} else if (ratingType === "yield"){
var api = new mw.Api();
api.get({
action : 'wbrinsertrating',
username : mw.user.getName(),
question : page,
yield : score,
format : 'json'
format : 'json'
}, {
}, {
Line 736: Line 759:
});
});
}
}
function getRating(type, page) {
else if (ratingType === "quality"){
var api = new mw.Api();
var api = new mw.Api();
api.get({
api.get({
action : 'wbrgetrating',
action : 'wbrinsertrating',
username : mw.user.getName(),
question : page,
question : page,
quality : score,
format : 'json'
format : 'json'
}, {
}, {
ok : function (res) {
ok : function (res) {}
if (type === "difficulty") {
return res.difficulty;
}
if (type === "quality") {
return res.quality;
}
if (type === "yield") {
return res.yield;
}
}
});
});
}
}
}
function parseQuestions(examObj) {
function parseQuestions(examObj) {
var tobeParsed = null;
var tobeParsed = null;

Revision as of 03:12, 1 March 2014