inject-gallery-x.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. <style>
  37. .gallery-wrapper{
  38. margin-left: auto;
  39. margin-right: auto;
  40. min-height:340px;
  41. width:90%;
  42. padding-bottom: 18px;
  43. }
  44. .longrid .post .text .gallery-wrapper div{
  45. margin-left: 0;
  46. margin-right: 0;
  47. }
  48. </style>
  49. <div id="gallery-<?=$gallery->id?>" class="gallery-wrapper"></div>
  50. <div class="image-title"><?=$gallery->name?></div>
  51. <script type="text/javascript">
  52. window.addEventListener("DOMContentLoaded",function () {
  53. $('#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?> ] });
  54. $('#gallery-<?=$gallery->id?>').on('fotorama:show', function (e, fotorama, extra) { console.log('cnt+')} );
  55. });
  56. </script>
  57. <?
  58. }