1- /*! p5.js v0.3.13 December 05 , 2014 */
1+ /*! p5.js v0.3.13 December 21 , 2014 */
22var shim = function ( require ) {
33 window . requestDraw = function ( ) {
44 return window . requestAnimationFrame || window . webkitRequestAnimationFrame || window . mozRequestAnimationFrame || window . oRequestAnimationFrame || window . msRequestAnimationFrame || function ( callback , element ) {
@@ -2423,7 +2423,7 @@ var imagepixels = function (require, core, filters, p5Color) {
24232423 else
24242424 context [ name ] = definition ( ) ;
24252425} ( 'reqwest' , this , function ( ) {
2426- 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 ( ) {
2426+ 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 ( ) {
24272427 } , isArray = typeof Array . isArray == 'function' ? Array . isArray : function ( a ) {
24282428 return a instanceof Array ;
24292429 } , defaultHeaders = {
@@ -2457,13 +2457,20 @@ var imagepixels = function (require, core, filters, p5Color) {
24572457 return data ;
24582458 }
24592459 } ;
2460+ function succeed ( r ) {
2461+ var protocol = protocolRe . exec ( r . url ) ;
2462+ protocol = protocol && protocol [ 1 ] || window . location . protocol ;
2463+ return httpsRe . test ( protocol ) ? twoHundo . test ( r . request . status ) : ! ! r . request . response ;
2464+ }
24602465 function handleReadyState ( r , success , error ) {
24612466 return function ( ) {
24622467 if ( r . _aborted )
24632468 return error ( r . request ) ;
2469+ if ( r . _timedOut )
2470+ return error ( r . request , 'Request is aborted: timeout' ) ;
24642471 if ( r . request && r . request [ readyState ] == 4 ) {
24652472 r . request . onreadystatechange = noop ;
2466- if ( twoHundo . test ( r . request . status ) )
2473+ if ( succeed ( r ) )
24672474 success ( r . request ) ;
24682475 else
24692476 error ( r . request ) ;
@@ -2473,9 +2480,10 @@ var imagepixels = function (require, core, filters, p5Color) {
24732480 function setHeaders ( http , o ) {
24742481 var headers = o [ 'headers' ] || { } , h ;
24752482 headers [ 'Accept' ] = headers [ 'Accept' ] || defaultHeaders [ 'accept' ] [ o [ 'type' ] ] || defaultHeaders [ 'accept' ] [ '*' ] ;
2483+ var isAFormData = typeof FormData === 'function' && o [ 'data' ] instanceof FormData ;
24762484 if ( ! o [ 'crossOrigin' ] && ! headers [ requestedWith ] )
24772485 headers [ requestedWith ] = defaultHeaders [ 'requestedWith' ] ;
2478- if ( ! headers [ contentType ] )
2486+ if ( ! headers [ contentType ] && ! isAFormData )
24792487 headers [ contentType ] = o [ 'contentType' ] || defaultHeaders [ 'contentType' ] ;
24802488 for ( h in headers )
24812489 headers . hasOwnProperty ( h ) && 'setRequestHeader' in http && http . setRequestHeader ( h , headers [ h ] ) ;
@@ -2507,7 +2515,6 @@ var imagepixels = function (require, core, filters, p5Color) {
25072515 script . src = url ;
25082516 script . async = true ;
25092517 if ( typeof script . onreadystatechange !== 'undefined' && ! isIE10 ) {
2510- script . event = 'onclick' ;
25112518 script . htmlFor = script . id = '_reqwest_' + reqId ;
25122519 }
25132520 script . onload = script . onreadystatechange = function ( ) {
@@ -2568,9 +2575,15 @@ var imagepixels = function (require, core, filters, p5Color) {
25682575 this . fn = fn ;
25692576 init . apply ( this , arguments ) ;
25702577 }
2571- function setType ( url ) {
2572- var m = url . match ( / \. ( j s o n | j s o n p | h t m l | x m l ) ( \? | $ ) / ) ;
2573- return m ? m [ 1 ] : 'js' ;
2578+ function setType ( header ) {
2579+ if ( header . match ( 'json' ) )
2580+ return 'json' ;
2581+ if ( header . match ( 'javascript' ) )
2582+ return 'js' ;
2583+ if ( header . match ( 'text' ) )
2584+ return 'html' ;
2585+ if ( header . match ( 'xml' ) )
2586+ return 'xml' ;
25742587 }
25752588 function init ( o , fn ) {
25762589 this . url = typeof o == 'string' ? o : o [ 'url' ] ;
@@ -2583,12 +2596,12 @@ var imagepixels = function (require, core, filters, p5Color) {
25832596 this . _completeHandlers = [ ] ;
25842597 this . _erred = false ;
25852598 this . _responseArgs = { } ;
2586- var self = this , type = o [ 'type' ] || setType ( this . url ) ;
2599+ var self = this ;
25872600 fn = fn || function ( ) {
25882601 } ;
25892602 if ( o [ 'timeout' ] ) {
25902603 this . timeout = setTimeout ( function ( ) {
2591- self . abort ( ) ;
2604+ timedOut ( ) ;
25922605 } , o [ 'timeout' ] ) ;
25932606 }
25942607 if ( o [ 'success' ] ) {
@@ -2614,6 +2627,7 @@ var imagepixels = function (require, core, filters, p5Color) {
26142627 }
26152628 }
26162629 function success ( resp ) {
2630+ var type = o [ 'type' ] || resp && setType ( resp . getResponseHeader ( 'Content-Type' ) ) ;
26172631 resp = type !== 'jsonp' ? self . request : resp ;
26182632 var filteredResponse = globalSetupOptions . dataFilter ( resp . responseText , type ) , r = filteredResponse ;
26192633 try {
@@ -2649,6 +2663,10 @@ var imagepixels = function (require, core, filters, p5Color) {
26492663 }
26502664 complete ( resp ) ;
26512665 }
2666+ function timedOut ( ) {
2667+ self . _timedOut = true ;
2668+ self . request . abort ( ) ;
2669+ }
26522670 function error ( resp , msg , t ) {
26532671 resp = self . request ;
26542672 self . _responseArgs . resp = resp ;
@@ -2700,6 +2718,9 @@ var imagepixels = function (require, core, filters, p5Color) {
27002718 this . _errorHandlers . push ( fn ) ;
27012719 }
27022720 return this ;
2721+ } ,
2722+ 'catch' : function ( fn ) {
2723+ return this . fail ( fn ) ;
27032724 }
27042725 } ;
27052726 function reqwest ( o , fn ) {
@@ -3659,9 +3680,6 @@ var outputfiles = function (require, core) {
36593680 p5 . prototype . endRecord = function ( ) {
36603681 throw 'not yet implemented' ;
36613682 } ;
3662- p5 . prototype . escape = function ( content ) {
3663- return content . replace ( / & / g, '&' ) . replace ( / < / g, '<' ) . replace ( / > / g, '>' ) . replace ( / " / g, '"' ) . replace ( / ' / g, ''' ) ;
3664- } ;
36653683 p5 . PrintWriter = function ( filename , extension ) {
36663684 var self = this ;
36673685 this . name = filename ;
@@ -3800,7 +3818,7 @@ var outputfiles = function (require, core) {
38003818 if ( header [ 0 ] !== '0' ) {
38013819 pWriter . println ( ' <tr>' ) ;
38023820 for ( var k = 0 ; k < header . length ; k ++ ) {
3803- var e = p5 . prototype . escape ( header [ k ] ) ;
3821+ var e = escapeHelper ( header [ k ] ) ;
38043822 pWriter . println ( ' <td>' + e ) ;
38053823 pWriter . println ( ' </td>' ) ;
38063824 }
@@ -3810,7 +3828,7 @@ var outputfiles = function (require, core) {
38103828 pWriter . println ( ' <tr>' ) ;
38113829 for ( var col = 0 ; col < table . columns . length ; col ++ ) {
38123830 var entry = table . rows [ row ] . getString ( col ) ;
3813- var htmlEntry = p5 . prototype . escape ( entry ) ;
3831+ var htmlEntry = escapeHelper ( entry ) ;
38143832 pWriter . println ( ' <td>' + htmlEntry ) ;
38153833 pWriter . println ( ' </td>' ) ;
38163834 }
@@ -3823,6 +3841,9 @@ var outputfiles = function (require, core) {
38233841 pWriter . close ( ) ;
38243842 pWriter . flush ( ) ;
38253843 } ;
3844+ var escapeHelper = function ( content ) {
3845+ return content . replace ( / & / g, '&' ) . replace ( / < / g, '<' ) . replace ( / > / g, '>' ) . replace ( / " / g, '"' ) . replace ( / ' / g, ''' ) ;
3846+ } ;
38263847 p5 . prototype . writeFile = function ( dataToDownload , filename , extension ) {
38273848 var type = 'application/octet-stream' ;
38283849 if ( p5 . prototype . _isSafari ( ) ) {
0 commit comments