@@ -623,6 +623,9 @@ cc.loader = (function () {
623623 getXMLHttpRequest : function ( ) {
624624 var xhr = window . XMLHttpRequest ? new window . XMLHttpRequest ( ) : new ActiveXObject ( "MSXML2.XMLHTTP" ) ;
625625 xhr . timeout = 10000 ;
626+ if ( xhr . ontimeout === undefined ) {
627+ xhr . _timeoutId = - 1 ;
628+ }
626629 return xhr ;
627630 } ,
628631
@@ -770,12 +773,24 @@ cc.loader = (function () {
770773 } else {
771774 if ( xhr . overrideMimeType ) xhr . overrideMimeType ( "text\/plain; charset=utf-8" ) ;
772775 xhr . onload = function ( ) {
773- if ( xhr . readyState === 4 )
776+ if ( xhr . _timeoutId >= 0 ) {
777+ clearTimeout ( xhr . _timeoutId ) ;
778+ }
779+ if ( xhr . readyState === 4 ) {
774780 xhr . status === 200 ? cb ( null , xhr . responseText ) : cb ( { status :xhr . status , errorMessage :errInfo } , null ) ;
781+ }
775782 } ;
776- xhr . onerror = xhr . ontimeout = function ( ) {
783+ xhr . onerror = function ( ) {
777784 cb ( { status : xhr . status , errorMessage : errInfo } , null ) ;
778785 } ;
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+ } ;
779794 }
780795 xhr . send ( null ) ;
781796 } else {
@@ -787,22 +802,34 @@ cc.loader = (function () {
787802 } ,
788803
789804 loadCsb : function ( url , cb ) {
790- var xhr = new XMLHttpRequest ( ) ,
805+ var xhr = cc . loader . getXMLHttpRequest ( ) ,
791806 errInfo = "load " + url + " failed!" ;
792807 xhr . open ( "GET" , url , true ) ;
793808 xhr . responseType = "arraybuffer" ;
794809
795810 xhr . onload = function ( ) {
811+ if ( xhr . _timeoutId >= 0 ) {
812+ clearTimeout ( xhr . _timeoutId ) ;
813+ }
796814 var arrayBuffer = xhr . response ; // Note: not oReq.responseText
797815 if ( arrayBuffer ) {
798816 window . msg = arrayBuffer ;
799817 }
800- if ( xhr . readyState === 4 )
818+ if ( xhr . readyState === 4 ) {
801819 xhr . status === 200 ? cb ( null , xhr . response ) : cb ( { status :xhr . status , errorMessage :errInfo } , null ) ;
820+ }
802821 } ;
803- xhr . onerror = xhr . ontimeout = function ( ) {
822+ xhr . onerror = function ( ) {
804823 cb ( { status :xhr . status , errorMessage :errInfo } , null ) ;
805824 } ;
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+ } ;
806833 xhr . send ( null ) ;
807834 } ,
808835
@@ -2650,8 +2677,7 @@ cc.game = /** @lends cc.game# */{
26502677 this . _renderContext = cc . _renderContext = cc . webglContext
26512678 = cc . create3DContext ( localCanvas , {
26522679 'stencil' : true ,
2653- 'alpha' : false ,
2654- 'preserveDrawingBuffer' : false
2680+ 'alpha' : false
26552681 } ) ;
26562682 }
26572683 // WebGL context created successfully
0 commit comments