Advertisement
slo_nik

fotorama

Aug 14th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.45 KB | None | 0 0
  1. <?php
  2.            $allImg = '';
  3.  
  4.            foreach($images as $val) :
  5.            
  6.              if($val->itemId != 0) :
  7.  
  8.               $title = ($val->getTitle() == null) ? Yii::t('app', 'SITE_NAME') : $val->getTitle();
  9.               $val->year = ($val->year != null) ? $val->year.' год.' : '';
  10.  
  11.               $allImg .= "{img : '" . Url::to(['/images/default/download/', 'id' => $val->id]) . "', caption: '\"" . $title . "\", " . $val->getDesc() . ", " . $val->year . "', height: '64px', id: 'hash_" . $val->id . "'},";
  12.  
  13.              endif;
  14.  
  15.            endforeach;
  16.  
  17. $url = Yii::$app->UrlManager->createUrl(['/site/select']);
  18. $t = Yii::t('app', 'SITE_NAME');
  19. $script = <<<JS
  20.  
  21.   var fotoDiv = $('.fotorama').fotorama({
  22.                     width: '100%',
  23.                     height: '75%',
  24.                     thumbratio: 'auto',
  25.                     hash: true,
  26.                     nav: 'thumbs',
  27.                     data: [
  28.                        $allImg
  29.                     ]
  30.                   })
  31.  
  32. var fotorama = fotoDiv.data('fotorama')
  33.   $("#email-form").on("change", function(){
  34.      
  35.         var data = $(this).serialize();
  36.  
  37.         $.ajax({
  38.           url : '$url',
  39.           type : 'POST',
  40.           data : data,
  41.           dataType : 'json',
  42.           success : function(responce){
  43.               var imagesArray = new Array();
  44.               var countObj = responce.files.length
  45.               if(countObj > 0){
  46.                 for(var i = 0; i < countObj; i++){
  47.                   if(responce.files[i].title == null){
  48.                     responce.files[i].title = "$t"
  49.                   }
  50.                   if(responce.files[i].description == null){
  51.                      responce.files[i].description = ""
  52.                   }
  53.                   if(responce.files[i].year == null){
  54.                      responce.files[i].year = ""
  55.                   }
  56.                   else{
  57.                      responce.files[i].year = responce.files[i].year + " год"
  58.                   }
  59.                   imagesArray.push({img: responce.files[i].img, id: "hash_" + responce.files[i].id,
  60.                                     caption: "\"" +  responce.files[i].title + "\", " + responce.files[i].description + ", " + responce.files[i].year});
  61.                 }
  62.               }
  63.  
  64.                fotorama.load(
  65.                     imagesArray
  66.                   )
  67.           }
  68.         })
  69.  
  70.   })
  71.  
  72. JS;
  73.  
  74.  $this->registerJs($script, View::POS_END);
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement