Created
September 6, 2012 23:41
-
-
Save kenany/3661447 to your computer and use it in GitHub Desktop.
Swiftype snippet in CoffeeScript
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
# Swiftype relies on the creation of the global variable window.Swiftype. | |
# Due to CoffeeScript's top-level function safety wrapper, the snippet requires | |
# modification in order to make the Swiftype variable break free of lexical | |
# scope hell. | |
# I would love some feedback on whether the existential operator is a better | |
# choice than simply using `or` | |
Swiftype = window.Swiftype ? {} | |
Swiftype.key = 'api key here' | |
Swiftype.inputElement = '#st-search-input' | |
Swiftype.resultContainingElement = '#st-results-container' | |
Swiftype.attachElement = '#st-search-input' | |
Swiftype.renderStyle = 'overlay' | |
window.Swiftype = Swiftype | |
# There are multiple ways to load the embed.js script: | |
# Manually | |
script = document.createElement 'script' | |
script.type = 'text/javascript' | |
script.async = true | |
script.src = '//swiftype.com/embed.js' | |
entry = document.getElementsByTagName('script')[0] | |
entry.parentNode.insertBefore script, entry | |
# Modernizr.load (a.k.a. yepnopejs) | |
Modernizr.load '//swiftype.com/embed.js' | |
# etc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment