Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide modal elements before loading #76

Merged
merged 2 commits into from
Apr 30, 2024
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
17 changes: 13 additions & 4 deletions view/frontend/web/css/source/_module.less
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
}

.catalog-product-stores-availability-content {
display: none;

.fulltext-search-wrapper {
.form {
display: flex;
Expand All @@ -44,10 +46,8 @@

.store-view-map .map {
max-width: 100%;
height: 400px;
background: #666;
height: 0;
z-index: 1;
float: left;
display: inline-block;
margin-bottom: 20px;
width: 100%;
Expand All @@ -60,7 +60,6 @@
margin: 10px 0 0;
padding: 0;
max-height: 215px;
min-height: 215px;
overflow-y: scroll;

li.result-item {
Expand Down Expand Up @@ -115,6 +114,16 @@
.catalog-product-retailer-availability .showavailability {
cursor: pointer;
}

.modal-popup {
.catalog-product-stores-availability-content {
display: block;
}

.store-view-map .map {
height: 400px;
}
}
}

//
Expand Down
65 changes: 16 additions & 49 deletions view/frontend/web/js/retailer/product-availability.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,53 +35,19 @@ define([
* Search Shop per words
*/
onSearchOffers: function() {
this.displayedOffers(
this.filterPerWords(this.storeOffers(), this.fulltextSearch())
);
},

/**
* Custom filter to allow approaching result per words
*
* @param markers
* @param terms
* @returns {[]|jQuery|*[]|*|null}
*/
filterPerWords(markers, terms) {
let self = this;
let arrayOfTerms = terms.split(' ');
let term = $.map(arrayOfTerms, function (tm) {
if (tm.length <= 2) {
// ignore smallest term for performance reason
return null;
}
return $.ui.autocomplete.escapeRegex(self.normalizeAccent(tm));
}).join('|');
let matcher= new RegExp("\\b" + term, "i");

if (term.length <= 2) {
// ignore smallest term for performance reason
return null;
}

return $.grep(markers, function (marker) {
// try to match one of the 4 elements
return matcher.test(marker.name)
|| matcher.test(marker.postCode)
|| matcher.test(self.normalizeAccent(marker.city))
|| matcher.test(marker.region)
;
});
},

/**
* Replace accent from string
*
* @param str
* @returns {*}
*/
normalizeAccent: function(str) {
return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "")
registry.get(this.name + '.geocoder', function (geocoder) {
this.geocoder = geocoder;
this.geocoder.fulltextSearch(this.fulltextSearch());
this.geocoder.currentResult.subscribe(function (result) {
if (result && result.location) {
this.findPositionSuccess(
{coords: {latitude: result.location.lat, longitude: result.location.lng}},
this.fulltextSearch()
);
}
}.bind(this));
this.geocoder.onSearch();
}.bind(this));
},

/**
Expand Down Expand Up @@ -145,18 +111,19 @@ define([
geolocalizeMe: function() {
registry.get(this.name + '.geocoder', function (geocoder) {
this.geocoder = geocoder;
this.geocoder.geolocalize(this.geolocationSuccess.bind(this))
this.geocoder.geolocalize(this.findPositionSuccess.bind(this))
}.bind(this));
},

/**
* Action on geolocation success
*/
geolocationSuccess: function(position) {
findPositionSuccess: function(position) {
if (position.coords && position.coords.latitude && position.coords.longitude) {
registry.get(this.name + '.map', function (map) {
this.map = map;
this.map.applyPosition(position);
this.map.addMarkerWithMyPosition(position);
}.bind(this));

this.updateDisplayedOffers();
Expand Down
Loading