Blame view

frontend/components/BgWidget.php 939 Bytes
ecf49b1b   Administrator   second
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  <?php
  namespace frontend\components;
  
  use Yii;
  use yii\base\Widget;
  use yii\helpers\Html;
  use yii\web\View;
  use common\models\Bg;
  
  class BgWidget extends Widget{
  	public $bg;
  	
  	public function init(){
  		parent::init();
                  $view = Yii::$app->getView();
                  $view->registerJs("
                      var heightR = $('.f').height();// высота экрана
                      var widthR = $(window).width();// ширина экрана
  
                      $('#bg').css({'height':heightR+100}); 
                  ", View::POS_READY, 'bg');                 
  		$this->bg = Bg::find()->orderBy('random()')->one();
  	}
  	
8e889dc6   Administrator   20.07.16
25
26
27
  	public function run(){
  		if(isset($this->bg) && !empty($this->bg)){
  			return '<a id="bg" style="width:100%;height:100%;position:absolute;z-index:-1;background: url(/storage/bg/'.$this->bg->image.') center top no-repeat;" href="'.$this->bg->url.'" title="'.$this->bg->title.'"></a>
ecf49b1b   Administrator   second
28
  ';
8e889dc6   Administrator   20.07.16
29
30
  		}
  
ecf49b1b   Administrator   second
31
32
33
  	}
  }
  ?>