/** * Mageplaza * * NOTICE OF LICENSE * * This source file is subject to the Mageplaza.com license that is * available through the world-wide-web at this URL: * https://www.mageplaza.com/LICENSE.txt * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade this extension to newer * version in the future. * * @category Mageplaza * @package Mageplaza_Blog * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) * @license https://www.mageplaza.com/LICENSE.txt */ require([ 'jquery' ], function ($) { 'use strict'; var cmtBox = $('.default-cmt__content__cmt-block__cmt-box__cmt-input'), submitCmt = $('.default-cmt__content__cmt-block__cmt-box__cmt-btn__btn-submit'), defaultCmt = $('ul.default-cmt__content__cmt-content:first'), likeBtn = defaultCmt.find('.btn-like'), replyBtn = defaultCmt.find('.btn-reply'); submitComment(); likeComment(likeBtn); showReply(replyBtn); $('li.default-cmt__content__cmt-content__cmt-row:first').css({'border-top': 'none'}); $('.default-cmt__cmt-login__btn-login').click(function () { var socialPopup = $("[href$='social-login-popup']"); if (socialPopup.length) { socialPopup.first().trigger("click"); } else { window.location.href = loginUrl; } }); /** * Check the guest name and email input is valid * * @returns {boolean} */ function checkGuestFormValidate() { if (isLogged == 'No') { return $("#default-cmt__content__cmt-block__guest-form").valid(); } return true; } /** * The comment submit button action */ function submitComment() { submitCmt.click(function () { $(".default-cmt__content__cmt-block__cmt-box").find('.messages').hide(); if (checkGuestFormValidate()) { var cmtText = cmtBox.val(); if (cmtText.trim().length) { $('.default-cmt_loading').show(); $(this).prop('disabled', true); var ajaxRequest = ajaxCommentActions(cmtText, submitCmt); ajaxRequest.done(function () { cmtBox.val(''); $('.default-cmt_loading').hide(); $(this).prop('disabled', false); }.bind(this)); } else { $('.default-cmt__content__cmt-block__cmt-box__cmt-input').parent().append(messengerBox.cmt_warning); } } }); } //like action function likeComment(btn) { btn.each(function () { var likeEl = $(this); likeEl.click(function () { var cmtId = $(this).attr('data-cmt-id'), cmtRowContainer = $(this).closest('.default-cmt__content__cmt-content__cmt-row'); if (isLogged === 'Yes') { var likeCount = $(this).find('span').text(); if ($(this).attr('click') === '1') { if ($(this).hasClass('mpblog-liked')) { $(this).css('color', '#333333'); likeCount--; $(this).find('span').text((likeCount === 0) ? "" : likeCount); $(this).removeClass('mpblog-liked') } else { likeCount++; $(this).find('span').text(likeCount); $(this).css('color', likedColor); $(this).addClass('mpblog-liked') } $.ajax({ type: "POST", url: window.location.href, data: {cmtId: cmtId}, success: function (response) { if (response.status === 'ok') { $(likeEl).attr('click', '1'); } else if (response.status === 'error' && response.hasOwnProperty(error)) { defaultCmt.append(response.error); } } }); } $(this).attr('click', '0'); } else { cmtRowContainer.append(messengerBox.login_warning); jQuery.fn.fadeOutAndRemove = function (speed) { $(this).fadeOut(speed, function () { $(this).remove(); }) }; var removeNotification = function () { $('.message.error.message-error').fadeOutAndRemove('normal'); }; setTimeout(removeNotification, 3000); } }); }); } //show reply function showReply(btn) { btn.each(function () { $(this).click(function () { var cmtId = (typeof $(this).closest('.default-cmt__content__cmt-content__cmt-row').parent().parent().parent().parent().attr('data-cmt-id') !== 'undefined') ? $(this).closest('.default-cmt__content__cmt-content__cmt-row').parent().parent().attr('data-cmt-id') : $(this).attr('data-cmt-id'), inputCmtID = $(this).attr('data-cmt-id'), cmtRowCmt = $("div").find('#cmt-row'); var cmtRowContainer = $(this).closest('.default-cmt__content__cmt-content__cmt-row'); if ($("li.cmt-row-" + cmtId).find("ul").length) { var cmtRowContainer = $("#cmt-id-" + cmtId + " ul:last-child"); } var cmtRow = cmtRowContainer.find('.row__' + inputCmtID); var cmtName = $(".username__" + inputCmtID).text(); if (isLogged === 'Yes') { if (cmtRowCmt.length) { cmtRowCmt.toggle(); $("#cmt-row").remove(); } if (cmtRow.length) { cmtRow.toggle(); $("#cmt-row").remove(); } else { cmtRowContainer.append('
' + sub[i] + '
'; } return html; } var cmtRow = '' + htmlComment(cmt.cmt_text) + '