Add AMD support.

This commit is contained in:
Hyunje Alex Jun 2015-02-12 18:45:04 +00:00
parent 7a8b47179c
commit 11997131f4
3 changed files with 19 additions and 7 deletions

View File

@ -4,7 +4,8 @@
"browser": true
},
"globals": {
"$": true
"$": true,
"define": true
},
"rules" : {
"quotes": false,

View File

@ -5,7 +5,13 @@
var ps = require('../main');
window.PerfectScrollbar = ps;
if (typeof window.Ps === 'undefined') {
window.Ps = ps;
if (typeof define === 'function' && define.amd) {
// AMD
define(ps);
} else {
// Add to a global object.
window.PerfectScrollbar = ps;
if (typeof window.Ps === 'undefined') {
window.Ps = ps;
}
}

View File

@ -33,9 +33,14 @@ function mountJQuery(jQuery) {
};
}
var jq = window.jQuery ? window.jQuery : window.$;
if (typeof jq !== 'undefined') {
mountJQuery(jq);
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], mountJQuery);
} else {
var jq = window.jQuery ? window.jQuery : window.$;
if (typeof jq !== 'undefined') {
mountJQuery(jq);
}
}
module.exports = mountJQuery;