Widget:SandboxNew: Difference between revisions
Jump to navigation
Jump to search
Matt Pijoan (talk | contribs) No edit summary |
Matt Pijoan (talk | contribs) No edit summary |
||
Line 36: | Line 36: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
var countdownTimer, countdownCurrent; | var countdownTimer, countdownCurrent; | ||
$.getScript("http://wikidoc.org/includes/jquery.timer.js", function (){ | $.getScript("http://wikidoc.org/includes/jquery.timer.js", function () { | ||
$(document).ready(function(){ | $(document).ready(function () { | ||
countdownTimer = $.timer(function () { | |||
var min = parseInt(countdownCurrent / 6000); | |||
var sec = parseInt(countdownCurrent / 100) - (min * 60); | |||
var micro = pad(countdownCurrent - (sec * 100) - (min * 6000), 2); | |||
var output = "00"; | |||
if (min > 0) { | |||
output = pad(min, 2); | |||
} | |||
$('.countdowntime').html(output + ":" + pad(sec, 2)); | |||
if (countdownCurrent == 0) { | |||
countdownTimer.stop(); | |||
endExam(); | |||
} else { | |||
countdownCurrent -= 7; | |||
if (countdownCurrent < 0) { | |||
countdownCurrent = 0; | |||
} | |||
} | |||
}, 70, false); | |||
}); | |||
}); | }); | ||
$(document).ready(function () { | |||
$.getScript("http://wikidoc.org/resources/mediawiki.api/mediawiki.api.js", function () { | |||
if (!mw.user.name()) { | |||
alert("Please Log In To Continue."); | |||
window.location.replace("http://wikidoc.org/index.php?title=Special:UserLogin&returnto=User%3AMatt+Pijoan"); | |||
} | |||
}); | |||
}); | }); | ||
function endExam() { | |||
hideButtons(); | |||
var correct = 0; | |||
var Results = $("input[name='results']").val().split(","); | |||
for (var i = 0; i < Results.length; i++) { | |||
if (Results[i].valueOf() == new String("true").valueOf()) { | |||
correct++; | |||
} | |||
function endExam(){ | } | ||
hideButtons(); | var n = (100 / Results.length) * correct; | ||
var correct = 0; | var Q = document.getElementById('question'); | ||
var Results = $("input[name='results']").val().split(","); | Q.innerHTML = "<h2>Exam Results:</h2>"; | ||
for (var i=0;i<Results.length;i++){ | Q.innerHTML += "<br /><br /><b>Questions Asked:</b> " + Results.length.toString(); | ||
if(Results[i].valueOf() == new String("true").valueOf()){ | Q.innerHTML += "<br /><br /><b>Questions Answered Correctly:</b> " + correct.toString(); | ||
correct++; | Q.innerHTML += "<br /><br /><b>Score:</b> " + Math.floor(n).toString() + "%"; | ||
} | Q.innerHTML += "<form><input type='button' onclick='location.reload()' value='Back to start' /><input type='button' onclick='selectExam()' value='Start a new exam' /></form>"; | ||
} | return; | ||
var n = (100 / Results.length ) * correct; | |||
var Q = document.getElementById('question'); | |||
Q.innerHTML = "<h2>Exam Results:</h2>"; | |||
Q.innerHTML += "<br /><br /><b>Questions Asked:</b> " + Results.length.toString(); | |||
Q.innerHTML += "<br /><br /><b>Questions Answered Correctly:</b> " + correct.toString(); | |||
Q.innerHTML += "<br /><br /><b>Score:</b> " + Math.floor(n).toString() + "%"; | |||
Q.innerHTML += "<form><input type='button' onclick='location.reload()' value='Back to start' /><input type='button' onclick='selectExam()' value='Start a new exam' /></form>"; | |||
return; | |||
} | } | ||
function loginCheck(arg, exam){ | function loginCheck(arg, exam) { | ||
var Q = document.getElementById('question'); | var Q = document.getElementById('question'); | ||
var form = "Man Mode: <input type='radio' name='type' id='type' value='ph' /> Korean Mode: <input type='radio' name='type' id='type' value='fc' />"; | var form = "Man Mode: <input type='radio' name='type' id='type' value='ph' /> Korean Mode: <input type='radio' name='type' id='type' value='fc' />"; | ||
Q.innerHTML = form; | Q.innerHTML = form; | ||
$("input[name='type']").click(function(){ | $("input[name='type']").click(function () { | ||
$("input[name='FC']").val($("input[name='type']:checked").val()); | $("input[name='FC']").val($("input[name='type']:checked").val()); | ||
var form = "Timer?<br />Yes <input type='radio' name='timer' value=1 /> No: <input type='radio' name='timer' value=0 />"; | var form = "Timer?<br />Yes <input type='radio' name='timer' value=1 /> No: <input type='radio' name='timer' value=0 />"; | ||
Q.innerHTML = form; | Q.innerHTML = form; | ||
$("input[name='timer']").click(function(){ | $("input[name='timer']").click(function () { | ||
if($("input[name='timer']:checked").val()==='1'){ | if ($("input[name='timer']:checked").val() === '1') { | ||
var sel = "<select name='amt' id='amt'><option disabled selected>Choose</option><option value='1'>1</option><option value='30'>30</option><option value='40'>40</option></select>"; | var sel = "<select name='amt' id='amt'><option disabled selected>Choose</option><option value='1'>1</option><option value='30'>30</option><option value='40'>40</option></select>"; | ||
Q.innerHTML = sel; | Q.innerHTML = sel; | ||
$("#amt").change(function(){ | $("#amt").change(function () { | ||
countdownCurrent = parseInt($("#amt").val())*6000; | countdownCurrent = parseInt($("#amt").val()) * 6000; | ||
examHandler(arg, exam); | examHandler(arg, exam); | ||
}); | }); | ||
} else { | } else { | ||
examHandler(arg, exam); | examHandler(arg, exam); | ||
} | } | ||
}); | }); | ||
}); | }); | ||
} | } | ||
function pad(number, length) { | function pad(number, length) { | ||
var str = '' + number; | var str = '' + number; | ||
while (str.length < length) {str = '0' + str;} | while (str.length < length) { | ||
str = '0' + str; | |||
} | |||
return str; | return str; | ||
} | } | ||
function examHandler(arg,exam){ | function examHandler(arg, exam) { | ||
if(arg === 'Random'){ | if (arg === 'Random') { | ||
selectExam(exam); | selectExam(exam); | ||
} else if(arg === 'Queue'){ | } else if (arg === 'Queue') { | ||
queueExam(); | queueExam(); | ||
} else { | } else { | ||
alert("Wat."); | alert("Wat."); | ||
} | |||
$('#next').on('click', function (event) { | |||
var Q = document.getElementById('question'); | |||
Q.innerHTML = ""; | |||
var Questions = $("input[name='stash']").val().split(","); | |||
var Pos = parseInt($("input[name='pos']").val()); | |||
if (Pos < Questions.length) { | |||
$("input[name='pos']").val(Pos + 1); | |||
loadQuestion(); | |||
} else { | |||
endExam(); | |||
return; | |||
} | |||
}); | |||
$('#home').on('click', function (event) { | |||
location.reload(); | |||
}); | |||
$('#back').on('click', function (event) { | |||
var Q = document.getElementById('question'); | |||
Q.innerHTML = ""; | |||
var Questions = $("input[name='stash']").val().split(","); | |||
var Pos = parseInt($("input[name='pos']").val()); | |||
if (Pos > 0) { | |||
$("input[name='pos']").val(Pos - 1); | |||
loadQuestion(); | |||
} else { | |||
alert("Already at beginning"); | |||
} | |||
}); | |||
} | } | ||
function questionCount(exam, main, sub) { | |||
var | var queryString = "[[ ExamType :: " + exam + " ]] [[ MainCategory :: "; | ||
for (var i = 0; i < main.length; i++) { | |||
queryString += main[i]; | |||
if (i != main.length - 1) { | |||
queryString += " || "; | |||
} | |||
} | |||
queryString += " ]] [[ SubCategory :: "; | |||
for (var j = 0; j < sub.length; j++) { | |||
queryString += sub[j]; | |||
if (i != sub.length - 1) { | |||
queryString += " || "; | |||
} | |||
} | |||
queryString += " ]]"; | |||
var api = new mw.Api(); | |||
api.post({ | |||
action : 'ask', | |||
query : queryString, | |||
format : 'json', | |||
async : false | |||
}, { | |||
ok : function (data) { | |||
alert(Object.keys(data.query.results).length); | |||
} | |||
}); | |||
} | } | ||
else { | |||
function queueExam() { | |||
var api = new mw.Api(); | |||
var result; | |||
var pageString = "User:" + mw.user.name() + "/WBRQueue"; | |||
api.get({ | |||
action : 'query', | |||
format : 'json', | |||
titles : pageString, | |||
export : 'export', | |||
}, { | |||
ok : function (data) { | |||
var xml = data.query.export["*"]; | |||
xmlDoc = $.parseXML(xml), | |||
$xml = $(xmlDoc), | |||
$title = $xml.find("text"); | |||
if ($title.text().indexOf('Placeholder,') == -1) { | |||
addNewSection("User:" + mw.user.name() + "/WBRQueue", 'Placeholder,', mw.user.tokens.get('editToken')); | |||
alert('First Timah!'); | |||
return false; | |||
} | |||
var Questions = $title.text().split(","); | |||
Questions = jQuery.grep(Questions, function (value) { | |||
return value != 'Placeholder'; | |||
}); | |||
if (Questions.length < 1) { | |||
alert("You do not have a Queue!"); | |||
return false; | |||
} else { | |||
$("input[name='stash']").val(Questions); | |||
var Q = document.getElementById('question'); | |||
Q.innerHTML = ""; | |||
$('#next').css('visibility', 'visible'); | |||
} | |||
} | |||
}); | |||
} | } | ||
}); | function selectExam(exam) { | ||
var Q = document.getElementById('question'); | |||
if (exam === "MCAT") { | |||
var mc = new Array("Biology", "Cell", "Enzymes", "Microbiology", "Cellular Metabolism", "Reproduction", "Embryology", "Musculoskeletal System", "Digestive System ", "Excretory System", "Respiratory System", "Skin", "Circulatory System", "Immune System", "Homeostasis", "Endocrine System", "Nervous System ", "Genetics", "Evolution", "Organic Chemistry", "Nomenclature", "Bonding/Structure", "Isomers", "Alkanes", "AlkenesAlkynes", "Haloalkanes", "Aromatic Compounds", "Alcohols", "Ethers", "Aldehydes ", "Ketones", "Carboxylic Acid", "Carboxylic Acid Derivatives", "Amines", "Nitrogen Containing Compounds", "Purification", "Spectroscopy", "Separations", "Carbohydrates", "Amino Acids", "Peptides", "Proteins", "Nucleic", "Acids", "Chemistry", "Atomic Structure", "Periodic Table", "Phases", "Gases", "Bonding", "Stoichiometry", "Kinetics", "Thermochemistry", "Phases", "Solutions", "Acids and Bases", "Redox Reactions", "Electrochemistry", "Physics", "Kinematics", "Fluids", "Solids", "Newtonian Mechanics", "Momentum", "Energy", "Thermodynamics", "Electrostatics", "Magnetism", "DC Circuits", "AC Circuits", "Periodic Motion", "Waves", "Sound", "Optics", "Light", "Atomic Phenomena", "Nuclear Phenomena"); | |||
var tableTemp = "<table style='width:100%;'><th><td><b>Keyword</b></td></th><tr>"; | |||
for (var i = 0; i < mc.length; i++) { | |||
tableTemp += "<td><input type='checkbox' name='MainCat' value='" + mc[i] + "' />" + mc[i] + "</td>"; | |||
if ((i + 1) % 4 == 0) { | |||
tableTemp += "</tr><tr>"; | |||
} | |||
} | |||
Q.innerHTML += tableTemp + "</tr></table><input type='checkbox' name='SubCat' style='visibility:hidden' value='MCAT' checked />"; | |||
} else { | |||
var categories = new Array(); | |||
if (exam === "USMLE Step 1") { | |||
categories['main'] = new Array("Anatomy", "Behavioral Science/Psychiatry", "Biochemistry", "Biostatistics/ Epidemiology", "Embryology", "Ethics", "Genetics", "Histology", "Immunology", "Microbiology", "Pathology", "Pathophysiology", "Pharmacology", "Physiology"); | |||
categories['sub'] = new Array("Cardiology", "Dermatology", "Endocrine", "Gastrointestinal", "Genitourinary", "Head and Neck", "Hematology", "Musculoskeletal/Rheumatology", "Neurology", "Oncology", "Pulmonology", "Reproductive", "Renal", "Vascular", "General Principles", "Infectious Disease"); | |||
} else if (exam === "USMLE Step 2 CK") { | |||
categories['main'] = new Array("Internal medicine", "Surgery", "OB/GYN", "Pediatrics", "Psychiatry"); | |||
categories['sub'] = new Array("Allergy/Immunology", "Cardiovascular", "Dermatology", "Endocrine", "Gastrointestinal", "Hepatology", "Genitourinary", "Head and Neck", "Hematology", "Infectious Disease", "Musculoskeletal/Rheumatology", "Neurology", "Obstetrics & Gynecology", "Oncology", "Ophthalmology", "Pediatrics", "Poisoning", "Preventive Medicine", "Psychiatry", "Respiratory", "Surgery", "Biostatistics/ Epidemiology", "Ethics", "Electrolytes", "Genetics", "Miscellaneous"); | |||
} else if (exam === "USMLE Step 3") { | |||
categories['main'] = new Array("Community Medical Health Center", "Primary Care Office", "Inpatient Facilities", "Emergency Room"); | |||
categories['sub'] = new Array("Allergy/Immunology", "Cardiovascular", "Dermatology", "Endocrine", "Gastrointestinal", "Hepatology", "Genitourinary", "Head and Neck", "Hematology", "Infectious Disease", "Musculoskeletal/Rheumatology", "Neurology", "Obstetrics & Gynecology", "Oncology", "Ophthalmology", "Pediatrics", "Poisoning", "Preventive Medicine", "Psychiatry", "Respiratory", "Surgery", "Biostatistics/ Epidemiology", "Ethics", "Electrolytes", "Genetics", "Miscellaneous"); | |||
} else if (exam === "Board Review") { | |||
categories['main'] = new Array("Adolescent Medicine", "Advanced Heart Failure and Transplant Cardiology", "Allergy & Immunology", "Cardiovascular Disease", "Clinical Cardiac Electrophysiology", "Critical Care Medicine", "Endocrinology", "Diabetes & Metabolism", "Gastroenterology", "Geriatric Medicine", "Hematology", "Hospice & Palliative Medicine", "Hospital Medicine", "Focused Practice", "Infectious Disease", "Internal Medicine", "Interventional Cardiology", "Medical Oncology", "Nephrology", "Pulmonary Disease", "Rheumatology", "Sleep Medicine", "Sports Medicine", "Transplant Hepatology"); | |||
categories['sub'] = new Array("Anesthesiology", "Dermatology", "Emergency Medicine", "Emergency Medicine/Critical Care Medicine", "Family Medicine", "Medical Genetics", "Neurology", "Nuclear Medicine", "Pediatrics", "Physical Medicine & Rehab", "Preventative Medicine", "Psychiatry"); | |||
} else { | |||
alert('Coming Soon!'); | |||
location.reload(); | |||
return false; | |||
} | |||
var table = "<center><h1>Build your own exam!</h1></center><br /><br /><b>First: Select All That Apply:</b><br /><br /><br />"; | |||
table += "<table style='width:100%;'><tr><td style='width:49%;'><b>Main Category</b></td><td style='width:49%;'><b>Sub Category</b></td></tr>"; | |||
if (categories['sub'].length >= categories['main'].length) { | |||
for (var i = 0; i < categories['sub'].length; i++) { | |||
if (categories['main'][i]) { | |||
table += "<tr><td><input type='checkbox' name='MainCat' value='" + categories['main'][i] + "' />" + categories['main'][i] + "</td><td><input type='checkbox' name='SubCat' value='" + categories['sub'][i] + "' />" + categories['sub'][i] + "</td></tr>"; | |||
} else { | |||
table += "<tr><td></td><td><input type='checkbox' name='SubCat' value='" + categories['sub'][i] + "' />" + categories['sub'][i] + "</td></tr>"; | |||
} | |||
} | |||
} else { | |||
for (var i = 0; i < categories['main'].length; i++) { | |||
if (categories['sub'][i]) { | |||
table += "<tr><td><input type='checkbox' name='MainCat' value='" + categories['main'][i] + "' />" + categories['main'][i] + "</td><td><input type='checkbox' name='SubCat' value='" + categories['sub'][i] + "' />" + categories['sub'][i] + "</td></tr>"; | |||
} else { | |||
table += "<tr><td><input type='checkbox' name='MainCat' value='" + categories['main'][i] + "' />" + categories['main'][i] + "</td><td></td></tr>"; | |||
} | |||
} | |||
} | |||
table += "</table>" | |||
var Q = document.getElementById('question'); | |||
Q.innerHTML = table; | |||
} | |||
Q.innerHTML += "<div id='SelectAll' class='noSelect WBRButton'>Select All Main Categories</div><div id='UnselectAll' class='noSelect WBRButton'>Select All Sub Categories</div><div id='CountQ' class='noSelect WBRButton'>Count Questions</div><br /><br /><br /><br /><b>Second: choose the number of questions you would like to answer. The maximum number of questions you can select is 45.</b><br /><br /><br />Number of questions:<input type='text' id='numQues' /><br /><br /><div id='Go' class='noSelect WBRButton'>Click here to begin the exam</div>"; | |||
$("#Go").click(function () { | |||
if (countdownCurrent) { | |||
countdownTimer.toggle(); | |||
} | |||
var Mfields = $("[name=MainCat]").serializeArray(); | |||
var Sfields = $("[name=SubCat]").serializeArray(); | |||
var sMain = new Array(); | |||
var sSub = new Array(); | |||
if (Mfields.length === 0) { | |||
alert('No Main Category Selected'); | |||
selectExam(); | |||
} else if (Sfields.length === 0) { | |||
alert('No Sub Category Selected'); | |||
selectExam(); | |||
} else if (!parseInt($("#numQues").val())) { | |||
alert('Invalid Number of Quesitons'); | |||
selectExam(); | |||
} else if (parseInt($("#numQues").val()) > 45) { | |||
alert('Too Many Questions'); | |||
selectExam(); | |||
} else if (parseInt($("#numQues").val()) <= 1) { | |||
alert('Too Few Questions'); | |||
selectExam(); | |||
} else { | |||
$("[name=MainCat]:checked").each(function () { | |||
sMain.push($(this).val()); | |||
}); | |||
$("[name=SubCat]:checked").each(function () { | |||
sSub.push($(this).val()); | |||
}); | |||
var numQues = $("#numQues").val(); | |||
var Questions = loadExam(exam, numQues, sSub, sMain).toString(); | |||
$("input[name='stash']").val(Questions); | |||
var Q = document.getElementById('question'); | |||
Q.innerHTML = ""; | |||
$('#home').css('visibility', 'visible'); | |||
loadQuestion(); | |||
} | |||
}); | |||
$("#SelectAll").click(function () { | |||
if ($("#SelectAll").html() === "Select All Main Categories") { | |||
$("[name=MainCat]").each(function () { | |||
$(this).attr('checked', true); | |||
$("#SelectAll").html("Clear All Main Categories"); | |||
}); | |||
} else { | |||
$("[name=MainCat]").each(function () { | |||
$(this).attr('checked', false); | |||
$("#SelectAll").html("Select All Main Categories"); | |||
}); | |||
} | |||
}); | |||
$("#UnselectAll").click(function () { | |||
if ($("#UnselectAll").html() === "Select All Sub Categories") { | |||
$("[name=SubCat]").each(function () { | |||
$(this).attr('checked', true); | |||
$("#UnselectAll").html("Clear All Sub Categories"); | |||
}); | |||
} else { | |||
$("[name=SubCat]").each(function () { | |||
$(this).attr('checked', false); | |||
$("#UnselectAll").html("Select All Sub Categories"); | |||
}); | |||
} | |||
}); | |||
$("#CountQ").click(function () { | |||
var sMain = new Array(); | |||
var sSub = new Array(); | |||
$("[name=MainCat]:checked").each(function () { | |||
sMain.push($(this).val()); | |||
$( | }); | ||
$("[name=SubCat]:checked").each(function () { | |||
sSub.push($(this).val()); | |||
}); | |||
questionCount(exam, sMain, sSub); | |||
}); | |||
}); | |||
} | } | ||
function | function loadExam(exam, numQues, SubCat, MainCat) { | ||
var | $.ajaxSetup({ | ||
async : false | |||
}); | |||
var Questions = new Array(); | |||
while (numQues > Questions.length) { | |||
var api = new mw.Api(); | |||
var QueryString = '[[ExamType::' + exam + ']] [[MainCategory::' + MainCat[Math.floor(Math.random() * MainCat.length)] + ']] [[SubCategory::' + SubCat[Math.floor(Math.random() * SubCat.length)] + ']]'; | |||
api.get({ | |||
action : 'ask', | |||
query : QueryString, | |||
format : 'json', | |||
async : false | |||
}, { | |||
ok : function (data) { | |||
$.each(data.query.results, function (index, value) { | |||
Questions.push(index); | |||
api. | }); | ||
} | |||
}) | |||
.error(function (error) { | |||
$.each(error, function (key, value) { | |||
alert(key + ': ' + value); | |||
ok: function (data) { | }); | ||
}); | |||
}}); | } | ||
return Questions; | |||
} | } | ||
function | function loadQuestion() { | ||
var | var Questions = $("input[name='stash']").val().split(","); | ||
var | var name = Questions[parseInt($("input[name='pos']").val()) - 1]; | ||
$.ajaxSetup({ | |||
async : false | |||
}); | |||
var right = " "; | |||
var qs = "[[" + name + "]]|?PageAuthor|?Prompt|?RightAnswer|?AnswerA|?AnswerB|?AnswerC|?AnswerD|?AnswerE|?Explanation|?AnswerAExp|?AnswerBExp|?AnswerCExp|?AnswerDExp|?AnswerEExp|?WBRImage|?WBRImageCaption|?WBRImagePlace"; | |||
var api = new mw.Api(); | |||
api.get({ | |||
action : 'ask', | |||
query : qs, | |||
format : 'json' | |||
}, { | |||
ok : function (data) { | |||
hideButtons(); | |||
$.each(data.query.results, function (index, value) { | |||
var short = value.printouts; | |||
var temp = $("input[name='stash']").val().split(","); | |||
var Q = document.getElementById('question'); | |||
var author = ' '; | |||
if (short.PageAuthor['0']) { | |||
author = short.PageAuthor['0']; | |||
} | |||
Q.innerHTML = "<b>Author:</b> " + author + "<br /><br /><b>Question " + $("input[name='pos']").val() + " / " + temp.length + "</b><br /><br />" + short.Prompt + "<br /><div id='promptImage' class='imageDiv'></div><br />"; | |||
right = short.RightAnswer; | |||
if (short.AnswerA.length > 0) { | |||
Q.innerHTML += "<div style='border:5px solid #FFF;' class='answer' id='A'> A. " + short.AnswerA + "<div id='AnsAImage' class='imageDiv'></div></div>"; | |||
} | |||
if (short.AnswerAExp.length > 0) { | |||
if( | Q.innerHTML += "<div style='height:0px; visibility:hidden;border:3px solid #FFF;' class='answerExp' id='Ae'><i> " + short.AnswerAExp['0'].fulltext + "</i></div>"; | ||
Q.innerHTML += | } | ||
if (short.AnswerB.length > 0) { | |||
Q.innerHTML += "<div style='border:5px solid #FFF;border:3px solid #FFF;' class='answer' id='B'> B. " + short.AnswerB + "<div id='AnsBImage' class='imageDiv'></div></div>"; | |||
} | |||
if (short.AnswerBExp.length > 0) { | |||
Q.innerHTML += "<div style='height:0px; visibility:hidden;' class='answerExp' id='Be'><i> " + short.AnswerBExp['0'].fulltext + "</i></div>"; | |||
} | |||
if (short.AnswerC.length > 0) { | |||
Q.innerHTML += "<div style='border:5px solid #FFF;border:3px solid #FFF;' class='answer' id='C'> C. " + short.AnswerC + "<div id='AnsCImage' class='imageDiv'></div></div>"; | |||
} | |||
if (short.AnswerCExp.length > 0) { | |||
Q.innerHTML += "<div style='height:0px; visibility:hidden;' class='answerExp' id='Ce'><i> " + short.AnswerCExp['0'].fulltext + "</i></div>"; | |||
} | } | ||
if (short.AnswerD.length > 0) { | |||
Q.innerHTML += "<div style='border:5px solid #FFF;border:3px solid #FFF;' class='answer' id='D'> D. " + short.AnswerD + "<div id='AnsDImage' class='imageDiv'></div></div>"; | |||
} | } | ||
if (short.AnswerDExp.length > 0) { | |||
Q.innerHTML += "<div style='height:0px; visibility:hidden;' class='answerExp' id='De'><i> " + short.AnswerDExp['0'].fulltext + "</i></div>"; | |||
} | |||
if (short.AnswerE.length > 0) { | |||
Q.innerHTML += "<div style='border:5px solid #FFF;border:3px solid #FFF;' class='answer' id='E'> E. " + short.AnswerE + "<div id='AnsEImage' class='imageDiv'></div></div>"; | |||
} | |||
if( | if (short.AnswerEExp.length > 0) { | ||
Q.innerHTML += "<div style='height:0px; visibility:hidden;' class='answerExp' id='Ee'><i> " + short.AnswerEExp['0'].fulltext + "</i></div>"; | |||
} | |||
} | |||
if (short.WBRImage) { | |||
for (var i = 0; i < short.WBRImage.length; i++) { | |||
if (short.WBRImagePlace[i] === "Prompt") { | |||
document.getElementById('promptImage').innerHTML += getImage(short.WBRImage[i], short.WBRImageCaption[i]); | |||
} | |||
if (short.WBRImagePlace[i] === "Answer A") { | |||
document.getElementById('AnsAImage').innerHTML += getImage(short.WBRImage[i], short.WBRImageCaption[i]); | |||
} | |||
if (short.WBRImagePlace[i] === "Answer B") { | |||
document.getElementById('AnsBImage').innerHTML += getImage(short.WBRImage[i], short.WBRImageCaption[i]); | |||
} | |||
if (short.WBRImagePlace[i] === "Answer C") { | |||
document.getElementById('AnsCImage').innerHTML += getImage(short.WBRImage[i], short.WBRImageCaption[i]); | |||
} | |||
if (short.WBRImagePlace[i] === "Answer D") { | |||
document.getElementById('AnsDImage').innerHTML += getImage(short.WBRImage[i], short.WBRImageCaption[i]); | |||
} | |||
if (short.WBRImagePlace[i] === "Answer E") { | |||
document.getElementById('AnsEImage').innerHTML += getImage(short.WBRImage[i], short.WBRImageCaption[i]); | |||
} | |||
} | |||
} | |||
$("div.answer").mouseover(function () { | |||
$(this).css({ | |||
'border' : '5px solid #000' | |||
}) | |||
}).mouseout(function () { | |||
$(this).css({ | |||
'border' : '5px solid #FFF' | |||
}) | |||
}); | |||
$("div.answer").click(function () { | |||
var Results = $("input[name='results']").val().split(","); | |||
var Pos = parseInt($("input[name='pos']").val()) - 1; | |||
$(".answerExp").css("height", "auto"); | |||
$(".answerExp").css("visibility", "visible"); | |||
$("div#" + $(this).attr("id")).css({ | |||
'border' : '5px solid #000' | |||
}); | |||
$("div#" + short.RightAnswer.valueOf()).css({ | |||
'color' : '#F00' | |||
}); | |||
if (short.RightAnswer.valueOf() == $(this).attr("id").valueOf()) { | |||
Results[Pos] = true; | |||
removeFromQueue(value.fulltext); | |||
} else { | |||
Results[Pos] = false; | |||
addToQueue(value.fulltext); | |||
} | |||
Q.innerHTML += "<br /><br />The correct answer is: " + short.RightAnswer.valueOf() + "<br /><br /><i>" + short.Explanation + "</i><div id='ExpImage'></div><br />"; | |||
if (short.WBRImage) { | |||
for (var i = 0; i <= short.WBRImage.length; i++) { | |||
if (short.WBRImagePlace[i] === "Prompt") { | |||
document.getElementById('ExpImage') | |||
} | |||
} | |||
} | |||
$("input[name='results']").val(Results.toString()); | |||
showButtons(); | |||
$("input[name='stash']").val(Questions.toString()); | |||
}); | |||
}); | }); | ||
} | |||
}); | |||
} | } | ||
function getImage(filename, caption){ | function getImage(filename, caption) { | ||
var api = new mw.Api(); | |||
var result; | |||
api.get({ | |||
action : 'parse', | |||
text : '[[File:' + filename + ']]', | |||
format : 'json', | |||
async : false | |||
}, { | |||
ok: function(data) { | ok : function (data) { | ||
result = data.parse.text['*']; | |||
}}); | } | ||
}); | |||
if (caption === "no-display") { | |||
return result; | |||
} else { | |||
result += caption; | |||
return result; | |||
} | |||
} | } | ||
function showButtons(){ | function showButtons() { | ||
$('#next').css('visibility','visible'); | $('#next').css('visibility', 'visible'); | ||
$('#back').css('visibility','visible'); | $('#back').css('visibility', 'visible'); | ||
} | } | ||
function hideButtons(){ | function hideButtons() { | ||
$('#next').css('visibility','hidden'); | $('#next').css('visibility', 'hidden'); | ||
$('#back').css('visibility','hidden'); | $('#back').css('visibility', 'hidden'); | ||
} | } | ||
function removeFromQueue(question) { | |||
var api = new mw.Api(); | |||
var result; | |||
var pageString = "User:" + mw.user.name() + "/WBRQueue"; | |||
api.get({ | |||
action : 'query', | |||
format : 'json', | |||
titles : pageString, | |||
export : 'export', | |||
}, { | |||
ok : function (data) { | |||
var xml = data.query.export["*"]; | |||
xmlDoc = $.parseXML(xml), | |||
$xml = $(xmlDoc), | |||
$title = $xml.find("text"); | |||
if ($title.text().indexOf(question) != -1) { | |||
var pageContent = $title.text().split(','); | |||
pageContent = jQuery.grep(pageContent, function (value) { | |||
return value != question; | |||
}); | |||
var token = mw.user.tokens.get('editToken') | |||
addNewSection("User:" + mw.user.name() + "/WBRQueue2", question, token); | |||
} | |||
} | |||
}); | |||
return result; | |||
var token = mw.user.tokens.get( 'editToken' ) | |||
addNewSection( "User:" + mw.user.name() + "/WBRQueue2",question, token ); | |||
} | |||
}}); | |||
return result; | |||
} | } | ||
function addToQueue(question){ | function addToQueue(question) { | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
var result; | var result; | ||
var pageString = | var pageString = "User:" + mw.user.name() + "/WBRQueue"; | ||
api.get( { | api.get({ | ||
action : 'query', | |||
format : 'json', | |||
titles : pageString, | |||
export : 'export', | |||
}, { | |||
ok:function (data) { | ok : function (data) { | ||
var xml = data.query.export["*"]; | |||
xmlDoc = $.parseXML(xml), | |||
$xml = $(xmlDoc), | |||
$title = $xml.find("text"); | |||
var pageContent = $title.text().split(','); | var pageContent = $title.text().split(','); | ||
pageContent.push(question); | pageContent.push(question); | ||
var token = mw.user.tokens.get( 'editToken' ); | var token = mw.user.tokens.get('editToken'); | ||
addNewSection( "User:" + mw.user.name() + "/WBRQueue",question, token ); | addNewSection("User:" + mw.user.name() + "/WBRQueue", question, token); | ||
}}); | } | ||
return result; | }); | ||
return result; | |||
} | } | ||
function addNewSection(title, content, editToken) { | |||
function addNewSection( title, content, editToken ) { | $.ajaxSetup({ | ||
$.ajaxSetup({async: false}); | async : false | ||
}); | |||
$.ajax({ | |||
url : mw.util.wikiScript('api'), | |||
data : { | |||
format : 'json', | |||
action : 'edit', | |||
title : title, | |||
text : content, | |||
token : editToken, | |||
recreate : 'r', | |||
}, | |||
dataType : 'json', | |||
type : 'POST', | |||
success : function (data) { | |||
if (data && data.edit && data.edit.result == 'Success') { | |||
// reload page if edit was successful | |||
} else if (data && data.error) { | |||
alert('Error: Not Logged In'); | |||
} else { | |||
alert('Error: Not Logged In'); | |||
} | |||
}, | |||
error : function (xhr) { | |||
alert('Error: Not Logged In. Please log in to create a Question.'); | |||
} | |||
}); | |||
} | } | ||
$('#changeslist').ready(function() { | $('#changeslist').ready(function () { | ||
$.getScript("http://wikidoc.org/resources/mediawiki.api/mediawiki.api.js", function(){ | $.getScript("http://wikidoc.org/resources/mediawiki.api/mediawiki.api.js", function () { | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
var pageString = | var pageString = "WBRCurrentQuestion"; | ||
api.get( { | api.get({ | ||
action : 'query', | |||
format : 'json', | |||
titles : pageString, | |||
export : 'export', | |||
}, { | |||
ok:function (data) { | ok : function (data) { | ||
var xml = data.query.export["*"]; | |||
xmlDoc = $.parseXML(xml), | |||
$xml = $(xmlDoc), | |||
$title = $xml.find("text"); | |||
var curr = parseInt($title.text()); | |||
document.getElementById('queslink').innerHTML = "<a id='add' href='http://wikidoc.org/index.php/Special:FormEdit/WBRQuestion/WBR" + curr + "'><img src='http://static.wikidoc.org/5/54/Click_here_to_add_a_question.png' /></a>"; | |||
$('#add').click(function(){ | $('#add').click(function () { | ||
addNewSection("WBRCurrentQuestion", parseInt(curr + 1).toString(), mw.user.tokens.get('editToken')); | |||
}); | |||
} | |||
}); | |||
}); | |||
}); | }); | ||
</script> | </script> |