@@ -157,7 +157,9 @@ function mdListItemDirective($mdAria, $mdConstant, $timeout) {
157
157
158
158
function postLink ( $scope , $element , $attr , ctrl ) {
159
159
160
- var proxies = [ ] ;
160
+ var proxies = [ ] ,
161
+ firstChild = $element [ 0 ] . firstElementChild ,
162
+ hasClick = firstChild && firstChild . hasAttribute ( 'ng-click' ) ;
161
163
162
164
computeProxies ( ) ;
163
165
computeClickable ( ) ;
@@ -187,25 +189,25 @@ function mdListItemDirective($mdAria, $mdConstant, $timeout) {
187
189
var children = $element . children ( ) ;
188
190
if ( children . length && ! children [ 0 ] . hasAttribute ( 'ng-click' ) ) {
189
191
angular . forEach ( proxiedTypes , function ( type ) {
190
- angular . forEach ( $element [ 0 ] . firstElementChild . querySelectorAll ( type ) , function ( child ) {
192
+ angular . forEach ( firstChild . querySelectorAll ( type ) , function ( child ) {
191
193
proxies . push ( child ) ;
192
194
} ) ;
193
195
} ) ;
194
196
}
195
197
}
196
198
function computeClickable ( ) {
197
- if ( proxies . length || $element [ 0 ] . firstElementChild . hasAttribute ( 'ng-click' ) ) {
199
+ if ( proxies . length || hasClick ) {
198
200
$element . addClass ( 'md-clickable' ) ;
199
201
200
202
ctrl . attachRipple ( $scope , angular . element ( $element [ 0 ] . querySelector ( '.md-no-style' ) ) ) ;
201
203
}
202
204
}
203
205
204
- if ( ! $element [ 0 ] . firstElementChild . hasAttribute ( 'ng-click' ) && ! proxies . length ) {
205
- $element [ 0 ] . firstElementChild . addEventListener ( 'keypress' , function ( e ) {
206
+ if ( ! hasClick && ! proxies . length ) {
207
+ firstChild . addEventListener ( 'keypress' , function ( e ) {
206
208
if ( e . target . nodeName != 'INPUT' ) {
207
209
if ( e . keyCode == $mdConstant . KEY_CODE . SPACE ) {
208
- $element [ 0 ] . firstElementChild . click ( ) ;
210
+ firstChild . click ( ) ;
209
211
e . preventDefault ( ) ;
210
212
e . stopPropagation ( ) ;
211
213
}
@@ -216,9 +218,9 @@ function mdListItemDirective($mdAria, $mdConstant, $timeout) {
216
218
$element . off ( 'click' ) ;
217
219
$element . off ( 'keypress' ) ;
218
220
219
- if ( proxies . length ) {
221
+ if ( proxies . length && firstChild ) {
220
222
$element . children ( ) . eq ( 0 ) . on ( 'click' , function ( e ) {
221
- if ( $element [ 0 ] . firstElementChild . contains ( e . target ) ) {
223
+ if ( firstChild . contains ( e . target ) ) {
222
224
angular . forEach ( proxies , function ( proxy ) {
223
225
if ( e . target !== proxy && ! proxy . contains ( e . target ) ) {
224
226
angular . element ( proxy ) . triggerHandler ( 'click' ) ;
0 commit comments