( function ( $ ) {
    $( window ).on( "elementor/frontend/init", function () {
        var WPMOZODropdownButton = elementorModules.frontend.handlers.Base.extend( {
            bindEvents: function () {
                this.change();
            },
            change: function () {
				jQuery( document ).ready( function($) {
					$( '.wpmozo_dropdown_button' ).each( function () {
						var $wrap       = $(this).find( '.wpmozo_dropdown_button_wrap' );
						var $inner      = $wrap.find( '.wpmozo_dropdown_button_inner' );
						var $button     = $wrap.find( '.wpmozo_readmore_button' );
						var $menu       = $wrap.find( '.wpmozo_dropdown_menu_items' );
						var triggerType = $wrap.data( 'trigger-type' ) || 'click';
						var triggerSpeed = $wrap.data( 'trigger-speed' ) || 300;
				
						// Hide the menu initially
						$menu.hide();
						if ( triggerType === 'hover' ) {
							$button.on( 'mouseenter', function() {
								$menu.stop( true, true ).slideDown( triggerSpeed );
							} );
							$inner.on( 'mouseleave', function() {
								$menu.stop( true, true ).slideUp( triggerSpeed );
							} );
						} else {
							// Toggle on click
							$button.on( 'click', function(e) {
								e.preventDefault();
								e.stopPropagation();
								$menu.stop( true, true ).slideToggle( triggerSpeed );
							} );
				
							// Close dropdown if clicked outside
							$( document ).on( 'click', function(e) {
								if ( ! $inner.is( e.target ) && $inner.has( e.target ).length === 0 ) {
									$menu.slideUp( triggerSpeed );
								}
							} );
						}
					} );
				} ); // Document ready.				
			},
		} );
		elementorFrontend.elementsHandler.attachHandler( "wpmozo_ae_dropdown_button", WPMOZODropdownButton );
	} );
} )( jQuery );
