-
Notifications
You must be signed in to change notification settings - Fork 7
/
CropImage.php
72 lines (63 loc) · 1.79 KB
/
CropImage.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
<?php
namespace mdm\widgets;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\widgets\InputWidget;
/**
* Description of CropImage
*
* @author Misbahul D Munir <[email protected]>
* @since 1.0
*/
class CropImage extends InputWidget
{
/**
* @var array the HTML attributes for the input tag.
* @see Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $imgOptions = [];
/**
*
* @var array
*/
public $clientOptions = [];
/**
*
* @var string
*/
public $cropParam = 'crop';
/**
* @inheritdoc
*/
public function init()
{
parent::init();
}
/**
* @inheritdoc
*/
public function run()
{
$id = $this->options['id'] = $this->getId();
Html::addCssClass($this->options, 'dcorpbox');
Html::addCssClass($this->imgOptions, 'content');
CropAsset::register($this->getView());
$clientOptions = $this->clientOptions;
$this->imgOptions['id'] = $id . '-img';
$clientOptions['imgTemplate'] = Html::tag('img', '',$this->imgOptions);
$opts = Json::encode($clientOptions);
$js = "jQuery('#{$id}').dCropBox($opts);";
$this->getView()->registerJs($js);
$inputOptions = ['style' => 'visibility:hidden;', 'class' => 'file-input', 'id' => $id . '-file'];
if ($this->hasModel()) {
$fileInput = Html::activeFileInput($this->model, $this->attribute, $inputOptions);
} else {
$fileInput = Html::fileInput($this->name, $this->value, $inputOptions);
}
return $this->render('crop-image', [
'options' => $this->options,
'fileInput' => $fileInput,
'cropParam' => $this->cropParam,
]);
}
}