forked from newerton/yii2-fancybox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFancyBox.php
94 lines (77 loc) · 2.17 KB
/
FancyBox.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* @copyright Copyright (c) 2014 Newerton Vargas de Araújo
* @link http://newerton.com.br
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package yii2-fancybox
* @version 1.0.0
*/
namespace newerton\fancybox;
use yii\base\Widget;
use yii\helpers\Json;
use yii\base\InvalidConfigException;
/**
* fancyBox is a tool that offers a nice and elegant way to add zooming
* functionality for images, html content and multi-media on your webpages
*
* @author Newerton Vargas de Araújo <[email protected]>
* @since 1.0
*/
class FancyBox extends Widget {
/**
* @var type string target of the widget
*/
public $target;
/**
* @var type boolean whether to enable the easing functions. You must set the eansing on $config
*/
public $helpers = false;
/**
* @var type bollean whether to enable mouse interaction
*/
public $mouse = true;
// @ array of config settings for fancybox
/**
*
* @var type array of config settings for fancybox
*/
public $config = [];
/**
* @var array to use for $.fancybox.open( [group], [options] ) scenario
*/
public $group = [];
/**
* @inheritdoc
*/
public function init() {
if (is_null($this->target)) {
throw new InvalidConfigException('"FancyBox.target has not been defined.');
}
// publish the required assets
$this->registerClientScript();
}
/**
* @inheritdoc
*/
public function run() {
$view = $this->getView();
$config = Json::encode($this->config);
if(!empty($this->group)){
$config = Json::encode($this->group).','.$config;
}
$view->registerJs("jQuery('{$this->target}').fancybox({$config});");
}
/**
* Registers required script for the plugin to work as DatePicker
*/
public function registerClientScript() {
$view = $this->getView();
FancyBoxAsset::register($view);
if ($this->mouse) {
MousewheelAsset::register($view);
}
if ($this->helpers) {
FancyBoxHelpersAsset::register($view);
}
}
}