Skip to content

Commit

Permalink
Merge 824c2db into d4fde73
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Capaldo committed Dec 19, 2017
2 parents d4fde73 + 824c2db commit 2b3fad2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ If you provide a number, that will be how many `ms` to wait; if you provide `tru

[demo](https://jasonslyvia.github.io/react-lazyload/examples/#/debounce)

### customEvent

Type: String
LazyLoad will attach a customEvent to the window, to be dispatched on demand. Default is `triggerLazyLoad` if passing prop `customEvent` and can be triggered with `window.dispatchEvent(new Event("triggerLazyLoad"));`. It can also be given a preferred string like `customEvent={"eventName"}` and then called with `window.dispatchEvent(new Event("eventName"));`.


## Utility

### forceCheck
Expand Down
13 changes: 13 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,25 @@ var LazyLoad = function (_Component) {


if (scroll) {
(0, _event.on)(window, 'touchmove', finalLazyLoadHandler, passiveEvent);
(0, _event.on)(window, 'scroll', finalLazyLoadHandler, passiveEvent);
(0, _event.on)(document.body, 'scroll', finalLazyLoadHandler, passiveEvent);
}

if (resize) {
(0, _event.on)(window, 'resize', finalLazyLoadHandler, passiveEvent);
}

if (this.props.mouse) {
(0, _event.on)(window, 'mouseover', finalLazyLoadHandler, passiveEvent);
}

if (this.props.customEvent) {
var myEventName = typeof this.props.customEvent === 'string' ? this.props.customEvent : 'triggerLazyLoad';
var customeEventImageLoad = document.createEvent('Event');
customeEventImageLoad.initEvent(myEventName, true, true);
(0, _event.on)(window, myEventName, finalLazyLoadHandler, passiveEvent);
}
}

listeners.push(this);
Expand Down
13 changes: 13 additions & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,25 @@ class LazyLoad extends Component {
const { scroll, resize } = this.props;

if (scroll) {
on(window, 'touchmove', finalLazyLoadHandler, passiveEvent);
on(window, 'scroll', finalLazyLoadHandler, passiveEvent);
on(document.body, 'scroll', finalLazyLoadHandler, passiveEvent);
}

if (resize) {
on(window, 'resize', finalLazyLoadHandler, passiveEvent);
}

if(this.props.mouse) {
on(window, 'mouseover', finalLazyLoadHandler, passiveEvent);
}

if(this.props.customEvent) {
var myEventName = typeof this.props.customEvent === 'string' ? this.props.customEvent : 'triggerLazyLoad';
var customeEventImageLoad = document.createEvent('Event');
customeEventImageLoad.initEvent(myEventName, true, true);
on(window, myEventName, finalLazyLoadHandler, passiveEvent);
}
}

listeners.push(this);
Expand Down

0 comments on commit 2b3fad2

Please sign in to comment.