Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jap Mul Eindbaas committed May 14, 2015
0 parents commit d8b51c6
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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',
],
]
]);
```
23 changes: 23 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]"
}
],
"require": {
"yiisoft/yii2": "*",
"bower-asset/lightbox2": "2.7.1",
},
"autoload": {
"psr-4": {
"branchonline\\lightbox\\": "src/"
}
}
}

33 changes: 33 additions & 0 deletions src/Lightbox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace branchonline\lightbox;

use yii\base\Widget;
use yii\helpers\Html;

class Lightbox extends Widget {

public $files = [];

public function init() {
LightboxAsset::register($this->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;
}

}
23 changes: 23 additions & 0 deletions src/LightboxAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace branchonline\lightbox;

use yii\web\AssetBundle;

class LightboxAsset extends AssetBundle {

public $sourcePath = '@bower/lightbox2';

public $js = [
'/js/lightbox.min.js',
];

public $css = [
'css/lightbox.css'
];

public $depends = [
'yii\web\JqueryAsset',
];
}

0 comments on commit d8b51c6

Please sign in to comment.