From 4fda65c8622f7b91d9ba0a1b2c5ac578b9a44d3b Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Tue, 26 Jan 2016 16:53:15 +0100 Subject: Swap CommonJS and AMD module check so that CommonJS is checked first. Fixes Webpack module bundling --- src/js/plyr.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/js') diff --git a/src/js/plyr.js b/src/js/plyr.js index ac6c7d20..8c281d93 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -11,12 +11,12 @@ 'use strict'; /*global define,module*/ - if (typeof define === 'function' && define.amd) { - // AMD - define(null, function() { factory(root, document) }); - } else if (typeof module === 'object') { + if (typeof module === 'object') { // Node, CommonJS-like module.exports = factory(root, document); + } else if (typeof define === 'function' && define.amd) { + // AMD + define(null, function() { factory(root, document) }); } else { // Browser globals (root is window) root.plyr = factory(root, document); -- cgit v1.2.3 From a285fcc4ec45816d43fa3bfe35c23dd21e7bfc63 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Tue, 26 Jan 2016 17:05:57 +0100 Subject: Check for module.exports as well for CommonJS Modules --- src/js/plyr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/js') diff --git a/src/js/plyr.js b/src/js/plyr.js index 8c281d93..76623068 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -11,7 +11,7 @@ 'use strict'; /*global define,module*/ - if (typeof module === 'object') { + if (typeof module === 'object' && typeof module.exports === 'object') { // Node, CommonJS-like module.exports = factory(root, document); } else if (typeof define === 'function' && define.amd) { -- cgit v1.2.3 From 31a0eb8d1472ff792fe64cb75e81de16b7a5ea0b Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Wed, 27 Jan 2016 21:27:58 +0100 Subject: Get the proper window reference on initialization. The previous code assumed that `this` points to the browsers window object, which is not the case when using a module bundler. So we check for the variable `window` first, before falling back to `this`. (taken from jQuery's codebase) --- src/js/plyr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/js') diff --git a/src/js/plyr.js b/src/js/plyr.js index 76623068..2cee1210 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -21,7 +21,7 @@ // Browser globals (root is window) root.plyr = factory(root, document); } -}(this, function(window, document) { +}(typeof window !== 'undefined' ? window : this, function(window, document) { 'use strict'; /*global YT,$f*/ -- cgit v1.2.3