Skip to content

Instantly share code, notes, and snippets.

@jlong
Created August 28, 2015 16:04
Show Gist options
  • Save jlong/720fcbbd7858760c66e9 to your computer and use it in GitHub Desktop.
Save jlong/720fcbbd7858760c66e9 to your computer and use it in GitHub Desktop.
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