Skip to content

Commit

Permalink
fixes #1157 by supporting a css filename to be passed in the 'brandin…
Browse files Browse the repository at this point in the history
…g' parameter. The css extension may be omitted as it is added automatically. Multiple brading CSS can be used by providing their names separated by commas in the 'branding' parameter, the CSS files are loaded in the order they are specified and after all the base CSS has been loaded. Using 'branding=false' is an alias for 'branding=nobranding.css' in order to keep retrocompatibility.
  • Loading branch information
chalkos committed Jun 1, 2018
1 parent b43329d commit 4aaa6b4
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions roda-ui/roda-wui/src/main/resources/config/theme/theme.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
var FOOTER_ADDED = false;

$(document).ready(function() {
// getUrlParameters function based on
// from https://stackoverflow.com/a/2880929/1483200
var urlParams = (function () {
var urlParams,
match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) {
return decodeURIComponent(s.replace(pl, " "));
},
query = window.location.search.substring(1);

var search = window.location.search;
if(/branding=false/.test(search)) {
$("head").append('<link rel="stylesheet" type="text/css" href="api/v1/theme?resource_id=nobranding.css">');
}
urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
return urlParams;
})();

// keep branding=false retrocompatibility
if (urlParams['branding'] === 'false') {
urlParams['branding'] = 'nobranding.css';
}

if ((typeof urlParams['branding']) === 'string') {
var brandings = urlParams['branding'].split(',');

brandings.forEach(function(branding){
if (branding.endsWith("css")) {
$(document).on('DOMNodeInserted', ".footer", function(e) {
$("head").append('<link rel="stylesheet" type="text/css" href="api/v1/theme?resource_id=' + branding + '">');
});
} else {
// allow branding to be specified without extension
$(document).on('DOMNodeInserted', ".footer", function(e) {
$("head").append('<link rel="stylesheet" type="text/css" href="api/v1/theme?resource_id=' + branding + '.css">');
});
}
});
}

// necessary to pass on the accessibility test
$(document).on('DOMNodeInserted', "thead", function(e) {
$(document).on('DOMNodeInserted', "thead", function(e) {
$("img").each(function(index) {
var imageAlt = $(this).attr('alt');
if(!(typeof attr !== typeof undefined && attr !== false)) {
Expand All @@ -27,9 +61,5 @@ $(document).ready(function() {
FOOTER_ADDED = true;
});
}

if(/branding=false/.test(search)) {
$(".roda").css("background-color", "white");
}
});
});
});

0 comments on commit 4aaa6b4

Please sign in to comment.