1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hauntd\vote\widgets; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\bootstrap\Html; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @author Alexander Kononenko <[email protected]> |
10
|
|
|
* @package hauntd\vote\widgets |
11
|
|
|
*/ |
12
|
|
|
class Favorite extends VoteToggle |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
public $jsCodeKey = 'vote-favorite'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
public $viewFile = 'favorite'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
|
|
public function getDefaultOptions() |
28
|
|
|
{ |
29
|
|
|
return array_merge(parent::getDefaultOptions(), [ |
30
|
|
|
'class' => 'vote-toggle vote-toggle-favorite', |
31
|
|
|
]); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
|
public function getDefaultButtonOptions() |
38
|
|
|
{ |
39
|
|
|
return array_merge(parent::getDefaultButtonOptions(), [ |
40
|
|
|
'icon' => Html::icon('glyphicon glyphicon-star'), |
41
|
|
|
'label' => Yii::t('vote', 'Add to favorites'), |
42
|
|
|
'labelAdd' => Yii::t('vote', 'Add to favorites'), |
43
|
|
|
'labelRemove' => Yii::t('vote', 'Remove from favorites'), |
44
|
|
|
]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Initialize with default events. |
49
|
|
|
* |
50
|
|
|
* @param string $selector |
51
|
|
|
*/ |
52
|
|
|
public function initJsEvents($selector) |
53
|
|
|
{ |
54
|
|
|
parent::initJsEvents($selector); |
55
|
|
|
$this->jsChangeCounters = " |
56
|
|
|
if (data.success) { |
57
|
|
|
$('$selector .vote-count').text(data.aggregate.positive); |
58
|
|
|
var label = ''; |
59
|
|
|
if (data.toggleValue) { |
60
|
|
|
label = button.attr('data-label-remove'); |
61
|
|
|
button.addClass('vote-active'); |
62
|
|
|
} else { |
63
|
|
|
label = button.attr('data-label-add'); |
64
|
|
|
button.removeClass('vote-active'); |
65
|
|
|
} |
66
|
|
|
button.find('.vote-label').text(label); |
67
|
|
|
} |
68
|
|
|
"; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|