Melding:Common.js
Lína 25: | Lína 25: | ||
output_params_array.push(key + '=' + output_params[key]) | output_params_array.push(key + '=' + output_params[key]) | ||
}) | }) | ||
− | output = output + (output_params_array.join('&')) | + | output = output + (output_params_array.join('&')); |
− | |||
$(this).attr('href', output); | $(this).attr('href', output); | ||
} | } |
Útgáfa síðunnar 3. september 2020 kl. 13:28
$(document).ready(function() { if (!document.cookie) return; var lang = document.cookie.match('lang=(..)'); if (lang) { lang = lang[1]; $('a:not(#switch_language a)').each(function() { var url = $(this).attr('href'); if (!url) return; var split = url.match(/^(.+)(?:\?(.+))?$/) if (!(url.startsWith('https://andrum.is') || url.startsWith('/'))) return; if (split) { var base = split[1] var input_params = split[2] || '' var output = base + '?' var output_params = {} var output_params_array = [] input_params.split(/&/g).forEach(function(part) { var item = part.split("=") if (item[0]) { output_params[item[0]] = item[1] } }) output_params['lang'] = lang Object.keys(output_params).forEach(function(key) { output_params_array.push(key + '=' + output_params[key]) }) output = output + (output_params_array.join('&')); $(this).attr('href', output); } }) } });
Instagram • Facebook