yii2mod / yii2-comments

Comments module for Yii2
MIT License
159 stars 64 forks source link

Collaboration with https://docs.infiniteajaxscroll.com/ #111

Open ahmadfadlydziljalal opened 1 year ago

ahmadfadlydziljalal commented 1 year ago

WIth this Yii2 component, https://bitbucket.org/ereminmdev/yii2-infinite-scroll/src/master/, I got the re-initialization still failed. Can you provide a comment of the following code ?

For now, the comment is redirect to something like: http://localhost/comment/default/create?entity=x---

$JS = <<<JS

jQuery.ias().on("rendered", function(elements) {

    let pjaxContainer;
    let pjaxContainerId;

    let form;
    let formId;

    jQuery.each(elements, function(key, element){

        pjaxContainer = jQuery(element).find('div').closest('.comment-wrapper');
        pjaxContainerId = '#' + pjaxContainer.children().first().attr('id');

        form = jQuery(element).find('div').closest('form');
        formId = '#' + form.attr('id');

        jQuery.pjax.reload({
            container: pjaxContainerId, 
            timeout: 1000000, 
            scrollTo: false, 
            url: window.location.href
        }).done(function() {
            jQuery(formId).comment('init', {
                pjaxContainerId: pjaxContainerId
            });
        });

    });

});

jQuery(document).on('pjax:complete', function(event) {
    console.log(event.target);   
});
JS;

$this->registerJs($JS);