PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 3.1.6
Responsive Menu – Create Mobile-Friendly Menu v3.1.6
4.7.3 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 All 90 releases
responsive-menu / app / Walkers / Walker.php

Walker.php in Responsive Menu – Create Mobile-Friendly Menu 3.1.6, at app/Walkers/Walker.php

134 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ResponsiveMenu\Walkers;
4 use ResponsiveMenu\Collections\OptionsCollection;
5
6 class Walker extends \Walker_Nav_Menu {
7
8 private $current_item;
9
10 public function __construct(OptionsCollection $options) {
11 $this->options = $options;
12 }
13
14 public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
15
16 $this->setCurrentItem($item);
17
18 $classes = empty($item->classes) ? array() : (array) $item->classes;
19 $responsive_menu_classes = $classes;
20
21 # Turn into our Responsive Menu Classes
22 foreach($classes as $class):
23 switch($class):
24 case 'menu-item': $responsive_menu_classes[] = 'responsive-menu-item'; break;
25 case 'current-menu-item': $responsive_menu_classes[] = 'responsive-menu-current-item'; break;
26 case 'menu-item-has-children': $responsive_menu_classes[] = 'responsive-menu-item-has-children'; break;
27 case 'current-menu-parent': $responsive_menu_classes[] = 'responsive-menu-item-current-parent'; break;
28 case 'current-menu-ancestor': $responsive_menu_classes[] = 'responsive-menu-item-current-ancestor'; break;
29 endswitch;
30 endforeach;
31
32 /* Clear child class if we are at the final depth level */
33 if(isset($responsive_menu_classes)):
34 if($depth + 1 == $this->options['menu_depth'] && ($key = array_search('responsive-menu-item-has-children', $responsive_menu_classes)) !== false) {
35 unset($responsive_menu_classes[$key]);
36 }
37 endif;
38
39 $class_names = join(' ', array_unique($responsive_menu_classes));
40 $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
41
42 $id = ' id="responsive-menu-item-' . esc_attr( $item->ID ) . '"';
43
44 $output .= '<li' . $id . $class_names .'>';
45
46 $atts = array();
47 $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
48 $atts['target'] = ! empty( $item->target ) ? $item->target : '';
49 $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
50 $atts['href'] = ! empty( $item->url ) ? $item->url : '';
51 $atts['class'] = 'responsive-menu-item-link';
52
53 $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth);
54
55 $attributes = '';
56 foreach ($atts as $attr => $value) {
57 if (!empty( $value)) {
58 $value = ('href' === $attr ) ? esc_url( $value) : esc_attr($value);
59 $attributes .= ' ' . $attr . '="' . $value . '"';
60 }
61 }
62
63 $title = apply_filters('the_title', $item->title, $item->ID);
64 $title = apply_filters('nav_menu_item_title', $title, $item, $args, $depth);
65
66 /* Calculate which arrow to show */
67 if(in_array('responsive-menu-item-has-children', $responsive_menu_classes)):
68 $inactive_arrow = '<div class="responsive-menu-subarrow">' . $this->options->getInActiveArrow() . '</div>';
69 $active_arrow = '<div class="responsive-menu-subarrow responsive-menu-subarrow-active">' . $this->options->getActiveArrow() . '</div>';
70 if($this->options['auto_expand_all_submenus'] == 'on'):
71 $initial_arrow = $active_arrow;
72 elseif(
73 $this->options['auto_expand_current_submenus'] == 'on' && (in_array('responsive-menu-item-current-parent', $responsive_menu_classes)
74 || in_array('responsive-menu-item-current-ancestor', $responsive_menu_classes))):
75 $initial_arrow = $active_arrow;
76 else:
77 $initial_arrow = $inactive_arrow;
78 endif;
79 else:
80 $initial_arrow = '';
81 endif;
82
83 /* Clear Arrow if we are at the final depth level */
84 if($depth + 1 == $this->options['menu_depth'])
85 $initial_arrow = '';
86
87 $item_output = '<a'. $attributes .'>';
88 $item_output .= $title;
89 $item_output .= $initial_arrow;
90
91 if(isset($item->description) && $item->description && $this->options['submenu_descriptions_on'])
92 $item_output .= '<span class="responsive-menu-item-description">' . $item->description . '</span>';
93
94 $item_output .= '</a>';
95
96 $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
97
98 }
99
100 public function start_lvl(&$output, $depth = 0, $args = array()) {
101 $output .= "<ul class='responsive-menu-submenu responsive-menu-submenu-depth-" . ($depth + 1) . $this->getSubmenuClassOpenOrNot() . "'>";
102 }
103
104 public function end_el(&$output, $item, $depth = 0, $args = array()) {
105 $output .= "</li>";
106 }
107
108 public function end_lvl(&$output, $depth = 0, $args = array()) {
109 $output .= "</ul>";
110 }
111
112 public function setCurrentItem($item) {
113 $this->current_item = $item;
114 }
115
116 public function getCurrentItem() {
117 return $this->current_item;
118 }
119
120 public function getSubmenuClassOpenOrNot() {
121 return $this->expandAllSubmenuOptionsIsOn() || $this->expandCurrentSubmenuOnAndItemIsParent() ? ' responsive-menu-submenu-open' : '';
122 }
123
124 public function expandAllSubmenuOptionsIsOn() {
125 return $this->options['auto_expand_all_submenus'] == 'on';
126 }
127
128 public function expandCurrentSubmenuOnAndItemIsParent() {
129 return ($this->options['auto_expand_current_submenus'] == 'on')
130 && ($this->getCurrentItem()->current_item_ancestor || $this->getCurrentItem()->current_item_parent);
131 }
132
133 }
134