Skip to content

Instantly share code, notes, and snippets.

@doublejosh
Last active March 18, 2017 01:54
Show Gist options
  • Save doublejosh/1fea94493c140bcda332c67e443693d9 to your computer and use it in GitHub Desktop.
Save doublejosh/1fea94493c140bcda332c67e443693d9 to your computer and use it in GitHub Desktop.
Param visibility
/**
* Reveal content based on param value.
*
* @param {object} options
* @property {string} paramName
* @property {string} regex
* @property {string} selector
*/
function paramVisible(options) {
var urlObj = Tabia.util.parseUrl(),
$elm = $(options.selector);
if (urlObj.params[options.paramName].match(options.regex)) {
$elm.style('display', 'auto');
return;
}
$elm.style('display', 'none');
}
// EXAMPLE...
paramVisible({
param: 'authenticated',
regex: /^(now|prior)$/,
selector: '.share'
});
// ?authenticated=now
// <div class="share">
// You should be sharing
// </div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment