Typesetter/include/js/autocomplete.js

57 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-09-08 19:52:21 +02:00
$(function(){
$(document).on('focus', 'input.title-autocomplete:not(.ui-autocomplete-input)', function(){
var gptitles = false;
var that = this;
/**
* Load the titles dynamically
*
*/
var url = gpBLink+'/Admin?cmd=autocomplete-titles';
$.getJSON(url,function(data){
gptitles = data;
Autocomplete();
});
/**
* Set up autocomplete on the field
*
*/
function Autocomplete(){
$(that)
.css({'position':'relative',zIndex:12000}) //position and zIndex are needed because of bugs with the jquery ui
.autocomplete({
source: gptitles,
delay: 100, /* since we're using local data */
minLength: 0,
appendTo : '#gp_admin_html',
select: function(event,ui){
if( ui.item ){
this.value = ui.item[1];
return false;
}
}
}).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "ui-autocomplete-item", item[1] )
.append( '<a>' + $gp.htmlchars(item[0]) + '<span>'+$gp.htmlchars(item[1])+'</span></a>' )
.appendTo( ul );
};
}
});
});