-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathscript.js
76 lines (71 loc) · 2.8 KB
/
script.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
jQuery( document ).ready( function () {
/* Hovering a language in the shortlist highlights it in the long list */
jQuery( "#langshortlist" ).children().each((i, elt) => {
elt.addEventListener('mouseover', event => {
let lang = elt.textContent;
jQuery( elt ).addClass('active');
jQuery( `#langlonglist li[val=${lang}]` ).addClass('active')
.parent().closest('li').addClass('active');
});
elt.addEventListener('mouseout', event => {
let lang = elt.textContent;
jQuery( elt ).removeClass('active');
jQuery( `#langlonglist li[val=${lang}]` ).removeClass('active')
.parent().closest('li').removeClass('active');
});
});
/* Checking the shortlist boxes updates the text form and the longlist */
jQuery("#langshortlist input").each((i, elt) => {
elt.addEventListener('change', event => {
let checkboxes = jQuery( "#langshortlist input" ).toArray();
let text = checkboxes.filter(e => e.checked)
.map(e => e.labels[0].textContent)
.join();
jQuery( "input[name='langdelete_w']" )
.val(text)
.addClass('ani-ld-text-added');
});
elt.addEventListener('change', event => {
let lang = event.target.labels[0].textContent;
let $elt = jQuery( event.target );
if ($elt.prop("checked")) {
jQuery( `#langlonglist li[val=${lang}]` ).addClass('enabled');
$elt.parents("li").first().addClass('enabled');
} else {
jQuery( `#langlonglist li[val=${lang}]` ).removeClass('enabled');
$elt.parents("li").first().removeClass('enabled');
}
});
});
// Remove animation class when done
jQuery( "input[name='langdelete_w']" ).on("animationend", event => {
if (event.originalEvent.animationName == 'ld-text-added') {
jQuery( event.target ).removeClass('ani-ld-text-added');
}
});
/* Changing the text in the form checks the right checkboxes
* (and animates them) */
jQuery( "input[name='langdelete_w']" ).on('input', event => {
let t = jQuery( event.target ).val();
let langs = jQuery( "#langshortlist input[type='checkbox']" )
.map((i, elt) => elt.labels[0].textContent )
.toArray();
let to_check = t.split(',');
for (let lang of langs) {
let $e = jQuery( `input#shortlang-${lang}` );
let will_check = to_check.indexOf(lang) != -1;
if ($e.prop("checked") ^ will_check) {
$e
.prop("checked", will_check)
.addClass('ani-ld-text-added');
}
}
});
// Remove animation class when done
jQuery( "#langshortlist input[type='checkbox']" ).on("animationend", event => {
if (event.originalEvent.animationName == 'ld-text-added') {
jQuery( event.target ).removeClass('ani-ld-text-added');
}
});
/* */
});