PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 3.0.12
Responsive Menu – Create Mobile-Friendly Menu v3.0.12
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 / src / app / Mappers / JsMapper.php

JsMapper.php in Responsive Menu – Create Mobile-Friendly Menu 3.0.12, at src/app/Mappers/JsMapper.php

193 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ResponsiveMenu\Mappers;
4 use ResponsiveMenu\Collections\OptionsCollection;
5
6 class JsMapper {
7
8 public function map(OptionsCollection $options) {
9
10 $animation_speed = $options['animation_speed'] ? $options['animation_speed']->getValue() * 1000 : 500;
11
12 $js = <<<JS
13
14 jQuery(document).ready(function($) {
15
16 var ResponsiveMenu = {
17 trigger: '{$options['button_click_trigger']}',
18 animationSpeed: {$animation_speed},
19 breakpoint: {$options['breakpoint']},
20 pushButton: '{$options['button_push_with_animation']}',
21 animationType: '{$options['animation_type']}',
22 animationSide: '{$options['menu_appear_from']}',
23 pageWrapper: '{$options['page_wrapper']}',
24 isOpen: false,
25 triggerTypes: 'click',
26 activeClass: 'is-active',
27 container: '#responsive-menu-container',
28 openClass: 'responsive-menu-open',
29 accordion: '{$options['accordion_animation']}',
30 activeArrow: '{$options->getActiveArrow()}',
31 inactiveArrow: '{$options->getInActiveArrow()}',
32 wrapper: '#responsive-menu-wrapper',
33 closeOnBodyClick: '{$options['menu_close_on_body_click']}',
34 closeOnLinkClick: '{$options['menu_close_on_link_click']}',
35 itemTriggerSubMenu: '{$options['menu_item_click_to_trigger_submenu']}',
36 linkElement: '.responsive-menu-item-link',
37 openMenu: function() {
38 $(this.trigger).addClass(this.activeClass);
39 $('html').addClass(this.openClass);
40 $('.responsive-menu-button-icon-active').hide();
41 $('.responsive-menu-button-icon-inactive').show();
42 this.setWrapperTranslate();
43 this.isOpen = true;
44 },
45 closeMenu: function() {
46 $(this.trigger).removeClass(this.activeClass);
47 $('html').removeClass(this.openClass);
48 $('.responsive-menu-button-icon-inactive').hide();
49 $('.responsive-menu-button-icon-active').show();
50 this.clearWrapperTranslate();
51 this.isOpen = false;
52 },
53 triggerMenu: function() {
54 this.isOpen ? this.closeMenu() : this.openMenu();
55 },
56 triggerSubArrow: function(subarrow) {
57 var sub_menu = $(subarrow).parent().next('.responsive-menu-submenu');
58 var self = this;
59 if(this.accordion == 'on') {
60 /* Get Top Most Parent and the siblings */
61 var top_siblings = sub_menu.parents('.responsive-menu-item-has-children').last().siblings('.responsive-menu-item-has-children');
62 var first_siblings = sub_menu.parents('.responsive-menu-item-has-children').first().siblings('.responsive-menu-item-has-children');
63 /* Close up just the top level parents to key the rest as it was */
64 top_siblings.children('.responsive-menu-submenu').slideUp(200, 'linear').removeClass('responsive-menu-submenu-open');
65 /* Set each parent arrow to inactive */
66 top_siblings.each(function() {
67 $(this).find('.responsive-menu-subarrow').first().html(self.inactiveArrow);
68 });
69 /* Now Repeat for the current item siblings */
70 first_siblings.children('.responsive-menu-submenu').slideUp(200, 'linear').removeClass('responsive-menu-submenu-open');
71 first_siblings.each(function() {
72 $(this).find('.responsive-menu-subarrow').first().html(self.inactiveArrow);
73 });
74 }
75 if(sub_menu.hasClass('responsive-menu-submenu-open')) {
76 sub_menu.slideUp(200, 'linear').removeClass('responsive-menu-submenu-open');
77 $(subarrow).html(this.inactiveArrow);
78 } else {
79 sub_menu.slideDown(200, 'linear').addClass('responsive-menu-submenu-open');
80 $(subarrow).html(this.activeArrow);
81 }
82 },
83 menuHeight: function() {
84 return $(this.container).height();
85 },
86 menuWidth: function() {
87 return $(this.container).width();
88 },
89 wrapperHeight: function() {
90 return $(this.wrapper).height();
91 },
92 setWrapperTranslate: function() {
93 switch(this.animationSide) {
94 case 'left':
95 translate = 'translateX(' + this.menuWidth() + 'px)'; break;
96 case 'right':
97 translate = 'translateX(-' + this.menuWidth() + 'px)'; break;
98 case 'top':
99 translate = 'translateY(' + this.wrapperHeight() + 'px)'; break;
100 case 'bottom':
101 translate = 'translateY(-' + this.menuHeight() + 'px)'; break;
102 }
103 if(this.animationType == 'push') {
104 $(this.pageWrapper).css({'transform':translate});
105 $('html, body').css('overflow-x', 'hidden');
106 }
107 if(this.pushButton == 'on') {
108 $('#responsive-menu-button').css({'transform':translate});
109 }
110 },
111 clearWrapperTranslate: function() {
112 self = this;
113 if(this.animationType == 'push') {
114 $(this.pageWrapper).css({'transform':''});
115 setTimeout(function() {
116 $('html, body').css('overflow-x', '');
117 }, self.animationSpeed);
118 }
119 if(this.pushButton == 'on') {
120 $('#responsive-menu-button').css({'transform':''});
121 }
122 },
123 init: function() {
124 var self = this;
125 $(this.trigger).on(this.triggerTypes, function(e){
126 e.stopPropagation();
127 self.triggerMenu();
128 });
129 $('.responsive-menu-subarrow').on('click', function(e) {
130 e.preventDefault();
131 e.stopPropagation();
132 self.triggerSubArrow(this);
133 });
134 $(window).resize(function() {
135 if($(window).width() > self.breakpoint) {
136 if(self.isOpen){
137 self.closeMenu();
138 }
139 } else {
140 if($('.responsive-menu-open').length>0){
141 self.setWrapperTranslate();
142 }
143 }
144 });
145 if(this.closeOnLinkClick == 'on') {
146 $(this.linkElement).on('click', function(e) {
147 e.preventDefault();
148 /* Fix for when close menu on parent clicks is on */
149 if(self.itemTriggerSubMenu == 'on' && $(this).is('.responsive-menu-item-has-children > ' + self.linkElement)) {
150 return;
151 }
152 old_href = $(this).attr('href');
153 old_target = typeof $(this).attr('target') == 'undefined' ? '_self' : $(this).attr('target');
154 if(self.isOpen) {
155 if($(e.target).closest('.responsive-menu-subarrow').length) {
156 return;
157 }
158 self.closeMenu();
159 setTimeout(function() {
160 window.open(old_href, old_target);
161 }, self.animationSpeed);
162 }
163 });
164 }
165 if(this.closeOnBodyClick == 'on') {
166 $(document).on('click', 'body', function(e) {
167 if(self.isOpen) {
168 if($(e.target).closest('#responsive-menu-container').length || $(e.target).closest('#responsive-menu-button').length) {
169 return;
170 }
171 }
172 self.closeMenu();
173 });
174 }
175 if(this.itemTriggerSubMenu == 'on') {
176 $('.responsive-menu-item-has-children > ' + this.linkElement).on('click', function(e) {
177 e.preventDefault();
178 self.triggerSubArrow($(this).children('.responsive-menu-subarrow').first());
179 });
180 }
181 }
182 };
183 ResponsiveMenu.init();
184 });
185
186 JS;
187
188 return $js;
189
190 }
191
192 }
193