HEX
Server: Apache
System: Linux webd001.cluster127.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64
User: mciraet (192513)
PHP: 8.2.31
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/mciraet/www/wp-content/plugins/js_composer/modules/scroll-to-element/assets/js/module.js
( function () {
	'use strict';

	function scrollToElement () {
		var model = window.vc.latestAddedElement;
		if ( !model || !model.view || !model.view.el ) {
			return;
		}

		var element = model.view.el;
		var offset = 250;
		var elementTop = element.getBoundingClientRect().top;
		var iframe = document.getElementById( 'vc_inline-frame' );
		var scrollTop = window.scrollY || document.documentElement.scrollTop;
		var offsetPosition = elementTop + scrollTop - offset;

		// Don't scroll if element is already in viewport
		if ( elementTop >= 0 && elementTop <= window.innerHeight ) {
			return;
		}

		if ( iframe ) {
			// For frontend editor
			var iframeWindow = iframe.contentWindow;
			scrollTop =
				iframeWindow.scrollY ||
				iframeWindow.document.documentElement.scrollTop;
			offsetPosition = elementTop + scrollTop - offset;

			iframeWindow.scrollTo({
				top: offsetPosition,
				behavior: 'smooth'
			});
		} else {
			// For backend editor
			window.scrollTo({
				top: offsetPosition,
				behavior: 'smooth'
			});
		}
	}

	function initializeScrollLogic () {
		vc.events.on( 'afterLoadShortcode', _.debounce( scrollToElement, 300 ) );
		vc.events.on( 'templateAdd', _.debounce( scrollToElement, 300 ) );
	}
	var isModuleEnabled = window.vc_modules && ( !window.vc_modules.hasOwnProperty( 'vc-scroll-to-element' ) || window.vc_modules['vc-scroll-to-element']);
	var isFrontendEditor = 'admin_frontend_editor' === window.vc_mode;
	if ( isModuleEnabled ) {
		if ( isFrontendEditor ) {
			// Initialize once on this event to prevent scroll on initial editor load
			vc.events.once( 'shortcodeView:ready', initializeScrollLogic );
		} else {
			vc.events.on( 'shortcodeView:ready', _.debounce( scrollToElement, 300 ) );
		}
	}
})();