Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Step 3.16: Add input directive
  • Loading branch information
DAB0mB authored and Dotan Simha committed Nov 23, 2016
1 parent d0d5ac0 commit 60aa704
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions client/scripts/directives/input.directive.js
@@ -0,0 +1,51 @@
import { Directive } from 'angular-ecmascript/module-helpers';

export default class InputDirective extends Directive {
constructor() {
super(...arguments);

this.restrict = 'E';

this.scope = {
'returnClose': '=',
'onReturn': '&',
'onFocus': '&',
'onBlur': '&'
};
}

link(scope, element) {
element.bind('focus', (e) => {
if (!scope.onFocus) return;

this.$timeout(() => {
scope.onFocus();
});
});

element.bind('blur', (e) => {
if (!scope.onBlur) return;

this.$timeout(() => {
scope.onBlur();
});
});

element.bind('keydown', (e) => {
if (e.which != 13) return;

if (scope.returnClose) {
element[0].blur();
}

if (scope.onReturn) {
this.$timeout(() => {
scope.onReturn();
});
}
});
}
}

InputDirective.$name = 'input';
InputDirective.$inject = ['$timeout'];

0 comments on commit 60aa704

Please sign in to comment.