Last active
August 29, 2015 13:56
-
-
Save jbdietrich/9036976 to your computer and use it in GitHub Desktop.
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
</style> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(function() { | |
// intercept request and send it to an endpoint that honors sessions | |
var redirectSearch = function(e, data) { | |
var queryRegex = /suggestions_query=([^&]+)/g; | |
if (data.url.indexOf("/hc/api/v2/dropbox/search") != -1) { | |
var query = queryRegex.exec(data.url)[1]; | |
$(".branding").html('<div id="query" style="display:none">' + query + '</div>'); | |
data.url = "/api/v2/search.json?query=type:article " + query +"&per_page=5"; | |
return true; | |
} else { | |
return true; | |
} | |
}; | |
// make the response look like what the tab expects | |
var modifyResults = function(data, type) { | |
var parsed = JSON.parse(data); | |
var edit = function(entries) { | |
for (var entry in entries) { | |
entries[entry]['forum_type'] = 'Articles'; | |
entries[entry]['title'] = entries[entry]['name']; | |
entries[entry]['excerpt'] = ''; | |
entries[entry]['relative_path'] = entries[entry]['html_url'].match(/\.\w+(\/.+)/)[1]; | |
} | |
return entries; | |
}; | |
var rawData = { "total_entries": parsed.count, "entries": edit(parsed.results) }; | |
data = JSON.stringify(rawData); | |
return data; | |
}; | |
// if there are enough results to generate a 'see all n results...' link, modify it | |
var changeSearch = function(){ | |
var query = $("#query").html(); | |
$(".more").attr("href", "/hc/en-us/search?query=" + query); | |
}; | |
$.ajaxSetup( { beforeSend: redirectSearch, dataFilter: modifyResults, complete: changeSearch } ); | |
}); | |
</script> | |
<style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment