-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextMistakeWidget.php
114 lines (101 loc) · 3.16 KB
/
TextMistakeWidget.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* TextMistake class file.
*
* @property string $assetsPath
* @property string $assetsUrl
* @property array $plugins
*
* @author Khramov Alexsandr <[email protected]>
* @version 0.1
*
* @link https://github.com/corpsepk/text-mistake
*/
class TextMistakeWidget extends CWidget
{
/**
* Assets package ID.
*/
const PACKAGE_ID = 'textmistake';
/**
* @var array {@link http://tarampampam.github.io/jquery.textmistake/ options}.
*/
public $options = array();
/**
* @var array
*/
public $package = array();
/**
* Init widget.
*/
public function init()
{
parent::init();
$this->options = array_merge($this->defaultOptions, $this->options);
$this->registerClientScript();
}
/**
* Register CSS and Script.
*/
protected function registerClientScript()
{
// Prepare script package.
$this->package = array_merge(array(
'baseUrl' => $this->getAssetsUrl(),
'js' => array(
YII_DEBUG ? 'jquery.textmistake.js' : 'jquery.textmistake.min.js',
),
'depends' => array(
'jquery',
),
), $this->package);
$clientScript = Yii::app()->getClientScript();
$options = CJavaScript::encode($this->options);
$clientScript
->addPackage(self::PACKAGE_ID, $this->package)
->registerPackage(self::PACKAGE_ID)
->registerScript(
$this->id,
'jQuery(document).textmistake('.$options.');',
CClientScript::POS_READY
);
}
/**
* Get the assets path.
* @return string
*/
public function getAssetsPath()
{
return dirname(__FILE__) . '/assets';
}
/**
* Publish assets and return url.
* @return string
*/
public function getAssetsUrl()
{
return Yii::app()->getAssetManager()->publish($this->getAssetsPath());
}
public function getDefaultOptions()
{
return array(
'mailTo' => '[email protected]',
'l10n' => array(
'title' => Yii::t('TextMistakeWidget.widget', 'Report a typo author:'),
'urlHint' => Yii::t('TextMistakeWidget.widget', 'Url of the page with error:'),
'errTextHint' => Yii::t('TextMistakeWidget.widget', 'Text with the error:'),
'yourComment' => Yii::t('TextMistakeWidget.widget', 'Your comment:'),
'userComment' => Yii::t('TextMistakeWidget.widget', 'Comment by user:'),
'commentPlaceholder' => Yii::t('TextMistakeWidget.widget', 'Type comment'),
'cancel' => Yii::t('TextMistakeWidget.widget', 'Cancel'),
'send' => Yii::t('TextMistakeWidget.widget', 'Send'),
'mailSubject' => Yii::t('TextMistakeWidget.widget', 'Typo on the site'),
'mailTitle' => Yii::t('TextMistakeWidget.widget', 'Typo on the site'),
'mailSended' => Yii::t('TextMistakeWidget.widget', 'Notification sent'),
'mailSendedDesc' => Yii::t('TextMistakeWidget.widget', 'Your notification has been sent successfully. Thank you for your feedback!'),
'mailNotSended' => Yii::t('TextMistakeWidget.widget', 'Sending error'),
'mailNotSendedDesc' => Yii::t('TextMistakeWidget.widget', 'Your message has not been sent, sorry.'),
)
);
}
}