Last active
February 4, 2016 23:06
-
-
Save chucknado/cc2669a170a14a74b9df to your computer and use it in GitHub Desktop.
JavaScript for multi-product search in HC
This file contains hidden or 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: 'zendesk', hostname: 'support.zendesk.com'}, | |
{product: 'zopim', hostname: 'zopimsupport.zendesk.com'}, | |
{product: 'inbox', hostname: 'inbox.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