-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jap Mul Eindbaas
committed
May 14, 2015
0 parents
commit d8b51c6
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
], | ||
] | ||
]); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/" | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]; | ||
} | ||
|