Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Initialize dropdown to have no default selection #22

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions dist/smart-area.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ angular.module('smartArea', [])
},
replace: true,
link: function(scope, textArea){
scope.textArea = textArea;
if(textArea[0].tagName.toLowerCase() !== 'textarea'){
console.warn("smartArea can only be used on textareas");
return false;
Expand Down Expand Up @@ -152,7 +153,9 @@ angular.module('smartArea', [])
$scope.trackCaret();

// TODO Track caret on another fake area, so I don't have to recalculate autocomplete triggers every time the cursor moves.
checkTriggers();
if(document.activeElement === $scope.textArea[0]) {
checkTriggers();
}
});

/* +----------------------------------------------------+
Expand Down Expand Up @@ -194,13 +197,20 @@ angular.module('smartArea', [])
if($scope.dropdown.content.length > 0) {
var code = event.keyCode || event.which;
if (code === 13) { // Enter
if($scope.dropdown.current !== -1) {
event.preventDefault();
event.stopPropagation();
// Add the selected word from the Dropdown
// to the areaData in the current position
$timeout(function(){
$scope.dropdown.selected($scope.dropdown.content[$scope.dropdown.current]);
},0);
} else {
$timeout(function(){
$scope.dropdown.content = [];
$element[0].focus();
},0);
}
}else if(code === 38){ // Up
event.preventDefault();
event.stopPropagation();
Expand Down Expand Up @@ -370,7 +380,7 @@ angular.module('smartArea', [])
// I need to get the index of the last match
var searchable = text.substr(0, position),
match, found = false, lastPosition = -1;
element.trigger.lastIndex = 0;
element.trigger.lastIndex = 0;
while ((match = element.trigger.exec(searchable)) !== null){
if(match.index === lastPosition){
break;
Expand Down Expand Up @@ -452,7 +462,7 @@ angular.module('smartArea', [])
});

$scope.dropdown.customSelect = null;
$scope.dropdown.current = 0;
$scope.dropdown.current = -1;
$scope.dropdown.content = suggestions;
}

Expand All @@ -477,6 +487,12 @@ angular.module('smartArea', [])
}, 0);
});

$element.bind('blur', function () {
$timeout(function(){
$scope.dropdown.content = [];
}, 250);
});

$element.bind('keydown', function(event){
resetScroll();
$scope.keyboardEvents(event);
Expand Down
2 changes: 1 addition & 1 deletion dist/smart-area.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/smart-area.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.