Code Duplication    Length = 28-29 lines in 2 locations

widgets/Vote.php 1 location

@@ 63-90 (lines=28) @@
60
    /**
61
     * Initialize with default events.
62
     */
63
    public function initJsEvents()
64
    {
65
        parent::initJsEvents();
66
        $selector = $this->getSelector($this->options['class']);
67
        if (!isset($this->jsChangeCounters)) {
68
            $this->jsChangeCounters = "
69
                if (typeof(data.success) !== 'undefined') {
70
                    $('$selector .vote-count span').text(data.aggregate.positive - data.aggregate.negative);
71
                    vote.find('button').removeClass('vote-active');
72
                    button.addClass('vote-active');
73
                }
74
            ";
75
        }
76
        if (!isset($this->jsBeforeVote)) {
77
            $this->jsBeforeVote = "
78
                $('$selector .vote-btn').prop('disabled', 'disabled').addClass('vote-loading');
79
                $('$selector .vote-count')
80
                    .addClass('vote-loading')
81
                    .append('<div class=\"vote-loader\"><span></span><span></span><span></span></div>');
82
            ";
83
        }
84
        if (!isset($this->jsAfterVote)) {
85
            $this->jsAfterVote = "
86
                $('$selector .vote-btn').prop('disabled', false).removeClass('vote-loading');
87
                $('$selector .vote-count').removeClass('vote-loading').find('.vote-loader').remove();
88
            ";
89
        }
90
    }
91
92
    /**
93
     * Registers jQuery handler.

widgets/VoteToggle.php 1 location

@@ 83-111 (lines=29) @@
80
    /**
81
     * Initialize with default events.
82
     */
83
    public function initJsEvents()
84
    {
85
        parent::initJsEvents();
86
        $selector = $this->getSelector($this->options['class']);
87
        if (!isset($this->jsChangeCounters)) {
88
            $this->jsChangeCounters = "
89
                if (typeof(data.success) !== 'undefined') {
90
                    $('$selector .vote-count').text(data.aggregate.positive);
91
                    if (data.toggleValue) {
92
                        button.addClass('vote-active');
93
                    } else {
94
                        button.removeClass('vote-active');
95
                    }
96
                }
97
            ";
98
        }
99
        if (!isset($this->jsBeforeVote)) {
100
            $this->jsBeforeVote = "
101
                $('$selector .vote-btn').prop('disabled', 'disabled').addClass('vote-loading');
102
                $('$selector .vote-btn').append('<div class=\"vote-loader\"><span></span><span></span><span></span></div>');
103
            ";
104
        }
105
        if (!isset($this->jsAfterVote)) {
106
            $this->jsAfterVote = "
107
                $('$selector .vote-btn').prop('disabled', false).removeClass('vote-loading');
108
                $('$selector .vote-btn .vote-loader').remove();
109
            ";
110
        }
111
    }
112
113
    /**
114
     * Registers jQuery handler.