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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ angular.module('myApp', ['angularViewportWatch']);
## Directive Usage

```html
<div ng-repeat="item in items" viewport-watch>...</div>
<div ng-repeat="item in items" viewport-watch viewport-watch-container>...</div>
```

To specify a different container to look at and listen to you can specify `viewport-watch-container`. It accepts a querySelector string.

## Manual watcher toggling

In some cases you might want to disable or enable the watchers of some scope regardless of its position relative to the view port. This can be done easily by broadcasting an event to this scope (this will effect only scopes that have the `viewport-watch` directive on them):
Expand Down
13 changes: 10 additions & 3 deletions angular-viewport-watch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

(function() {
function viewportWatch(scrollMonitor, $timeout) {
function viewportWatch(scrollMonitor, $timeout, $parse) {
var viewportUpdateTimeout;
function debouncedViewportUpdate() {
$timeout.cancel(viewportUpdateTimeout);
Expand All @@ -12,7 +12,14 @@
return {
restrict: "AE",
link: function(scope, element, attr) {
var elementWatcher = scrollMonitor.create(element, scope.$eval(attr.viewportWatch || "0"));
if($parse(attr.viewportWatch)(scope) == false){
return false;
}

var container = (attr.viewportWatchContainer && attr.viewportWatchContainer.length > 1) ? attr.viewportWatchContainer : undefined;

var elementWatcher = scrollMonitor.create(element, scope.$eval(attr.viewportWatch || "0"), container);

function watchDuringDisable() {
this.$$watchersBackup = this.$$watchersBackup || [];
this.$$watchers = this.$$watchersBackup;
Expand Down Expand Up @@ -73,6 +80,6 @@
}
};
}
viewportWatch.$inject = [ "scrollMonitor", "$timeout" ];
viewportWatch.$inject = [ "scrollMonitor", "$timeout", "$parse" ];
angular.module("angularViewportWatch", []).directive("viewportWatch", viewportWatch).value("scrollMonitor", window.scrollMonitor);
})();
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-viewport-watch",
"version": "0.1.4",
"version": "0.1.10",
"main": "angular-viewport-watch.js",
"ignore": [
".*",
Expand All @@ -17,7 +17,7 @@
],
"dependencies": {
"angular": "^1.2.0",
"scrollMonitor": "~1.0.10"
"scrollMonitor": "https://github.com/dirkgroenen/scrollMonitor.git#1.0.15"
},
"devDependencies": {
"angular-mocks": "^1.2.0",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "angular-viewport-watch",
"version": "0.0.0",
"version": "0.1.11",
"main": "angular-viewport-watch.js",
"dependencies": {},
"devDependencies": {
"coveralls": "^2.10.0",
Expand Down