T
T
tigra2015-12-10 15:10:24
JavaScript
tigra, 2015-12-10 15:10:24

Where and how to re-initialize fancybox on ajax load?

After loading with Ajax, fancybox stops working on photos. It turns out you need to re-initialize fancybox. Where can I do it in php? I don't want to mess with js

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tigra, 2015-12-15
@tigroid3

actually it turned out like this) the extention infiniteScroll.IasPager has an onRenderComplete parameter, we push the initialization there)

$this->widget('zii.widgets.CListView', array(
......
  pager' => array(
  .....
  'onRenderComplete' => new CJavaScriptExpression('function () {
        $("a[rel=gallery]").fancybox();
      }'
)));

A
Alexander N++, 2015-12-14
@sanchezzzhak

live

<?php
$jsCode=<<<'JS'
  $('.content').on('click','.fancybox', function(e) {
        $(this).fancybox();
    });
});
JS;
$this->registerJs($jsCode);
?>

or so after ajax request, no matter which one we initialize fancybox
$(document).ajaxStop(function() { 
    $('.fancybox').fancybox();
  });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question