Skip to content

Commit c0a488f

Browse files
committed
Bug #30 - $digest overwhelming calls
1 parent 05dd760 commit c0a488f

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

lib/scripts/directive.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
$document.on('click', function (evt) {
4040
if ($scope.find(evt.target).length === 0) {
41-
$scope.log('Color Picker: Document Hide Event');
41+
$scope.log('Color Picker: Document Click Event');
4242
$scope.hide();
4343
}
4444
});
@@ -74,11 +74,11 @@
7474
$scope.lightnessUpdate();
7575
};
7676

77-
$scope.hide = function (apply) {
77+
$scope.hide = function () {
7878
$scope.log('Color Picker: Hide Event');
79-
$scope.visible = false;
8079

81-
if (apply !== false) {
80+
if ($scope.visible) {
81+
$scope.visible = false;
8282
$scope.$apply();
8383
}
8484
};
@@ -339,7 +339,7 @@
339339
// HELPER FUNCTIONS
340340
//---------------------------
341341
$scope.log = function () {
342-
//console.log.apply(console, arguments);
342+
// console.log.apply(console, arguments);
343343
};
344344

345345
// taken and modified from jQuery's find
@@ -363,26 +363,14 @@
363363
results = context.querySelectorAll(selector);
364364

365365
} else {
366-
if ($scope.contains(context, selector)) {
366+
if (context.contains(selector)) {
367367
results.push(selector);
368368
}
369369
}
370370

371371
return angular.element(results);
372372
};
373373

374-
$scope.contains = function (a, b) {
375-
if (b) {
376-
while ((b = b.parentNode)) {
377-
if (b === a) {
378-
return true;
379-
}
380-
}
381-
}
382-
383-
return false;
384-
};
385-
386374
// taken and modified from jQuery's offset
387375
$scope.offset = function (el) {
388376
var docElem, win, rect, doc, elem = el[0];
@@ -426,6 +414,10 @@
426414

427415

428416
$scope.init();
417+
418+
$scope.$on('$destroy', function() {
419+
$document.off('click');
420+
});
429421
}
430422
};
431423
};

0 commit comments

Comments
 (0)