'use strict' ; import type HTMLAttributes from '../Core/Renderer/HTML/HTMLAttributes' ; import G from '../Core/Globals.js' ; const { doc } = G ; import U from '../Core/Utilities.js' ; const { createElement , discardElement , merge , objectEach } = U ; private declare global { namespace Highcharts { type JSONType = ReturnType < JSON [ 'parse' ] > ; interface AjaxErrorCallbackFunction { ( request , error ) : void ; } interface AjaxSuccessCallbackFunction { ( response , xhr ) : void ; } interface AjaxSettingsObject { data : ( string | AnyRecord ) ; dataType : string ; error : AjaxErrorCallbackFunction ; headers : Record < string , string > ; responseType : 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' ; success : AjaxSuccessCallbackFunction ; type : ( 'get' | 'post' | 'update' | 'delete' ) ; url : string ; } } } function param { Partial < Highcharts . AjaxSettingsObject > } attr return { false | undefined } function ajax ( attr ) { const options = merge ( true , { url : false as any , type : 'get' , dataType : 'json' , success : false as any , error : false as any , data : false as any , headers : { } } as Highcharts . AjaxSettingsObject , attr ) , headers = { json : 'application/json' , xml : 'application/xml' , text : 'text/plain' , octet : 'application/octet-stream' } , r = new XMLHttpRequest ( ) ; private param { XMLHttpRequest } xhr param { string | Error } err function handleError ( xhr , err ) { if ( options . error ) { options . error ( xhr , err ) ; } else { } } if ( ! options . url ) { return false ; } r . open ( ( options . type as any ) . toUpperCase ( ) , options . url , true ) ; if ( ! options . headers [ 'Content-Type' ] ) { r . setRequestHeader ( 'Content-Type' , headers [ options . dataType ] || headers . text ) ; } objectEach ( options . headers , function ( val , key ) : void { r . setRequestHeader ( key , val ) ; } ) ; if ( options . responseType ) { r . responseType = options . responseType ; } r . onreadystatechange = function ( ) : void { let res ; if ( r . readyState === 4 ) { if ( r . status === 200 ) { if ( options . responseType !== 'blob' ) { res = r . responseText ; if ( options . dataType === 'json' ) { try { res = JSON . parse ( res ) ; } catch ( e ) { return handleError ( r , e ) ; } } } return options . success && options . success ( res , r ) ; } handleError ( r , r . responseText ) ; } } ; try { options . data = JSON . stringify ( options . data ) ; } catch ( e ) { } r . send ( options . data || ( true as any ) ) ; } function param { string } url param { Function } success function getJSON ( url , success ) { HttpUtilities . ajax ( { url : url , success : success , dataType : 'json' , headers : { 'Content-Type' : 'text/plain' } } ) ; } private function param { string } url param { Object } data param { Highcharts . Dictionary < string > } formAttributes function post ( url , data , formAttributes ? ) { const form = createElement ( 'form' , merge ( { method : 'post' , action : url , enctype : 'multipart/form-data' } , formAttributes ) , { display : 'none' } , doc . body ) as unknown as HTMLFormElement ; objectEach ( data , function ( val , name ) : void { createElement ( 'input' , { type : 'hidden' , name : name , value : val } , null as any , form ) ; } ) ; form . submit ( ) ; discardElement ( form ) ; } const HttpUtilities = { ajax , getJSON , post } ; export default HttpUtilities ; interface name type { string | Highcharts . Dictionary < any > } name type { "json" | "xml" | "text" | "octet" } name type { Function } name type { Highcharts . Dictionary < string > } name type { Function } name type { string } name type { string } ( '' ) ;