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 |
||
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 643: | Line 643: | ||
} | } | ||
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() + "%"); | |||
}); | }); | ||
} | } | ||
Line 1,012: | Line 1,016: | ||
} | } | ||
$(document).ready(ensureLoggedIn); | $(document).ready(ensureLoggedIn); | ||
</script> | </script> | ||
<div id="exam">pewp</div> | <div id="exam">pewp</div> | ||
</includeonly> | </includeonly> |