Skip to content

Commit

Permalink
Merge pull request #717 from cozzbie/gh-pages
Browse files Browse the repository at this point in the history
Fix issues with SSR builds by adding window bind and Date reference.
  • Loading branch information
aFarkas committed Nov 8, 2019
2 parents 7a7f5d9 + 780e6d3 commit 55f936b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
8 changes: 3 additions & 5 deletions lazysizes-umd.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(function(window, factory) {
var lazySizes = factory(window, window.document);
var lazySizes = factory(window, window.document, Date);
if(typeof module == 'object' && module.exports){
module.exports = lazySizes;
} else if (typeof define == 'function' && define.amd) {
define(lazySizes);
} else {
window.lazySizes = lazySizes;
}
}(window, function l(window, document) {
}(window, function l(window, document, Date) {
'use strict';
/*jshint eqnull:true */

Expand Down Expand Up @@ -58,15 +58,13 @@

var docElem = document.documentElement;

var Date = window.Date;

var supportPicture = window.HTMLPictureElement;

var _addEventListener = 'addEventListener';

var _getAttribute = 'getAttribute';

var addEventListener = window[_addEventListener];
var addEventListener = window[_addEventListener].bind(window);

var setTimeout = window.setTimeout;

Expand Down
8 changes: 3 additions & 5 deletions lazysizes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(function(window, factory) {
var lazySizes = factory(window, window.document);
var lazySizes = factory(window, window.document, Date);
window.lazySizes = lazySizes;
if(typeof module == 'object' && module.exports){
module.exports = lazySizes;
}
}(typeof window != 'undefined' ?
window : {}, function l(window, document) {
window : {}, function l(window, document, Date) {
'use strict';
/*jshint eqnull:true */

Expand Down Expand Up @@ -56,15 +56,13 @@

var docElem = document.documentElement;

var Date = window.Date;

var supportPicture = window.HTMLPictureElement;

var _addEventListener = 'addEventListener';

var _getAttribute = 'getAttribute';

var addEventListener = window[_addEventListener];
var addEventListener = window[_addEventListener].bind(window);

var setTimeout = window.setTimeout;

Expand Down
2 changes: 1 addition & 1 deletion src/common.wrapper
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function(window, factory) {
var lazySizes = factory(window, window.document);
var lazySizes = factory(window, window.document, Date);
window.lazySizes = lazySizes;
if(typeof module == 'object' && module.exports){
module.exports = lazySizes;
Expand Down
10 changes: 6 additions & 4 deletions src/lazysizes-core.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function l(window, document) {
function l(window, document, Date) { // Pass in the windoe Date function also for SSR because the Date class can be lost
'use strict';
/*jshint eqnull:true */

Expand Down Expand Up @@ -49,15 +49,17 @@ function l(window, document) {

var docElem = document.documentElement;

var Date = window.Date;

var supportPicture = window.HTMLPictureElement;

var _addEventListener = 'addEventListener';

var _getAttribute = 'getAttribute';

var addEventListener = window[_addEventListener];
/**
* Update to bind to window because 'this' becomes null during SSR
* builds.
*/
var addEventListener = window[_addEventListener].bind(window);

var setTimeout = window.setTimeout;

Expand Down
8 changes: 3 additions & 5 deletions src/lazysizes-intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
if(typeof module == 'object' && module.exports){
module.exports = lazySizes;
} else {
window.lazySizes = factory(window, window.document);
window.lazySizes = factory(window, window.document, Date);
}
}(window, function l(window, document) {
}(window, function l(window, document, Date) {
'use strict';

/*jshint eqnull:true */
Expand All @@ -14,15 +14,13 @@

var docElem = document.documentElement;

var Date = window.Date;

var supportPicture = window.HTMLPictureElement;

var _addEventListener = 'addEventListener';

var _getAttribute = 'getAttribute';

var addEventListener = window[_addEventListener];
var addEventListener = window[_addEventListener].bind(window);

var setTimeout = window.setTimeout;

Expand Down

0 comments on commit 55f936b

Please sign in to comment.