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