diff --git a/3rd-party-loaders/hammerjs.browser.js b/3rd-party-loaders/hammerjs.browser.js new file mode 100644 index 0000000..d3a70f1 --- /dev/null +++ b/3rd-party-loaders/hammerjs.browser.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = function () { + return require('hammerjs'); +}; diff --git a/3rd-party-loaders/hammerjs.js b/3rd-party-loaders/hammerjs.js new file mode 100644 index 0000000..a86245e --- /dev/null +++ b/3rd-party-loaders/hammerjs.js @@ -0,0 +1,12 @@ +'use strict'; + +var sandbox = require('sandboxed-module'); + +module.exports = function(window) { + return sandbox.require('hammerjs', { + globals: { + window: window, + document: window.document + } + }); +}; diff --git a/3rd-party-loaders/jquery.browser.js b/3rd-party-loaders/jquery.browser.js new file mode 100644 index 0000000..9a2cf7f --- /dev/null +++ b/3rd-party-loaders/jquery.browser.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = function () { + return require('jquery'); +}; diff --git a/3rd-party-loaders/jquery.js b/3rd-party-loaders/jquery.js new file mode 100644 index 0000000..330afd1 --- /dev/null +++ b/3rd-party-loaders/jquery.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = function(window) { + return require('jquery')(window); +}; diff --git a/jquery.hammer.js b/jquery.hammer.js index e444b5c..515ac84 100644 --- a/jquery.hammer.js +++ b/jquery.hammer.js @@ -2,7 +2,13 @@ if (typeof define === 'function' && define.amd) { define(['jquery', 'hammerjs'], factory); } else if (typeof exports === 'object') { - factory(require('jquery'), require('hammerjs')); + module.exports = function (window) { + var hammerjsFactory = require('./3rd-party-loaders/hammerjs'); + var jqueryFactory = require('./3rd-party-loaders/jquery'); + var Hammer = hammerjsFactory(window); + var jQuery = window.jQuery || jqueryFactory(window); + return factory(jQuery, Hammer); + }; } else { factory(jQuery, Hammer); } diff --git a/package.json b/package.json index ddd9e8b..e74f419 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,15 @@ "jquery" ], "dependencies": { - "hammerjs": "2.0.x", - "jquery": "2.1.x" + "sandboxed-module": "^1.0.2", + "hammerjs": "^2.0.4" + }, + "peerDependencies": { + "jquery": "1.x || 2.x" + }, + "browser": { + "./3rd-party-loaders/hammerjs.js": "./3rd-party-loaders/hammerjs.browser.js", + "./3rd-party-loaders/jquery.js": "./3rd-party-loaders/jquery.browser.js" }, "author": "J. Tangelder", "license": "MIT",