From c970b658e65fe83fa94394597958d70134604877 Mon Sep 17 00:00:00 2001 From: khawkins98 <khawkins98@gmail.com> Date: Mon, 11 Sep 2017 13:34:44 +0100 Subject: [PATCH] Add utility functions --- js/ebi-global-includes/script/1_about.js | 22 ++++++++++++++++++- .../script/4_ebiFrameworkContent.js | 16 ++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/js/ebi-global-includes/script/1_about.js b/js/ebi-global-includes/script/1_about.js index 0d1d6189..55af185d 100644 --- a/js/ebi-global-includes/script/1_about.js +++ b/js/ebi-global-includes/script/1_about.js @@ -1,4 +1,24 @@ -// Copyright (c) EMBL-EBI 2017 +// Copyright (c) EMBL-EBI 2017 // Do not edit this file directly. // It is made by concating .js files with by npm into script.js. // Source files: js/ebi-css-build/script/*.js + +/** + * Utility function to get params from the URL. + * + * @param {string} name The string to look for + * @param {string} [url=browserURL] Optionally pass a specific URL to parse + * + * @example + * query string: ?foo=lorem&bar=&baz + * var foo = getParameterByName('foo'); // "lorem" + */ +function ebiGetParameterByName(name, url) { + if (!url) url = window.location.href; + name = name.replace(/[\[\]]/g, "\\$&"); + var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), + results = regex.exec(url); + if (!results) return null; + if (!results[2]) return ''; + return decodeURIComponent(results[2].replace(/\+/g, " ")); +} diff --git a/js/ebi-global-includes/script/4_ebiFrameworkContent.js b/js/ebi-global-includes/script/4_ebiFrameworkContent.js index f82e5f82..1c085e68 100644 --- a/js/ebi-global-includes/script/4_ebiFrameworkContent.js +++ b/js/ebi-global-includes/script/4_ebiFrameworkContent.js @@ -1,9 +1,21 @@ +/** + * Utility function to toggle classes. Chiefly to show the #embl-bar. + */ +function ebiToggleClass(element, toggleClass){ + var currentClass = element.className; + var newClass; + if(currentClass.split(" ").indexOf(toggleClass) > -1){ // has class + newClass = currentClass.replace(new RegExp('\\b'+toggleClass+'\\b','g'),"") + } else{ + newClass = currentClass + " " + toggleClass; + } + element.className = newClass.trim(); +} + /** * Remove global-nav/global-nav-expanded from header/footer if body.no-global-nav is set */ function ebiFrameworkHideGlobalNav() { - // - // try { var hasGlobalMasthead = document.getElementById('masthead-black-bar') !== null; var disabled = document.body.className.indexOf('no-global-nav') !== -1; -- GitLab