Skip to content

Instantly share code, notes, and snippets.

@kmaglione
Created February 26, 2014 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmaglione/9220650 to your computer and use it in GitHub Desktop.
Save kmaglione/9220650 to your computer and use it in GitHub Desktop.
ConvertTermsToURI: function(terms) {
// Create an array to hold each search term
var termArray = new Array();
// Split up the search term string based on the space character
termArray = terms.split(" ");
// Call the DoEncode function on each item in our array
termArray.forEach(this.DoEncode);
// Join the array with the plus sign and return the result
return termArray.join("+");
},
////////////////////////////////////////////////////////////////////////////
// The DoEncode() function gets called on an array of search terms. Each
// incoming term is encoded, for use in a URL.
////////////////////////////////////////////////////////////////////////////
DoEncode: function(element, index, array) {
// Modify the array element by calling encodeURIComponent on it
array[index] = encodeURIComponent(element);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment