( function ( $ ) {

    var WidgetTFLStatsBarHandler = function ($scope, $) {

        $scope.find('.tfl-stats-bar-content').each(function () {

            var dataperc = $(this).data('perc');

            $(this).animate({"width": dataperc + "%"}, dataperc * 20);

        });

    };

    var WidgetTFLStatsBarHandlerOnScroll = function ($scope, $) {

        $scope.themesflatWaypoint(function (direction) {

            WidgetTFLStatsBarHandler($(this.element), $);

            this.destroy(); // Done with handle on scroll

        }, {
            offset: (window.innerHeight || document.documentElement.clientHeight) - 150
        });

    };

    // Make sure you run this code under Elementor..
    $( window ).on( 'elementor/frontend/init', function () {
        if (elementorFrontend.isEditMode()) {

            elementorFrontend.hooks.addAction( 'frontend/element_ready/tfl-stats-bars.default', WidgetTFLStatsBarHandler );

        } else {

            elementorFrontend.hooks.addAction( 'frontend/element_ready/tfl-stats-bars.default', WidgetTFLStatsBarHandlerOnScroll );

        }

    } );

} )( jQuery );