fixes search keyboard support
This commit is contained in:
@@ -14,7 +14,7 @@ angular.module('umbraco.directives')
|
||||
.directive('onKeydown', function () {
|
||||
return {
|
||||
link: function (scope, elm, attrs) {
|
||||
$key('keydown', scope, elm, attrs);
|
||||
scope.$apply(attrs.onKeydown);
|
||||
}
|
||||
};
|
||||
})
|
||||
|
||||
@@ -21,7 +21,7 @@ angular.module('umbraco.services')
|
||||
keyboardManagerService.bind = function (label, callback, opt) {
|
||||
|
||||
//replace ctrl key with meta key
|
||||
if(isMac){
|
||||
if(isMac && label !== "ctrl+space"){
|
||||
label = label.replace("ctrl","meta");
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,83 @@
|
||||
* Controls the search functionality in the site
|
||||
*
|
||||
*/
|
||||
function SearchController($scope, searchService, $log, navigationService) {
|
||||
function SearchController($scope, searchService, $log, $location, navigationService) {
|
||||
|
||||
$scope.searchTerm = null;
|
||||
$scope.searchResults = [];
|
||||
$scope.isSearching = false;
|
||||
$scope.selectedResult = -1;
|
||||
|
||||
|
||||
$scope.navigateResults = function(ev){
|
||||
//38: up 40: down, 13: enter
|
||||
|
||||
switch(ev.keyCode){
|
||||
case 38:
|
||||
iterateResults(true);
|
||||
break;
|
||||
case 40:
|
||||
iterateResults(false);
|
||||
break;
|
||||
case 13:
|
||||
$location.path($scope.selectedItem.editorPath);
|
||||
navigationService.hideSearch();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var group = undefined;
|
||||
var groupIndex = -1;
|
||||
var itemIndex = -1;
|
||||
$scope.selectedItem = undefined;
|
||||
|
||||
|
||||
function iterateResults(up){
|
||||
//default group
|
||||
if(!group){
|
||||
group = $scope.groups[0];
|
||||
groupIndex = 0;
|
||||
}
|
||||
|
||||
if(up){
|
||||
if(itemIndex === 0){
|
||||
if(groupIndex === 0){
|
||||
gotoGroup($scope.groups.length-1, true);
|
||||
}else{
|
||||
gotoGroup(groupIndex-1, true);
|
||||
}
|
||||
}else{
|
||||
gotoItem(itemIndex-1);
|
||||
}
|
||||
}else{
|
||||
if(itemIndex < group.results.length-1){
|
||||
gotoItem(itemIndex+1);
|
||||
}else{
|
||||
if(groupIndex === $scope.groups.length-1){
|
||||
gotoGroup(0);
|
||||
}else{
|
||||
gotoGroup(groupIndex+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function gotoGroup(index, up){
|
||||
groupIndex = index;
|
||||
group = $scope.groups[groupIndex];
|
||||
|
||||
if(up){
|
||||
gotoItem(group.results.length-1);
|
||||
}else{
|
||||
gotoItem(0);
|
||||
}
|
||||
}
|
||||
|
||||
function gotoItem(index){
|
||||
itemIndex = index;
|
||||
$scope.selectedItem = group.results[itemIndex];
|
||||
}
|
||||
|
||||
//watch the value change but don't do the search on every change - that's far too many queries
|
||||
// we need to debounce
|
||||
@@ -19,12 +91,14 @@ function SearchController($scope, searchService, $log, navigationService) {
|
||||
if ($scope.searchTerm) {
|
||||
$scope.isSearching = true;
|
||||
navigationService.showSearch();
|
||||
$scope.selectedItem = undefined;
|
||||
searchService.searchAll({ term: $scope.searchTerm }).then(function (result) {
|
||||
$scope.searchResults = result;
|
||||
$scope.groups = _.filter(result, function(group){return group.results.length > 0;});
|
||||
});
|
||||
}else{
|
||||
$scope.isSearching = false;
|
||||
navigationService.hideSearch();
|
||||
$scope.selectedItem = undefined;
|
||||
}
|
||||
}, 100));
|
||||
|
||||
|
||||
@@ -19,12 +19,13 @@
|
||||
<form class="form-search" novalidate>
|
||||
<i class="icon-search"></i>
|
||||
<input type="text"
|
||||
hotkey="ctrl+shift+s"
|
||||
hotkey="ctrl+space"
|
||||
id="search-field"
|
||||
ng-model="searchTerm"
|
||||
class="umb-search-field search-query"
|
||||
localize="placeholder"
|
||||
placeholder="@placeholders_search"/>
|
||||
placeholder="@placeholders_search"
|
||||
ng-keydown="navigateResults($event)"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -38,8 +39,8 @@
|
||||
<h5><localize key="general_searchResults">Search results</localize></h5>
|
||||
</div>
|
||||
|
||||
<ul class="umb-search-group" ng-repeat="resultGroup in searchResults">
|
||||
<li ng-repeat="result in resultGroup.results">
|
||||
<ul class="umb-search-group" ng-repeat="group in groups">
|
||||
<li ng-repeat="result in group.results" ng-class="{'current':selectedItem == result}">
|
||||
<div>
|
||||
<a ng-class="{'first':$first}" ng-click="searchHide()" ng-href="#/{{result.editorPath}}">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user