diff --git a/.eslintrc b/.eslintrc index 367d6e3..3324c41 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,7 +4,8 @@ "browser": true }, "globals": { - "$": true + "$": true, + "define": true }, "rules" : { "quotes": false, diff --git a/src/js/adaptor/global.js b/src/js/adaptor/global.js index dce0e3a..6f63bae 100644 --- a/src/js/adaptor/global.js +++ b/src/js/adaptor/global.js @@ -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; + } } diff --git a/src/js/adaptor/jquery.js b/src/js/adaptor/jquery.js index cbc1058..02e53a5 100644 --- a/src/js/adaptor/jquery.js +++ b/src/js/adaptor/jquery.js @@ -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;