Diferencia entre revisiones de «MediaWiki:Filtros.js»
Ir a la navegación
Ir a la búsqueda
Línea 51: | Línea 51: | ||
}); | }); | ||
+ | |||
+ | // Control de parámetros | ||
+ | //Recuperamos parámetros | ||
+ | var get_params = function(search_string) { | ||
+ | |||
+ | var parse = function(params, pairs) { | ||
+ | var pair = pairs[0]; | ||
+ | var parts = pair.split('='); | ||
+ | var key = decodeURIComponent(parts[0]); | ||
+ | var value = decodeURIComponent(parts.slice(1).join('=')); | ||
+ | |||
+ | // Handle multiple parameters of the same name | ||
+ | if (typeof params[key] === "undefined") { | ||
+ | params[key] = value; | ||
+ | } else { | ||
+ | params[key] = [].concat(params[key], value); | ||
+ | } | ||
+ | |||
+ | return pairs.length == 1 ? params : parse(params, pairs.slice(1)) | ||
+ | } | ||
+ | |||
+ | // Get rid of leading ? | ||
+ | return search_string.length == 0 ? {} : parse({}, search_string.substr(1).split('&')); | ||
+ | } | ||
+ | |||
+ | var params = get_params(location.search); | ||
+ | if(params["search"]){ | ||
+ | document.querySelectorAll(".mw-search-result-heading a").forEach(a => { | ||
+ | a.href = a.href + "?search="+params["search"]; | ||
+ | }); | ||
+ | } |
Revisión del 12:53 10 feb 2021
jQuery(document).ready(function($){
function listFilter(input, list) {
var sc = true;
$(input)
.change( function () {
var filter = $(this).val();
if(filter) {
$(list).find("li:not(:Contains(" + filter + "))").slideUp(function(){
if($(this).closest('.mw-category-group').find('li:visible').length == 0){
if($(this).closest('.mw-category-group').is(':visible')) {
$(this).closest('.mw-category-group').slideUp();
}
} else {
if(!$(this).closest('.mw-category-group').is(':visible')) {
$(this).closest('.mw-category-group').slideDown();
}
}
});
$(list).find("li:Contains(" + filter + ")").slideDown(function(){
if(!$(this).closest('.mw-category-group').is(':visible')) {
$(this).closest('.mw-category-group').slideDown();
}
});
} else {
$(list).find("li").slideDown();
$('.mw-category-group').slideDown();
}
return false;
})
.keyup( function () {
$(this).change();
if(sc) {$("html, body").animate({ scrollTop: $(".filtro").offset().top - 80 }, 500);sc=false;}
});
}
if($('.mw-category').length > 0){
var filtro = $('<div class="filtro"><input type="text" id="filtro" /></div>');
$('.mw-category').prepend(filtro);
listFilter($('#filtro'),$('.mw-category '));
}
});
// Control de parámetros
//Recuperamos parámetros
var get_params = function(search_string) {
var parse = function(params, pairs) {
var pair = pairs[0];
var parts = pair.split('=');
var key = decodeURIComponent(parts[0]);
var value = decodeURIComponent(parts.slice(1).join('='));
// Handle multiple parameters of the same name
if (typeof params[key] === "undefined") {
params[key] = value;
} else {
params[key] = [].concat(params[key], value);
}
return pairs.length == 1 ? params : parse(params, pairs.slice(1))
}
// Get rid of leading ?
return search_string.length == 0 ? {} : parse({}, search_string.substr(1).split('&'));
}
var params = get_params(location.search);
if(params["search"]){
document.querySelectorAll(".mw-search-result-heading a").forEach(a => {
a.href = a.href + "?search="+params["search"];
});
}