forked from corpsepk/yii2-magnific-popup
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MagnificPopup.php
executable file
·99 lines (85 loc) · 2.7 KB
/
MagnificPopup.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
95
96
97
98
99
<?php
namespace porcelanosa\magnificPopup;
use yii;
use yii\web\JsExpression;
use yii\helpers\Json;
class MagnificPopup extends \yii\base\Widget
{
/**
* Jquery selector to which element should apply the magnific-popup.
* @var string jQuery Selector
*/
public $target;
/**
* Options in the documentation for magnific-popup
* @see http://dimsemenov.com/plugins/magnific-popup/documentation.html
* @var array Magnific-Popup Option
*/
public $options = array();
/**
* @var type
*/
public $defaultOptions = array(
'type' => 'image'
);
/**
* Language for internationalization.
* Null for auto detect.
* @var string
*/
public $language;
/**
* Effects in http://codepen.io/dimsemenov/pen/GAIkt
* @var string
* ***** LIST OF Avilable value
* 'fade', 'with-zoom', 'zoom-in', 'newspaper', 'move-horizontal', 'move-from-top', '3d-unfold', 'zoom-out'
*/
public $effect;
/**
* Alias for 'type' in option;
*
* <li>ajax</li>
* <li>iframe</li>
* <li>image</li>
* <li>inline</li>
*
* @var type string
*/
public $type;
/**
* @var string asset class
*/
public $asset = '\porcelanosa\magnificPopup\MagnificPopupAsset';
/**
* Run this widget.
* This method registers necessary javascript.
*/
public function run() {
$effectList = ['fade', 'with-zoom', 'zoom-in', 'newspaper',
'move-horizontal', 'move-from-top', '3d-unfold', 'zoom-out'
];
if ($this->effect && in_array($this->effect, $effectList)) {
$this->defaultOptions['mainClass'] = 'mfp-' . $this->effect;
$this->defaultOptions['removalDelay'] = 500;
$this->defaultOptions['callbacks'] = array(
'beforeOpen' => new JsExpression("function() {this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');}")
);
if ($this->effect == 'with-zoom') {
$this->defaultOptions = array_merge($this->defaultOptions, array(
'zoom' => array(
'enabled' => true,
),
));
}
}
if ($this->type !== null) {
$this->options['type'] = $this->type;
}
$view = $this->getView();
$asset = $this->asset;
$options = array_merge($this->defaultOptions, $this->options);
$js = "jQuery('{$this->target}').magnificPopup(" . Json::encode($options) . ");";
$asset::register($view);
$view->registerJs($js);
}
}