Skip to content

Commit

Permalink
Hide modal elements before loading (#76)
Browse files Browse the repository at this point in the history
* Add position marker and hide map element before loading

* Search form with geocoder and apply position

---------

Co-authored-by: Cédric Magrez <[email protected]>
  • Loading branch information
cemag44300 and cemag44 authored Apr 30, 2024
1 parent ce6c4c6 commit 0f242c6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 53 deletions.
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

0 comments on commit 0f242c6

Please sign in to comment.