|
|
@@ -21,9 +21,15 @@ function (angular, app, _) {
|
|
|
var variable = scope.variable;
|
|
|
|
|
|
scope.show = function() {
|
|
|
+ if (scope.selectorOpen) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
scope.selectorOpen = true;
|
|
|
scope.giveFocus = 1;
|
|
|
scope.oldCurrentText = variable.current.text;
|
|
|
+ scope.highlightIndex = -1;
|
|
|
+
|
|
|
var currentValues = variable.current.value;
|
|
|
|
|
|
if (_.isString(currentValues)) {
|
|
|
@@ -37,11 +43,39 @@ function (angular, app, _) {
|
|
|
return option;
|
|
|
});
|
|
|
|
|
|
+ scope.search = {query: '', options: scope.options};
|
|
|
+
|
|
|
$timeout(function() {
|
|
|
bodyEl.on('click', scope.bodyOnClick);
|
|
|
}, 0, false);
|
|
|
};
|
|
|
|
|
|
+ scope.queryChanged = function() {
|
|
|
+ scope.highlightIndex = -1;
|
|
|
+ scope.search.options = _.filter(scope.options, function(option) {
|
|
|
+ return option.text.toLowerCase().indexOf(scope.search.query.toLowerCase()) !== -1;
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ scope.keyDown = function (evt) {
|
|
|
+ if (evt.keyCode === 27) {
|
|
|
+ scope.hide();
|
|
|
+ }
|
|
|
+ if (evt.keyCode === 40) {
|
|
|
+ scope.moveHighlight(1);
|
|
|
+ }
|
|
|
+ if (evt.keyCode === 38) {
|
|
|
+ scope.moveHighlight(-1);
|
|
|
+ }
|
|
|
+ if (evt.keyCode === 13) {
|
|
|
+ scope.optionSelected(scope.search.options[scope.highlightIndex], {});
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ scope.moveHighlight = function(direction) {
|
|
|
+ scope.highlightIndex = (scope.highlightIndex + direction) % scope.search.options.length;
|
|
|
+ };
|
|
|
+
|
|
|
scope.optionSelected = function(option, event) {
|
|
|
option.selected = !option.selected;
|
|
|
|
|
|
@@ -100,10 +134,6 @@ function (angular, app, _) {
|
|
|
|
|
|
scope.hide = function() {
|
|
|
scope.selectorOpen = false;
|
|
|
- // if (scope.oldCurrentText !== variable.current.text) {
|
|
|
- // scope.onUpdated();
|
|
|
- // }
|
|
|
-
|
|
|
bodyEl.off('click', scope.bodyOnClick);
|
|
|
};
|
|
|
|