|
|
@ -160,10 +160,10 @@ $(document).ready(function() |
|
|
|
|
|
|
|
// Autocomplete for search - Contact Joca in case of trouble
|
|
|
|
|
|
|
|
|
|
|
|
$('#search').on("input", function() { |
|
|
|
var query = this.value; |
|
|
|
|
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
url: "/autocomplete_suggestions", |
|
|
|
data: $('form').serialize(), |
|
|
@ -173,83 +173,21 @@ $('#search').on("input", function() { |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
function getData() { |
|
|
|
var deferredData = new jQuery.Deferred(); |
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
type: "GET", |
|
|
|
url: "/autocomplete_suggestions", |
|
|
|
dataType: "json", |
|
|
|
success: function(data) { |
|
|
|
deferredData.resolve(data); |
|
|
|
} |
|
|
|
}); |
|
|
|
return deferredData; // contains the passed data
|
|
|
|
}; |
|
|
|
|
|
|
|
var dataDeferred = getData(); |
|
|
|
|
|
|
|
$.when(dataDeferred).done( function( data ) { |
|
|
|
var suggestion_list = data; |
|
|
|
console.log(suggestion_list); |
|
|
|
$().ready(function() { |
|
|
|
// search only, if the regexp matches
|
|
|
|
var suggestions = data; |
|
|
|
|
|
|
|
// Defines for the example the match to take which is any word (with Umlauts!!).
|
|
|
|
function _leftMatch(string, area) { |
|
|
|
//return string.substring(0, area.selectionStart).match(/[\wäöüÄÖÜß]+$/)
|
|
|
|
//console.log(string.substring(string.lastIndexOf(" ")+1).match(/[\wäöüÄÖÜß]+$/))
|
|
|
|
return string.substring(string.lastIndexOf(" ")+1).match(/[\wäöüÄÖÜß]+$/) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function _setCursorPosition(area, pos) { |
|
|
|
if (area.setSelectionRange) { |
|
|
|
area.setSelectionRange(pos, pos); |
|
|
|
} else if (area.createTextRange) { |
|
|
|
var range = area.createTextRange(); |
|
|
|
range.collapse(true); |
|
|
|
range.moveEnd('character', pos); |
|
|
|
range.moveStart('character', pos); |
|
|
|
range.select(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("#search").autocomplete({ |
|
|
|
position: { my : "right top", at: "right bottom" }, |
|
|
|
source: function(request, response) { |
|
|
|
var str = _leftMatch(request.term, $("#search")[0]); |
|
|
|
str = (str != null) ? str[0] : ""; |
|
|
|
console.log(str); |
|
|
|
response($.ui.autocomplete.filter( |
|
|
|
suggestions, str)); |
|
|
|
}, |
|
|
|
minLength: 1, // does have no effect, regexpression is used instead
|
|
|
|
focus: function() { |
|
|
|
// prevent value inserted on focus
|
|
|
|
return false; |
|
|
|
}, |
|
|
|
// Insert the match inside the ui element at the current position by replacing the matching substring
|
|
|
|
select: function(event, ui) { |
|
|
|
//alert("completing "+ui.item.value);},
|
|
|
|
var m = _leftMatch(this.value, this)[0]; |
|
|
|
var beg = this.value.substring(0, this.selectionStart - m.length); |
|
|
|
this.value = beg + ui.item.value + this.value.substring(this.selectionStart, this.value.length); |
|
|
|
var pos = beg.length + ui.item.value.length; |
|
|
|
_setCursorPosition(this, pos); |
|
|
|
return false; |
|
|
|
}, |
|
|
|
search:function(event, ui) { |
|
|
|
var m = _leftMatch(this.value, this); |
|
|
|
return (m != null ) |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}) |
|
|
|
|
|
|
|
// Start autocomplete
|
|
|
|
var availableTags = data; |
|
|
|
console.log(availableTags); |
|
|
|
$( "#search" ).autocomplete({ |
|
|
|
source: availableTags |
|
|
|
}); |
|
|
|
// End of autocomplete
|
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|