Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
angular.module('dom.util', [])
.service('inDom', function($document) {
return function inDom(element) {
var el = angular.element(element);
return $document[0].body.contains(el[0]);
};
})
.service('isVisible', function(inDom) {
return function isVisible(element) {
var el = angular.element(element);
return inDom(element) && el[0].offsetParent !== null;
};
})
.service('whenVisible', function($q, $timeout, isVisible) {
return function whenVisible(element, delay) {
var el = angular.element(element)
, deferred = $q.defer()
;
if (delay === undefined) { delay = 100; }
function wait() {
if (isVisible(el)) {
deferred.resolve();
} else {
$timeout(wait, delay, false);
}
}
$timeout(wait, 0, false);
return deferred.promise;
};
})
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment