diff --git a/README.md b/README.md new file mode 100644 index 0000000..9fd9c43 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +Lightbox Widget for Yii 2 +========= +- Lightbox widget based on Lightbox2 extension http://lokeshdhakar.com/projects/lightbox2/ + +Installation +------------ + +The preferred way to install this extension is through [composer](http://getcomposer.org/download/). + +Either run + +``` +php composer.phar require --prefer-dist branchonline/yii2-lightbox "*" +``` + +or add + +```json +"branchonline/yii2-lightbox": "*" +``` + +to the require section of your composer.json. + +Usage +------------ +Once the extension is installed, simply add widget to your page as follows: + +```php +echo Lightbox::widget([ + 'files' => [ + [ + 'thumb' => 'url/to/thumb.ext', + 'original' => 'url/to/original.ext', + 'title' => 'optional title', + ], + ] +]); +``` diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..3c811a3 --- /dev/null +++ b/composer.json @@ -0,0 +1,23 @@ +{ + "name": "branchonline/yii2-lightbox", + "description": "Lightbox widget for Yii2", + "type": "yii2-extension", + "keywords": ["yii2", "module"], + "license": "Apache-2.0", + "authors": [ + { + "name": "Jap Mul", + "email": "jap@branchonline.nl" + } + ], + "require": { + "yiisoft/yii2": "*", + "bower-asset/lightbox2": "2.7.1", + }, + "autoload": { + "psr-4": { + "branchonline\\lightbox\\": "src/" + } + } +} + diff --git a/src/Lightbox.php b/src/Lightbox.php new file mode 100644 index 0000000..93f2c03 --- /dev/null +++ b/src/Lightbox.php @@ -0,0 +1,33 @@ +getView()); + } + + public function run() { + $html = ''; + foreach($this->files as $file) { + if(!isset($file['thumb']) || !isset($file['original'])) { + continue; + } + + $img = Html::img($file['thumb']); + $a = Html::a($img, $file['original'], [ + 'data-lightbox' => 'image-' . uniqid(), + 'data-title' => isset($file['title']) ? $file['title'] : '', + ]); + $html .= $a; + } + return $html; + } + +} diff --git a/src/LightboxAsset.php b/src/LightboxAsset.php new file mode 100644 index 0000000..b38868e --- /dev/null +++ b/src/LightboxAsset.php @@ -0,0 +1,23 @@ +