(function ($) {
	"use strict";
	var WidgetBackToTop = function ($scope, $) {
		if ( $scope.find( '.ecbctop' ).length ) {
			var ecbctop     = document.querySelector( ".ecbctop" ),
				rootElement = document.documentElement,
				bttoffset   = ecbctop.dataset.bttoffset;

			function ecscrollmoment() {
				var scrollTotal = rootElement.scrollHeight - rootElement.clientHeight
				if ((rootElement.scrollTop / scrollTotal ) > bttoffset) {
					ecbctop.classList.add( "ecbctshow" )
				} else {
					ecbctop.classList.remove( "ecbctshow" )
				}
			}

			function ecscrolltop() {
				rootElement.scrollTo(
					{
						top: 0,
						behavior: "smooth"
					}
				)
			}
			ecbctop.addEventListener( "click", ecscrolltop )
			document.addEventListener( "scroll", ecscrollmoment )
		}
	};

	$( window ).on(
		'elementor/frontend/init',
		function () {
			elementorFrontend.hooks.addAction( 'frontend/element_ready/ecafe-back-to-top.default', WidgetBackToTop );
		}
	);
})( jQuery );