@@ -27,16 +27,16 @@ angular.module('angular-advanced-searchbox', [])
2727 return attr . templateUrl || 'angular-advanced-searchbox.html' ;
2828 } ,
2929 controller : [
30- '$scope' , '$attrs' , '$element' , '$timeout' , '$filter' ,
31- function ( $scope , $attrs , $element , $timeout , $filter ) {
30+ '$scope' , '$attrs' , '$element' , '$timeout' , '$filter' , 'setFocusFor' ,
31+ function ( $scope , $attrs , $element , $timeout , $filter , setFocusFor ) {
3232
3333 $scope . parametersLabel = $scope . parametersLabel || 'Parameter Suggestions' ;
3434 $scope . parametersDisplayLimit = $scope . parametersDisplayLimit || 8 ;
3535 $scope . placeholder = $scope . placeholder || 'Search ...' ;
3636 $scope . searchThrottleTime = $scope . searchThrottleTime || 1000 ;
3737 $scope . searchParams = [ ] ;
3838 $scope . searchQuery = '' ;
39- $scope . setSearchFocus = false ;
39+ $scope . setFocusFor = setFocusFor ;
4040 var searchThrottleTimer ;
4141 var changeBuffer = [ ] ;
4242
@@ -116,6 +116,7 @@ angular.module('angular-advanced-searchbox', [])
116116
117117 var searchParam = $scope . searchParams [ index ] ;
118118 searchParam . editMode = true ;
119+ setFocusFor ( 'searchParam:' + searchParam . key ) ;
119120
120121 $scope . $emit ( 'advanced-searchbox:enteredEditMode' , searchParam ) ;
121122 } ;
@@ -223,7 +224,7 @@ angular.module('angular-advanced-searchbox', [])
223224 $scope . enterEditMode ( undefined , $scope . searchParams . length - 1 ) ;
224225 } else if ( $scope . searchParams . length === 0 ) {
225226 // no search parameter available anymore
226- $scope . setSearchFocus = true ;
227+ setFocusFor ( 'searchbox' ) ;
227228 }
228229 } ;
229230
@@ -237,7 +238,7 @@ angular.module('angular-advanced-searchbox', [])
237238 if ( currentIndex < $scope . searchParams . length - 1 ) {
238239 $scope . enterEditMode ( undefined , currentIndex + 1 ) ;
239240 } else {
240- $scope . setSearchFocus = true ;
241+ setFocusFor ( 'searchbox' ) ;
241242 }
242243 } ;
243244
@@ -363,27 +364,30 @@ angular.module('angular-advanced-searchbox', [])
363364 ]
364365 } ;
365366 } )
366- . directive ( 'nitSetFocus' , [
367- '$timeout' , '$parse' ,
368- function ( $timeout , $parse ) {
367+ . directive ( 'setFocusOn' , [
368+ function ( ) {
369369 return {
370370 restrict : 'A' ,
371371 link : function ( $scope , $element , $attrs ) {
372- var model = $parse ( $attrs . nitSetFocus ) ;
373- $scope . $watch ( model , function ( value ) {
374- if ( value === true ) {
375- $timeout ( function ( ) {
376- $element [ 0 ] . focus ( ) ;
377- } ) ;
372+ return $scope . $on ( 'advanced-searchbox:setFocusOn' , function ( e , id ) {
373+ if ( id === $attrs . setFocusOn ) {
374+ return $element [ 0 ] . focus ( ) ;
378375 }
379376 } ) ;
380- /*$element.bind('blur', function() {
381- $scope.$apply(model.assign($scope, false));
382- });*/
383377 }
384378 } ;
385379 }
386380 ] )
381+ . factory ( 'setFocusFor' , [
382+ '$rootScope' , '$timeout' ,
383+ function ( $rootScope , $timeout ) {
384+ return function ( id ) {
385+ return $timeout ( function ( ) {
386+ return $rootScope . $broadcast ( 'advanced-searchbox:setFocusOn' , id ) ;
387+ } ) ;
388+ } ;
389+ }
390+ ] )
387391 . directive ( 'nitAutoSizeInput' , [
388392 '$timeout' ,
389393 function ( $timeout ) {
0 commit comments