1
+ /* global attachEvent */
2
+
1
3
/**
2
4
* Module requirements.
3
5
*/
@@ -33,7 +35,7 @@ function XHR (opts) {
33
35
this . requestTimeout = opts . requestTimeout ;
34
36
this . extraHeaders = opts . extraHeaders ;
35
37
36
- if ( global . location ) {
38
+ if ( typeof location !== 'undefined' ) {
37
39
var isSSL = 'https:' === location . protocol ;
38
40
var port = location . port ;
39
41
@@ -42,7 +44,7 @@ function XHR (opts) {
42
44
port = isSSL ? 443 : 80 ;
43
45
}
44
46
45
- this . xd = opts . hostname !== global . location . hostname ||
47
+ this . xd = ( typeof location !== 'undefined' && opts . hostname !== location . hostname ) ||
46
48
port !== opts . port ;
47
49
this . xs = opts . secure !== isSSL ;
48
50
}
@@ -271,7 +273,7 @@ Request.prototype.create = function () {
271
273
return ;
272
274
}
273
275
274
- if ( global . document ) {
276
+ if ( typeof document !== 'undefined' ) {
275
277
this . index = Request . requestsCount ++ ;
276
278
Request . requests [ this . index ] = this ;
277
279
}
@@ -333,7 +335,7 @@ Request.prototype.cleanup = function (fromError) {
333
335
} catch ( e ) { }
334
336
}
335
337
336
- if ( global . document ) {
338
+ if ( typeof document !== 'undefined' ) {
337
339
delete Request . requests [ this . index ] ;
338
340
}
339
341
@@ -373,7 +375,7 @@ Request.prototype.onLoad = function () {
373
375
*/
374
376
375
377
Request . prototype . hasXDR = function ( ) {
376
- return 'undefined' !== typeof global . XDomainRequest && ! this . xs && this . enablesXDR ;
378
+ return typeof XDomainRequest !== 'undefined' && ! this . xs && this . enablesXDR ;
377
379
} ;
378
380
379
381
/**
@@ -395,11 +397,11 @@ Request.prototype.abort = function () {
395
397
Request . requestsCount = 0 ;
396
398
Request . requests = { } ;
397
399
398
- if ( global . document ) {
399
- if ( global . attachEvent ) {
400
- global . attachEvent ( 'onunload' , unloadHandler ) ;
401
- } else if ( global . addEventListener ) {
402
- global . addEventListener ( 'beforeunload' , unloadHandler , false ) ;
400
+ if ( typeof document !== 'undefined' ) {
401
+ if ( typeof attachEvent === 'function' ) {
402
+ attachEvent ( 'onunload' , unloadHandler ) ;
403
+ } else if ( typeof addEventListener === 'function' ) {
404
+ addEventListener ( 'beforeunload' , unloadHandler , false ) ;
403
405
}
404
406
}
405
407
0 commit comments