Melding:Common.js
Lína 1: | Lína 1: | ||
− | |||
$(document).ready(function() { | $(document).ready(function() { | ||
if (!document.cookie) return; | if (!document.cookie) return; | ||
Lína 5: | Lína 4: | ||
if (lang) { | if (lang) { | ||
lang = lang[1]; | lang = lang[1]; | ||
− | $('a').each(function() { | + | $('a:not(#switch_language a)').each(function() { |
var url = $(this).attr('href'); | var url = $(this).attr('href'); | ||
if (!url) return; | if (!url) return; | ||
Lína 27: | Lína 26: | ||
}) | }) | ||
output = output + (output_params_array.join('&')) | output = output + (output_params_array.join('&')) | ||
+ | console.log({ split, input_params, url, output_params, output }) | ||
$(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('&')) console.log({ split, input_params, url, output_params, output }) $(this).attr('href', output); } }) } });
Instagram • Facebook