UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 2.88 kB
import{raiseError}from'../event-api';import{extend2,isFirefox}from'../lib';var UNDEF,MSXMLHTTP='Microsoft.XMLHTTP',MSXMLHTTP2='Msxml2.XMLHTTP',FUNCTION='function',GET='GET',POST='POST',XHREQERROR='XmlHttprequest Error',RUN='run',ERRNO='1110111515A',win=window,version=parseFloat(win.navigator.appVersion.split('MSIE')[1]),ielt8=!!(5.5<=version&&7>=version),fileProtocol='file:'===win.location.protocol,AXObject=win.ActiveXObject,XHRNative=(!AXObject||!fileProtocol)&&win.XMLHttpRequest,counters={objects:0,xhr:0,requests:0,success:0,failure:0,idle:0},newXmlHttpRequest=function(){var a;if(XHRNative)return newXmlHttpRequest=function(){return counters.xhr++,new XHRNative},newXmlHttpRequest();try{a=new AXObject(MSXMLHTTP2),newXmlHttpRequest=function(){return counters.xhr++,new AXObject(MSXMLHTTP2)}}catch(b){try{a=new AXObject(MSXMLHTTP),newXmlHttpRequest=function(){return counters.xhr++,new AXObject(MSXMLHTTP)}}catch(b){a=!1}}return a};class Ajax{constructor(a,b){this.onSuccess=a,this.onError=b,this.open=!1,counters.objects++,counters.idle++}static stats(a){return a?counters[a]:extend2({},counters)}transact(a,b,c,d){var e,f,g=this,h=g.xmlhttp,j=Ajax.headers,k=g.onError,l=g.onSuccess,m=a===POST,n=Object.prototype.hasOwnProperty;-1!==b.search(/^(http:\/\/|https:\/\/)/)&&win.location.hostname!==/(http:\/\/|https:\/\/)([^\/\:]*)/.exec(b)[2]?delete j['X-Requested-By']:!n.call(j,'X-Requested-By')&&(j['X-Requested-By']='FusionCharts'),(!h||ielt8||isFirefox)&&(h=newXmlHttpRequest(),g.xmlhttp=h),h.onreadystatechange=function(){try{4===h.readyState&&(!h.status&&fileProtocol||200<=h.status&&300>h.status||304===h.status||1223===h.status||0===h.status?(l&&l(h.responseText,g,d,b),counters.success++):k&&(k(new Error(XHREQERROR),g,d,b),counters.failure++),counters.idle--,g.open=!1)}catch(a){k&&k(a,g,d,b),win.FC_DEV_ENVIRONMENT&&setTimeout(function(){throw a},0),counters.failure++}};try{if(h.open(m?POST:GET,b,!0),h.overrideMimeType&&h.overrideMimeType('text/plain'),!m)e=null;else if('string'==typeof c)e=c;else{for(f in e=[],c)e.push(f+'='+(c[f]+'').replace(/\=/g,'%3D').replace(/\&/g,'%26'));e=e.join('&')}for(f in j)h.setRequestHeader(f,j[f]);h.send(e),counters.requests++,counters.idle++,g.open=!0}catch(a){raiseError(global.core,ERRNO,RUN,XHREQERROR,a.message)}return h}get(a,b){return this.transact(GET,a,UNDEF,b)}post(a,b,c){return this.transact(POST,a,b,c)}abort(){var a=this,b=a.xmlhttp;return a.open=!1,b&&typeof b.abort==FUNCTION&&b.readyState&&0!==b.readyState&&b.abort()}dispose(){var a=this;return a.open&&a.abort(),delete a.onError,delete a.onSuccess,delete a.xmlhttp,delete a.open,counters.objects--,a=null}}Ajax.headers={"If-Modified-Since":'Sat, 29 Oct 1994 19:43:31 GMT',"X-Requested-With":'XMLHttpRequest',"X-Requested-By":'FusionCharts',Accept:'text/plain, */*',"Content-Type":'application/x-www-form-urlencoded; charset=UTF-8'};export default Ajax;