PluginProbe ʕ •ᴥ•ʔ
My Sticky Bar – Floating Notification Bar & Sticky Header (formerly myStickymenu) / 2.6.6
My Sticky Bar – Floating Notification Bar & Sticky Header (formerly myStickymenu) v2.6.6
2.9.1 2.9.0 2.8.9 2.8.8 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 2.0 2.0.1 2.0.3 2.0.4 2.0.5 2.0.6 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7
mystickymenu / js / mystickymenu.js
mystickymenu / js Last commit date
morphext 3 years ago detectmobilebrowser.js 3 years ago iris-script.js 3 years ago jquery.star-rating-svg.min.js 3 years ago mystickymenu-admin.js 2 years ago mystickymenu.js 3 years ago mystickymenu.min.js 5 years ago select2.min.js 3 years ago slick.min.js 3 years ago welcomebar-front.js 2 years ago
mystickymenu.js
423 lines
1 /*!
2 * myStickymenu by m.r.d.a
3 * v2.0.4
4 */
5 (function( $ ) {
6 "use strict";
7
8 $(document).ready(function($){
9
10 if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) && option.device_mobile != 1) {
11 return false;
12 } else if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) != true && option.device_desktop != 1 ) {
13 return false;
14 }
15
16 // get Sticky Class setting if class name existts
17 if ($(option.mystickyClass) [0]){
18 // Do nothing
19 } else {
20 // Do something if class does not exist and stop
21 console.log("myStickymenu: Entered Sticky Class does not exist, change it in Dashboard / Settings / myStickymenu / Sticky Class. ");
22 return;
23 }
24
25
26 // Get class name
27 var mystickyClass = document.querySelector(option.mystickyClass);
28
29 // get disable at small screen size setting
30 var disableWidth = parseInt(option.disableWidth);
31
32 // get disable at large screen size setting
33 var disableLargeWidth = parseInt(option.disableLargeWidth);
34
35 // get transition effect (slide or fade)
36 var mystickyTransition = option.mystickyTransition;
37
38 // get activaton height setting
39 var activationHeight = parseInt(option.activationHeight);
40
41 // if is admin bar showing, needed for auto calc of activation height when admin bar is showing
42 var adminBar = option.adminBar;
43
44 // disable on scroll down
45 var mysticky_disable_down = option.mysticky_disable_down;
46
47 var viewportWidth;
48
49 function calcViewportWidth(e){
50
51 // Calculate actual viewport width
52 var e = window, a = 'inner';
53
54 if (!('innerWidth' in window )) {
55 a = 'client';
56 e = document.documentElement || document.body;
57 }
58 viewportWidth = e[ a+'Width' ];
59
60 }
61
62 calcViewportWidth();
63
64 var parentmysticky = mystickyClass.parentNode;
65
66 var wrappermysticky = document.createElement('div');
67 var position = 0;
68 for(var i = 0; i < parentmysticky.childNodes.length; i++) {
69 if(parentmysticky.childNodes[i] == mystickyClass) {
70 position = i;
71 break;
72 }
73 }
74
75 wrappermysticky.id = 'mysticky-wrap';
76 wrappermysticky.appendChild(mystickyClass);
77 parentmysticky.insertBefore(wrappermysticky, parentmysticky.childNodes[position]);
78
79 var parentnav = mystickyClass.parentNode;
80 var wrappernav = document.createElement('div');
81 wrappernav.id = 'mysticky-nav';
82 parentnav.replaceChild(wrappernav, mystickyClass);
83 wrappernav.appendChild(mystickyClass);
84
85 // get activation height from settings
86 if ( activationHeight == "0" ) {
87 var autoActivate = true;
88 }
89
90 var mydivHeight;
91
92
93 function initialDivHeight(){
94
95 // get initial element height of selected sticky class
96 mydivHeight = (mystickyClass.offsetHeight);
97
98 // when initial element have margin bottom - awaken example using #masthead class
99 if (parseInt($(mystickyClass).css("marginBottom")) > 0) {
100
101 // element have margin bottom, apply it to initial wrap
102 //$(mystickyClass).css("marginBottom").replace('px', '')
103 wrappermysticky.style.marginBottom = ($(mystickyClass).css("marginBottom"));
104 }
105
106 if (mydivHeight == "0") {
107 // something is wrong, wrapper cant be zero, if so content will jump while scroll. Awaken theme (for example) with .awaken-navigation-container class selected will use this part. Calculate height based on element children height
108
109 $(mystickyClass).children().filter(':visible').each(function(){
110 mydivHeight = $(this).outerHeight(true);
111
112 });
113
114 }
115
116 if (viewportWidth >= disableWidth) {
117 //wrappermysticky.style.height = mydivHeight + 'px';
118 }
119 }
120
121 initialDivHeight();
122
123 var myfixedHeight;
124
125 function fixedDivHeight(){
126 //if ( autoActivate == true ) {
127
128 // calculate element height while fixed
129 mystickyClass.classList.add('myfixed')
130
131 myfixedHeight = $(".myfixed").outerHeight();
132 if (myfixedHeight == "0") {
133 // something is wrong, wrapper cant be zero, try to calculate again with div children.
134 $(".myfixed").children().filter(':visible').each(function(){
135 myfixedHeight = $(this).outerHeight(true);
136 });
137 }
138
139 mystickyClass.classList.remove('myfixed');
140
141 }
142
143 fixedDivHeight();
144
145 var adminBarHeight = 0;
146
147 function calcAdminBarHeight(){
148
149 if ((adminBar == "true" ) && (viewportWidth > 600)) {
150
151 if ($("#wpadminbar")[0]){
152 adminBarHeight = $('#wpadminbar').height();
153 } else {
154 adminBarHeight = 0;
155 }
156 } else {
157 adminBarHeight = 0;
158 }
159
160
161 //wrappernav.style.top = adminBarHeight + "px";
162 if (mystickyTransition == "slide") {
163 wrappernav.style.top = "-" + myfixedHeight + "px";
164 //wrappernav.style.top = "-" + myfixedHeight + "px";
165 } else {
166 wrappernav.style.top = adminBarHeight + "px";
167 }
168
169 }
170
171 calcAdminBarHeight();
172
173
174 var mydivWidth;
175
176 function initialDivWidth(){
177 var rect = $(mystickyClass)[0].getBoundingClientRect();
178 mydivWidth = rect.width;
179 }
180
181 initialDivWidth();
182
183 var deactivationHeight = activationHeight;
184
185 function calcActivationHeight() {
186
187 // If activate height (Make visible on Scroll) is set to 0, automatic calculation will be used.
188 if ( autoActivate == true ) {
189
190 // Automatic calculation of activation and deactivation height (Make visible on Scroll is set to 0).
191 if (mystickyTransition == "slide") {
192 // Slide effect is selected
193 //activationHeight = $(mystickyClass).offset().top + mystickyClass.offsetHeight - adminBarHeight;
194 activationHeight = $(mystickyClass).offset().top + mydivHeight - adminBarHeight;
195 deactivationHeight = $(mystickyClass).offset().top + mydivHeight - adminBarHeight;
196 //deactivationHeight = $(mystickyClass).offset().top - adminBarHeight;
197
198 if (mysticky_disable_down == "on") {
199 deactivationHeight = $(mystickyClass).offset().top - adminBarHeight;
200 }
201 }
202
203 if (mystickyTransition == "fade") {
204 // Fade effect is selected
205 if (mysticky_disable_down == "false") {
206 activationHeight = $(mystickyClass).offset().top - adminBarHeight;
207 deactivationHeight = $(mystickyClass).offset().top - adminBarHeight;
208 }
209
210 if (mysticky_disable_down == "on") {
211 // Fade effect is selected
212 activationHeight = $(mystickyClass).offset().top - adminBarHeight + mydivHeight;
213 deactivationHeight = $(mystickyClass).offset().top - adminBarHeight;
214 }
215
216 }
217
218 }
219
220 }
221
222 calcActivationHeight();
223
224 function headerDeactivateOnHeight() {
225
226 if ( autoActivate == true ) {
227
228 if ( mydivHeight > myfixedHeight ){
229 // Auto activate is true, Make visible on Scroll is set to 0, menu is probably header
230
231 if (mystickyTransition == "slide") {
232 // slide effect is selected
233 deactivationHeight = activationHeight;
234
235 if (mysticky_disable_down == "on") {
236 deactivationHeight = activationHeight - myfixedHeight;
237 }
238
239 } else {
240 activationHeight = mydivHeight;
241 deactivationHeight = mydivHeight;
242
243 }
244 }
245 }
246 }
247
248 headerDeactivateOnHeight();
249
250
251
252 var hasScrollY = 'scrollY' in window;
253 var lastScrollTop = 0;
254
255 function onScroll(e) {
256 var mystickymenu_top_pos = $( '.mysticky-welcomebar-fixed' ).css( 'top' );
257 var welcombar_position = $( '.mysticky-welcomebar-fixed' ).data('position');
258 var welcombar_height = $( '.mysticky-welcomebar-fixed' ).outerHeight();
259 var mystickymenu_show = $( '.mysticky-welcomebar-fixed' ).length;
260 var welcomebar_appear = $( 'body' ).hasClass( 'mysticky-welcomebar-apper' );
261 if( mystickymenu_show && parseInt(mystickymenu_top_pos) >= 0 && welcombar_position == 'top' && welcomebar_appear ) {
262 var mystickymenu_pos = welcombar_height;
263 adminBarHeight = 0;
264 } else {
265 var mystickymenu_pos = '';
266 }
267 //initialDivHeight();
268
269 // if body width is larger than disable at small screen size setting
270
271 if (viewportWidth >= disableWidth) {
272
273 if ( disableLargeWidth == 0 || viewportWidth <= disableLargeWidth ) {
274
275 //if (mysticky_disable_down == "on") {
276
277 var y = hasScrollY ? window.scrollY : document.documentElement.scrollTop;
278 //var yScrollPosition = $(this).scrollTop();
279 /*30-04-2020 st*/
280 if( document.documentElement.scrollTop == 0 ) {
281 wrappernav.classList.remove('wrapfixed');
282 }
283 /*30-04-2020 end*/
284
285 // add up or down class to the element depending on scroll direction
286 if (0 <= y ) {
287 //var st = $(this).scrollTop();
288 if (y >= lastScrollTop){
289
290 // downscroll code
291 // add myfixed and wrapfixed class to selected fixed element while scroll down
292 y >= activationHeight ? mystickyClass.classList.add('myfixed') : "";
293 y >= activationHeight ? wrappernav.classList.add('wrapfixed') : "";
294
295 y >= activationHeight ? wrappermysticky.style.height = mydivHeight + 'px' : "";
296 y >= activationHeight ? mystickyClass.style.width = mydivWidth + "px" : "";
297
298
299 if (mystickyTransition == "slide") {
300
301 if (mysticky_disable_down == "false") {
302 //y < activationHeight + (myfixedHeight + 250) - adminBarHeight ? wrappernav.style.top = "-" + myfixedHeight + "px" : '';
303 //wrappernav.style.top = "-" + myfixedHeight + "px"
304 y >= activationHeight + myfixedHeight - adminBarHeight ? wrappernav.style.top = (adminBarHeight + mystickymenu_pos) + "px" : wrappernav.style.top = "-" + myfixedHeight + "px";
305
306 }
307
308 if ( mydivHeight > myfixedHeight ){
309 // if it's header (guess)
310
311 if (mysticky_disable_down == "false") {
312
313 y < activationHeight + myfixedHeight ? wrappernav.style.top = "-" + mydivHeight + "px" : '';
314 y >= activationHeight + myfixedHeight ? wrappernav.style.top = (adminBarHeight + mystickymenu_pos) + "px" : '';
315
316 }
317
318 }
319
320 }
321
322 wrappernav.classList.add('down');
323 wrappernav.classList.remove('up');
324
325
326 if (mysticky_disable_down == "on") {
327 wrappernav.style.top = "-" + (mydivHeight + adminBarHeight ) + "px";
328 jQuery('#mysticky-nav ' + option.mystickyClass+'.elementor-sticky').hide();
329 //jQuery('#mysticky-nav ' + option.mystickyClass).css( 'top' , "-" + (mydivHeight + adminBarHeight ) + "px");
330 }
331
332 } else {
333 // upscroll code
334 var x = hasScrollY ? window.scrollY : document.documentElement.scrollTop;
335 //x > deactivationHeight ? '' : mystickyClass.classList.remove('myfixed') ;
336 //x > deactivationHeight ? '' : wrappernav.classList.remove('wrapfixed');
337
338 x > deactivationHeight ? "" : wrappermysticky.style.height = "";
339 x > deactivationHeight ? "" : mystickyClass.style.width = "";
340
341 if (mystickyTransition == "slide") {
342
343 x > deactivationHeight ? '' : mystickyClass.classList.remove('myfixed') ;
344 x > deactivationHeight ? '' : wrappernav.classList.remove('wrapfixed');
345
346 if (mysticky_disable_down == "false") {
347
348 x < deactivationHeight + myfixedHeight + 200 - adminBarHeight ? wrappernav.style.top = "-" + myfixedHeight + "px" : '';
349 }
350
351 } else {
352 x > deactivationHeight ? "" : mystickyClass.classList.remove('myfixed') ;
353 x > deactivationHeight ? "" : wrappernav.classList.remove('wrapfixed');
354 }
355 wrappernav.classList.remove('down');
356 wrappernav.classList.add('up');
357
358 if (mysticky_disable_down == "on") {
359 wrappernav.style.top = (adminBarHeight + mystickymenu_pos) + "px";
360 jQuery('#mysticky-nav '+ option.mystickyClass).css( 'width' , mydivWidth + "px");
361 jQuery('#mysticky-nav ' + option.mystickyClass+'.elementor-sticky').show();
362
363 }
364
365 }
366
367 lastScrollTop = y;
368
369 } else {
370 //if (mysticky_disable_down == "on") {
371 wrappernav.classList.remove('up');
372 //}
373 }
374
375 } // if disableWidth is greater than zero
376
377
378 } // if disableLargeWidth is 0 or greater than zero
379
380 }
381
382 document.addEventListener('scroll', onScroll);
383
384
385 var width = $(window).width()
386
387 function OnResizeDocument () {
388 // don't recalculate on height change, only width
389 if($(window).width() != width ){
390
391 wrappernav.classList.remove('up');
392 wrappernav.classList.remove('down');
393
394 if ($(".wrapfixed")[0]){
395 // If class wrapfixed exists
396 // Remove myfixed and wrapfixed clases so we can calculate
397 //mystickyClass.classList.remove('myfixed');
398 //wrappernav.classList.remove('wrapfixed');
399
400 } else {
401 // Else class wrapfixed does not exists
402 initialDivHeight();
403
404 // Remove width
405 mystickyClass.style.removeProperty("width");
406 initialDivWidth();
407
408 }
409 calcViewportWidth();
410 calcAdminBarHeight();
411 fixedDivHeight();
412 calcActivationHeight();
413 headerDeactivateOnHeight();
414 }
415 }
416
417 window.addEventListener('resize', OnResizeDocument);
418
419 // need to test this, it should fire script on mobile orientation change, since onresize is somehow faulty in this case
420 window.addEventListener('orientationchange', OnResizeDocument);
421 });
422
423 })(jQuery);