-
-
Notifications
You must be signed in to change notification settings - Fork 277
/
EditList.js
84 lines (69 loc) · 1.99 KB
/
EditList.js
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
/*
* Copyright (C) 2015 MetaBrainz Foundation
*
* This file is part of MusicBrainz, the open internet music database,
* and is licensed under the GPL version 2, or (at your option) any
* later version: http://www.gnu.org/licenses/gpl-2.0.txt
*/
import $ from 'jquery';
import MB from '../../MB.js';
var SELECTED_CLASS = {
'1': 'vote-yes',
'0': 'vote-no',
'-1': 'vote-abs',
};
MB.Control.EditList = function (container) {
var self = {};
var $container = $(container);
self.initialize = function () {
var $voteOptions = $container
.find('input[type="radio"]')
.first()
.parents('.voteopts')
.clone()
.addClass('overall-vote');
$voteOptions.find('label').each(function () {
$(this).attr('for', $(this).attr('for').replace(/id-enter-vote.vote.\d+/, 'vote-all'));
});
$voteOptions.find('input').each(function () {
$(this).attr('id', $(this).attr('id').replace(/id-enter-vote.vote.\d+/, 'vote-all'));
$(this).attr('name', 'vote-on-all');
});
$voteOptions.find(':input').prop('checked', false);
$voteOptions.find('.vote').attr('class', 'vote');
$voteOptions.prepend(
$('<div>').text(l('Vote on all edits:')),
);
/*
* :nth-child would make more sense, but I couldn't get it working
* - ocharles
*/
$voteOptions.find('input').each(function (i) {
$(this).click(function () {
$container.find('div.voteopts').each(function () {
$(this)
.find('input')
.eq(i)
.prop('checked', true)
.change();
});
});
});
$container.before($voteOptions);
};
self.initialize();
return self;
};
$(function () {
$('div.vote input[type="radio"]').change(function () {
$(this)
.parents('.voteopts')
.find('.vote')
.attr('class', 'vote');
$(this)
.parent('label')
.parent('.vote')
.addClass(SELECTED_CLASS[$(this).val()]);
});
$('div.vote input[checked="checked"]').change();
});