@@ -623,6 +623,9 @@ cc.loader = (function () {
623
623
getXMLHttpRequest : function ( ) {
624
624
var xhr = window . XMLHttpRequest ? new window . XMLHttpRequest ( ) : new ActiveXObject ( "MSXML2.XMLHTTP" ) ;
625
625
xhr . timeout = 10000 ;
626
+ if ( xhr . ontimeout === undefined ) {
627
+ xhr . _timeoutId = - 1 ;
628
+ }
626
629
return xhr ;
627
630
} ,
628
631
@@ -770,12 +773,24 @@ cc.loader = (function () {
770
773
} else {
771
774
if ( xhr . overrideMimeType ) xhr . overrideMimeType ( "text\/plain; charset=utf-8" ) ;
772
775
xhr . onload = function ( ) {
773
- if ( xhr . readyState === 4 )
776
+ if ( xhr . _timeoutId >= 0 ) {
777
+ clearTimeout ( xhr . _timeoutId ) ;
778
+ }
779
+ if ( xhr . readyState === 4 ) {
774
780
xhr . status === 200 ? cb ( null , xhr . responseText ) : cb ( { status :xhr . status , errorMessage :errInfo } , null ) ;
781
+ }
775
782
} ;
776
- xhr . onerror = xhr . ontimeout = function ( ) {
783
+ xhr . onerror = function ( ) {
777
784
cb ( { status : xhr . status , errorMessage : errInfo } , null ) ;
778
785
} ;
786
+ if ( xhr . ontimeout === undefined ) {
787
+ xhr . _timeoutId = setTimeout ( function ( ) {
788
+ xhr . ontimeout ( ) ;
789
+ } , xhr . timeout ) ;
790
+ }
791
+ xhr . ontimeout = function ( ) {
792
+ cb ( { status : xhr . status , errorMessage : "Request timeout: " + errInfo } , null ) ;
793
+ } ;
779
794
}
780
795
xhr . send ( null ) ;
781
796
} else {
@@ -787,22 +802,34 @@ cc.loader = (function () {
787
802
} ,
788
803
789
804
loadCsb : function ( url , cb ) {
790
- var xhr = new XMLHttpRequest ( ) ,
805
+ var xhr = cc . loader . getXMLHttpRequest ( ) ,
791
806
errInfo = "load " + url + " failed!" ;
792
807
xhr . open ( "GET" , url , true ) ;
793
808
xhr . responseType = "arraybuffer" ;
794
809
795
810
xhr . onload = function ( ) {
811
+ if ( xhr . _timeoutId >= 0 ) {
812
+ clearTimeout ( xhr . _timeoutId ) ;
813
+ }
796
814
var arrayBuffer = xhr . response ; // Note: not oReq.responseText
797
815
if ( arrayBuffer ) {
798
816
window . msg = arrayBuffer ;
799
817
}
800
- if ( xhr . readyState === 4 )
818
+ if ( xhr . readyState === 4 ) {
801
819
xhr . status === 200 ? cb ( null , xhr . response ) : cb ( { status :xhr . status , errorMessage :errInfo } , null ) ;
820
+ }
802
821
} ;
803
- xhr . onerror = xhr . ontimeout = function ( ) {
822
+ xhr . onerror = function ( ) {
804
823
cb ( { status :xhr . status , errorMessage :errInfo } , null ) ;
805
824
} ;
825
+ if ( xhr . ontimeout === undefined ) {
826
+ xhr . _timeoutId = setTimeout ( function ( ) {
827
+ xhr . ontimeout ( ) ;
828
+ } , xhr . timeout ) ;
829
+ }
830
+ xhr . ontimeout = function ( ) {
831
+ cb ( { status : xhr . status , errorMessage : "Request timeout: " + errInfo } , null ) ;
832
+ } ;
806
833
xhr . send ( null ) ;
807
834
} ,
808
835
@@ -2650,8 +2677,7 @@ cc.game = /** @lends cc.game# */{
2650
2677
this . _renderContext = cc . _renderContext = cc . webglContext
2651
2678
= cc . create3DContext ( localCanvas , {
2652
2679
'stencil' : true ,
2653
- 'alpha' : false ,
2654
- 'preserveDrawingBuffer' : false
2680
+ 'alpha' : false
2655
2681
} ) ;
2656
2682
}
2657
2683
// WebGL context created successfully
0 commit comments