PluginProbe ʕ •ᴥ•ʔ
My Sticky Bar – Floating Notification Bar & Sticky Header (formerly myStickymenu) / 2.3.9
My Sticky Bar – Floating Notification Bar & Sticky Header (formerly myStickymenu) v2.3.9
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
445 lines
1 /*!
2 * myStickymenu by m.r.d.a
3 * v2.0.4
4 */
5
6 (function( $ ) {
7 "use strict";
8
9 $(document).ready(function($){
10
11 if ( jQuery.browser.mobile && !option.device_mobile) {
12 return false;
13 } else if ( !jQuery.browser.mobile && !option.device_desktop) {
14 return false;
15 }
16
17 // get Sticky Class setting if class name existts
18 if ($(option.mystickyClass) [0]){
19 // Do nothing
20 } else {
21 // Do something if class does not exist and stop
22 console.log("myStickymenu: Entered Sticky Class does not exist, change it in Dashboard / Settings / myStickymenu / Sticky Class. ");
23 return;
24 }
25
26
27 // Get class name
28 var mystickyClass = document.querySelector(option.mystickyClass);
29
30 // get disable at small screen size setting
31 var disableWidth = parseInt(option.disableWidth);
32
33 // get disable at large screen size setting
34 var disableLargeWidth = parseInt(option.disableLargeWidth);
35
36 // get transition effect (slide or fade)
37 var mystickyTransition = option.mystickyTransition;
38
39 // get activaton height setting
40 var activationHeight = parseInt(option.activationHeight);
41
42 // if is admin bar showing, needed for auto calc of activation height when admin bar is showing
43 var adminBar = option.adminBar;
44
45 // disable on scroll down
46 var mysticky_disable_down = option.mysticky_disable_down;
47
48 var viewportWidth;
49
50 function calcViewportWidth(e){
51
52 // Calculate actual viewport width
53 var e = window, a = 'inner';
54
55 if (!('innerWidth' in window )) {
56 a = 'client';
57 e = document.documentElement || document.body;
58 }
59 viewportWidth = e[ a+'Width' ];
60
61 }
62
63 calcViewportWidth();
64
65 var parentmysticky = mystickyClass.parentNode;
66
67 var wrappermysticky = document.createElement('div');
68 var position = 0;
69 for(var i = 0; i < parentmysticky.childNodes.length; i++) {
70 if(parentmysticky.childNodes[i] == mystickyClass) {
71 position = i;
72 break;
73 }
74 }
75
76 wrappermysticky.id = 'mysticky-wrap';
77 wrappermysticky.appendChild(mystickyClass);
78 parentmysticky.insertBefore(wrappermysticky, parentmysticky.childNodes[position]);
79
80 var parentnav = mystickyClass.parentNode;
81 var wrappernav = document.createElement('div');
82 wrappernav.id = 'mysticky-nav';
83 parentnav.replaceChild(wrappernav, mystickyClass);
84 wrappernav.appendChild(mystickyClass);
85
86 // get activation height from settings
87 if ( activationHeight == "0" ) {
88 var autoActivate = true;
89 }
90
91 var mydivHeight;
92
93
94 function initialDivHeight(){
95
96 // get initial element height of selected sticky class
97 mydivHeight = (mystickyClass.offsetHeight);
98
99 // when initial element have margin bottom - awaken example using #masthead class
100 if (parseInt($(mystickyClass).css("marginBottom")) > 0) {
101
102 // element have margin bottom, apply it to initial wrap
103 //$(mystickyClass).css("marginBottom").replace('px', '')
104 wrappermysticky.style.marginBottom = ($(mystickyClass).css("marginBottom"));
105 }
106
107 if (mydivHeight == "0") {
108 // 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
109
110 $(mystickyClass).children().filter(':visible').each(function(){
111 mydivHeight = $(this).outerHeight(true);
112
113 });
114
115 }
116
117 if (viewportWidth >= disableWidth) {
118 //wrappermysticky.style.height = mydivHeight + 'px';
119 }
120 }
121
122 initialDivHeight();
123
124 var myfixedHeight;
125
126 function fixedDivHeight(){
127 //if ( autoActivate == true ) {
128
129 // calculate element height while fixed
130 mystickyClass.classList.add('myfixed')
131
132 myfixedHeight = $(".myfixed").outerHeight();
133
134 if (myfixedHeight == "0") {
135 // something is wrong, wrapper cant be zero, try to calculate again with div children.
136 $(".myfixed").children().filter(':visible').each(function(){
137 myfixedHeight = $(this).outerHeight(true);
138 });
139 }
140
141 mystickyClass.classList.remove('myfixed');
142
143 //}
144
145 }
146
147 fixedDivHeight();
148
149 var adminBarHeight = 0;
150
151 function calcAdminBarHeight(){
152
153 if ((adminBar == "true" ) && (viewportWidth > 600)) {
154
155 if ($("#wpadminbar")[0]){
156 adminBarHeight = $('#wpadminbar').height();
157 } else {
158 adminBarHeight = 0;
159 }
160 } else {
161 adminBarHeight = 0;
162 }
163
164
165 //wrappernav.style.top = adminBarHeight + "px";
166 if (mystickyTransition == "slide") {
167 wrappernav.style.top = "-" + myfixedHeight + "px";
168 //wrappernav.style.top = "-" + myfixedHeight + "px";
169 } else {
170 wrappernav.style.top = adminBarHeight + "px";
171 }
172
173 }
174
175 calcAdminBarHeight();
176
177
178 var mydivWidth;
179
180 function initialDivWidth(){
181
182 var rect = $(mystickyClass)[0].getBoundingClientRect();
183 mydivWidth = rect.width;
184
185 //var mydivWidth = ((mystickyClass.offsetWidth) + 'px');
186 //mystickyClass.style.width = mydivWidth + "px";
187
188 }
189
190 initialDivWidth();
191
192
193
194
195 var deactivationHeight = activationHeight;
196
197 function calcActivationHeight() {
198
199 // If activate height (Make visible on Scroll) is set to 0, automatic calculation will be used.
200 if ( autoActivate == true ) {
201
202 // Automatic calculation of activation and deactivation height (Make visible on Scroll is set to 0).
203 if (mystickyTransition == "slide") {
204 // Slide effect is selected
205 //activationHeight = $(mystickyClass).offset().top + mystickyClass.offsetHeight - adminBarHeight;
206 activationHeight = $(mystickyClass).offset().top + mydivHeight - adminBarHeight;
207 deactivationHeight = $(mystickyClass).offset().top + mydivHeight - adminBarHeight;
208 //deactivationHeight = $(mystickyClass).offset().top - adminBarHeight;
209
210 if (mysticky_disable_down == "on") {
211 deactivationHeight = $(mystickyClass).offset().top - adminBarHeight;
212
213 }
214
215 }
216
217 if (mystickyTransition == "fade") {
218
219 if (mysticky_disable_down == "false") {
220 // Fade effect is selected
221 activationHeight = $(mystickyClass).offset().top - adminBarHeight;
222
223 deactivationHeight = $(mystickyClass).offset().top - adminBarHeight;
224
225 }
226
227 if (mysticky_disable_down == "on") {
228
229 // Fade effect is selected
230 activationHeight = $(mystickyClass).offset().top - adminBarHeight + mydivHeight;
231 deactivationHeight = $(mystickyClass).offset().top - adminBarHeight;
232
233 }
234
235 }
236
237 }
238
239 }
240
241 calcActivationHeight();
242
243 function headerDeactivateOnHeight() {
244
245
246 if ( autoActivate == true ) {
247
248 if ( mydivHeight > myfixedHeight ){
249 // Auto activate is true, Make visible on Scroll is set to 0, menu is probably header
250
251
252
253 if (mystickyTransition == "slide") {
254 // slide effect is selected
255 deactivationHeight = activationHeight;
256
257 if (mysticky_disable_down == "on") {
258 deactivationHeight = activationHeight - myfixedHeight;
259
260 }
261
262
263 } else {
264 activationHeight = mydivHeight;
265 deactivationHeight = mydivHeight;
266
267 }
268
269 }
270
271 }
272
273 }
274
275 headerDeactivateOnHeight();
276
277
278 var hasScrollY = 'scrollY' in window;
279 var lastScrollTop = 0;
280
281 function onScroll(e) {
282
283 //initialDivHeight();
284 // if body width is larger than disable at small screen size setting
285
286 if (viewportWidth >= disableWidth) {
287
288 if ( disableLargeWidth == 0 || viewportWidth <= disableLargeWidth ) {
289
290 //if (mysticky_disable_down == "on") {
291
292 var y = hasScrollY ? window.scrollY : document.documentElement.scrollTop;
293
294 //var yScrollPosition = $(this).scrollTop();
295
296 // add up or down class to the element depending on scroll direction
297 if (0 <= y ) {
298
299 //var st = $(this).scrollTop();
300
301 if (y >= lastScrollTop){
302
303 // downscroll code
304
305 // add myfixed and wrapfixed class to selected fixed element while scroll down
306 y >= activationHeight ? mystickyClass.classList.add('myfixed') : "";
307 y >= activationHeight ? wrappernav.classList.add('wrapfixed') : "";
308
309 y >= activationHeight ? wrappermysticky.style.height = mydivHeight + 'px' : "";
310 y >= activationHeight ? mystickyClass.style.width = mydivWidth + "px" : "";
311
312
313 if (mystickyTransition == "slide") {
314
315 if (mysticky_disable_down == "false") {
316 //y < activationHeight + (myfixedHeight + 250) - adminBarHeight ? wrappernav.style.top = "-" + myfixedHeight + "px" : '';
317 //wrappernav.style.top = "-" + myfixedHeight + "px"
318 y >= activationHeight + myfixedHeight - adminBarHeight ? wrappernav.style.top = adminBarHeight + "px" : wrappernav.style.top = "-" + myfixedHeight + "px";
319
320 }
321
322 if ( mydivHeight > myfixedHeight ){
323 // if it's header (guess)
324
325 if (mysticky_disable_down == "false") {
326
327 y < activationHeight + myfixedHeight ? wrappernav.style.top = "-" + mydivHeight + "px" : '';
328 y >= activationHeight + myfixedHeight ? wrappernav.style.top = adminBarHeight + "px" : '';
329
330 }
331
332 }
333
334 }
335
336 wrappernav.classList.add('down');
337 wrappernav.classList.remove('up');
338
339
340 if (mysticky_disable_down == "on") {
341 wrappernav.style.top = "-" + (mydivHeight + adminBarHeight ) + "px";
342 jQuery('#mysticky-nav ' + option.mystickyClass+'.elementor-sticky').hide();
343 //jQuery('#mysticky-nav ' + option.mystickyClass).css( 'top' , "-" + (mydivHeight + adminBarHeight ) + "px");
344 }
345
346 } else {
347 // upscroll code
348
349 var x = hasScrollY ? window.scrollY : document.documentElement.scrollTop;
350 //x > deactivationHeight ? '' : mystickyClass.classList.remove('myfixed') ;
351 //x > deactivationHeight ? '' : wrappernav.classList.remove('wrapfixed');
352
353 x > deactivationHeight ? "" : wrappermysticky.style.height = "";
354 x > deactivationHeight ? "" : mystickyClass.style.width = "";
355
356 if (mystickyTransition == "slide") {
357
358 x > deactivationHeight ? '' : mystickyClass.classList.remove('myfixed') ;
359 x > deactivationHeight ? '' : wrappernav.classList.remove('wrapfixed');
360
361 if (mysticky_disable_down == "false") {
362
363 x < deactivationHeight + myfixedHeight + 200 - adminBarHeight ? wrappernav.style.top = "-" + myfixedHeight + "px" : '';
364 }
365
366 } else {
367
368 x > deactivationHeight ? "" : mystickyClass.classList.remove('myfixed') ;
369 x > deactivationHeight ? "" : wrappernav.classList.remove('wrapfixed');
370
371 }
372
373
374 wrappernav.classList.remove('down');
375 wrappernav.classList.add('up');
376
377 if (mysticky_disable_down == "on") {
378 wrappernav.style.top = adminBarHeight + "px";
379 jQuery('#mysticky-nav '+ option.mystickyClass).css( 'width' , mydivWidth + "px");
380 jQuery('#mysticky-nav ' + option.mystickyClass+'.elementor-sticky').show();
381
382 }
383
384 }
385
386 lastScrollTop = y;
387
388 } else {
389 //if (mysticky_disable_down == "on") {
390 wrappernav.classList.remove('up');
391 //}
392 }
393
394 } // if disableWidth is greater than zero
395
396
397 } // if disableLargeWidth is 0 or greater than zero
398
399 }
400
401 document.addEventListener('scroll', onScroll);
402
403
404 var width = $(window).width()
405
406 function OnResizeDocument () {
407
408 // don't recalculate on height change, only width
409 if($(window).width() != width ){
410
411 wrappernav.classList.remove('up');
412 wrappernav.classList.remove('down');
413
414 if ($(".wrapfixed")[0]){
415 // If class wrapfixed exists
416 // Remove myfixed and wrapfixed clases so we can calculate
417 mystickyClass.classList.remove('myfixed');
418 wrappernav.classList.remove('wrapfixed');
419
420 } else {
421 // Else class wrapfixed does not exists
422 initialDivHeight();
423
424 // Remove width
425 mystickyClass.style.removeProperty("width");
426 initialDivWidth();
427
428 }
429 calcViewportWidth();
430 calcAdminBarHeight();
431 fixedDivHeight();
432 calcActivationHeight();
433 headerDeactivateOnHeight();
434
435 }
436
437 }
438
439 window.addEventListener('resize', OnResizeDocument);
440 // need to test this, it should fire script on mobile orientation change, since onresize is somehow faulty in this case
441 window.addEventListener('orientationchange', OnResizeDocument);
442
443 });
444
445 })(jQuery);