-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsuggest.js
43 lines (41 loc) · 1.22 KB
/
suggest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import Ember from 'ember';
export default Ember.Mixin.create({
selectedFunction: '',
placeHolderText: '',
doDebounce: null,
inputVal: '',
selectedVal: '',
suggestions: Ember.A(),
debounceTime: 0,
miniumCharLength: 2,
escapedChars: [40,38, 13],
showSuggest: false,
keyUp: function(event){
var _scope = this;
if(event.keyCode === 27){
this.set('showSuggest', false);
}else if(this.escapedChars.indexOf(event.keyCode) === -1){
if(typeof this.get('targetObject').hideAlerts === 'function'){
this.get('targetObject').hideAlerts();
}
var noSpace = $(event.target).val().replace(/(^\s+|\s+$)/g, '');
if($(event.target).hasClass('typeahead') && noSpace.length > this.miniumCharLength ){
this.set('inputVal', noSpace);
Ember.run.debounce(this, this.doDebounce, this.debounceTime);
}
}
},
focusOut: function(){
var _scope = this;
var func = function(){
if( _scope.isDestroyed ) return;
_scope.set('showSuggest', false);
};
Ember.run.later(this, func, 300); // set a little delay so give the select a chance to set
},
actions: {
selectItem: function(value){
this.send(this.selectedFunction, value);
}
}
});