Last active
December 31, 2015 03:19
-
-
Save mrmartineau/7926397 to your computer and use it in GitHub Desktop.
String.substitute and example used on the uk.thebar.com
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
String.prototype.substitute = function (object) { | |
return this.replace(/\{(.+?)\}/g, function (match, name) { | |
return name in object ? object[name] : match; | |
}); | |
}; |
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
var query = this.options.queryUrl.substitute({ | |
spirits: this.element.find('.ingredients-list-spirits .is-selected').map(function() { | |
return $(this).data('value'); | |
}).get().join(), | |
mixers: this.element.find('.ingredients-list-mixers .is-selected').map(function() { | |
return $(this).data('value'); | |
}).get().join(), | |
garnishes: this.element.find('.ingredients-list-garnishes .is-selected').map(function() { | |
return $(this).data('value'); | |
}).get().join() | |
}); | |
$(this).attr('href',query.substitute({ type : $(this).attr('data-type') })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment