Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions angular-viewport-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
return {
restrict: "AE",
link: function(scope, element, attr) {
var elementWatcher = scrollMonitor.create(element, scope.$eval(attr.viewportWatch || "0"));
var elementWatcher;
function watchDuringDisable() {
this.$$watchersBackup = this.$$watchersBackup || [];
this.$$watchers = this.$$watchersBackup;
Expand Down Expand Up @@ -56,12 +56,23 @@
function enableDigest() {
toggleWatchers(scope, true);
}
if (!elementWatcher.isInViewport) {
scope.$evalAsync(disableDigest);
debouncedViewportUpdate();
function createElementWatcher() {
elementWatcher = scrollMonitor.create(element, scope.$eval(attr.viewportWatch || "0"));
if (!elementWatcher.isInViewport) {
scope.$evalAsync(disableDigest);
debouncedViewportUpdate();
}
elementWatcher.enterViewport(enableDigest);
elementWatcher.exitViewport(disableDigest);
}
if ('$applyAsync' in scope) {
// Wrapping scrollMonitor creation in $applyAsync prevents layout trashing in case this directive
// is applied to ngRepeat-ed elements.
scope.$applyAsync(createElementWatcher);
} else {
// Angular pre-1.3 compatibility. Will cause Layout when each ngRepeat-ed element is rendered.
createElementWatcher();
}
elementWatcher.enterViewport(enableDigest);
elementWatcher.exitViewport(disableDigest);
scope.$on("toggleWatchers", function(event, enable) {
toggleWatchers(scope, enable);
});
Expand Down
23 changes: 17 additions & 6 deletions dist/scripts/angular-viewport-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
return {
restrict: "AE",
link: function(scope, element, attr) {
var elementWatcher = scrollMonitor.create(element, scope.$eval(attr.viewportWatch || "0"));
var elementWatcher;
function watchDuringDisable() {
this.$$watchersBackup = this.$$watchersBackup || [];
this.$$watchers = this.$$watchersBackup;
Expand Down Expand Up @@ -56,12 +56,23 @@
function enableDigest() {
toggleWatchers(scope, true);
}
if (!elementWatcher.isInViewport) {
scope.$evalAsync(disableDigest);
debouncedViewportUpdate();
function createElementWatcher() {
elementWatcher = scrollMonitor.create(element, scope.$eval(attr.viewportWatch || "0"));
if (!elementWatcher.isInViewport) {
scope.$evalAsync(disableDigest);
debouncedViewportUpdate();
}
elementWatcher.enterViewport(enableDigest);
elementWatcher.exitViewport(disableDigest);
}
if ('$applyAsync' in scope) {
// Wrapping scrollMonitor creation in $applyAsync prevents layout trashing in case this directive
// is applied to ngRepeat-ed elements.
scope.$applyAsync(createElementWatcher);
} else {
// Angular pre-1.3 compatibility. Will cause Layout when each ngRepeat-ed element is rendered.
createElementWatcher();
}
elementWatcher.enterViewport(enableDigest);
elementWatcher.exitViewport(disableDigest);
scope.$on("toggleWatchers", function(event, enable) {
toggleWatchers(scope, enable);
});
Expand Down