@@ -104,7 +104,7 @@ function $StateRefDirective($state, $timeout) {
104
104
105
105
var activeDirective = uiSrefActive [ 1 ] || uiSrefActive [ 0 ] ;
106
106
if ( activeDirective ) {
107
- activeDirective . $$setStateInfo ( ref . state , params ) ;
107
+ activeDirective . $$addStateInfo ( ref . state , params ) ;
108
108
}
109
109
if ( newHref === null ) {
110
110
nav = false ;
@@ -223,30 +223,50 @@ function $StateRefActiveDirective($state, $stateParams, $interpolate) {
223
223
return {
224
224
restrict : "A" ,
225
225
controller : [ '$scope' , '$element' , '$attrs' , function ( $scope , $element , $attrs ) {
226
- var state , params , activeClass ;
226
+ var states = [ ] , activeClass ;
227
227
228
228
// There probably isn't much point in $observing this
229
229
// uiSrefActive and uiSrefActiveEq share the same directive object with some
230
230
// slight difference in logic routing
231
231
activeClass = $interpolate ( $attrs . uiSrefActiveEq || $attrs . uiSrefActive || '' , false ) ( $scope ) ;
232
232
233
233
// Allow uiSref to communicate with uiSrefActive[Equals]
234
- this . $$setStateInfo = function ( newState , newParams ) {
235
- state = $state . get ( newState , stateContext ( $element ) || $state . $current ) ;
236
- params = newParams ;
237
- update ( ) ;
234
+ this . $$addStateInfo = function ( newState , newParams ) {
235
+ var state = $state . get ( newState , stateContext ( $element ) ) ;
236
+ if ( state ) {
237
+ states . push ( {
238
+ state : state ,
239
+ params : newParams
240
+ } ) ;
241
+ update ( ) ;
242
+ }
238
243
} ;
239
244
240
245
$scope . $on ( '$stateChangeSuccess' , update ) ;
241
246
242
247
// Update route state
243
248
function update ( ) {
244
- $element [ ( isMatch ( ) ? "add" : "remove" ) + "Class" ] ( activeClass ) ;
249
+ if ( anyMatch ( ) ) {
250
+ $element . addClass ( activeClass ) ;
251
+ } else {
252
+ $element . removeClass ( activeClass ) ;
253
+ }
254
+ }
255
+
256
+ function anyMatch ( ) {
257
+ for ( var i = 0 ; i < states . length ; i ++ ) {
258
+ if ( isMatch ( states [ i ] . state , states [ i ] . params ) ) {
259
+ return true ;
260
+ }
261
+ }
262
+ return false ;
245
263
}
246
264
247
- function isMatch ( ) {
265
+ function isMatch ( state , params ) {
248
266
if ( typeof $attrs . uiSrefActiveEq !== 'undefined' ) {
249
- return $state . $current . self === state && matchesParams ( ) ;
267
+ return $state . is ( state . name , params ) ;
268
+ } else {
269
+ return $state . includes ( state . name , params ) ;
250
270
}
251
271
return $state . includes ( state . name ) && matchesParams ( ) ;
252
272
}
0 commit comments