PluginProbe ʕ •ᴥ•ʔ
My Sticky Bar – Floating Notification Bar & Sticky Header (formerly myStickymenu) / 2.4.3
My Sticky Bar – Floating Notification Bar & Sticky Header (formerly myStickymenu) v2.4.3
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
detectmobilebrowser.js 7 years ago iris-script.js 6 years ago mystickymenu-admin.js 6 years ago mystickymenu.js 6 years ago mystickymenu.min.js 6 years ago select2.min.js 6 years ago
mystickymenu.js
446 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 ( jQuery.browser.mobile && !option.device_mobile) {
11 return false;
12 } else if ( !jQuery.browser.mobile && !option.device_desktop) {
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
133 if (myfixedHeight == "0") {
134 // something is wrong, wrapper cant be zero, try to calculate again with div children.
135 $(".myfixed").children().filter(':visible').each(function(){
136 myfixedHeight = $(this).outerHeight(true);
137 });
138 }
139
140 mystickyClass.classList.remove('myfixed');
141
142 //}
143
144 }
145
146 fixedDivHeight();
147
148 var adminBarHeight = 0;
149
150 function calcAdminBarHeight(){
151
152 if ((adminBar == "true" ) && (viewportWidth > 600)) {
153
154 if ($("#wpadminbar")[0]){
155 adminBarHeight = $('#wpadminbar').height();
156 } else {
157 adminBarHeight = 0;
158 }
159 } else {
160 adminBarHeight = 0;
161 }
162
163
164 //wrappernav.style.top = adminBarHeight + "px";
165 if (mystickyTransition == "slide") {
166 wrappernav.style.top = "-" + myfixedHeight + "px";
167 //wrappernav.style.top = "-" + myfixedHeight + "px";
168 } else {
169 wrappernav.style.top = adminBarHeight + "px";
170 }
171
172 }
173
174 calcAdminBarHeight();
175
176
177 var mydivWidth;
178
179 function initialDivWidth(){
180
181 var rect = $(mystickyClass)[0].getBoundingClientRect();
182 mydivWidth = rect.width;
183
184 //var mydivWidth = ((mystickyClass.offsetWidth) + 'px');
185 //mystickyClass.style.width = mydivWidth + "px";
186
187 }
188
189 initialDivWidth();
190
191
192
193
194 var deactivationHeight = activationHeight;
195
196 function calcActivationHeight() {
197
198 // If activate height (Make visible on Scroll) is set to 0, automatic calculation will be used.
199 if ( autoActivate == true ) {
200
201 // Automatic calculation of activation and deactivation height (Make visible on Scroll is set to 0).
202 if (mystickyTransition == "slide") {
203 // Slide effect is selected
204 //activationHeight = $(mystickyClass).offset().top + mystickyClass.offsetHeight - adminBarHeight;
205 activationHeight = $(mystickyClass).offset().top + mydivHeight - adminBarHeight;
206 deactivationHeight = $(mystickyClass).offset().top + mydivHeight - adminBarHeight;
207 //deactivationHeight = $(mystickyClass).offset().top - adminBarHeight;
208
209 if (mysticky_disable_down == "on") {
210 deactivationHeight = $(mystickyClass).offset().top - adminBarHeight;
211
212 }
213
214 }
215
216 if (mystickyTransition == "fade") {
217
218 if (mysticky_disable_down == "false") {
219 // Fade effect is selected
220 activationHeight = $(mystickyClass).offset().top - adminBarHeight;
221
222 deactivationHeight = $(mystickyClass).offset().top - adminBarHeight;
223
224 }
225
226 if (mysticky_disable_down == "on") {
227
228 // Fade effect is selected
229 activationHeight = $(mystickyClass).offset().top - adminBarHeight + mydivHeight;
230 deactivationHeight = $(mystickyClass).offset().top - adminBarHeight;
231
232 }
233
234 }
235
236 }
237
238 }
239
240 calcActivationHeight();
241
242 function headerDeactivateOnHeight() {
243
244
245 if ( autoActivate == true ) {
246
247 if ( mydivHeight > myfixedHeight ){
248 // Auto activate is true, Make visible on Scroll is set to 0, menu is probably header
249
250 if (mystickyTransition == "slide") {
251 // slide effect is selected
252 deactivationHeight = activationHeight;
253
254 if (mysticky_disable_down == "on") {
255 deactivationHeight = activationHeight - myfixedHeight;
256 }
257
258 } else {
259 activationHeight = mydivHeight;
260 deactivationHeight = mydivHeight;
261
262 }
263 }
264 }
265 }
266
267 headerDeactivateOnHeight();
268
269
270
271 var hasScrollY = 'scrollY' in window;
272 var lastScrollTop = 0;
273
274
275 function onScroll(e) {
276 var mystickymenu_top_pos = $( '.mysticky-welcomebar-fixed' ).css( 'top' );
277 var welcombar_position = $( '.mysticky-welcomebar-fixed' ).data('position');
278 var welcombar_height = $( '.mysticky-welcomebar-fixed' ).outerHeight();
279 var mystickymenu_show = $( '.mysticky-welcomebar-fixed' ).length;
280 var welcomebar_appear = $( 'body' ).hasClass( 'mysticky-welcomebar-apper' );
281 if( mystickymenu_show && parseInt(mystickymenu_top_pos) >= 0 && welcombar_position == 'top' && welcomebar_appear ) {
282 var mystickymenu_pos = welcombar_height;
283 adminBarHeight = 0;
284 } else {
285 var mystickymenu_pos = '';
286 }
287 //initialDivHeight();
288
289 // if body width is larger than disable at small screen size setting
290
291 if (viewportWidth >= disableWidth) {
292
293 if ( disableLargeWidth == 0 || viewportWidth <= disableLargeWidth ) {
294
295 //if (mysticky_disable_down == "on") {
296
297 var y = hasScrollY ? window.scrollY : document.documentElement.scrollTop;
298 //var yScrollPosition = $(this).scrollTop();
299 /*30-04-2020 st*/
300 if( document.documentElement.scrollTop == 0 ) {
301 wrappernav.classList.remove('wrapfixed');
302 }
303 /*30-04-2020 end*/
304
305 // add up or down class to the element depending on scroll direction
306 if (0 <= y ) {
307
308 //var st = $(this).scrollTop();
309
310
311 if (y >= lastScrollTop){
312
313 // downscroll code
314 // add myfixed and wrapfixed class to selected fixed element while scroll down
315 y >= activationHeight ? mystickyClass.classList.add('myfixed') : "";
316 y >= activationHeight ? wrappernav.classList.add('wrapfixed') : "";
317
318 y >= activationHeight ? wrappermysticky.style.height = mydivHeight + 'px' : "";
319 y >= activationHeight ? mystickyClass.style.width = mydivWidth + "px" : "";
320
321
322 if (mystickyTransition == "slide") {
323
324 if (mysticky_disable_down == "false") {
325 //y < activationHeight + (myfixedHeight + 250) - adminBarHeight ? wrappernav.style.top = "-" + myfixedHeight + "px" : '';
326 //wrappernav.style.top = "-" + myfixedHeight + "px"
327 y >= activationHeight + myfixedHeight - adminBarHeight ? wrappernav.style.top = (adminBarHeight + mystickymenu_pos) + "px" : wrappernav.style.top = "-" + myfixedHeight + "px";
328
329 }
330
331 if ( mydivHeight > myfixedHeight ){
332 // if it's header (guess)
333
334 if (mysticky_disable_down == "false") {
335
336 y < activationHeight + myfixedHeight ? wrappernav.style.top = "-" + mydivHeight + "px" : '';
337 y >= activationHeight + myfixedHeight ? wrappernav.style.top = (adminBarHeight + mystickymenu_pos) + "px" : '';
338
339 }
340
341 }
342
343 }
344
345 wrappernav.classList.add('down');
346 wrappernav.classList.remove('up');
347
348
349 if (mysticky_disable_down == "on") {
350 wrappernav.style.top = "-" + (mydivHeight + adminBarHeight ) + "px";
351 jQuery('#mysticky-nav ' + option.mystickyClass+'.elementor-sticky').hide();
352 //jQuery('#mysticky-nav ' + option.mystickyClass).css( 'top' , "-" + (mydivHeight + adminBarHeight ) + "px");
353 }
354
355 } else {
356 // upscroll code
357 var x = hasScrollY ? window.scrollY : document.documentElement.scrollTop;
358 //x > deactivationHeight ? '' : mystickyClass.classList.remove('myfixed') ;
359 //x > deactivationHeight ? '' : wrappernav.classList.remove('wrapfixed');
360
361 x > deactivationHeight ? "" : wrappermysticky.style.height = "";
362 x > deactivationHeight ? "" : mystickyClass.style.width = "";
363
364 if (mystickyTransition == "slide") {
365
366 x > deactivationHeight ? '' : mystickyClass.classList.remove('myfixed') ;
367 x > deactivationHeight ? '' : wrappernav.classList.remove('wrapfixed');
368
369 if (mysticky_disable_down == "false") {
370
371 x < deactivationHeight + myfixedHeight + 200 - adminBarHeight ? wrappernav.style.top = "-" + myfixedHeight + "px" : '';
372 }
373
374 } else {
375 x > deactivationHeight ? "" : mystickyClass.classList.remove('myfixed') ;
376 x > deactivationHeight ? "" : wrappernav.classList.remove('wrapfixed');
377 }
378 wrappernav.classList.remove('down');
379 wrappernav.classList.add('up');
380
381 if (mysticky_disable_down == "on") {
382 wrappernav.style.top = (adminBarHeight + mystickymenu_pos) + "px";
383 jQuery('#mysticky-nav '+ option.mystickyClass).css( 'width' , mydivWidth + "px");
384 jQuery('#mysticky-nav ' + option.mystickyClass+'.elementor-sticky').show();
385
386 }
387
388 }
389
390 lastScrollTop = y;
391
392 } else {
393 //if (mysticky_disable_down == "on") {
394 wrappernav.classList.remove('up');
395 //}
396 }
397
398 } // if disableWidth is greater than zero
399
400
401 } // if disableLargeWidth is 0 or greater than zero
402
403 }
404
405 document.addEventListener('scroll', onScroll);
406
407
408 var width = $(window).width()
409
410 function OnResizeDocument () {
411 // don't recalculate on height change, only width
412 if($(window).width() != width ){
413
414 wrappernav.classList.remove('up');
415 wrappernav.classList.remove('down');
416
417 if ($(".wrapfixed")[0]){
418 // If class wrapfixed exists
419 // Remove myfixed and wrapfixed clases so we can calculate
420 //mystickyClass.classList.remove('myfixed');
421 //wrappernav.classList.remove('wrapfixed');
422
423 } else {
424 // Else class wrapfixed does not exists
425 initialDivHeight();
426
427 // Remove width
428 mystickyClass.style.removeProperty("width");
429 initialDivWidth();
430
431 }
432 calcViewportWidth();
433 calcAdminBarHeight();
434 fixedDivHeight();
435 calcActivationHeight();
436 headerDeactivateOnHeight();
437 }
438 }
439
440 window.addEventListener('resize', OnResizeDocument);
441
442 // need to test this, it should fire script on mobile orientation change, since onresize is somehow faulty in this case
443 window.addEventListener('orientationchange', OnResizeDocument);
444 });
445
446 })(jQuery);