From 3f60ebcf87335e40605ccea82f4b8e1c889c6e94 Mon Sep 17 00:00:00 2001 From: Anthony Hell Date: Wed, 25 Mar 2015 09:41:02 -0600 Subject: [PATCH] Added support of AMD and common.js module added support of AMD module (e.g. for require.js) and common.js (e.g. for browserify) --- src/js/waves.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/js/waves.js b/src/js/waves.js index 6586436..bddaee3 100644 --- a/src/js/waves.js +++ b/src/js/waves.js @@ -7,8 +7,29 @@ * https://github.com/fians/Waves/blob/master/LICENSE */ -;(function(window) { - 'use strict'; +;(function(window, factory) { + "use strict"; + + // AMD. Register as an anonymous module. Wrap in function so we have access + // to root via `this`. + if (typeof define === "function" && define.amd) { + define([], function() { + return factory.apply(window); + }); + } + + // Node. Does not work with strict CommonJS, but only CommonJS-like + // environments that support module.exports, like Node. + else if (typeof exports === "object") { + module.exports = factory.call(window); + } + + // Browser globals. + else { + window.Waves = factory.call(window); + } +})(typeof global === "object" ? global : this, function () { + "use strict"; var Waves = Waves || {}; var $$ = document.querySelectorAll.bind(document); @@ -324,5 +345,5 @@ element.addEventListener('mousedown', showEffect, false); }; - window.Waves = Waves; -})(window); + return Waves; +});