Code Duplication    Length = 20-21 lines in 2 locations

widgets/Vote.php 1 location

@@ 95-115 (lines=21) @@
92
    /**
93
     * Registers jQuery handler.
94
     */
95
    protected function registerJs()
96
    {
97
        $js = new JsExpression("
98
            $('body').on('click', '[data-rel=\"{$this->jsCodeKey}\"] button', function(event) {
99
                var vote = $(this).closest('[data-rel=\"{$this->jsCodeKey}\"]'),
100
                    button = $(this),
101
                    action = button.attr('data-action'),
102
                    entity = vote.attr('data-entity'),
103
                    target = vote.attr('data-target-id');
104
                jQuery.ajax({
105
                    url: '$this->voteUrl', type: 'POST', dataType: 'json', cache: false,
106
                    data: { 'VoteForm[entity]': entity, 'VoteForm[targetId]': target, 'VoteForm[action]': action },
107
                    beforeSend: function(jqXHR, settings) { $this->jsBeforeVote },
108
                    success: function(data, textStatus, jqXHR) { $this->jsChangeCounters $this->jsShowMessage },
109
                    complete: function(jqXHR, textStatus) { $this->jsAfterVote },
110
                    error: function(jqXHR, textStatus, errorThrown) { $this->jsErrorVote }
111
                });
112
            });
113
        ");
114
        $this->view->registerJs($js, View::POS_END, $this->jsCodeKey);
115
    }
116
}
117

widgets/VoteToggle.php 1 location

@@ 116-135 (lines=20) @@
113
    /**
114
     * Registers jQuery handler.
115
     */
116
    protected function registerJs()
117
    {
118
        $js = new JsExpression("
119
            $('body').on('click', '[data-rel=\"{$this->jsCodeKey}\"] button', function(event) {
120
                var vote = $(this).closest('[data-rel=\"{$this->jsCodeKey}\"]'),
121
                    button = $(this),
122
                    entity = vote.attr('data-entity'),
123
                    target = vote.attr('data-target-id');
124
                jQuery.ajax({
125
                    url: '$this->voteUrl', type: 'POST', dataType: 'json', cache: false,
126
                    data: { 'VoteForm[entity]': entity, 'VoteForm[targetId]': target, 'VoteForm[action]': 'toggle' },
127
                    beforeSend: function(jqXHR, settings) { $this->jsBeforeVote },
128
                    success: function(data, textStatus, jqXHR) { $this->jsChangeCounters $this->jsShowMessage },
129
                    complete: function(jqXHR, textStatus) { $this->jsAfterVote },
130
                    error: function(jqXHR, textStatus, errorThrown) { $this->jsErrorVote }
131
                });
132
            });
133
        ");
134
        $this->view->registerJs($js, View::POS_END, $this->jsCodeKey);
135
    }
136
}
137