Created
August 28, 2015 16:04
-
-
Save jlong/720fcbbd7858760c66e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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