Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'instant_search_cleanup' into search_results

  • Loading branch information...
commit 20e589bcb8d711d66e11b312c0539614b933139b 2 parents 447d7db + 630ab6e
@Nagyman authored
Showing with 27 additions and 17 deletions.
  1. +27 −17 media/javascript/instantsearch.js
View
44 media/javascript/instantsearch.js
@@ -1,6 +1,9 @@
+/**
+ * Searching as the user types.
+ */
function instantSearch() {
$("#id_search_button").click(function() {
- if ($("#id_site_search_2").val() == '') {
+ if($("#id_site_search_2").val() == '') {
$("#id_search_result").empty();
$("#id_search_result").hide();
$("#id_search_title").html("No search term entered");
@@ -10,25 +13,32 @@ function instantSearch() {
url: "/api/v1/file/search/",
data: {format: 'jsonp', q: $("#id_site_search_2").val()},
success: function(searchres, text, xhqr) {
- strstart = this.url.indexOf("&q=") + 3;
- strend = this.url.indexOf("&", strstart);
- if (strend == -1) orig_query = this.url.substring(strstart);
- else orig_query = this.url.substring(strstart, strend);
- orig_query2 = unescape(orig_query.replace(/\+/g, " "));
+ var strstart = this.url.indexOf("&q=") + 3;
+ var strend = this.url.indexOf("&", strstart);
+ if (strend == -1) {
+ var orig_query = this.url.substring(strstart);
+ } else {
+ var orig_query = this.url.substring(strstart, strend);
+ }
+ var orig_query2 = unescape(orig_query.replace(/\+/g, " "));
// Block any old queries that come through after the latest one
- if (orig_query2 != $("#id_site_search_2").val()) return false;
+ if (orig_query2 != $("#id_site_search_2").val()) {
+ return false;
+ }
+
$("#id_search_result").empty();
+
for (var i=0; i<searchres.objects.length; i++) {
- $("#id_search_result").append("<li class=\"module-item\">\n" +
- "<p class=\"module-item-title\">\n" +
- " File: <a href=" + searchres.objects[i].absolute_url + "?highlight=" +
- $("#id_site_search_2").val() + ">" + searchres.objects[i].project.name +
- " - " + searchres.objects[i].name + "</a>\n" +
- "</p>\n" +
- "<p>\n" +
- " " + searchres.objects[i].text + "\n" +
- "</p>\n" +
- "</li>\n");
+ $("#id_search_result").append([
+ '<li class="module-item">',
+ '<p class="module-item-title">',
+ 'File: <a href="', searchres.objects[i].absolute_url,
+ '?highlight=', $("#id_site_search_2").val(), '">',
+ searchres.objects[i].project.name,
+ " - ", searchres.objects[i].name, "</a>",
+ "</p>",
+ "<p>", searchres.objects[i].text, "</p>",
+ "</li>"].join(''));
}
},
dataType: 'jsonp'
Please sign in to comment.
Something went wrong with that request. Please try again.