Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/js/constants/selectors-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const facetedsearch = {
range: '.js-faceted-slider',
rangeContainer: '.js-faceted-slider-container',
filterSlider: '.js-faceted-filter-slider',
offCanvasFaceted: '#offcanvas-faceted',
};

export const pageLoader = '.js-page-loader';
Expand Down
9 changes: 8 additions & 1 deletion src/js/modules/facetedsearch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import wNumb from 'wnumb';
import initFacets from './update';
import filterHandler from './filter-handler';

const initSliders = () => {
// eslint-disable-next-line import/prefer-default-export
export const initSliders = () => {
const {Theme} = window;

// Get all slider configurations found in the DOM
Expand Down Expand Up @@ -70,6 +71,12 @@ const initSliders = () => {
const sliderValues = JSON.parse(<string>container.dataset.sliderValues);

if (!container.noUiSlider) {
// if we initiate slider with noUiBase he create another one we have to delete it before.
const noUiBase = container.querySelector('.noUi-base');

if (noUiBase) {
noUiBase.remove();
}
initiatedSlider = noUiSlider.create(container, {
start: sliderValues ?? [min, max],
tooltips: [tooltipsFormat, tooltipsFormat],
Expand Down
3 changes: 3 additions & 0 deletions src/js/responsive-toggler.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import EVENTS from '@js/constants/events-map';
import selectorsMap from '@constants/selectors-map';
import initResponsiveToggler from './responsive-toggler';
import initEmitter from './prestashop';
import {
desktopElement, mobileElement, mobileElementId, contentValue, desktopElementId,
} from './constants/mocks/swapElements-data';
import ThemeType = Theme.ThemeType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ga-devfront why this import? seems useless.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on my side then I test without this it fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this import is required elsewhere.
obraz

Is this even a valid way of importing modules?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


beforeAll(() => {
document.body.innerHTML = `
Expand All @@ -18,6 +20,7 @@ beforeAll(() => {
window.Theme = {
...window.Theme,
events: EVENTS,
selectors: selectorsMap,
};

initEmitter();
Expand Down
18 changes: 17 additions & 1 deletion src/js/responsive-toggler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* file that was distributed with this source code.
*/
import swapElements from '@helpers/swapElements';
import {facetedsearch} from '@constants/selectors-map';
import {initSliders} from '@js/modules/facetedsearch';
import {Offcanvas} from 'bootstrap';

const {prestashop} = window;

Expand All @@ -28,15 +31,28 @@ export function toggleMobileStyles() {
swapElements(source, target);
}
});

// we have to init again sliders because we reconstruct the dom
initSliders();
} else {
Array.prototype.forEach.call(document.querySelectorAll("*[id^='_mobile_']"), (el) => {
Array.prototype.forEach.call(document.querySelectorAll("*[id^='_mobile_']"), async (el) => {
const source = document.querySelector(`#${el.id}`);
const target = document.querySelector(`#${el.id.replace('_mobile_', '_desktop_')}`);

if (target && source) {
swapElements(source, target);
}
});

// we close the old mobile interface
const offCanvasFacetedElement = document.querySelector(facetedsearch.offCanvasFaceted) as HTMLElement;

if (offCanvasFacetedElement != null) {
Offcanvas.getInstance(offCanvasFacetedElement)?.hide();
}

// we have to init again sliders because we reconstruct the dom
initSliders();
}

prestashop.emit(events.responsiveUpdate, {
Expand Down
4 changes: 3 additions & 1 deletion types/selectors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import {qtyInput} from "@constants/selectors-map";

declare type facetedsearch = {
range: string,
rangeContainer: string,
filterSlider: string,
offCanvasFaceted: string,
};

declare type pageLoader = string;
Expand Down Expand Up @@ -152,6 +154,6 @@ type SelectorsMap = {
mobileMenu: mobileMenu,
visiblePassword: visiblePassword,
desktopMenu: desktopMenu,
quantityInput: quantityInput,
qtyInput: quantityInput,
formValidation: formValidation,
};