Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from magefan/issues-with-comments
Browse files Browse the repository at this point in the history
added changes from merge requsts [3,4,5]
  • Loading branch information
magefan authored Jun 12, 2023
2 parents cf5313e + b31b327 commit 29e7983
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion view/frontend/templates/post/view-modern.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
.post-content ol {margin-bottom: 0.8em;}
</style>

<div class="_post-view modern">
<div class="post-view modern">
<div class="post-holder post-holder-<?= (int)$_post->getId() ?>">

<div class="post-header clearfix">
Expand Down
41 changes: 21 additions & 20 deletions view/frontend/templates/post/view/comments/magefan.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,34 @@
action="<?= $block->escapeUrl($block->getFormUrl()) ?>"
method="post">
<?= $block->getBlockHtml('formkey') ?>
<input type="hidden" name="post_id" value="<?= (int)($block->getPost()->getId()) ?>" />
<textarea name="text" class="w-full"
<input class="form-input" type="hidden" name="post_id" value="<?= (int)($block->getPost()->getId()) ?>" />
<textarea name="text" class="w-full form-textarea"
placeholder="<?= $canPost ? $block->escapeHtml(__('Add a comment...')) : $block->escapeHtml(__('Sign in to add a comment...')) ?>" <?php if (!$canPost) {?>
disabled="disabled"<?php } ?>
required
data-validate="{required:true}"></textarea>
<div class="c-btn-hld hidden">
<div class="c-btn-hld hidden mt-5">

<?php if ($canPost && !$session->getCustomerGroupId()) { ?>
<div class="lr-hld">
<div class="left-hld">
<div class="lr-hld flex justify-between">
<div class="left-hld w-[49%]">
<input type="text"
name="author_nickname"
value=""
placeholder="<?= $block->escapeHtml(__('Full Name')) ?>"
class="input-text required-entry w-full"
class="input-text required-entry w-full form-input"
data-validate="{required:true}"
autocomplete="off"
required
aria-required="true">
</div>
<div class="right-hld">
<div class="right-hld w-[49%]">
<input type="email"
name="author_email"
autocomplete="email"
value=""
placeholder="<?= $block->escapeHtml(__('Email')) ?>"
class="input-text w-full"
class="input-text w-full form-email"
required
data-validate="{required:true, 'validate-email':true}"
aria-required="true">
Expand All @@ -77,7 +77,7 @@
<div id="recaptcha-append-to"><?= $block->getChildHtml('blog.post.comments.magefan.additional'); ?></div>

<?php if ($canPost) { ?>
<button type="submit"><?= $block->escapeHtml(__('Submit')) ?></button>
<button type="submit" class="btn btn-default inline-block text-white text-sm font-medium leading-none py-2.5 px-3 bg-[#4db2ec] hover:bg-[#222] rounded-none mt-5"><?= $block->escapeHtml(__('Submit')) ?></button>
<?php } else { ?>
<button type="button"
onclick="window.location='<?= $block->escapeUrl($block->getCustomerUrl()->getLoginUrl()) ?>';">
Expand Down Expand Up @@ -109,50 +109,50 @@ if ($commentsCount) {
</div>

<!-- reply comment form -->
<div id="c-replyform-comment mb-4" class="c-replyform c-replyform-comment" style="display:none">
<div id="c-replyform-comment" class="c-replyform c-replyform-comment mb-4" style="display:none">
<form class="reply-form-blog-recaptcha"
action="<?= $block->escapeUrl($block->getFormUrl()) ?>"
method="post">
<?= $block->getBlockHtml('formkey') ?>
<input type="hidden" name="post_id" value="<?= $block->escapeHtml($block->getPost()->getId()) ?>" />
<input type="hidden" name="parent_id" value="" />
<textarea class="refresh-value w-full"
<textarea class="refresh-value w-full form-textarea"
name="text"
placeholder="<?= $canPost ? $block->escapeHtml(__('Add a reply...')) : $block->escapeHtml(__('Sign in to add a comment...')) ?>" <?php if (!$canPost) {?>
disabled="disabled"<?php } ?>
required
data-validate="{required:true}"></textarea>
<div class="c-btn-hld">
<div class="c-btn-hld mt-5">

<?php if ($canPost && !$session->getCustomerGroupId()) { ?>
<div class="lr-hld">
<div class="left-hld">
<div class="lr-hld flex justify-between">
<div class="left-hld w-[49%]">
<input type="text"
name="author_nickname"
value=""
placeholder="<?= $block->escapeHtml(__('Full Name')) ?>"
class="input-text required-entry refresh-value w-full"
class="input-text required-entry refresh-value w-full form-input"
data-validate="{required:true}"
required
autocomplete="off"
aria-required="true">
</div>
<div class="right-hld">
<div class="right-hld w-[49%]">
<input type="email"
name="author_email"
autocomplete="email"
value=""
placeholder="<?= $block->escapeHtml(__('Email')) ?>"
class="input-text required-entry refresh-value w-full"
class="input-text required-entry refresh-value w-full form-email"
data-validate="{required:true, 'validate-email':true}"
required
aria-required="true">
</div>
</div>
<?php } ?>
<button type="button" class="cancel reply-cancel-action" ><?= $block->escapeHtml(__('Cancel')) ?></button>
<button type="button" class="cancel reply-cancel-action mt-5 mr-4" ><?= $block->escapeHtml(__('Cancel')) ?></button>
<?php if ($canPost) { ?>
<button type="submit"><?= $block->escapeHtml(__('Submit')) ?></button>
<button class="read-more btn btn-default inline-block text-white text-sm font-medium leading-none py-2.5 px-3 bg-[#4db2ec] hover:bg-[#222] rounded-none mt-5" type="submit"><?= $block->escapeHtml(__('Submit')) ?></button>
<?php if ($block->displayPrivacyPolicyCheckbox()) { ?>
<?= $block->getChildBlock('display_privacy_policy_checkbox')->setCommentType('comment')->toHtml(); ?>
<?php } ?>
Expand Down Expand Up @@ -191,7 +191,8 @@ if ($commentsCount) {
if (isCommentElementVisible) {
document.removeEventListener('scroll', initCommentsJs);

const script = document.createElement('script')
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = '<?= $escaper->escapeUrl($block->getViewFileUrl('Hyva_MagefanBlog/js/magefan-comments.js')) ?>';
document.head.append(script);
}
Expand Down
51 changes: 25 additions & 26 deletions view/frontend/web/js/magefan-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

var msgLifetime = 4000;
var $hd = document.querySelector('#post-comments');

var getMessageHtml = function (msg, type) {
var h = document.createElement('div');
h.classList.add('message-' + type, type, 'message');
Expand Down Expand Up @@ -44,31 +43,31 @@
event.preventDefault();
var $form = event.target;

Array.prototype.forEach.call($hd.querySelectorAll('form [type=submit]'), function(submitButton, i) {
submitButton.setAttribute('disabled', 'disabled');
});
if ($form.classList.contains('comment-form-blog-recaptcha')){
$form.querySelector('button[type=submit]').setAttribute('disabled', 'disabled');
}

fetch($form.getAttribute('action'), {
method: 'POST',
body: new URLSearchParams(new FormData($form)).toString(),
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest'
}
}).then(function (response) {
if (response.ok) {
return response.json();
}
return Promise.reject(response);
}).then(function (response) {
if (response.success) {
processSuccess($form, response.message);
} else {
processError($form, response.message);
}
}).catch(function (error) {
console.warn(error);
});
method: 'POST',
body: new URLSearchParams(new FormData($form)).toString(),
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest'
}
}).then(function (response) {
if (response.ok) {
return response.json();
}
return Promise.reject(response);
}).then(function (response) {
if (response.success) {
processSuccess($form, response.message);
} else {
processError($form, response.message);
}
}).catch(function (error) {
console.warn(error);
});

return false;
});
Expand Down Expand Up @@ -112,8 +111,8 @@
}

$hd.querySelector('form textarea').addEventListener('click', function (event) {
if (event.target.closest('.no-active')) {
event.target.closest('.no-active').classList.remove('no-active');
if (event.target.closest('form').querySelector('.c-btn-hld')) {
event.target.closest('form').querySelector('.c-btn-hld').classList.remove('hidden');
}
});

Expand Down

0 comments on commit 29e7983

Please sign in to comment.