Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/webroot/rsrc/js/phui/behavior-phui-selectable-list.js
12241 views
1
/**
2
* @provides javelin-behavior-phui-selectable-list
3
* @requires javelin-behavior
4
* javelin-stratcom
5
* javelin-dom
6
*/
7
8
JX.behavior('phui-selectable-list', function() {
9
10
JX.Stratcom.listen('click', 'phui-oi-selectable', function(e) {
11
if (!e.isNormalClick()) {
12
return;
13
}
14
15
// If the user clicked a link, ignore it.
16
if (e.getNode('tag:a')) {
17
return;
18
}
19
20
var root = e.getNode('phui-oi-selectable');
21
22
// If the user did not click the checkbox, pretend they did. This makes
23
// the entire element a click target to make changing the selection set a
24
// bit easier.
25
if (!e.getNode('tag:input')) {
26
var checkbox = getCheckbox(root);
27
checkbox.checked = !checkbox.checked;
28
29
e.kill();
30
}
31
32
setTimeout(JX.bind(null, redraw, root), 0);
33
});
34
35
function getCheckbox(root) {
36
return JX.DOM.find(root, 'input');
37
}
38
39
function redraw(root) {
40
var checkbox = getCheckbox(root);
41
JX.DOM.alterClass(root, 'phui-oi-selected', !!checkbox.checked);
42
}
43
44
});
45
46