Skip to content

Commit

Permalink
Rewritten account favorite component
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Jan 18, 2022
1 parent ab78938 commit 01b1af0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
9 changes: 6 additions & 3 deletions client/html/themes/default/account-favorite.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
border-bottom-color: var(--ai-secondary, #555);
}

.account-favorite .favorite-items {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}

.account-favorite .favorite-item {
display: inline-block;
vertical-align: top;
position: relative;
text-align: end;
width: 180px;
margin: 1%;
padding: 0;
}

.account-favorite .media-item {
Expand Down
23 changes: 11 additions & 12 deletions client/html/themes/default/account-favorite.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@ AimeosAccountFavorite = {
/**
* Deletes a favorite item without page reload
*/
setupProductRemoval: function() {
onRemoveProduct() {

$("body").on("click", ".account-favorite .delete", function() {
$("body").on("click", ".account-favorite .delete", ev => {

var form = $(this).parents("form");
$(this).parents("favorite-item").addClass("loading");
const form = $(ev.currentTarget).closest("form");
$(ev.currentTarget).closest("favorite-item").addClass("loading");

fetch(form.attr("action"), {
body: new FormData(form.get(0)),
body: new FormData(form[0]),
method: 'POST'
}).then(response => {
return response.text();
}).then(data => {
var doc = document.createElement("html");
doc.innerHTML = data;
const doc = $("<html/>").html(data);

if($(".aimeos.account-favorite .favorite-items", doc).length) {
$(".aimeos.account-favorite").html($(".aimeos.account-favorite", doc).html());
} else {
$(".aimeos.account-favorite").replaceWith($(".aimeos.account-favorite", doc));

if(!$(".aimeos.account-favorite .favorite-items").length) {
Aimeos.removeOverlay();
}
});
Expand All @@ -37,8 +36,8 @@ AimeosAccountFavorite = {
/**
* Initializes the account favorite actions
*/
init: function() {
this.setupProductRemoval();
init() {
this.onRemoveProduct();
}
};

Expand Down

0 comments on commit 01b1af0

Please sign in to comment.