forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc-search.js
More file actions
101 lines (86 loc) · 3 KB
/
Copy pathdoc-search.js
File metadata and controls
101 lines (86 loc) · 3 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
$(function () {
// search form
var form = jQuery("#search_form");
function anyAdvancedActive() {
var advanced = false;
var by = form.find("input[name=by]:checked");
if (by.length > 0)
by.closest(".search_field").find("input,select").not("input[name=by]").each(function () {
if ($.trim(this.value))
advanced = true;
});
return advanced;
}
function toggleSubmit() {
var nameSearch = $.trim($("#id_name").val());
form.find("input[type=submit]").get(0).disabled = !nameSearch && !anyAdvancedActive();
}
function togglePlusMinus(toggler, toggled) {
var img = toggler.find("img").get(0);
if (toggled.is(":hidden")) {
toggled.show();
img.src = "/images/minus.png";
} else {
toggled.hide();
img.src = "/images/plus.png";
}
}
function updateAdvanced() {
form.find("input[name=by]:checked").closest(".search_field").find("input,select").not("input[name=by]").each(function () {
this.disabled = false;
});
form.find("input[name=by]").not(":checked").closest(".search_field").find("input,select").not("input[name=by]").each(function () {
this.disabled = true;
});
toggleSubmit();
}
if (form.length > 0) {
form.find(".search_field input[name=by]").closest("label").click(updateAdvanced);
form.find(".search_field input,select")
.change(toggleSubmit).click(toggleSubmit).keyup(toggleSubmit);
form.find(".toggle_advanced").click(function () {
var advanced = $(this).next();
advanced.find('.search_field input[type="radio"]').attr("checked", false);
togglePlusMinus($(this), advanced);
updateAdvanced();
});
updateAdvanced();
}
// search results
$('.search-results .addtolist a').click(function(e) {
e.preventDefault();
var trigger = $(this);
$.ajax({
url: trigger.attr('href'),
type: 'POST',
cache: false,
dataType: 'json',
success: function(response){
if (response.success) {
trigger.replaceWith('added');
}
}
});
});
$("a.ballot-icon").click(function (e) {
e.preventDefault();
$.ajax({
url: $(this).data("popup"),
success: function (data) {
showModalBox(data);
},
error: function () {
showModalBox("<div>Error retrieving popup content</div>");
}
});
}).each(function () {
// bind right-click shortcut
var editPositionUrl = $(this).data("edit");
if (editPositionUrl) {
$(this).bind("contextmenu", function (e) {
e.preventDefault();
window.location = editPositionUrl;
});
}
});
});