Skip to content

Commit

Permalink
1.10
Browse files Browse the repository at this point in the history
JS:
- replace link by url
PHP:
- add phpLIKE.php to use autocomplete whithout SQL
  • Loading branch information
ComeBurguburu committed Feb 1, 2015
1 parent 5c40a26 commit f626185
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
12 changes: 9 additions & 3 deletions js/autocomplete.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ Copyright (c) 2015-2042

// This is the easiest way to have default options.
var settings = $.extend({
link: "php/search.php",
url: "php/search.php",
autohide: true,
callback: null,
className: "select-autocomplete",
dataSelector: "span",
show_all: false,
max_values: 10,
param_name: "search",
no_result: "no result"
no_result: "no result",
key: null,
value: null
}, options),
search_field = $(this),
index = 0,
Expand All @@ -48,6 +50,10 @@ Copyright (c) 2015-2042
data = {};
data.show_all = settings.show_all;
data.max_values = settings.max_values;

if(settings.key !== null && settings.value !== null) {
data[settings.key] = settings.value;
}

$(result).css({border: "1px solid black", width: "90.5%" });
search_field.width("90%");
Expand Down Expand Up @@ -116,7 +122,7 @@ Copyright (c) 2015-2042
oldValue = search_field.val();

$.post(
settings.link,
settings.url,
data,
function (response) {
if (response === "" && search_field.val() !== "") {
Expand Down
25 changes: 25 additions & 0 deletions php/phpLIKE.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/*!
Autocomplete a input Ajax wrapper for jQuery
phpLIKE equivalent of SQL LIKE in PHP
by Côme BURGUBURU
Version 1.8.0
Full source at https://github.com/ComeBurguburu/autocomplete
Copyright (c) 2015-2042
*/
/*
return $input string without all accents
*/
function insensitive_accent($input) {
return preg_replace("/^'|[^A-Za-z0-9\s-]|'$/", '', iconv("utf-8", "ascii//TRANSLIT//IGNORE", $input));
}
/*
detect if $substring is contained in $string
case insensitive
accent insensitive
return boolean
*/
function LIKE($string, $substring){
return stripos(insensitive_accent($string),insensitive_accent($substring))!== false;
}
2 changes: 1 addition & 1 deletion php/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
exit;
}
if(trim($_REQUEST["search"])==""){
if(!(isset($_REQUEST["show_all"]) && $_REQUEST["show_all"]=="true")){
if(!(isset($_REQUEST["show_all"]) && $_REQUEST["show_all"]==="true")){
die("");
}
}
Expand Down

0 comments on commit f626185

Please sign in to comment.