Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Keep focus on field while typing, fixes #167
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkgroenen committed Dec 27, 2015
1 parent 433a77e commit 70e9dd1
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/app/search/search.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ angular.module('mopify.search', [

.controller("SearchController", function SearchController($rootScope, $scope, $routeParams, $route, $timeout, $location, Spotify, SpotifyLogin, mopidyservice, stationservice, util, Settings){

$scope.query = $routeParams.query;
var typingTimeout = null;
$scope.$watch(function() {
return $routeParams.query;
}, function(val) {
$scope.query = val;
$scope.typing();
});

// Set focus on input
$rootScope.focussearch = true;
var typingTimeout = null;

// Define empty result scope
$scope.results = {
Expand Down Expand Up @@ -64,7 +67,7 @@ angular.module('mopify.search', [
*/
$scope.typing = function(event){
// Close the search overlay on ESC press
if(event.keyCode === 27)
if(event !== undefined && event.keyCode === 27)
$scope.closeSearch();

if($scope.query.trim().length === 0 || $scope.query === previousQuery)
Expand Down Expand Up @@ -134,6 +137,9 @@ angular.module('mopify.search', [
resultsloaded++;
if(resultsloaded == 2)
getTopMatchingResult($scope.query, $scope.results);

// Put focus on search
$rootScope.focussearch = true;
});
};

Expand Down Expand Up @@ -294,8 +300,14 @@ angular.module('mopify.search', [
return;

if($scope.query.trim().length > 0 && $scope.query !== previous){
$location.url("/search?query=" + $scope.query + "&refer=" + $location.url());
$scope.query = "";
var refer;

if($location.url().indexOf("/search") > -1)
refer = $routeParams.refer;
else
refer = $location.url();

$location.url("/search?query=" + $scope.query + "&refer=" + refer);
}

previous = $scope.query;
Expand All @@ -313,5 +325,11 @@ angular.module('mopify.search', [
}
});

$scope.$watch(function() {
return $routeParams.query;
}, function(val) {
$scope.query = val;
});

});

0 comments on commit 70e9dd1

Please sign in to comment.