Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mikeisonthenets
Last active April 9, 2018 18:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeisonthenets/17f1ece455646194d9e7aacc4388eb1d to your computer and use it in GitHub Desktop.
Save mikeisonthenets/17f1ece455646194d9e7aacc4388eb1d to your computer and use it in GitHub Desktop.
Standard Embed Template Override
<script type="text/javascript">
(function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
(w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);
e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
})(window,document,'script','//s.swiftypecdn.com/install/v2/st.js','_st');
_st('install','YOUR_INSTALL_KEY','2.0.0', {
install: {
web: {
templates: {
default: {
search: {
result_item: {
page: "<a onclick='event.preventDefault(); window.open(\"{{ full_result.url | escapeUrl }}\");' class='st-ui-result' data-st-result-doc-id='{{result.doc_id}}'> <span class='st-ui-type-detail' title='{{ result.title }});'> </span> <span class='st-ui-type-heading'>{{ result.title }}</span> <span class='st-ui-type-detail'> {{ result.body }} </span> </a> "
}
},
autocomplete: {
result_item: {
page: "<a onclick='event.preventDefault(); window.open(\"{{ full_result.url | escapeUrl }}\");' class='st-ui-result' data-st-result-doc-id='{{result.doc_id}}'> <span class='st-ui-type-detail' title='{{ result.title }});'> </span> <span class='st-ui-type-heading'>{{ result.title }}</span> <span class='st-ui-type-detail'> {{ result.body }} </span> </a> "
}
}
}
}
}
}
});
</script>
@mikeisonthenets
Copy link
Author

mikeisonthenets commented Sep 20, 2017

The above templates are still the standard embed HTML markup but with the inclusion of the window.open() method to automatically open clicked results into a new tab.

It's important to note that it's still possible for the end user's browser configuration to be set to ignore or handle the window.open instruction differently.

To Use:

Update the template above to replace YOUR_INSTALL_KEY with your embed scripts install key value, and configure the HTML templates as desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment