Last active
April 5, 2019 08:05
-
-
Save dreamyguy/e5faa4cb2a64ee9bff50675918fd9b88 to your computer and use it in GitHub Desktop.
Visualising margins for UX Debugging [8 of 8]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getUrlParam(param, url) { | |
let theUrl = url; | |
if (!url) { | |
theUrl = location.href; | |
} | |
const theParam = param.replace(/[[]/, '\\[').replace(/[\]]/, '\\]'); | |
const regexLogic = `[\\?&]${theParam}=([^&#]*)`; | |
const regex = new RegExp(regexLogic); | |
const results = regex.exec(theUrl); | |
return results === null ? null : results[1]; | |
} | |
function addWrapperClassIfUrlParam(wrapperClass, param) { | |
const b = document.querySelector('body'); | |
// Only proceed if 'body' is found on the page | |
if (b !== null) { | |
if (getUrlParam(param)) { | |
b.classList.add(wrapperClass); | |
} | |
} | |
} | |
document.addEventListener('DOMContentLoaded', () => { | |
addWrapperClassIfUrlParam('show-helpers', 'helpers'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment