Skip to content

Commit

Permalink
Wrapping plugin block in a check for global window object
Browse files Browse the repository at this point in the history
- window might not be available, i.e. when rendering React components server-side
  • Loading branch information
Nathan Bryant committed Nov 4, 2016
1 parent 4d77d57 commit 6f0d751
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
18 changes: 10 additions & 8 deletions dist/shave.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ function shave(target, maxHeight, opts) {
}
}

var plugin = window.$ || window.jQuery || window.Zepto;
if (plugin) {
plugin.fn.extend({
shave: function shaveFunc(maxHeight, opts) {
return shave(this, maxHeight, opts);
}
});
if (typeof window !== 'undefined') {
var plugin = window.$ || window.jQuery || window.Zepto;
if (plugin) {
plugin.fn.extend({
shave: function shaveFunc(maxHeight, opts) {
return shave(this, maxHeight, opts);
}
});
}
}

return shave;

})));
})));
6 changes: 3 additions & 3 deletions dist/shave.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions src/shave.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ export default function shave(target, maxHeight, opts) {
}
}

const plugin = window.$ || window.jQuery || window.Zepto;
if (plugin) {
plugin.fn.extend({
shave: function shaveFunc(maxHeight, opts) {
return shave(this, maxHeight, opts);
},
});
if (typeof window !== 'undefined') {
const plugin = window.$ || window.jQuery || window.Zepto;
if (plugin) {
plugin.fn.extend({
shave: function shaveFunc(maxHeight, opts) {
return shave(this, maxHeight, opts);
},
});
}
}

0 comments on commit 6f0d751

Please sign in to comment.