فهرست منبع

Add Keys enum; use it when detecting keystrokes in the input suggestions component.

Paulo Reis 8 سال پیش
والد
کامیت
522084a504

+ 2 - 2
services/web/public/coffee/components/inputSuggestions.coffee

@@ -1,7 +1,7 @@
 define [
 	"base"
 ], (App) ->
-	inputSuggestionsController = ($scope, $element, $attrs) ->
+	inputSuggestionsController = ($scope, $element, $attrs, Keys) ->
 		ctrl = @ 
 		ctrl.showHint = false
 		ctrl.hasFocus = false
@@ -14,7 +14,7 @@ define [
 			ctrl.suggestion = null
 			ctrl.onBlur()
 		ctrl.handleKeyDown = ($event) ->
-			if ($event.which == 9 or $event.which == 13) and ctrl.suggestion? and ctrl.suggestion != ""
+			if ($event.which == Keys.TAB or $event.which == Keys.ENTER) and ctrl.suggestion? and ctrl.suggestion != ""
 				$event.preventDefault()
 				ctrl.localNgModel += ctrl.suggestion
 			ctrl.suggestion = null

+ 1 - 0
services/web/public/coffee/main.coffee

@@ -22,6 +22,7 @@ define [
 	"main/learn"
 	"main/affiliations/controllers/UserAffiliationsController"
 	"main/affiliations/factories/UserAffiliationsDataService"
+	"main/keys"
 	"analytics/AbTestingManager"
 	"directives/asyncForm"
 	"directives/stopPropagation"

+ 16 - 0
services/web/public/coffee/main/keys.coffee

@@ -0,0 +1,16 @@
+define [
+	"base"
+], (App) ->
+	App.constant "Keys",
+		ENTER     : 13
+		TAB       : 9
+		ESCAPE    : 27
+		SPACE     : 32
+		BACKSPACE : 8
+		UP        : 38
+		DOWN      : 40
+		LEFT      : 37
+		RIGHT     : 39
+		PERIOD    : 190
+		COMMA     : 188
+		END       : 35