Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Catched some bugs and refactor into ES6 style

dominik-zeglen96d6de13ddcf
diff --git a/saleor/static/dashboard/js/components/side-menu.js b/saleor/static/dashboard/js/components/side-menu.js
index 920e1feb55..8b6bdd5e9e 100644
--- a/saleor/static/dashboard/js/components/side-menu.js
+++ b/saleor/static/dashboard/js/components/side-menu.js
@@ -7,14 +7,16 @@ function toggleMenu (e) {
const $mainNavTop = $('.side-nav');
const $toggleMenu = $('#toggle-menu');
-const mainNavTop = $mainNavTop.offset().top;
// -----
-$toggleMenu.on('click', toggleMenu);
-if ($mainNavTop.length > 0) {
- onScroll(() => {
- const stickSideMenu = Math.floor($(window).scrollTop()) > Math.ceil(mainNavTop);
- $('body').toggleClass('sticky-nav', stickSideMenu);
- });
+if ($mainNavTop.length) {
+ const mainNavTop = $mainNavTop.offset().top;
+ $toggleMenu.on('click', toggleMenu);
+ if ($mainNavTop.length > 0) {
+ onScroll(() => {
+ const stickSideMenu = Math.floor($(window).scrollTop()) > Math.ceil(mainNavTop);
+ $('body').toggleClass('sticky-nav', stickSideMenu);
+ });
+ }
}
diff --git a/saleor/static/dashboard/js/components/styleguide.js b/saleor/static/dashboard/js/components/styleguide.js
index 4c423f6614..855c704f34 100644
--- a/saleor/static/dashboard/js/components/styleguide.js
+++ b/saleor/static/dashboard/js/components/styleguide.js
@@ -1,11 +1,5 @@
-export default $(document).ready((e) => {
- let styleGuideMenu = $('.styleguide__menu');
+import { onScroll } from './utils';
- $(window).scroll(function () {
- if ($(this).scrollTop() > 100) {
- styleGuideMenu.addClass('fixed');
- } else {
- styleGuideMenu.removeClass('fixed');
- }
- });
+export default $(document).ready((e) => {
+ onScroll(() => $('.styleguide__menu').toggleClass('fixed', $(window).scrollTop() > 100));
});