2
2
* @ngdoc module
3
3
* @name material.components.navBar
4
4
*/
5
-
6
-
7
5
angular . module ( 'material.components.navBar' , [ 'material.core' ] )
8
6
. controller ( 'MdNavBarController' , MdNavBarController )
9
7
. directive ( 'mdNavBar' , MdNavBar )
@@ -138,38 +136,46 @@ function MdNavBar($mdAria, $mdTheming, $window, $mdUtil) {
138
136
* (https://www.w3.org/TR/wai-aria-1.0/complete#tablist) and
139
137
* tabs (https://www.w3.org/TR/wai-aria-1.0/complete#tab).
140
138
*
141
- * @param {!angular. JQLite } $element
142
- * @param {!angular.Scope } $scope
143
- * @param {!angular.Timeout } $timeout
139
+ * @param {!JQLite } $element
140
+ * @param {!IScope } $scope
141
+ * @param {!ITimeoutService } $timeout
144
142
* @param {!Object } $mdConstant
145
143
* @constructor
146
144
* @final
147
145
* @ngInject
148
146
*/
149
147
function MdNavBarController ( $element , $scope , $timeout , $mdConstant ) {
150
148
// Injected variables
151
- /** @private @const {!angular.Timeout} */
149
+ /**
150
+ * @private @const
151
+ * @type {!ITimeoutService }
152
+ */
152
153
this . _$timeout = $timeout ;
153
154
154
- /** @private @const {!angular.Scope} */
155
+ /**
156
+ * @private @const
157
+ * @type {!IScope }
158
+ */
155
159
this . _$scope = $scope ;
156
160
157
- /** @private @const {!Object} */
161
+ /**
162
+ * @private @const
163
+ * @type {!Object }
164
+ */
158
165
this . _$mdConstant = $mdConstant ;
159
166
160
167
// Data-bound variables.
161
- /** @type {string } */
168
+ /** @type {? string } */
162
169
this . mdSelectedNavItem ;
163
170
164
- /** @type {string } */
171
+ /** @type {? string } */
165
172
this . navBarAriaLabel ;
166
173
167
174
// State variables.
168
-
169
- /** @type {?angular.JQLite } */
175
+ /** @type {?HTMLElement } */
170
176
this . _navBarEl = $element [ 0 ] ;
171
177
172
- /** @type {?angular. JQLite } */
178
+ /** @type {?JQLite } */
173
179
this . _inkbar ;
174
180
175
181
var self = this ;
@@ -220,14 +226,12 @@ MdNavBarController.prototype._updateTabs = function(newValue, oldValue) {
220
226
// this._getTabs can return null if nav-bar has not yet been initialized
221
227
if ( ! tabs ) return ;
222
228
223
- var oldIndex = - 1 ;
224
229
var newIndex = - 1 ;
225
230
var newTab = this . _getTabByName ( newValue ) ;
226
231
var oldTab = this . _getTabByName ( oldValue ) ;
227
232
228
233
if ( oldTab ) {
229
234
oldTab . setSelected ( false ) ;
230
- oldIndex = tabs . indexOf ( oldTab ) ;
231
235
}
232
236
233
237
if ( newTab ) {
@@ -236,7 +240,7 @@ MdNavBarController.prototype._updateTabs = function(newValue, oldValue) {
236
240
}
237
241
238
242
this . _$timeout ( function ( ) {
239
- self . _updateInkBarStyles ( newTab , newIndex , oldIndex ) ;
243
+ self . _updateInkBarStyles ( newTab , newIndex ) ;
240
244
// Don't change focus when there is no newTab, the new and old tabs are the same, or when
241
245
// called from MdNavBarController._initTabs() which would have no oldTab defined.
242
246
if ( newTab && oldTab && ! sameTab ) {
@@ -247,6 +251,8 @@ MdNavBarController.prototype._updateTabs = function(newValue, oldValue) {
247
251
248
252
/**
249
253
* Repositions the ink bar to the selected tab.
254
+ * @param {MdNavItemController } tab the nav item that should have ink bar styles applied
255
+ * @param {number= } newIndex the index of the newly selected nav item
250
256
* @private
251
257
*/
252
258
MdNavBarController . prototype . _updateInkBarStyles = function ( tab , newIndex ) {
@@ -265,11 +271,11 @@ MdNavBarController.prototype._updateInkBarStyles = function(tab, newIndex) {
265
271
} ;
266
272
267
273
/**
268
- * Updates inkbar to match current tab.
274
+ * Updates ink bar to match current tab.
269
275
*/
270
276
MdNavBarController . prototype . updateSelectedTabInkBar = function ( ) {
271
277
this . _updateInkBarStyles ( this . _getSelectedTab ( ) ) ;
272
- }
278
+ } ;
273
279
274
280
/**
275
281
* Returns an array of the current tabs.
@@ -282,7 +288,7 @@ MdNavBarController.prototype._getTabs = function() {
282
288
. map ( function ( el ) {
283
289
return angular . element ( el ) . controller ( 'mdNavItem' ) ;
284
290
} ) ;
285
- return controllers . indexOf ( undefined ) ? controllers : null ;
291
+ return controllers . indexOf ( undefined ) ? controllers : [ ] ;
286
292
} ;
287
293
288
294
/**
@@ -326,11 +332,11 @@ MdNavBarController.prototype.getFocusedTab = function() {
326
332
* @private
327
333
*/
328
334
MdNavBarController . prototype . _findTab = function ( fn , startIndex ) {
329
- var tabs = this . _getTabs ( ) ;
330
- if ( startIndex === undefined || startIndex === null ) {
335
+ var tabs = this . _getTabs ( ) , i ;
336
+ if ( startIndex == null ) {
331
337
startIndex = 0 ;
332
338
}
333
- for ( var i = startIndex ; i < tabs . length ; i ++ ) {
339
+ for ( i = startIndex ; i < tabs . length ; i ++ ) {
334
340
if ( fn ( tabs [ i ] ) ) {
335
341
return tabs [ i ] ;
336
342
}
@@ -363,7 +369,7 @@ MdNavBarController.prototype._findTabReverse = function(fn, startIndex) {
363
369
*/
364
370
MdNavBarController . prototype . onFocus = function ( ) {
365
371
var tab = this . _getSelectedTab ( ) ;
366
- if ( tab && ! tab . _focused ) {
372
+ if ( tab && ! tab . isFocused ) {
367
373
tab . setFocused ( true ) ;
368
374
}
369
375
} ;
@@ -670,40 +676,66 @@ function MdNavItem($mdAria, $$rAF, $mdUtil, $window) {
670
676
671
677
/**
672
678
* Controller for the nav-item component.
673
- * @param {!angular. JQLite } $element
679
+ * @param {!JQLite } $element
674
680
* @constructor
675
681
* @final
676
682
* @ngInject
677
683
*/
678
684
function MdNavItemController ( $element ) {
679
685
680
- /** @private @const {!angular.JQLite} */
686
+ /**
687
+ * @private @const
688
+ * @type {!JQLite }
689
+ */
681
690
this . _$element = $element ;
682
691
683
692
// Data-bound variables
684
693
685
- /** @const {?Function} */
694
+ /**
695
+ * @const
696
+ * @type {?Function }
697
+ */
686
698
this . mdNavClick ;
687
699
688
- /** @const {?string} */
700
+ /**
701
+ * @const
702
+ * @type {?string }
703
+ */
689
704
this . mdNavHref ;
690
705
691
- /** @const {?string} */
706
+ /**
707
+ * @const
708
+ * @type {?string }
709
+ */
692
710
this . mdNavSref ;
693
- /** @const {?Object} */
711
+ /**
712
+ * @const
713
+ * @type {?Object }
714
+ */
694
715
this . srefOpts ;
695
- /** @const {?string} */
716
+ /**
717
+ * @const
718
+ * @type {?string }
719
+ */
696
720
this . name ;
697
721
698
- /** @type {string } */
722
+ /**
723
+ * @const
724
+ * @type {string }
725
+ */
699
726
this . navItemAriaLabel ;
700
727
701
728
// State variables
702
- /** @private {boolean} */
729
+ /**
730
+ * @private
731
+ * @type {boolean }
732
+ */
703
733
this . _selected = false ;
704
734
705
- /** @private {boolean} */
706
- this . _focused = false ;
735
+ /**
736
+ * @type {boolean }
737
+ */
738
+ this . isFocused = false ;
707
739
}
708
740
709
741
/**
@@ -715,7 +747,7 @@ MdNavItemController.prototype.getNgClassMap = function() {
715
747
'md-active' : this . _selected ,
716
748
'md-primary' : this . _selected ,
717
749
'md-unselected' : ! this . _selected ,
718
- 'md-focused' : this . _focused ,
750
+ 'md-focused' : this . isFocused ,
719
751
} ;
720
752
} ;
721
753
@@ -764,7 +796,7 @@ MdNavItemController.prototype.isSelected = function() {
764
796
* @param {boolean } isFocused
765
797
*/
766
798
MdNavItemController . prototype . setFocused = function ( isFocused ) {
767
- this . _focused = isFocused ;
799
+ this . isFocused = isFocused ;
768
800
769
801
if ( isFocused ) {
770
802
this . getButtonEl ( ) . focus ( ) ;
@@ -775,7 +807,7 @@ MdNavItemController.prototype.setFocused = function(isFocused) {
775
807
* @return {boolean } true if the tab has focus, false if not.
776
808
*/
777
809
MdNavItemController . prototype . hasFocus = function ( ) {
778
- return this . _focused ;
810
+ return this . isFocused ;
779
811
} ;
780
812
781
813
/**
0 commit comments