You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Security-Quiz/static/js/quiz.js

67 lines
1.7 KiB

$(function () {
var changed = false;
// Hints
$('.hint').replaceWith(function () {
return '<div><a href="#" class="hintlink" onclick="$(this).next().slideToggle(); return false;">Bekijk hint</a>' + $(this).hide()[0].outerHTML + '</div>';
});
$('#difficulty').change(function (e) {
var option = $(this).find(':selected').val();
$('.hintlink').toggle(option == 'normal');
$('.hint').toggle(option == 'easy');
window.localStorage.setItem('difficulty', option);
});
// Set the selected property
if (window.localStorage['difficulty']) {
var difficulty = window.localStorage['difficulty'];
} else {
var difficulty = 'normal';
}
$('#difficulty option').filter(function () {
return $(this).val() == difficulty;
}).prop('selected', true);
$('#difficulty').trigger('change');
function loadPage(page) {
$('#quiz').load('/' + page + '.html?cachebuster=' + Math.random());
}
function getPage(link) {
if (link.lastIndexOf('?') === -1) {
return '';
}
return link.substring(link.lastIndexOf('?') + 1);
}
// Dynamically load pages
$('#menu a').click(function (e, element) {
var page = getPage(e.target.href);
window.history.pushState({ page: page }, 'Security', e.target.href);
loadPage(page);
e.preventDefault();
});
window.onpopstate = function (event) {
if (event.state) {
loadPage(event.state.page);
} else {
window.location.href = '/';
}
}
// Load page
var page = getPage(window.location.href);
if (page !== '') {
loadPage(page);
}
});