@@ -232,22 +232,24 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
232
232
return {
233
233
restrict : 'E' ,
234
234
controller : 'MdListController' ,
235
- compile : function ( tEl , tAttrs ) {
235
+
236
+ compile : function ( tElement , tAttrs ) {
236
237
237
238
// Check for proxy controls (no ng-click on parent, and a control inside)
238
- var secondaryItems = tEl [ 0 ] . querySelectorAll ( '.md-secondary' ) ;
239
+ var secondaryItems = tElement [ 0 ] . querySelectorAll ( '.md-secondary' ) ;
239
240
var hasProxiedElement ;
240
241
var proxyElement ;
241
- var itemContainer = tEl ;
242
+ var itemContainer = tElement ;
242
243
243
- tEl [ 0 ] . setAttribute ( 'role' , 'listitem' ) ;
244
+ tElement [ 0 ] . setAttribute ( 'role' , 'listitem' ) ;
244
245
245
246
if ( tAttrs . ngClick || tAttrs . ngDblclick || tAttrs . ngHref || tAttrs . href || tAttrs . uiSref || tAttrs . ngAttrUiSref ) {
246
247
wrapIn ( 'button' ) ;
247
- } else if ( ! tEl . hasClass ( 'md-no-proxy' ) ) {
248
+ } else if ( ! tElement . hasClass ( 'md-no-proxy' ) ) {
248
249
249
- for ( var i = 0 , type ; type = proxiedTypes [ i ] ; ++ i ) {
250
- if ( proxyElement = tEl [ 0 ] . querySelector ( type ) ) {
250
+ for ( var i = 0 , type ; i < proxiedTypes . length ; ++ i ) {
251
+ proxyElement = tElement [ 0 ] . querySelector ( proxiedTypes [ i ] ) ;
252
+ if ( proxyElement !== null ) {
251
253
hasProxiedElement = true ;
252
254
break ;
253
255
}
@@ -256,7 +258,7 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
256
258
if ( hasProxiedElement ) {
257
259
wrapIn ( 'div' ) ;
258
260
} else {
259
- tEl . addClass ( 'md-no-proxy' ) ;
261
+ tElement . addClass ( 'md-no-proxy' ) ;
260
262
}
261
263
262
264
}
@@ -272,10 +274,11 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
272
274
var toggleTypes = [ 'md-switch' , 'md-checkbox' ] ;
273
275
var toggle ;
274
276
275
- for ( var i = 0 , toggleType ; toggleType = toggleTypes [ i ] ; ++ i ) {
276
- if ( toggle = tEl . find ( toggleType ) [ 0 ] ) {
277
+ for ( var i = 0 , toggleType ; i < toggleTypes . length ; ++ i ) {
278
+ toggle = tElement . find ( toggleTypes [ i ] ) [ 0 ] ;
279
+ if ( toggle ) {
277
280
if ( ! toggle . hasAttribute ( 'aria-label' ) ) {
278
- var p = tEl . find ( 'p' ) [ 0 ] ;
281
+ var p = tElement . find ( 'p' ) [ 0 ] ;
279
282
if ( ! p ) return ;
280
283
toggle . setAttribute ( 'aria-label' , 'Toggle ' + p . textContent ) ;
281
284
}
@@ -312,11 +315,14 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
312
315
}
313
316
}
314
317
318
+ /**
319
+ * @param {'div'|'button' } type
320
+ */
315
321
function wrapIn ( type ) {
316
- if ( type == 'div' ) {
322
+ if ( type === 'div' ) {
317
323
itemContainer = angular . element ( '<div class="md-no-style md-list-item-inner">' ) ;
318
- itemContainer . append ( tEl . contents ( ) ) ;
319
- tEl . addClass ( 'md-proxy-focus' ) ;
324
+ itemContainer . append ( tElement . contents ( ) ) ;
325
+ tElement . addClass ( 'md-proxy-focus' ) ;
320
326
} else {
321
327
// Element which holds the default list-item content.
322
328
itemContainer = angular . element (
@@ -330,30 +336,30 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
330
336
'<md-button class="md-no-style"></md-button>'
331
337
) ;
332
338
333
- copyAttributes ( tEl [ 0 ] , buttonWrap [ 0 ] ) ;
339
+ copyAttributes ( tElement [ 0 ] , buttonWrap [ 0 ] ) ;
334
340
335
341
// If there is no aria-label set on the button (previously copied over if present)
336
342
// we determine the label from the content and copy it to the button.
337
343
if ( ! buttonWrap . attr ( 'aria-label' ) ) {
338
- buttonWrap . attr ( 'aria-label' , $mdAria . getText ( tEl ) ) ;
344
+ buttonWrap . attr ( 'aria-label' , $mdAria . getText ( tElement ) ) ;
339
345
}
340
346
341
347
// We allow developers to specify the `md-no-focus` class, to disable the focus style
342
348
// on the button executor. Once more classes should be forwarded, we should probably make the
343
349
// class forward more generic.
344
- if ( tEl . hasClass ( 'md-no-focus' ) ) {
350
+ if ( tElement . hasClass ( 'md-no-focus' ) ) {
345
351
buttonWrap . addClass ( 'md-no-focus' ) ;
346
352
}
347
353
348
354
// Append the button wrap before our list-item content, because it will overlay in relative.
349
355
itemContainer . prepend ( buttonWrap ) ;
350
- itemContainer . children ( ) . eq ( 1 ) . append ( tEl . contents ( ) ) ;
356
+ itemContainer . children ( ) . eq ( 1 ) . append ( tElement . contents ( ) ) ;
351
357
352
- tEl . addClass ( '_md-button-wrap' ) ;
358
+ tElement . addClass ( '_md-button-wrap' ) ;
353
359
}
354
360
355
- tEl [ 0 ] . setAttribute ( 'tabindex' , '-1' ) ;
356
- tEl . append ( itemContainer ) ;
361
+ tElement [ 0 ] . setAttribute ( 'tabindex' , '-1' ) ;
362
+ tElement . append ( itemContainer ) ;
357
363
}
358
364
359
365
function wrapSecondaryItems ( ) {
@@ -391,7 +397,7 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
391
397
angular . element ( secondaryItem ) . removeClass ( 'md-secondary' ) ;
392
398
}
393
399
394
- tEl . addClass ( 'md-with-secondary' ) ;
400
+ tElement . addClass ( 'md-with-secondary' ) ;
395
401
container . append ( secondaryItem ) ;
396
402
}
397
403
@@ -422,13 +428,13 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
422
428
}
423
429
424
430
function isProxiedElement ( el ) {
425
- return proxiedTypes . indexOf ( el . nodeName . toLowerCase ( ) ) != - 1 ;
431
+ return proxiedTypes . indexOf ( el . nodeName . toLowerCase ( ) ) !== - 1 ;
426
432
}
427
433
428
434
function isButton ( el ) {
429
435
var nodeName = el . nodeName . toUpperCase ( ) ;
430
436
431
- return nodeName == "MD-BUTTON" || nodeName == "BUTTON" ;
437
+ return nodeName === "MD-BUTTON" || nodeName = == "BUTTON" ;
432
438
}
433
439
434
440
function hasClickEvent ( element ) {
@@ -493,7 +499,7 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
493
499
}
494
500
495
501
function computeClickable ( ) {
496
- if ( proxies . length == 1 || hasClick ) {
502
+ if ( proxies . length === 1 || hasClick ) {
497
503
$element . addClass ( 'md-clickable' ) ;
498
504
499
505
if ( ! hasClick ) {
@@ -502,29 +508,35 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
502
508
}
503
509
}
504
510
511
+ /**
512
+ * @param {MouseEvent } event
513
+ * @return {boolean }
514
+ */
505
515
function isEventFromControl ( event ) {
506
516
var forbiddenControls = [ 'md-slider' ] ;
517
+ var eventBubblePath = $mdUtil . getEventPath ( event ) ;
507
518
508
- // If there is no path property in the event , then we can assume that the event was not bubbled.
509
- if ( ! event . path ) {
519
+ // If there is no bubble path , then the event was not bubbled.
520
+ if ( ! eventBubblePath || eventBubblePath . length === 0 ) {
510
521
return forbiddenControls . indexOf ( event . target . tagName . toLowerCase ( ) ) !== - 1 ;
511
522
}
512
523
513
- // We iterate the event path up and check for a possible component.
524
+ // We iterate the event bubble path up and check for a possible component.
514
525
// Our maximum index to search, is the list item root.
515
- var maxPath = event . path . indexOf ( $element . children ( ) [ 0 ] ) ;
526
+ var maxPath = eventBubblePath . indexOf ( $element . children ( ) [ 0 ] ) ;
516
527
517
528
for ( var i = 0 ; i < maxPath ; i ++ ) {
518
- if ( forbiddenControls . indexOf ( event . path [ i ] . tagName . toLowerCase ( ) ) !== - 1 ) {
529
+ if ( forbiddenControls . indexOf ( eventBubblePath [ i ] . tagName . toLowerCase ( ) ) !== - 1 ) {
519
530
return true ;
520
531
}
521
532
}
533
+ return false ;
522
534
}
523
535
524
536
var clickChildKeypressListener = function ( e ) {
525
- if ( e . target . nodeName != 'INPUT' && e . target . nodeName != 'TEXTAREA' && ! e . target . isContentEditable ) {
537
+ if ( e . target . nodeName !== 'INPUT' && e . target . nodeName != = 'TEXTAREA' && ! e . target . isContentEditable ) {
526
538
var keyCode = e . which || e . keyCode ;
527
- if ( keyCode == $mdConstant . KEY_CODE . SPACE ) {
539
+ if ( keyCode === $mdConstant . KEY_CODE . SPACE ) {
528
540
if ( clickChild ) {
529
541
clickChild . click ( ) ;
530
542
e . preventDefault ( ) ;
@@ -541,16 +553,16 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
541
553
$element . off ( 'click' ) ;
542
554
$element . off ( 'keypress' ) ;
543
555
544
- if ( proxies . length == 1 && clickChild ) {
545
- $element . children ( ) . eq ( 0 ) . on ( 'click' , function ( e ) {
546
- // When the event is coming from an control and it should not trigger the proxied element
556
+ if ( proxies . length === 1 && clickChild ) {
557
+ $element . children ( ) . eq ( 0 ) . on ( 'click' , function ( clickEvent ) {
558
+ // When the event is coming from a control and it should not trigger the proxied element
547
559
// then we are skipping.
548
- if ( isEventFromControl ( e ) ) return ;
560
+ if ( isEventFromControl ( clickEvent ) ) return ;
549
561
550
- var parentButton = $mdUtil . getClosest ( e . target , 'BUTTON' ) ;
551
- if ( ! parentButton && clickChild . contains ( e . target ) ) {
562
+ var parentButton = $mdUtil . getClosest ( clickEvent . target , 'BUTTON' ) ;
563
+ if ( ! parentButton && clickChild . contains ( clickEvent . target ) ) {
552
564
angular . forEach ( proxies , function ( proxy ) {
553
- if ( e . target !== proxy && ! proxy . contains ( e . target ) ) {
565
+ if ( clickEvent . target !== proxy && ! proxy . contains ( clickEvent . target ) ) {
554
566
if ( proxy . nodeName === 'MD-MENU' ) {
555
567
proxy = proxy . children [ 0 ] ;
556
568
}
0 commit comments