Melding:Common.js
(Ný síða: →Language specific links: $(document).ready(function() { if (!document.cookie) return; var lang = document.cookie.match('lang=(..)'); if (lang) { lang = lang[1]; $('...) |
|||
Lína 27: | Lína 27: | ||
}) | }) | ||
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:27
/* Language specific links */ $(document).ready(function() { if (!document.cookie) return; var lang = document.cookie.match('lang=(..)'); if (lang) { lang = lang[1]; $('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