|
11 | 11 | } |
12 | 12 | else if ( typeof exports === 'object' ) { |
13 | 13 | // CommonJS |
14 | | - module.exports = function (root, $) { |
15 | | - if ( ! root ) { |
16 | | - // CommonJS environments without a window global must pass a |
17 | | - // root. This will give an error otherwise |
18 | | - root = window; |
19 | | - } |
20 | | - |
21 | | - if ( ! $ ) { |
22 | | - $ = typeof window !== 'undefined' ? // jQuery's factory checks for a global window |
23 | | - require('jquery') : |
24 | | - require('jquery')( root ); |
25 | | - } |
26 | | - |
| 14 | + var jq = require('jquery'); |
| 15 | + var cjsRequires = function (root, $) { |
27 | 16 | if ( ! $.fn.dataTable ) { |
28 | 17 | require('datatables.net-jqui')(root, $); |
29 | 18 | } |
30 | 19 |
|
31 | 20 | if ( ! $.fn.dataTable.StateRestore ) { |
32 | 21 | require('datatables.net-staterestore')(root, $); |
33 | 22 | } |
34 | | - |
35 | | - return factory( $, root, root.document ); |
36 | 23 | }; |
| 24 | + |
| 25 | + if (typeof window !== 'undefined') { |
| 26 | + module.exports = function (root, $) { |
| 27 | + if ( ! root ) { |
| 28 | + // CommonJS environments without a window global must pass a |
| 29 | + // root. This will give an error otherwise |
| 30 | + root = window; |
| 31 | + } |
| 32 | + |
| 33 | + if ( ! $ ) { |
| 34 | + $ = jq( root ); |
| 35 | + } |
| 36 | + |
| 37 | + cjsRequires( root, $ ); |
| 38 | + return factory( $, root, root.document ); |
| 39 | + }; |
| 40 | + } |
| 41 | + else { |
| 42 | + cjsRequires( window, jq ); |
| 43 | + module.exports = factory( jq, window, window.document ); |
| 44 | + } |
37 | 45 | } |
38 | 46 | else { |
39 | 47 | // Browser |
|
0 commit comments