Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Run callback twice for keydown, keyup, blur, focus with Angular 1.3+ #15

Open
tuanchauict opened this issue Jan 22, 2015 · 0 comments
Open

Comments

@tuanchauict
Copy link

I found these issues comes because you add directives : ngKeydown, ngKeyup, ... into <tagger/> by hand. The issues are: run callback functions twice for keydown, keyup, ... events

Those directives have been done by angular 1.3 (I only touch 1.3+, I'm not sure with former versions)

Solution: check version before adding (line 6)

if(angular.version.major < 1 || angular.version.major == 1 && angular.version.minor < 3){
    _ref = ["ngKeydown", "ngKeyup", "ngBlur", "ngFocus"];
    _fn = function (directiveName) {
        return angular.module("tagger").directive(directiveName, [
            "$parse", function ($parse) {
                return function (scope, element, attr) {
                    var eventName, fn;
                    fn = $parse(attr[directiveName]);
                    eventName = directiveName.substring(2).toLowerCase();
                    return element.bind(eventName, function (event) {
                        fn(scope, {
                            $event: event
                        });
                        if (!(scope.$$phase || scope.$parent.$$phase || scope.$root.$$phase)) {
                            return scope.$apply();
                        }
                    });
                };
            }
        ]);
    };
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        directiveName = _ref[_i];
        _fn(directiveName);
    }
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant