@@ -2471,7 +2471,7 @@ var imagepixels = function (require, core, filters, p5Color) {
24712471 else
24722472 context [ name ] = definition ( ) ;
24732473} ( 'reqwest' , this , function ( ) {
2474- var win = window , doc = document , httpsRe = / ^ h t t p / , protocolRe = / ( ^ \w + ) : \/ \/ / , twoHundo = / ^ ( 2 0 \d | 1 2 2 3 ) $ / , byTag = 'getElementsByTagName' , readyState = 'readyState' , contentType = 'Content-Type' , requestedWith = 'X-Requested-With' , head = doc [ byTag ] ( 'head' ) [ 0 ] , uniqid = 0 , callbackPrefix = 'reqwest_' + + new Date ( ) , lastValue , xmlHttpRequest = 'XMLHttpRequest' , xDomainRequest = 'XDomainRequest' , noop = function ( ) {
2474+ var win = window , doc = document , twoHundo = / ^ ( 2 0 \d | 1 2 2 3 ) $ / , byTag = 'getElementsByTagName' , readyState = 'readyState' , contentType = 'Content-Type' , requestedWith = 'X-Requested-With' , head = doc [ byTag ] ( 'head' ) [ 0 ] , uniqid = 0 , callbackPrefix = 'reqwest_' + + new Date ( ) , lastValue , xmlHttpRequest = 'XMLHttpRequest' , xDomainRequest = 'XDomainRequest' , noop = function ( ) {
24752475 } , isArray = typeof Array . isArray == 'function' ? Array . isArray : function ( a ) {
24762476 return a instanceof Array ;
24772477 } , defaultHeaders = {
@@ -2505,20 +2505,13 @@ var imagepixels = function (require, core, filters, p5Color) {
25052505 return data ;
25062506 }
25072507 } ;
2508- function succeed ( r ) {
2509- var protocol = protocolRe . exec ( r . url ) ;
2510- protocol = protocol && protocol [ 1 ] || window . location . protocol ;
2511- return httpsRe . test ( protocol ) ? twoHundo . test ( r . request . status ) : ! ! r . request . response ;
2512- }
25132508 function handleReadyState ( r , success , error ) {
25142509 return function ( ) {
25152510 if ( r . _aborted )
25162511 return error ( r . request ) ;
2517- if ( r . _timedOut )
2518- return error ( r . request , 'Request is aborted: timeout' ) ;
25192512 if ( r . request && r . request [ readyState ] == 4 ) {
25202513 r . request . onreadystatechange = noop ;
2521- if ( succeed ( r ) )
2514+ if ( twoHundo . test ( r . request . status ) )
25222515 success ( r . request ) ;
25232516 else
25242517 error ( r . request ) ;
@@ -2528,10 +2521,9 @@ var imagepixels = function (require, core, filters, p5Color) {
25282521 function setHeaders ( http , o ) {
25292522 var headers = o [ 'headers' ] || { } , h ;
25302523 headers [ 'Accept' ] = headers [ 'Accept' ] || defaultHeaders [ 'accept' ] [ o [ 'type' ] ] || defaultHeaders [ 'accept' ] [ '*' ] ;
2531- var isAFormData = typeof FormData === 'function' && o [ 'data' ] instanceof FormData ;
25322524 if ( ! o [ 'crossOrigin' ] && ! headers [ requestedWith ] )
25332525 headers [ requestedWith ] = defaultHeaders [ 'requestedWith' ] ;
2534- if ( ! headers [ contentType ] && ! isAFormData )
2526+ if ( ! headers [ contentType ] )
25352527 headers [ contentType ] = o [ 'contentType' ] || defaultHeaders [ 'contentType' ] ;
25362528 for ( h in headers )
25372529 headers . hasOwnProperty ( h ) && 'setRequestHeader' in http && http . setRequestHeader ( h , headers [ h ] ) ;
@@ -2563,6 +2555,7 @@ var imagepixels = function (require, core, filters, p5Color) {
25632555 script . src = url ;
25642556 script . async = true ;
25652557 if ( typeof script . onreadystatechange !== 'undefined' && ! isIE10 ) {
2558+ script . event = 'onclick' ;
25662559 script . htmlFor = script . id = '_reqwest_' + reqId ;
25672560 }
25682561 script . onload = script . onreadystatechange = function ( ) {
@@ -2623,15 +2616,9 @@ var imagepixels = function (require, core, filters, p5Color) {
26232616 this . fn = fn ;
26242617 init . apply ( this , arguments ) ;
26252618 }
2626- function setType ( header ) {
2627- if ( header . match ( 'json' ) )
2628- return 'json' ;
2629- if ( header . match ( 'javascript' ) )
2630- return 'js' ;
2631- if ( header . match ( 'text' ) )
2632- return 'html' ;
2633- if ( header . match ( 'xml' ) )
2634- return 'xml' ;
2619+ function setType ( url ) {
2620+ var m = url . match ( / \. ( j s o n | j s o n p | h t m l | x m l ) ( \? | $ ) / ) ;
2621+ return m ? m [ 1 ] : 'js' ;
26352622 }
26362623 function init ( o , fn ) {
26372624 this . url = typeof o == 'string' ? o : o [ 'url' ] ;
@@ -2644,12 +2631,12 @@ var imagepixels = function (require, core, filters, p5Color) {
26442631 this . _completeHandlers = [ ] ;
26452632 this . _erred = false ;
26462633 this . _responseArgs = { } ;
2647- var self = this ;
2634+ var self = this , type = o [ 'type' ] || setType ( this . url ) ;
26482635 fn = fn || function ( ) {
26492636 } ;
26502637 if ( o [ 'timeout' ] ) {
26512638 this . timeout = setTimeout ( function ( ) {
2652- timedOut ( ) ;
2639+ self . abort ( ) ;
26532640 } , o [ 'timeout' ] ) ;
26542641 }
26552642 if ( o [ 'success' ] ) {
@@ -2675,7 +2662,6 @@ var imagepixels = function (require, core, filters, p5Color) {
26752662 }
26762663 }
26772664 function success ( resp ) {
2678- var type = o [ 'type' ] || resp && setType ( resp . getResponseHeader ( 'Content-Type' ) ) ;
26792665 resp = type !== 'jsonp' ? self . request : resp ;
26802666 var filteredResponse = globalSetupOptions . dataFilter ( resp . responseText , type ) , r = filteredResponse ;
26812667 try {
@@ -2711,10 +2697,6 @@ var imagepixels = function (require, core, filters, p5Color) {
27112697 }
27122698 complete ( resp ) ;
27132699 }
2714- function timedOut ( ) {
2715- self . _timedOut = true ;
2716- self . request . abort ( ) ;
2717- }
27182700 function error ( resp , msg , t ) {
27192701 resp = self . request ;
27202702 self . _responseArgs . resp = resp ;
@@ -2766,9 +2748,6 @@ var imagepixels = function (require, core, filters, p5Color) {
27662748 this . _errorHandlers . push ( fn ) ;
27672749 }
27682750 return this ;
2769- } ,
2770- 'catch' : function ( fn ) {
2771- return this . fail ( fn ) ;
27722751 }
27732752 } ;
27742753 function reqwest ( o , fn ) {
0 commit comments