Skip to content

Commit

Permalink
Check for presence of addEventListener
Browse files Browse the repository at this point in the history
In some server side rendering environments window is present, presumably
for different modules to communicate via global variables. But
addEventListener is not present because there's no way for an event to
be fired.

In such environments tether causes rendering to fail because once it
checks for the presence of window, it assumes addEventListener is also
present.

This commit makes tether more cautious before calling addEventListener.
  • Loading branch information
dmnd committed Mar 15, 2016
1 parent ee05001 commit 402b622
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tether",
"version": "1.2.0",
"version": "1.2.1",
"homepage": "http://github.hubspot.com/tether",
"authors": [
"Zack Bloom <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tether",
"repo": "HubSpot/tether",
"version": "1.2.0",
"version": "1.2.1",
"description": "A client-side library to make absolutely positioned elements attach to elements in the page efficiently.",
"authors": [
"Zack Bloom <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion dist/js/tether.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ function now() {
lastDuration = now() - lastCall;
};

if (typeof window !== 'undefined') {
if (typeof window !== 'undefined' && typeof window.addEventListener !== 'undefined') {
['resize', 'scroll', 'touchmove'].forEach(function (event) {
window.addEventListener(event, tick);
});
Expand Down
2 changes: 1 addition & 1 deletion dist/js/tether.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tether",
"version": "1.2.0",
"version": "1.2.1",
"description": "A client-side library to make absolutely positioned elements attach to elements in the page efficiently.",
"authors": [
"Zack Bloom <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion src/js/tether.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function now() {
lastDuration = now() - lastCall;
};

if(typeof window !== 'undefined') {
if(typeof window !== 'undefined' && typeof window.addEventListener !== 'undefined') {
['resize', 'scroll', 'touchmove'].forEach(event => {
window.addEventListener(event, tick);
});
Expand Down

0 comments on commit 402b622

Please sign in to comment.