1+ /* global attachEvent */
2+
13/**
24 * Module requirements.
35 */
@@ -33,7 +35,7 @@ function XHR (opts) {
3335 this . requestTimeout = opts . requestTimeout ;
3436 this . extraHeaders = opts . extraHeaders ;
3537
36- if ( global . location ) {
38+ if ( typeof location !== 'undefined' ) {
3739 var isSSL = 'https:' === location . protocol ;
3840 var port = location . port ;
3941
@@ -42,7 +44,7 @@ function XHR (opts) {
4244 port = isSSL ? 443 : 80 ;
4345 }
4446
45- this . xd = opts . hostname !== global . location . hostname ||
47+ this . xd = ( typeof location !== 'undefined' && opts . hostname !== location . hostname ) ||
4648 port !== opts . port ;
4749 this . xs = opts . secure !== isSSL ;
4850 }
@@ -271,7 +273,7 @@ Request.prototype.create = function () {
271273 return ;
272274 }
273275
274- if ( global . document ) {
276+ if ( typeof document !== 'undefined' ) {
275277 this . index = Request . requestsCount ++ ;
276278 Request . requests [ this . index ] = this ;
277279 }
@@ -333,7 +335,7 @@ Request.prototype.cleanup = function (fromError) {
333335 } catch ( e ) { }
334336 }
335337
336- if ( global . document ) {
338+ if ( typeof document !== 'undefined' ) {
337339 delete Request . requests [ this . index ] ;
338340 }
339341
@@ -373,7 +375,7 @@ Request.prototype.onLoad = function () {
373375 */
374376
375377Request . prototype . hasXDR = function ( ) {
376- return 'undefined' !== typeof global . XDomainRequest && ! this . xs && this . enablesXDR ;
378+ return typeof XDomainRequest !== 'undefined' && ! this . xs && this . enablesXDR ;
377379} ;
378380
379381/**
@@ -395,11 +397,11 @@ Request.prototype.abort = function () {
395397Request . requestsCount = 0 ;
396398Request . requests = { } ;
397399
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 ) ;
403405 }
404406}
405407
0 commit comments