Skip to content
Snippets Groups Projects
Commit e74c7587 authored by Ken Hawkins's avatar Ken Hawkins
Browse files

Improve announcements matching

Only match subpaths when using `/*`
parent 78fa9f8d
No related branches found
No related tags found
No related merge requests found
Pipeline #62376 passed with stage
in 1 minute and 19 seconds
......@@ -164,5 +164,4 @@ Releases are available via NPM at https://www.npmjs.com/package/ebi-framework
Todo: Run the build process and serve with gulp and browsersync.
## Roadmap
- v1.4: Documentation, EMBL integration, abstracting core structure into a reusable "Framework for the Life Sciences"
- v1.5: Patterns, accessibility.
- v1.4: Transition to [the Visual Framework 2.0](https://visual-framework.github.io/vf-welcome/)
......@@ -390,6 +390,7 @@ function ebiInjectAnnouncements(message) {
/**
* Load the downtime/announcement messages, if any.
* We do match not by comparison but by find a url as an array key.
* For more info, see: https://gitlab.ebi.ac.uk/ebiwd/ebi.emblstatic.net-root-assets/tree/master/src
*/
function ebiFrameworkIncludeAnnouncements() {
......@@ -401,16 +402,18 @@ function ebiFrameworkIncludeAnnouncements() {
var currentHost = window.location.hostname,
currentPath = window.location.pathname;
// don't treat wwwdev as distinct from www
currentHost = currentHost.replace(/wwwdev/g , "www");
// don't treat `wwwdev` as distinct from `www`
currentHost = currentHost.replace(/wwwdev/g, "www");
// try to show any possible variations of the url
// Note: this is pretty simple stupid, but maybe it's more effective than a sophisticated solution?
ebiInjectAnnouncements(messages[currentHost]);
ebiInjectAnnouncements(messages[currentHost+'/']);
ebiInjectAnnouncements(messages[currentHost+'/*']);
// if the page has a path, try to make matches
// don't try to much no path or '/'
if (currentPath.length > 1) {
// don't try to much no path or '/'
// Is there an exact match
// console.log('matching:', currentHost+currentPath);
ebiInjectAnnouncements(messages[currentHost+currentPath]);
ebiInjectAnnouncements(messages[currentHost+currentPath + '/']);
// Handle wildcard matches like `/about/*`
var currentPathArray = currentPath.split('/');
// construct a list of possible paths to match
......@@ -418,24 +421,32 @@ function ebiFrameworkIncludeAnnouncements() {
// - /style-lab/frag1/frag2
// - /style-lab/frag1
// - /style-lab
var pathsToMatch = [currentHost+currentPathArray[0]];
var pathsToMatch = [currentHost + currentPathArray[0]];
for (var i = 1; i < currentPathArray.length; i++) {
var tempPath = pathsToMatch[i-1];
pathsToMatch.push(tempPath+'/'+currentPathArray[i])
var tempPath = pathsToMatch[i - 1];
pathsToMatch.push(tempPath + '/' + currentPathArray[i]);
}
// console.log(pathsToMatch);
for (var i = 0; i < pathsToMatch.length; i++) {
// console.log('matching:',pathsToMatch[i]);
ebiInjectAnnouncements(messages[pathsToMatch[i]]);
ebiInjectAnnouncements(messages[pathsToMatch[i]+'*']);
ebiInjectAnnouncements(messages[pathsToMatch[i]+'/*']);
// console.log('matching:', pathsToMatch[i]+'*');
// we only match partial paths if they end in *
ebiInjectAnnouncements(messages[pathsToMatch[i] + '*']);
ebiInjectAnnouncements(messages[pathsToMatch[i] + '/*']);
}
} else {
// no current path means we're on the root domain
// `https://www.ebi.ac.uk` should match `www.ebi.ac.uk` and `www.ebi.ac.uk/` and `www.ebi.ac.uk/*`
// console.log('matching:', currentHost);
ebiInjectAnnouncements(messages[currentHost]);
ebiInjectAnnouncements(messages[currentHost + '/']);
ebiInjectAnnouncements(messages[currentHost + '/*']);
}
}
}
function loadRemoteAnnouncements(file) {
if (window.XMLHttpRequest) {
var xmlhttp=new XMLHttpRequest();
var xmlhttp = new XMLHttpRequest();
}
xmlhttp.open("GET", file, true);
xmlhttp.onload = function (e) {
......@@ -461,5 +472,5 @@ function ebiFrameworkIncludeAnnouncements() {
} else {
loadRemoteAnnouncements('https://ebi.emblstatic.net/announcements.js');
}
}
......@@ -479,6 +479,7 @@ function ebiInjectAnnouncements(message) {
/**
* Load the downtime/announcement messages, if any.
* We do match not by comparison but by find a url as an array key.
* For more info, see: https://gitlab.ebi.ac.uk/ebiwd/ebi.emblstatic.net-root-assets/tree/master/src
*/
function ebiFrameworkIncludeAnnouncements() {
......@@ -490,16 +491,18 @@ function ebiFrameworkIncludeAnnouncements() {
var currentHost = window.location.hostname,
currentPath = window.location.pathname;
// don't treat wwwdev as distinct from www
// don't treat `wwwdev` as distinct from `www`
currentHost = currentHost.replace(/wwwdev/g, "www");
// try to show any possible variations of the url
// Note: this is pretty simple stupid, but maybe it's more effective than a sophisticated solution?
ebiInjectAnnouncements(messages[currentHost]);
ebiInjectAnnouncements(messages[currentHost + '/']);
ebiInjectAnnouncements(messages[currentHost + '/*']);
// if the page has a path, try to make matches
// don't try to much no path or '/'
if (currentPath.length > 1) {
// don't try to much no path or '/'
// Is there an exact match
// console.log('matching:', currentHost+currentPath);
ebiInjectAnnouncements(messages[currentHost + currentPath]);
ebiInjectAnnouncements(messages[currentHost + currentPath + '/']);
// Handle wildcard matches like `/about/*`
var currentPathArray = currentPath.split('/');
// construct a list of possible paths to match
......@@ -513,12 +516,20 @@ function ebiFrameworkIncludeAnnouncements() {
pathsToMatch.push(tempPath + '/' + currentPathArray[i]);
}
// console.log(pathsToMatch);
for (var i = 0; i < pathsToMatch.length; i++) {
// console.log('matching:',pathsToMatch[i]);
ebiInjectAnnouncements(messages[pathsToMatch[i]]);
// console.log('matching:', pathsToMatch[i]+'*');
// we only match partial paths if they end in *
ebiInjectAnnouncements(messages[pathsToMatch[i] + '*']);
ebiInjectAnnouncements(messages[pathsToMatch[i] + '/*']);
}
} else {
// no current path means we're on the root domain
// `https://www.ebi.ac.uk` should match `www.ebi.ac.uk` and `www.ebi.ac.uk/` and `www.ebi.ac.uk/*`
// console.log('matching:', currentHost);
ebiInjectAnnouncements(messages[currentHost]);
ebiInjectAnnouncements(messages[currentHost + '/']);
ebiInjectAnnouncements(messages[currentHost + '/*']);
}
}
......
This diff is collapsed.
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