Skip to content

Commit d73197f

Browse files
author
m.teimouri
committed
fix clickOutside bug
1 parent 33142fc commit d73197f

File tree

4 files changed

+23
-30
lines changed

4 files changed

+23
-30
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "adm-dtp",
3-
"version": "1.1.2",
3+
"version": "1.1.4",
44
"homepage": "https://github.com/AmirkabirDataMiners/ADM-dateTimePicker",
55
"authors": [
66
"ADM | Amirkabir Data Miners <info@adm-co.net>"

dist/ADM-dateTimePicker.js

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,44 +1434,37 @@
14341434
}
14351435

14361436
/* https://github.com/IamAdamJowett/angular-click-outside */
1437-
var clickOutside = function($document, $parse) {
1437+
var clickOutside = function($document) {
14381438
return {
14391439
restrict: 'A',
14401440
scope: {
14411441
clickOut: '&'
14421442
},
14431443
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);
14471447

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

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

14561454
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;
14631457

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+
}
14671465
}
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);
14751468
});
14761469
}
14771470
};
@@ -1505,6 +1498,6 @@
15051498
.factory('ADMdtpFactory', ['ADMdtpConvertor', ADMdtpFactory])
15061499
.directive('admDtp', ['ADMdtp', 'ADMdtpConvertor', 'ADMdtpFactory', 'constants', '$compile', '$timeout', ADMdtpDirective])
15071500
.directive('admDtpCalendar', ['ADMdtp', 'ADMdtpConvertor', 'ADMdtpFactory', 'constants', '$timeout', ADMdtpCalendarDirective])
1508-
.directive('clickOut', ['$document', '$parse', clickOutside])
1501+
.directive('clickOut', ['$document', clickOutside])
15091502
.config(['ADMdtpProvider', ADMdtpConfig]);
15101503
}(window.angular));

0 commit comments

Comments
 (0)