diff --git a/.jshintrc b/.jshintrc index 626284b2..013e31e8 100644 --- a/.jshintrc +++ b/.jshintrc @@ -10,6 +10,7 @@ "globals": { "OpenSeadragon": true, - "define": false + "define": false, + "module": false } } diff --git a/src/openseadragon.js b/src/openseadragon.js index 06f6d189..de7399e8 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -685,19 +685,10 @@ * @param {OpenSeadragon.Options} options - Viewer options. * @returns {OpenSeadragon.Viewer} */ -window.OpenSeadragon = window.OpenSeadragon || function( options ){ - +function OpenSeadragon( options ){ return new OpenSeadragon.Viewer( options ); - -}; - -if (typeof define === 'function' && define.amd) { - define(function () { - return (window.OpenSeadragon); - }); } - (function( $ ){ @@ -2596,3 +2587,20 @@ if (typeof define === 'function' && define.amd) { } }(OpenSeadragon)); + + +// Universal Module Definition, supports CommonJS, AMD and simple script tag +(function (root, factory) { + if (typeof define === 'function' && define.amd) { + // expose as amd module + define([], factory); + } else if (typeof module === 'object' && module.exports) { + // expose as commonjs module + module.exports = factory(); + } else { + // expose as window.OpenSeadragon + root.OpenSeadragon = factory(); + } +}(this, function () { + return OpenSeadragon; +}));