Skip to content

Instantly share code, notes, and snippets.

@scofennell
Created January 10, 2018 14:28
Show Gist options
  • Save scofennell/4d7343cba2647dd5cea8aed5b1824273 to your computer and use it in GitHub Desktop.
Save scofennell/4d7343cba2647dd5cea8aed5b1824273 to your computer and use it in GitHub Desktop.
LXB MCT JS
/**
* A global object with members that any of our jQuery plugins can use.
*
* @type {Object}
*/
var lxbMailChimpTools = {
/**
* Grab the value of a url var.
* @param {string} url Any url.
* @param {string} sParam The key for any url variable.
* @return {string} The value for sParam in url.
*/
getUrlParameter : function ( url, sParam ) {
// Will hold the value of sParam if it's present in url.
var out = '';
// Break the url apart at the query string.
var array = url.split( '?' );
// Grab the second half of the url.
var queryStr = array[1];
// Break the query string into key value pairs.
var pairs = queryStr.split( '&' );
// For each pair...
jQuery( pairs ).each( function( k, v ) {
// Break the pair into a key and a value.
var pair = v.split( '=' );
// If the key for this pair is what we're looking for...
if( pair[0] == sParam ) {
// Grab the value.
out = pair[1];
}
});
return out;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment