├── README.md ├── composer.json └── src ├── Lightbox.php └── LightboxAsset.php /README.md: -------------------------------------------------------------------------------- 1 | Lightbox Widget for Yii 2 2 | ========= 3 | - Lightbox widget based on Lightbox2 extension http://lokeshdhakar.com/projects/lightbox2/ 4 | 5 | Installation 6 | ------------ 7 | 8 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). 9 | 10 | Either run 11 | 12 | ``` 13 | php composer.phar require --prefer-dist branchonline/yii2-lightbox "*" 14 | ``` 15 | 16 | or add 17 | 18 | ```json 19 | "branchonline/yii2-lightbox": "*" 20 | ``` 21 | 22 | to the require section of your composer.json. 23 | 24 | Usage 25 | ------------ 26 | Once the extension is installed, simply add widget to your page as follows: 27 | 28 | ```php 29 | use branchonline\lightbox\Lightbox; 30 | 31 | echo Lightbox::widget([ 32 | 'files' => [ 33 | [ 34 | 'thumb' => 'url/to/thumb.ext', 35 | 'original' => 'url/to/original.ext', 36 | 'title' => 'optional title', 37 | ], 38 | ] 39 | ]); 40 | ``` 41 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "branchonline/yii2-lightbox", 3 | "description": "Lightbox widget for Yii2", 4 | "type": "yii2-extension", 5 | "keywords": ["yii2", "module"], 6 | "license": "Apache-2.0", 7 | "authors": [ 8 | { 9 | "name": "Jap Mul", 10 | "email": "jap@branchonline.nl" 11 | } 12 | ], 13 | "require": { 14 | "yiisoft/yii2": "*", 15 | "bower-asset/lightbox2": "2.7.1" 16 | }, 17 | "autoload": { 18 | "psr-4": { 19 | "branchonline\\lightbox\\": "src/" 20 | } 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/Lightbox.php: -------------------------------------------------------------------------------- 1 | getView()); 17 | } 18 | 19 | /** @inheritdoc */ 20 | public function run() { 21 | $html = ''; 22 | foreach ($this->files as $file) { 23 | if (!isset($file['thumb']) || !isset($file['original'])) { 24 | continue; 25 | } 26 | 27 | $attributes = [ 28 | 'data-title' => isset($file['title']) ? $file['title'] : '', 29 | ]; 30 | 31 | if (isset($file['group'])) { 32 | $attributes['data-lightbox'] = $file['group']; 33 | } else { 34 | $attributes['data-lightbox'] = 'image-' . uniqid(); 35 | } 36 | 37 | $thumbOptions = isset($file['thumbOptions']) ? $file['thumbOptions'] : []; 38 | $linkOptions = isset($file['linkOptions']) ? $file['linkOptions'] : []; 39 | 40 | $img = Html::img($file['thumb'], $thumbOptions); 41 | $a = Html::a($img, $file['original'], ArrayHelper::merge($attributes, $linkOptions)); 42 | 43 | $html .= $a; 44 | } 45 | return $html; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/LightboxAsset.php: -------------------------------------------------------------------------------- 1 |