adding all weblabels from weblabels.fsf.org
[weblabels.fsf.org.git] / www.fsf.org / 20131028 / files / static.fsf.org / plone2012 / collapsibleformfields.js
CommitLineData
5a920362 1
2/* - collapsibleformfields.js - */
3/* This code collapses fields in forms
4 * It is used in plone_forms/search_form.pt
5 *
6 * Creates a jQuery function to install a click handler that will
7 * collapse/expand form fields.
8 * On page load, runs it for $('.field.collapsible').
9 *
10 * It uses the following markup:
11 *
12 * <div class="collapsible'>
13 * <label class="collapser"> label of the field </label>
14 * <div class="collapse"> block to collapse </div>
15 * </div>
16 *
17 */
18
19
20(function($) {
21
22$.fn.do_search_collapse = function() {
23
24 function check_used(element) {
25 var e = $(element);
26
27 // is there a number of checkboxs with a toggle box
28 if (e.find('input[id$=_toggle]:checkbox').length > 0) {
29 // and the toggle checkbox is not checked.
30 if (e.find('input[id$=_toggle]:checkbox:checked').length === 0) {
31 return true;
32 }
33 }
34
35 // is there a normal text input fields that is not empty (=has a value)
36 if(e.find(':text[value]').length > 0) {
37 return true;
38 }
39
40 // drop downs
41 // we have an option marked as the default option
42 if(e.find('select .default_option').length > 0) {
43 // and this default option isn't selected
44 if(e.find('select .default_option:selected').length === 0) {
45 return true;
46 }
47 }
48 return false;
49 }
50
51 return this.each( function() {
52 var indicator = $(this).find('.collapser:first'),
53 collapse = $(this).find('.collapse:first');
54
55 // install click handler
56 indicator.click(function() {
57 var container = $(this).parent(),
58 target = container.find('.collapse:first');
59
60 target.slideToggle('normal');
61 $(this).toggleClass('expanded');
62 $(this).toggleClass('collapsed');
63 });
64
65 if (check_used(this)) {
66 indicator.addClass('expanded');
67 } else {
68 collapse.hide();
69 indicator.addClass('collapsed');
70 }
71 });
72};
73
74jQuery(function($){$('.field.collapsible').do_search_collapse();});
75
76
77}(jQuery));
78