inject-gallery-x.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. $nav = 'thumbs';
  11. $ratio = '';
  12. $c = Yii::$app->acache;
  13. $c->set('fotorama', true);
  14. $i=1;
  15. ob_start();
  16. foreach($gallery->getBehavior('galleryBehavior')->getImages() as $image){
  17. $add_cap = ($image->name != '')?", caption: '".$image->name."'":'';
  18. $mainimg = false;
  19. if( $image->type == 'post_gallery' ){
  20. if( ( $model->type == 2 || $model->type == 6 ) && !$mobile ){
  21. // лонгрид
  22. $mainimg = $image->getUrl('large');
  23. }else{
  24. $mainimg = $image->getUrl('medium');
  25. }
  26. }
  27. if( $mainimg ){
  28. $d = str_replace("\n", "", (string)$image->description);
  29. $u = trim($d);
  30. if( $u ){
  31. $d = ', html:'.json_encode('<div style="position:relative;" class="phfce"><span>'.$u.'</span></div>');
  32. }else{
  33. $d = '';
  34. }
  35. ?>
  36. {img: '<?=$mainimg?>', thumb: '<?=$image->getUrl('small')?>', full:'<?=$image->getUrl('large')?>', id:<?=$i?> <?=$add_cap?><?=$d?>},
  37. <?
  38. }elseif( $image->description ){
  39. $nav = 'dots';
  40. $ratio = 'ratio:16/9,';
  41. $d = str_replace("\n", "", (string)$image->description);
  42. //$d = htmlentities($d);
  43. //$d = json_encode($d);
  44. $u = trim($d);
  45. $d = json_encode('<div style="z-index:0;position:relative;" class="phfc"><span>'.$u.'</span></div>');
  46. ?>
  47. { img: '/img/e.gif', id:<?=$i?> <?=$add_cap?>, html:<?=$d?>,fit: 'contain'},
  48. <?
  49. }
  50. $i++;
  51. }
  52. $ltext = ob_get_contents();
  53. ob_end_clean();
  54. /*
  55. <link href="https://lib.amic.ru/js/fotorama/fotorama.css" rel="stylesheet">
  56. <script src="https://lib.amic.ru/js/fotorama/fotorama.js" defer></script>
  57. */
  58. ?>
  59. <div id="gallery-<?=$gallery->id?>" class="gallery-wrapper"></div>
  60. <div class="image-title"><?=$gallery->name?></div>
  61. <script type="text/javascript">
  62. window.addEventListener("DOMContentLoaded",function () {
  63. $('#gallery-<?=$gallery->id?>').fotorama({ <?=$ratio?>width:'100%',maxwidth:1200,maxheight:<?=$maxheight?>,minheight:250, fit: 'contain', thumbheight:70,thumbwidth:94, captions: true,nav:'<?=$nav?>', swipe:true, caption: 'overlay', allowfullscreen:'native',transition:'slide', data: [ <?=$ltext?> ] });
  64. $('#gallery-<?=$gallery->id?>').on('fotorama:show', function (e, fotorama, extra) {
  65. new Image().src = "https://counter.yadro.ru/hit;amicru?r"+escape(document.referrer)+((typeof(screen)=="undefined")?"":";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+";h"+escape(document.title.substring(0,150))+";"+Math.random();
  66. } ).on('fotorama:ready', function (e, fotorama) {
  67. //
  68. });
  69. });
  70. </script>
  71. <?/*
  72. <style>
  73. .fotorama__arr{
  74. z-index:9999;
  75. position:absolute;
  76. }
  77. .phfc{
  78. width:100%;
  79. text-align:center;
  80. height: 100%;
  81. }
  82. .phfc span{
  83. text-align:left;
  84. font-size:130%;
  85. line-height:normal;
  86. margin:auto 5px;
  87. position: absolute;
  88. top: 0;
  89. right: 0;
  90. bottom: 0;
  91. left: 0;
  92. height: fit-content;
  93. }
  94. .phfc iframe{
  95. aspect-ratio:16/9;
  96. height:auto;
  97. margin:auto;
  98. width:94%;
  99. display:block;
  100. padding:18px;
  101. }
  102. .phfce{
  103. width:100%;
  104. text-align:center;
  105. text-shadow: 2px 2px #000;
  106. display:flex;
  107. height:100%;
  108. background-color: #0000007d;
  109. color:#fff;
  110. }
  111. .phfce span{
  112. text-align:left;
  113. font-size:200%;
  114. line-height:normal;
  115. margin:auto 20px;
  116. }
  117. .fotorama--fullscreen .phfce span{
  118. font-size:400%;
  119. margin: auto 100px;
  120. }
  121. .fotorama--fullscreen .phfc span{
  122. font-size:400%;
  123. margin: auto 100px;
  124. color: #b7b7b7;
  125. display: block;
  126. text-align:left;
  127. line-height:normal;
  128. }
  129. .fotorama--fullscreen .phfc iframe{
  130. width:100%;
  131. }
  132. @media only screen and (min-width: 1300px) {
  133. .phfc span{
  134. font-size:130%;
  135. }
  136. }
  137. @media only screen and (max-width: 1300px) {
  138. .phfc span{
  139. font-size:110%;
  140. }
  141. }
  142. @media only screen and (max-width: 1200px) {
  143. .phfc span{
  144. font-size:85%;
  145. }
  146. .phfc h2{
  147. font-size:100%;
  148. font-weight: bold;
  149. }
  150. }
  151. @media only screen and (max-width: 994px) {
  152. .phfc span,h2{
  153. font-size:70%;
  154. }
  155. .phfc h2{
  156. font-weight: bold;
  157. }
  158. }
  159. @media only screen and (max-width: 534px) {
  160. .phfc span,h2{
  161. font-size:68%;
  162. }
  163. .phfc h2{
  164. font-weight: bold;
  165. }
  166. }
  167. @media only screen and (max-width: 386px) {
  168. .phfc span,h2{
  169. font-size:58%;
  170. }
  171. .phfc h2{
  172. font-weight: bold;
  173. }
  174. }
  175. @media only screen and (max-width: 310px) {
  176. .phfc span,h2{
  177. font-size:40%;
  178. }
  179. .phfc h2{
  180. font-weight: bold;
  181. }
  182. }
  183. </style>
  184. <?
  185. */
  186. }