Skip to content

Commit 33142fc

Browse files
author
m.teimouri
committed
update clickOutside module
1 parent de78a04 commit 33142fc

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

dist/ADM-dateTimePicker.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,37 +1433,45 @@
14331433
};
14341434
}
14351435

1436-
var clickOutside = function($document) {
1436+
/* https://github.com/IamAdamJowett/angular-click-outside */
1437+
var clickOutside = function($document, $parse) {
14371438
return {
14381439
restrict: 'A',
14391440
scope: {
14401441
clickOut: '&'
14411442
},
14421443
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);
14461447

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;
14501451

1451-
if (!e.target) return;
1452+
var i = 0, element;
1453+
if (!e || !e.target)
1454+
return;
14521455

14531456
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;
14561460

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;
14651463

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);
14671475
});
14681476
}
14691477
};
@@ -1497,6 +1505,6 @@
14971505
.factory('ADMdtpFactory', ['ADMdtpConvertor', ADMdtpFactory])
14981506
.directive('admDtp', ['ADMdtp', 'ADMdtpConvertor', 'ADMdtpFactory', 'constants', '$compile', '$timeout', ADMdtpDirective])
14991507
.directive('admDtpCalendar', ['ADMdtp', 'ADMdtpConvertor', 'ADMdtpFactory', 'constants', '$timeout', ADMdtpCalendarDirective])
1500-
.directive('clickOut', ['$document', clickOutside])
1508+
.directive('clickOut', ['$document', '$parse', clickOutside])
15011509
.config(['ADMdtpProvider', ADMdtpConfig]);
15021510
}(window.angular));

0 commit comments

Comments
 (0)