Last active
February 5, 2016 16:46
-
-
Save chucknado/c24c26053915f1b1abb3 to your computer and use it in GitHub Desktop.
Sample script for "Letting users search other Help Centers" at https://support.zendesk.com/hc/en-us/articles/xyz
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
function search_other_hc(hc, hostname) { | |
var search_string = encodeURIComponent(document.getElementById('query').value); | |
var lang = document.getElementsByTagName('html')[0].getAttribute('lang').toLowerCase(); | |
var url = 'https://' + hostname + '/hc/'+ lang + '/search?utf8=%E2%9C%93&commit=Search&query=' + search_string; | |
window.open(url); | |
} | |
function init_multi_product_search() { | |
if (document.getElementsByClassName('search-other-products')) { | |
var help_centers = [ {product: 'acme', hostname: 'acme.zendesk.com'}, | |
{product: 'ecme', hostname: 'ecme.zendesk.com'}, | |
{product: 'ocme', hostname: 'ocme.zendesk.com'} ]; | |
// set product link listeners | |
for (i = 0; i < help_centers.length; i++) { | |
(function() { | |
var hc = help_centers[i].product; | |
var hostname = help_centers[i].hostname; | |
var id = 'search_' + hc; | |
document.getElementById(id).addEventListener('click', function(){ search_other_hc(hc, hostname); }, false); | |
}()) | |
} | |
} | |
} | |
// event listeners | |
window.addEventListener('load', init_multi_product_search, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment