inject-gallery-x.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * @var $this \yii\web\View
  4. * @var $gallery \app\models\front\Gallery
  5. */
  6. use yii\helpers\Html;
  7. $mobile = Yii::$app->deviceDetect->isMobile();
  8. $maxheight = $mobile?'900':'750';
  9. if($gallery instanceof \app\models\front\Gallery && count($gallery->getBehavior('galleryBehavior')->getImages())>0 ){
  10. $c = Yii::$app->acache;
  11. $c->set('fotorama', true);
  12. $i=1;
  13. ob_start();
  14. foreach($gallery->getBehavior('galleryBehavior')->getImages() as $image){
  15. $add_cap = ($image->name != '')?", caption: '".$image->name."'":'';
  16. if( ( $model->type == 2 || $model->type == 6 ) && !$mobile ){
  17. // лонгрид
  18. $mainimg = $image->getUrl('large');
  19. }else{
  20. $mainimg = $image->getUrl('medium');
  21. }
  22. if( $mainimg ){
  23. ?>
  24. {img: '<?=$mainimg?>', thumb: '<?=$image->getUrl('small')?>', full:'<?=$image->getUrl('large')?>', id:<?=$i?> <?=$add_cap?>},
  25. <?
  26. }
  27. $i++;
  28. }
  29. $ltext = ob_get_contents();
  30. ob_end_clean();
  31. /*
  32. <link href="https://lib.amic.ru/js/fotorama/fotorama.css" rel="stylesheet">
  33. <script src="https://lib.amic.ru/js/fotorama/fotorama.js" defer></script>
  34. */
  35. ?>
  36. <div id="gallery-<?=$gallery->id?>" class="gallery-wrapper"></div>
  37. <div class="image-title"><?=$gallery->name?></div>
  38. <script type="text/javascript">
  39. window.addEventListener("DOMContentLoaded",function () {
  40. $('#gallery-<?=$gallery->id?>').fotorama({ width:'100%',maxwidth:1200,maxheight:<?=$maxheight?>,minheight:250, fit: 'contain', thumbheight:70,thumbwidth:94, captions: true,nav:'thumbs', caption: 'overlay', allowfullscreen:'native',transition:'slide', data: [ <?=$ltext?> ] });
  41. $('#gallery-<?=$gallery->id?>').on('fotorama:show', function (e, fotorama, extra) { console.log('cnt+')} );
  42. });
  43. </script>
  44. <?
  45. }