poketest/interface.js

174 lines
6.2 KiB
JavaScript

$(document).ready(function()
{
function random(min, max)
{
return Math.floor(Math.random()*(max-min+1)+min);
}
// have a nice little background
//$.backstretch("artwork/artwork"+random(1, 10)+".jpg");
// hamburger mobile
$("#hamburger .container").click(function()
{
if ($("nav").hasClass("active"))
{
$("nav ul").slideUp(200, function()
{
$("nav").removeClass("active");
});
}
else
{
$("nav").addClass("active");
$("nav ul").slideDown(200);
}
});
// splice url arguments
function gup(name, url)
{
if (!url) url = location.href;
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(url);
return results == null ? null : results[1];
}
// index.html
if (location.pathname.includes("index.html"))
{
// read url
local_gen = gup('gen', location.href);
if (local_gen != null)
{
if (local_gen == "all")
$('article #container #game #configuration input#all').attr('checked', true);
else
{
$('article #container #game #configuration input#select').attr('checked', true);
for (i = 0; i < local_gen.length; i++)
{
if (local_gen.charAt(i)) {
if (local_gen.charAt(i) == "m")
$('article #container #game #configuration #selected_options input#mega').attr('checked', true);
else if (local_gen.charAt(i) == "r")
$('article #container #game #configuration #selected_options input#regional').attr('checked', true);
else if (local_gen.charAt(i) == "g")
$('article #container #game #configuration #selected_options input#gigantamax').attr('checked', true);
else
$('article #container #game #configuration #selected_options input#' + local_gen.charAt(i) + 'g').attr('checked', true);
}
}
$('#selected_options').slideDown();
}
$('article #container #game #configuration select.lang').val(gup('lang', window.location.href));
if (gup('silhouette', window.location.href) == "true")
$('article #container #game #configuration input#silhouette').attr('checked', true);
else
$('article #container #game #configuration input#full').attr('checked', true);
if (gup('answertype', window.location.href) == "choice")
$('article #container #game #configuration input#choice').attr('checked', true);
else
$('article #container #game #configuration input#input').attr('checked', true);
$('article #container #game #configuration select.questions').val(gup('questions', window.location.href));
$('article #container #game #configuration select.time').val(gup('time', window.location.href));
}
else // if we did not come from a personalized URL, we read localstorage
{
if (localStorage.getItem('generation') != null)
{
if (localStorage.getItem('generation') != 'all')
{
gen_list = localStorage.getItem('generation');
$('article #container #game #configuration input#select').attr('checked', true);
for (i = 0; i < gen_list.length; i++)
{
if (gen_list.charAt(i))
{
if (gen_list.charAt(i) == "m")
$('article #container #game #configuration #selected_options input#mega').attr('checked', true);
else if (gen_list.charAt(i) == "r")
$('article #container #game #configuration #selected_options input#regional').attr('checked', true);
else if (gen_list.charAt(i) == "g")
$('article #container #game #configuration #selected_options input#gigantamax').attr('checked', true);
else
$('article #container #game #configuration #selected_options input#' + gen_list.charAt(i) + 'g').attr('checked', true);
}
}
$('#selected_options').slideDown();
}
else
$('article #container #game #configuration input#all').attr('checked', true);
}
if (localStorage.getItem('lang') != null)
$('article #game #configuration select.lang').val(localStorage.getItem('lang'));
if (localStorage.getItem('silhouette') != null)
$('article #game #configuration input:radio[name=silhouette]#'+localStorage.getItem('silhouette')).attr('checked', true);
if (localStorage.getItem('answertype') != null)
$('article #game #configuration input:radio[name=answertype]#'+localStorage.getItem('answertype')).attr('checked', true);
if (localStorage.getItem('questions') != null)
$('article #game #configuration select.questions').val(localStorage.getItem('questions'));
if (localStorage.getItem('time') != null)
$('article #game #configuration select.time').val(localStorage.getItem('time'));
}
// select generation toggle
$('#configuration input#all').click(function()
{
$('#selected_options').slideUp();
});
$('#configuration input#select').click(function()
{
$('#selected_options').slideDown();
});
}
// flashdex.html
if (location.pathname.includes("flashdex.html"))
{
// read url
local_gen = gup('gen', location.href);
if (local_gen != null)
{
if (local_gen == "all")
{
for (i = 0; i < 10; i++)
$('article #container #game #flashdex_config input#' + i + 'g').attr('checked', true);
$('article #container #game #flashdex_config input#mega').attr('checked', true);
$('article #container #game #flashdex_config input#regional').attr('checked', true);
$('article #container #game #flashdex_config input#gigantamax').attr('checked', true);
}
else
{
for (i = 0; i < local_gen.length; i++)
{
if (local_gen.charAt(i)) {
if (local_gen.charAt(i) == "m")
$('article #container #game #flashdex_config input#mega').attr('checked', true);
else if (local_gen.charAt(i) == "r")
$('article #container #game #flashdex_config input#regional').attr('checked', true);
else if (local_gen.charAt(i) == "g")
$('article #container #game #flashdex_config input#gigantamax').attr('checked', true);
else
$('article #container #game #flashdex_config input#' + local_gen.charAt(i) + 'g').attr('checked', true);
}
}
}
$('article #container #game #flashdex_config select.lang').val(gup('lang', window.location.href));
}
else
{
if (localStorage.getItem('lang') != null)
$('article #container #game #flashdex_config select.lang').val(localStorage.getItem('lang'));
}
}
});