/**
 * Custom JavaScript
 *
 * @package Rosea
 *
 * This file is part of the Rosea WordPress theme.
 *
 * Rosea WordPress Theme, Copyright 2026 nopStation
 * Rosea is distributed under the terms of the GNU General Public License v2 or later.
 *
 * @license GPL-2.0-or-later
 * @license URI: https://www.gnu.org/licenses/gpl-2.0.html
 */

(function($) {
	'use strict';

	$(document).ready(function() {
		
		// Scroll to top
		$(window).scroll(function () {
			if ($(this).scrollTop() > 100) {
				$('.scrollup').fadeIn();
			} else {
				$('.scrollup').fadeOut();
			}
		});
		
		$('.scrollup').click(function () {
			$("html, body").animate({scrollTop: 0}, 1000);
			return false;
		});
		
		// Dropdown menu
		$('.dropdown').on('mouseover', function() {
			var drop_item = $(this).children('.dropdown-menu');
			drop_item.show();
		});
		
		$('.dropdown').on('mouseleave', function() {
			var drop_item = $(this).children('.dropdown-menu');
			drop_item.hide();
		});
		
		// Mobile Menu Toggle
		// Open mobile menu
		$('#sidebarCollapse').on('click', function (e) {
			e.preventDefault();
			$('#sidebar').addClass('active');
			$('.overlay').addClass('active');
			$('body').css('overflow', 'hidden');
			$(this).attr('aria-expanded', 'true');
		});

		// Close mobile menu
		$('#dismiss, .overlay').on('click', function (e) {
			e.preventDefault();
			$('#sidebar').removeClass('active');
			$('.overlay').removeClass('active');
			$('body').css('overflow', '');
			$('#sidebarCollapse').attr('aria-expanded', 'false');
		});
		
		// Mobile Menu Submenu Toggle (supports nested submenus)
		$('#sidebar .menu-item-has-children > a').on('click', function(e) {
			e.preventDefault();
			var $parent = $(this).parent();
			$parent.toggleClass('active');
			// Close sibling submenus when opening a new one
			$parent.siblings('.menu-item-has-children').removeClass('active');
		});
		
	});

})(jQuery);









