Last active
March 18, 2017 01:54
-
-
Save doublejosh/1fea94493c140bcda332c67e443693d9 to your computer and use it in GitHub Desktop.
Param visibility
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
/** | |
* 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