|
|
@ -161,41 +161,53 @@ $(document).ready(function()
|
|
|
|
// Autocomplete for search - Contact Joca in case of trouble
|
|
|
|
// Autocomplete for search - Contact Joca in case of trouble
|
|
|
|
// Check: Code doesn't work inside document.ready function
|
|
|
|
// Check: Code doesn't work inside document.ready function
|
|
|
|
// Are the other functions correctly closed?
|
|
|
|
// Are the other functions correctly closed?
|
|
|
|
|
|
|
|
function split( val ) {
|
|
|
|
// Send query to server
|
|
|
|
return val.split( /,\s*/ );
|
|
|
|
$('#search').on("input", function() {
|
|
|
|
}
|
|
|
|
var query = this.value;
|
|
|
|
function extractLast( term ) {
|
|
|
|
|
|
|
|
return split( term ).pop();
|
|
|
|
$.ajax({
|
|
|
|
|
|
|
|
url: "/autocomplete_suggestions",
|
|
|
|
|
|
|
|
data: $('form').serialize(),
|
|
|
|
|
|
|
|
type: "POST",
|
|
|
|
|
|
|
|
async: false,
|
|
|
|
|
|
|
|
success: function(response) {
|
|
|
|
|
|
|
|
//console.log("Got your query!");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$( "#search" )
|
|
|
|
|
|
|
|
// don't navigate away from the field on tab when selecting an item
|
|
|
|
|
|
|
|
.on( "keydown", function( event ) {
|
|
|
|
|
|
|
|
if ( event.keyCode === $.ui.keyCode.TAB &&
|
|
|
|
|
|
|
|
$( this ).autocomplete( "instance" ).menu.active ) {
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.autocomplete({
|
|
|
|
|
|
|
|
source:function(request, response) {
|
|
|
|
|
|
|
|
$.getJSON("/autocomplete_suggestions",{
|
|
|
|
|
|
|
|
q: request.term, // in flask, "q" will be the argument to look for using request.args
|
|
|
|
|
|
|
|
}, function(data) {
|
|
|
|
|
|
|
|
response(data); // matching_results from jsonify
|
|
|
|
|
|
|
|
console.log("this" + data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
var JSONItems = ['battle'];
|
|
|
|
search: function() {
|
|
|
|
$.getJSON( "/autocomplete_suggestions", callbackFuncWithData);
|
|
|
|
// custom minLength
|
|
|
|
|
|
|
|
var term = extractLast( this.value );
|
|
|
|
|
|
|
|
if ( term.length < 2 ) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
function callbackFuncWithData() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("#search").autocomplete({
|
|
|
|
|
|
|
|
source: function( request, response ) {
|
|
|
|
|
|
|
|
$.getJSON( "autocomplete_suggestions", {
|
|
|
|
|
|
|
|
term: extractLast( request.term )
|
|
|
|
|
|
|
|
}, response );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}
|
|
|
|
focus: function() {
|
|
|
|
|
|
|
|
// prevent value inserted on focus
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
select: function( event, ui ) {
|
|
|
|
|
|
|
|
console.log(this.value);
|
|
|
|
// Get autocomplete_suggestions
|
|
|
|
str = this.value;
|
|
|
|
console.log("haha");
|
|
|
|
var terms = str.split(" ");
|
|
|
|
|
|
|
|
console.log(terms);
|
|
|
|
|
|
|
|
// remove the current input
|
|
|
|
|
|
|
|
terms.pop();
|
|
|
|
|
|
|
|
// add the selected item
|
|
|
|
|
|
|
|
terms.push( ui.item.value );
|
|
|
|
|
|
|
|
// add placeholder to get the comma-and-space at the end
|
|
|
|
|
|
|
|
terms.push( "" );
|
|
|
|
|
|
|
|
this.value = terms.join( " " );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|