Commit 8689b550 authored by Mark Swillus's avatar Mark Swillus
Browse files

Merge branch '68-auto-select-language-and-save-cookie-on-language-change' into 'master'

Resolve "~~Auto-select language and~~ save cookie on language change"

Closes #70 and #68

See merge request totem/website!55
parents e59a501c 6424d2e6
......@@ -54,5 +54,6 @@ Temporary Items
/data
/vendor
# Editor temporary files
# Editor related files
*.swp
.vscode
......@@ -13,5 +13,5 @@ apt-get update
apt-get install -y rsync
# Upload site.
rsync -r --verbose --compress --delete --exclude js-components ./build/* \
rsync -r --verbose --compress --delete --exclude js-components ./build/ \
"${FTP_USER}@ftp.greenhost.nl:${DOMAIN_NAME}/${SUBDOMAIN}"
......@@ -55,7 +55,7 @@
});
// Add target="_blank" to external links so they open in new tabs
var siteUrlPattern = "^https?:\/\/(www\.)?(workstation...\.lan:4567|localhost:4567|totem-project\.org)";
var siteUrlPattern = "^https?:\/\/(www\.)?(www-staging.)?(workstation...\.lan:4567|localhost:4567|totem-project\.org)";
var siteUrlMatch = RegExp(siteUrlPattern, "i");
var excludeMatch = /(^mailto:|^tel:|^#|^javascript:)/;
$("a").each(function() {
......@@ -65,7 +65,16 @@
}
});
});
document.setLangCookie = function(lang) {
var expiryDate = new Date();
expiryDate = expiryDate.setMonth(expiryDate.getMonth() + 12);
var domain = window.location.hostname;
var cookieParams = "domain=." + domain + ";path=/;SameSite=Strict;";
if (window.location.protocol == "https") {
cookieParams += "secure=true;";
}
document.cookie = "openedx-language-preference=" + lang + ";expires=" + expiryDate + ";" + cookieParams;
};
})(jQuery, window, document);
......@@ -35,7 +35,7 @@ end
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<% I18n.available_locales.select{|l| l != ::I18n.locale}.each do |loc| %>
<li class="dropdown-item">
<%= link_to(config[:locales][loc][:name], "/index.html", :locale => loc, :class => "nav-link") %>
<%= link_to(config[:locales][loc][:name], "/index.html", :locale => loc, :class => "nav-link", :onclick => "setLangCookie('#{loc}')") %>
</li>
<% end %>
</ul>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment