2014-12-20 14:26:46 +08:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
|
|
|
classNames: ['search-input'],
|
|
|
|
classNameBindings: ['active', 'value:clearable'],
|
|
|
|
|
2015-01-16 14:56:10 +08:00
|
|
|
layoutName: 'components/ui/controls/search-input',
|
|
|
|
|
2014-12-20 14:26:46 +08:00
|
|
|
didInsertElement: function() {
|
|
|
|
var self = this;
|
|
|
|
this.$().find('input').on('keydown', function(e) {
|
|
|
|
if (e.which == 27) {
|
|
|
|
self.clear();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.$().find('.clear').on('mousedown', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}).on('click', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
self.clear();
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
clear: function() {
|
|
|
|
this.set('value', '');
|
2015-01-16 14:56:10 +08:00
|
|
|
this.send('search');
|
2014-12-20 14:26:46 +08:00
|
|
|
this.$().find('input').focus();
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement: function() {
|
|
|
|
this.$().find('input').off('keydown');
|
|
|
|
this.$().find('.clear').off('mousedown click');
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
search: function() {
|
2015-01-16 14:56:10 +08:00
|
|
|
this.get('action')(this.get('value'));
|
2014-12-20 14:26:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|