Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added better support for node and browserify #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 3rd-party-loaders/hammerjs.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function () {
return require('hammerjs');
};
12 changes: 12 additions & 0 deletions 3rd-party-loaders/hammerjs.js
Original file line number Diff line number Diff line change
@@ -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
}
});
};
5 changes: 5 additions & 0 deletions 3rd-party-loaders/jquery.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function () {
return require('jquery');
};
5 changes: 5 additions & 0 deletions 3rd-party-loaders/jquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function(window) {
return require('jquery')(window);
};
8 changes: 7 additions & 1 deletion jquery.hammer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down