Skip to content

Commit d0dcb34

Browse files
pawelczakpawelczak
authored andcommitted
Closes #69. Template list
1 parent 53a8cc1 commit d0dcb34

File tree

10 files changed

+278
-7
lines changed

10 files changed

+278
-7
lines changed

demo/example_static_link.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>EasyAutocomplete static links</title>
5+
<link href="../dist/easy-autocomplete.min.css" rel="stylesheet" type="text/css">
6+
<script src="../lib/jquery-1.11.2.min.js"></script>
7+
<script src="../dist/jquery.easy-autocomplete.min.js" type="text/javascript" ></script>
8+
</head>
9+
<body>
10+
11+
<h1>EasyAutocomplete - static links</h1>
12+
13+
<input id="data-links" />
14+
15+
<script>
16+
17+
var options = {
18+
url: "resources/site.json",
19+
20+
getValue: "text",
21+
22+
template: {
23+
type: "links",
24+
fields: {
25+
link: "site"
26+
}
27+
},
28+
29+
list: {
30+
match: {
31+
enabled: false
32+
}
33+
},
34+
35+
theme: "plate-dark"
36+
};
37+
38+
$("#data-links").easyAutocomplete(options);
39+
40+
</script>
41+
42+
</body>
43+
44+
</html>

demo/resources/site.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[{
2+
"text": "Home",
3+
"site": "http://easyautocomplete.com"
4+
},
5+
{
6+
"text": "Guide",
7+
"site": "http://easyautocomplete.com/guide"
8+
},
9+
{
10+
"text": "Examples",
11+
"site": "http://easyautocomplete.com/examples"
12+
},
13+
{
14+
"text": "Themes",
15+
"site": "http://easyautocomplete.com/themes"
16+
},
17+
{
18+
"text": "Download",
19+
"site": "http://easyautocomplete.com/download"
20+
}
21+
]

dist/easy-autocomplete.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
.easy-autocomplete input:hover, .easy-autocomplete input:focus {
2323
box-shadow: none;
2424
}
25+
.easy-autocomplete a {
26+
display: block;
27+
}
2528
.easy-autocomplete.eac-blue-light input:hover, .easy-autocomplete.eac-blue-light input:focus {
2629
border-color: #66afe9;
2730
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset, 0 0 8px rgba(102, 175, 233, 0.6);

dist/easy-autocomplete.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jquery.easy-autocomplete.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ var EasyAutocomplete = (function(scope){
290290
function checkPropertiesIfExist(source, target) {
291291
for(var property in target) {
292292
if (source[property] === undefined) {
293-
consol.log("Option property '" + property + "' does not exist in EasyAutocomplete API.");
293+
consol.log("Property '" + property + "' does not exist in EasyAutocomplete options API.");
294294
}
295295

296296
if (typeof source[property] === "object" && !externalObject(property)) {
@@ -489,6 +489,15 @@ var EasyAutocomplete = (function(scope){
489489
},
490490
cssClass: "eac-icon-right"
491491
},
492+
links: {
493+
type: "links",
494+
fields: {
495+
link: ""
496+
},
497+
method: function(element) {
498+
return element;
499+
}
500+
},
492501
custom: {
493502
type: "custom",
494503
method: function() {}
@@ -513,7 +522,6 @@ var EasyAutocomplete = (function(scope){
513522

514523

515524
return buildMethod;
516-
517525
}
518526

519527
if (template.type === "iconRight") {
@@ -540,7 +548,7 @@ var EasyAutocomplete = (function(scope){
540548

541549
if (typeof _fields.iconSrc === "string") {
542550
buildMethod = function(elementValue, element) {
543-
return "<img class='eac-icon' src='" + element[_fields.iconSrc] + "' />" + elementValue ;
551+
return "<img class='eac-icon' src='" + element[_fields.iconSrc] + "' />" + elementValue;
544552
};
545553
} else if (typeof _fields.iconSrc === "function") {
546554
buildMethod = function(elementValue, element) {
@@ -551,6 +559,23 @@ var EasyAutocomplete = (function(scope){
551559
return buildMethod;
552560
}
553561

562+
if(template.type === "links") {
563+
564+
var buildMethod = "";
565+
566+
if (typeof _fields.link === "string") {
567+
buildMethod = function(elementValue, element) {
568+
return "<a href='" + element[_fields.link] + "' >" + elementValue + "</a>";
569+
};
570+
} else if (typeof _fields.link === "function") {
571+
buildMethod = function(elementValue, element) {
572+
return "<a href='" + _fields.link(element) + "' >" + elementValue + "</a>";
573+
};
574+
}
575+
576+
return buildMethod;
577+
}
578+
554579

555580
if (template.type === "custom") {
556581

0 commit comments

Comments
 (0)