Created
December 10, 2015 08:55
-
-
Save MagnusThor/01c2323f0e240818cfb1 to your computer and use it in GitHub Desktop.
symSug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular.module("auctionApp").directive("symSuggestions", function ($compile) { | |
| return { | |
| restrict: 'E', | |
| scope: { | |
| options: '=options', | |
| select: '&onSelect', | |
| trigger: '=trigger', | |
| // transclude: true | |
| }, | |
| link: function link(scope, element, attrs) { | |
| var keys = { up: 38, down: 40, enter: 13 }; // key map | |
| var index = -1; | |
| var el = angular.element(document.querySelector("#" + attrs.trigger)); | |
| el.on("keyup", function (evt) { | |
| switch (evt.keyCode) { | |
| case keys.up: | |
| index--; | |
| break; | |
| case keys.down: | |
| index++; | |
| break; | |
| case keys.enter: | |
| scope.select({ item: scope.options[index] }); | |
| break; | |
| default: | |
| }; | |
| }); | |
| }, | |
| templateUrl: "/app/suggestions.html" | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment