1433
1433
} ;
1434
1434
}
1435
1435
1436
- var clickOutside = function ( $document ) {
1436
+ /* https://github.com/IamAdamJowett/angular-click-outside */
1437
+ var clickOutside = function ( $document , $parse ) {
1437
1438
return {
1438
1439
restrict : 'A' ,
1439
1440
scope : {
1440
1441
clickOut : '&'
1441
1442
} ,
1442
1443
link : function ( $scope , elem , attr ) {
1443
- var classList = ( attr . outsideIfNot !== undefined ) ? attr . outsideIfNot . replace ( ', ' , ',' ) . split ( ',' ) : [ ] ;
1444
- if ( attr . id == undefined ) attr . $set ( 'id' , 'id_' + Math . random ( ) ) ;
1445
- if ( attr . id !== undefined ) classList . push ( attr . id ) ;
1444
+ var classList = ( attr . outsideIfNot !== undefined ) ? attr . outsideIfNot . replace ( ', ' , ',' ) . split ( ',' ) : [ ] , fn = $parse ( attr [ 'clickOutside' ] ) ;
1445
+ if ( attr . id ! == undefined )
1446
+ classList . push ( attr . id ) ;
1446
1447
1447
- $document . on ( 'click contextmenu' , function ( e ) {
1448
- var i = 0 ,
1449
- element ;
1448
+ var eventHandler = function ( e ) {
1449
+ if ( angular . element ( elem ) . hasClass ( "ng-hide" ) )
1450
+ return ;
1450
1451
1451
- if ( ! e . target ) return ;
1452
+ var i = 0 , element ;
1453
+ if ( ! e || ! e . target )
1454
+ return ;
1452
1455
1453
1456
for ( element = e . target ; element ; element = element . parentNode ) {
1454
- var id = element . id ;
1455
- var classNames = element . className ;
1457
+ var id = element . id ,
1458
+ classNames = element . className ,
1459
+ l = classList . length ;
1456
1460
1457
- if ( id !== undefined ) {
1458
- for ( i = 0 ; i < classList . length ; i ++ ) {
1459
- if ( id . indexOf ( classList [ i ] ) > - 1 || classNames . indexOf ( classList [ i ] ) > - 1 ) {
1460
- return ;
1461
- }
1462
- }
1463
- }
1464
- }
1461
+ if ( classNames && classNames . baseVal !== undefined )
1462
+ classNames = classNames . baseVal ;
1465
1463
1466
- $scope . $eval ( $scope . clickOut ) ;
1464
+ for ( i = 0 ; i < l ; i ++ )
1465
+ if ( ( id !== undefined && id . indexOf ( classList [ i ] ) > - 1 ) || ( classNames && classNames . indexOf ( classList [ i ] ) > - 1 ) )
1466
+ return ;
1467
+ }
1468
+ return $scope . $applyAsync ( function ( ) {
1469
+ return fn ( $scope ) ;
1470
+ } ) ;
1471
+ } ;
1472
+ $document . on ( 'click' , eventHandler ) ;
1473
+ $scope . $on ( '$destroy' , function ( ) {
1474
+ $document . off ( 'click' , eventHandler ) ;
1467
1475
} ) ;
1468
1476
}
1469
1477
} ;
1497
1505
. factory ( 'ADMdtpFactory' , [ 'ADMdtpConvertor' , ADMdtpFactory ] )
1498
1506
. directive ( 'admDtp' , [ 'ADMdtp' , 'ADMdtpConvertor' , 'ADMdtpFactory' , 'constants' , '$compile' , '$timeout' , ADMdtpDirective ] )
1499
1507
. directive ( 'admDtpCalendar' , [ 'ADMdtp' , 'ADMdtpConvertor' , 'ADMdtpFactory' , 'constants' , '$timeout' , ADMdtpCalendarDirective ] )
1500
- . directive ( 'clickOut' , [ '$document' , clickOutside ] )
1508
+ . directive ( 'clickOut' , [ '$document' , '$parse' , clickOutside ] )
1501
1509
. config ( [ 'ADMdtpProvider' , ADMdtpConfig ] ) ;
1502
1510
} ( window . angular ) ) ;
0 commit comments