/
project.js
43 lines (40 loc) · 1.4 KB
/
project.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
/* $Id$ */
Drupal.behaviors.projectAuto = function (context) {
// The initially selected term, if any.
var tid;
$('div.project-taxonomy-element input:not(.projectAuto-processed)', context).addClass('projectAuto-processed').each(function () {
if (this.checked) {
tid = this.value;
}
Drupal.projectMoveElement(this.value);
$(this).click(function () {
Drupal.projectSetTaxonomy(this.value);
});
});
// Only reset taxonomy selectors when initially attaching on edit forms.
if (tid) {
Drupal.projectSetTaxonomy(tid);
}
}
Drupal.projectMoveElement = function(tid) {
// move all elements with a class linked to this tid into the
// project taxonomy fieldset (similar to module sub-terms)
$('.related-tid-' + tid).each(function() {
$('#edit-tid-' + tid + '-wrapper').append($(this).parent().remove());
});
}
Drupal.projectSetTaxonomy = function (tid) {
$('div.project-taxonomy-element select').each(function () {
// If this is the selector for the currently selected term or a
// related element, show it (in case it was previously hidden).
if (this.id == 'edit-tid-' + tid || $(this).hasClass('related-tid-' + tid)) {
// Hide not the select but its containing div (which also contains
// the label).
$(this).parents('div.form-item').show();
}
// Otherwise, hide it.
else {
$(this).parents('div.form-item').hide();
}
});
}