jQuery(function($) {
var t;
jQuery(".menuBTN").on("click touchend", function() {
clearTimeout(t);
t = setTimeout(function() {
jQuery("#illicosearch-search").get(0).focus();
}, 500);
});
});
jQuery(document).ready(function () {
var recherche_en_cours = 0;
var mySearchTimeout;
jQuery("#illicosearch-search").keyup(function () {
clearTimeout(mySearchTimeout);
var filter = jQuery(this).val();
mySearchTimeout = setTimeout(function () {
var textRecherche = document.getElementById("illicosearch-search").value;
while (recherche_en_cours == 1) { sleep(100); }
if (textRecherche.length >= 3 && recherche_en_cours == 0) {
recherche_en_cours = 1;
moteur();
recherche_en_cours = 0;
}
else {
jQuery("#illicosearch-response").html("");
}
}, 150);
return true;
});
});
jQuery(document).click(function(event) {
if (jQuery(event.target).hasClass("remplace")) {
var recherche = jQuery(event.target).text();
jQuery("#illicosearch-search").val(recherche);
jQuery("#illicosearch-search").focus();
moteur();
}
});
function moteur(){
var textRecherche = document.getElementById("illicosearch-search").value;
var lang = jQuery("html").attr("lang");
jQuery.ajax({
url: "/wp-content/plugins/IllicoSearch/widgets/moteurv2.php",
method: "POST",
datatype: "json",
data: { resultRecherche: textRecherche, langue: lang},
success: function (data) {
jQuery("#illicosearch-response").html(data);
},
error: function (jqXHR, textStatus, errorThrown) {
jQuery("#illicosearch-response").html("Une erreur est survenue." + textStatus);
}
});
}