Skip to content

Commit

Permalink
Added "threshold" option, code optimizations, reduced weight & update…
Browse files Browse the repository at this point in the history
…d documentation.
  • Loading branch information
TarekRaafat committed Dec 20, 2018
1 parent 86472b2 commit d9116b3
Show file tree
Hide file tree
Showing 28 changed files with 90 additions and 68 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"wrap-iife": 2,
"no-unused-vars": 2,
"no-use-before-define": 2,
"comma-dangle": ["error", "always"],
"comma-dangle": 0,
"eol-last": ["error", "never"],
"max-params": ["error", 3],
"no-inline-comments": 2,
Expand All @@ -33,6 +33,9 @@
"spaced-comment": 2,
"no-var": 2,
"no-duplicate-imports": 2,
"max-len": ["error", {
"code": 95
}],
"indent": [
"error",
"tab"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

> Simple autocomplete pure vanilla Javascript library. <a href="https://tarekraafat.github.io/autoComplete.js/demo/" target="\_blank">Live Demo</a>
autoComplete.js is a simple pure vanilla Javascript library that's designed for speed, high versatility and seamless integration with wide range of projects & systems, made for users and developers in mind.
autoComplete.js is a simple pure vanilla Javascript library that's progressively designed for speed, high versatility and seamless integration with wide range of projects & systems, made for users and developers in mind.

## Features

Expand Down Expand Up @@ -53,13 +53,13 @@ git clone https://github.com/TarekRaafat/autoComplete.js.git
`CSS`

```html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/TarekRaafat/[email protected].2/dist/css/autoComplete.min.css"/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/TarekRaafat/[email protected].3/dist/css/autoComplete.min.css"/>
```

`JS`

```html
<script src="https://cdn.jsdelivr.net/gh/TarekRaafat/[email protected].2/dist/js/autoComplete.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/TarekRaafat/[email protected].3/dist/js/autoComplete.min.js"></script>
```

#### <a href="https://www.npmjs.com/package/@tarekraafat/autocomplete.js">npm</a> install `(Node Package Manager)`
Expand Down
20 changes: 10 additions & 10 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
<html lang="en">

<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>autoComplete.js - Vanilla Javascript</title>
<meta name="”description" content="”autoComplete.js" is an easy-to-use simple pure vanilla Javascript library thats built for speed, high versatility and seamless integration with wide range of projects and systems.” />
<meta name="keywords" content="autoComplete.js, easy-to-use, simple, pure, vanilla, Javascript, JS, library, speed, Lightning, fast, Versatile, Customizable, hackable, developer friendly, zero, no, Dependencies, Lightweight, high, integration, scalable, scalability, open source, open, source, guthub" />
<meta name="author" content="Tarek Raafat" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" media="screen" href="./css/autoComplete.css" />
<link rel="stylesheet" type="text/css" media="screen" href="./css/main.css" />
<link href="https://fonts.googleapis.com/css?family=PT+Sans" rel="stylesheet" />
<meta name=”description" content=”Simple autocomplete pure vanilla Javascript library thats designed for speed, high versatility and seamless integration with wide range of projects and systems.”>
<meta name="keywords" content="autoComplete.js, autocomplete, easy-to-use, simple, pure, vanilla, javascript, js, library, speed, lightning, fast, search, suggestions, versatile, customizable, hackable, developer friendly, zero dependencies, lightweight, high integration, scalable, scalability, open source, github">
<meta name="author" content="Tarek Raafat">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="./css/autoComplete.css">
<link rel="stylesheet" type="text/css" media="screen" href="./css/main.css">
<link href="https://fonts.googleapis.com/css?family=PT+Sans" rel="stylesheet">
</head>

<body>
Expand Down Expand Up @@ -57,7 +57,7 @@ <h1>
</h1>
</header>
<div class="body" align="center">
<input id="autoComplete" type="text" placeholder="Loading..." tabindex="0" />
<input id="autoComplete" type="text" placeholder="Loading..." tabindex="0">
<div class="mode">
<h4>mode</h4>
<div class="toggele">
Expand Down
13 changes: 6 additions & 7 deletions dist/js/autoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
}
};
this.searchEngine = config.searchEngine === "loose" ? "loose" : "strict";
this.threshold = Number(config.threshold) || 0;
this.renderResults = renderResults.createResultsList(config.renderResults ? {
destination: config.renderResults.destination,
position: config.renderResults.position
Expand All @@ -98,7 +99,7 @@
position: "afterend"
});
this.placeHolder = String(config.placeHolder) ? config.placeHolder : false;
this.maxResults = Number(config.maxResults) ? config.maxResults : 10;
this.maxResults = Number(config.maxResults) || 5;
this.highlight = config.highlight === true ? true : false;
this.dataAttribute = config.dataAttribute === Object ? {
tag: config.dataAttribute.tag,
Expand Down Expand Up @@ -130,17 +131,15 @@
match.push(recordChar);
}
if (searchPosition !== query.length) {
return "";
return false;
}
return match.join("");
} else {
if (record.toLowerCase().includes(query.toLowerCase())) {
if (this.highlight) {
this.resList.push(record.toLowerCase().replace(renderResults.getSearchInput().value.toLowerCase(), renderResults.highlight(renderResults.getSearchInput().value.toLowerCase())));
this.cleanResList.push(record);
return record.toLowerCase().replace(renderResults.getSearchInput().value.toLowerCase(), renderResults.highlight(renderResults.getSearchInput().value.toLowerCase()));
} else {
this.resList.push(record);
this.cleanResList.push(record);
return record;
}
}
}
Expand Down Expand Up @@ -170,7 +169,7 @@
value: function searchInputValidation(selector) {
var _this2 = this;
selector.addEventListener("keyup", function () {
if (selector.value.length > 0 && selector.value !== " ") {
if (selector.value.length > _this2.threshold && selector.value !== " ") {
renderResults.clearResults();
_this2.listMatchedResults();
if (_this2.onSelection) {
Expand Down
2 changes: 1 addition & 1 deletion dist/js/autoComplete.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d9116b3

Please sign in to comment.