
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php
/* -----------------------------------------------------------------------------
 * Mega Menu Walker
 * -------------------------------------------------------------------------- */
if ( ! class_exists( 'Presso_Mega_Menu_Waker', false ) ) {
	class Presso_Mega_Menu_Waker extends Walker_Nav_Menu {
		public $no_need_wrapper = array( 'default', 'columns_list' );
		public $enable_mega_menu = true;

		function __construct( $enable_mega_menu = true ) {
			$this->enable_mega_menu = $enable_mega_menu;
			add_filter( 'walker_nav_menu_start_el', array( $this, 'action_start_el' ), 10, 4 );
		}

		function action_start_el( $item_output, $item, $depth, $args ) {
			if ( $args->walker == $this ) {
				if ( ( $depth == 0 && ! in_array( $item->vw_menu_type, $this->no_need_wrapper ) ) || in_array( 'menu-item-has-children', $item->classes ) ) {
					$item_output .= '<div class="sub-menu-wrapper">';
				}
			}

			return $item_output;
		}

		function end_el( &$output, $item, $depth = 0, $args = array(), $current_object_id = 0 ) {

			if ( $this->enable_mega_menu && $depth == 0 ) {
				global $post;

				/* Add mega menu */
				ob_start();
				do_action( 'presso_action_mega_menu_render__'.$item->vw_menu_type, $item, $depth, $args, $current_object_id );
				$output .= ob_get_clean();
			}

			if ( ( $depth == 0 && ! in_array( $item->vw_menu_type, $this->no_need_wrapper ) ) || in_array( 'menu-item-has-children', $item->classes ) ) {
				$output .= "</div>\n"; // .vw-sub-menu-wrapper
			}
			
			$output .= "</li>\n";
		}
	}
}





/*//////////////////////////////////////
// Extra Class / Attribute
//////////////////////////////////////*/

add_filter( 'nav_menu_item_args', 'presso_default_menu_item_args', 10, 3 );
if ( ! function_exists( 'presso_default_menu_item_args' ) ) {
	function presso_default_menu_item_args( $args, $item, $depth ) {
		if ( ! isset( $item->vw_menu_type ) ) {
			$item->vw_menu_type = 'default';
		}

		return $args;
	}
}

add_filter( 'nav_menu_css_class', 'presso_add_menu_item_extra_class', 10, 4 );
if ( ! function_exists( 'presso_add_menu_item_extra_class' ) ) {
	function presso_add_menu_item_extra_class( $classes, $item, $args, $depth ) {
		$classes[] = 'menu-item-depth-' . $depth;
		$classes[] = ( $depth == 0 ? 'main-menu-item' : 'sub-menu-item' );

		return $classes;
	}
}

add_filter( 'nav_menu_css_class', 'presso_add_menu_icon', 99, 4 );
if ( ! function_exists( 'presso_add_menu_icon' ) ) {
	function presso_add_menu_icon( $classes, $item, $args, $depth ) {
		if ( $depth == 0 ) {
			$classes[] = 'vw-mega-item';
			$classes[] = 'vw-mega-item--'.str_replace( '_', '-', $item->vw_menu_type );
		}

		foreach ( $classes as $i => $class ) {
			if ( false !== strpos( $class, 'icon-' ) ) {
				$item->title = sprintf( '<i class="vw-icon %s"></i>', esc_attr( $class ) ) . $item->title;
				$classes[$i] = '';
			}
		}

		return $classes;
	}
}

add_filter( 'nav_menu_link_attributes', 'presso_add_menu_link_extra_attribute', 10, 4 );
if ( ! function_exists( 'presso_add_menu_link_extra_attribute' ) ) {
	function presso_add_menu_link_extra_attribute( $atts, $item, $args, $depth ) {
		$classes = ' menu-link ' . ( $depth > 0 ? 'sub-menu-link' : 'main-menu-link' );

		if ( isset( $atts[ 'class' ] ) ) {
			$atts[ 'class' ] .= $classes;
		} else {
			$atts[ 'class' ] = $classes;
		}

		return $atts;
	}
}

add_filter( 'walker_nav_menu_start_el', 'presso_add_menu_description', 10, 4 );
if ( ! function_exists( 'presso_add_menu_description' ) ) {
	function presso_add_menu_description( $item_output, $item, $depth, $args ) {
		if ( $depth > 0 ) {
			if ( ! empty( $item->description ) ) {
				$menu_description = '<span class="menu-description">'.$item->description.'</span>';

				$item_output = str_replace( $args->link_after, $menu_description.$args->link_after, $item_output );
			}
		}

		return $item_output;
	}
}