document.addEventListener( "DOMContentLoaded", function( event ) {

    let updateBtns = document.querySelectorAll( "[data-cms-update]" );
    updateBtns.forEach( function( button ) {
        button.addEventListener( "click", function() {
            let fn = this.getAttribute( "data-fn" );
            let data = {
                fn: fn
            }
            api2( data, function( r ){
                if ( r.result == "timeout" ) {
                    notify( __( "Connection lost", "update.mod.php"), 'info-error', 10000 );
                } else if ( r.info_text ) {
                    notify( r.info_text, r.info_class, 5000 );
                    if ( r.answer != null ) {
                        document.querySelector( "[data-"+data.fn+"-answer]" ).innerHTML = r.answer;
                    }
                    if ( r.reload ) {
                        window.location.reload( true );
                    }
                }
            });
        });
    });

    if ( window.location.hostname.match( /\.coffee-cms\.com/ ) ) {
        document.querySelector( ".info.developers_only" ).classList.remove( "developers_only" );
    }

});
