Skip to content

Commit 22de626

Browse files
committed
fixed blur event on FF adn chrome, fixed esc and tab key
1 parent b09219a commit 22de626

File tree

6 files changed

+29
-22
lines changed

6 files changed

+29
-22
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
* Zero configuration setup for basic usage
1111
* Highlighted keyword in suggestions
1212
* Configurable label for suggestions
13-
* Close with esc key or blur
13+
* Close with esc key, blur or tab
1414
* Selection with enter key or click
1515
* No results message
1616
* UI indication during search
1717
* Advanced usage with custom templates
1818

1919
### Requirements
2020

21-
* Boostrap
21+
* Bootstrap
2222
* Font awesome
2323

2424
### Basic usage
@@ -46,11 +46,10 @@ Place the autocomplete directive in your view
4646
btc-query="queryFunction"
4747
btc-callback="callbackFunction"
4848
btc-noresults="No results!"
49-
ng-model="city"></bootcomplete>
49+
ng-model="modelvariable"></bootcomplete>
5050
```
5151

52-
Define in your controller the query function (you should return a promise) with the searchstring as a parameter
53-
In this example ENDPOINT is a factory
52+
Define in your controller the query function (you should return a promise) with the searchstring as a parameter. In this example ENDPOINT is a factory
5453

5554
```js
5655
$scope.queryFunction = function (searchstring) {
@@ -68,8 +67,8 @@ $scope.callbackFunction = function () {
6867

6968
### Advanced usage
7069

71-
You can specify a custom template to display the suggestions using the results array
72-
Any boostrap/non-boostrap html is accepted, for example
70+
You can specify a custom template to display the suggestions using the results array.
71+
Any bootstrap/non-boostrap html is accepted, for example
7372

7473
```html
7574
<div class="media" ng-repeat="result in results">
@@ -81,10 +80,13 @@ Any boostrap/non-boostrap html is accepted, for example
8180
<div class="media-body">
8281
<h4 class="media-heading">{{result.title}}</h4>
8382
{{result.text}}
83+
<p><a href="" class="btc-clickLink" ng-click="select($index)"></a></p>
8484
</div>
8585
</div>
8686
```
8787

88+
classname "btc-clickLink" id required on any link that fires the selection.
89+
8890
### Options
8991

9092
#### btc-minlength

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bootcomplete",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"authors": [
55
"Matteo Leoni <leoni.matteo@gmail.com>"
66
],

dist/bootcomplete.min.js

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bootcomplete",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "A simple angular autocomplete made for bootstrap3",
55
"main": "index.js",
66
"scripts": {

src/bootcomplete.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ directive('bootcomplete', ["$compile", "$templateRequest", "$timeout", "$sce", f
1818
btcCallback: '='
1919
},
2020
template: "<div class='input-group input-group-{{btcSize}}'>\n"+
21-
"<input placeholder='{{btcPlaceholder}}' type='text' class='form-control' ng-blur='blur($event)'/>\n"+
21+
"<input placeholder='{{btcPlaceholder}}' type='text' class='form-control' ng-blur='blur($event)' autocomplete=\"off\"/>\n"+
2222
"<span class='input-group-addon'><i class='fa fa-refresh' ng-class=\"{'fa-spin': loading }\"></i></span>\n"+
2323
"</div>",
2424
link: function (scope, element, attrs, controller) {
2525

2626
var input = element[0].querySelector('.form-control'),
2727
suggestionTemplate = "<ul class=\"dropdown-menu\" style=\"position:static;display:block;float:none;}\">\n"+
2828
"<li ng-class=\"{'active':selectedIndex === $index}\" ng-repeat=\"result in results\" ng-show=\"results.length\">\n"+
29-
"<a ng-style=\"{'white-space':'normal'}\" href=\"\" ng-click=\"select($index)\" ng-bind-html=\"result.btclabel\"></a>\n"+
29+
"<a class=\"btc-clickLink\" ng-style=\"{'white-space':'normal'}\" href=\"\" ng-click=\"select($index)\" ng-bind-html=\"result.btclabel\"></a>\n"+
3030
"</li>\n"+
3131
"<li class=\"disabled\" ng-hide=\"results.length\">\n"+
3232
"<a href=\"\">{{noresultsMsg}}</a>\n"+
@@ -41,26 +41,31 @@ directive('bootcomplete', ["$compile", "$templateRequest", "$timeout", "$sce", f
4141

4242
// select item
4343
scope.select = function (index) {
44-
if (!scope.btcTemplate){
44+
45+
if (!scope.btcTemplate)
4546
delete scope.results[index].btclabel; // delete label from object
46-
}
47+
4748
element.controller('ngModel').$setViewValue(scope.results[index]);
4849
scope.btcCallback.call();
4950
scope.close();
5051
};
5152

5253
// close autocomplete
5354
scope.close = function () {
54-
input.value = '';
55-
scope.selectedIndex = -1;
5655
scope.visible = false;
56+
scope.selectedIndex = -1;
57+
input.value = '';
5758
};
5859

5960
// close on blur
60-
scope.blur = function (event) {
61-
// close only if the blur target is not a suggestion
62-
if (!event.relatedTarget)
61+
scope.blur = function (e) {
62+
setTimeout(function(){
63+
var focused = document.activeElement;
64+
if(focused.tagName!=='A' && focused.className.indexOf('btc-clickLink')===-1) {
6365
scope.close();
66+
scope.$apply();
67+
}// check the elemnt with focus
68+
},1);
6469
};
6570

6671
// append element to the DOM
@@ -123,8 +128,8 @@ directive('bootcomplete', ["$compile", "$templateRequest", "$timeout", "$sce", f
123128
if (scope.selectedIndex != -1)
124129
scope.select(scope.selectedIndex);
125130
}
126-
//esc
127-
if (e.keyCode === 27) {
131+
//esc or tab
132+
if (e.keyCode === 27 || e.keyCode === 9) {
128133
scope.close();
129134
}
130135

src/forecast.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</div>
1010
<div class="media-body">
1111
<div class="pull-right">
12-
<a href="" class="btn btn-sm btn-default" ng-click="select($index)">Read More...</a>
12+
<a href="" class="btn btn-sm btn-default btc-clickLink" ng-click="select($index)">Read More...</a>
1313
</div>
1414
<h5 class="media-heading">{{result.weather[0].description}} </h5>
1515
<span>{{result.main.temp}}°C {{result.main.humidity}}%</span>

0 commit comments

Comments
 (0)