annotate js/mpiwg.js @ 103:79a198e7b1b7

foldable table rows.
author casties
date Mon, 27 May 2013 11:32:30 +0200
parents 04a26a5d3d1d
children bf3dc3a12147 782477730916
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66
68b3d71eed27 formatting for preprint list. javascript for foldable divs.
casties
parents:
diff changeset
1 /*
68b3d71eed27 formatting for preprint list. javascript for foldable divs.
casties
parents:
diff changeset
2 * Javascript for MPIWG website
88
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
3 */
66
68b3d71eed27 formatting for preprint list. javascript for foldable divs.
casties
parents:
diff changeset
4
68b3d71eed27 formatting for preprint list. javascript for foldable divs.
casties
parents:
diff changeset
5 $(document).ready(function() {
88
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
6 /*
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
7 * autosubmit forms
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
8 */
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
9 $('form.autosubmit').find('.autosubmit').change(function() {
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
10 this.form.submit();
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
11 });
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
12 // hide submit button
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
13 $('form.autosubmit input[type="submit"].autosubmit').hide();
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
14
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
15 /*
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
16 * foldout divs
103
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
17 *
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
18 * foldable: .foldable is ancestor of .fold_head and .fold_body
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
19 * that are folded simultaneously.
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
20 *
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
21 * foldableById: .foldableById is ancestor of multiple .fold_head and .fold_body
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
22 * where each pair has a common unique .foldId_xxx.
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
23 *
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
24 * Clicking on .fold_head folds and unfolds .fold_body.
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
25 *
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
26 * If .foldable has .initially_open .fold_body is initially shown, else its
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
27 * initally hidden.
88
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
28 */
103
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
29 $('.foldable').each(function () {
88
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
30 var $this = $(this);
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
31 var $head = $this.find('.fold_head');
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
32 var $img = $head.find('img');
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
33 var $body = $this.find('.fold_body');
103
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
34 $head.on('click', function () {
88
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
35 $body.slideToggle('fast');
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
36 $img.toggle();
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
37 }).css('cursor', 'pointer');
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
38 if (! $this.hasClass('initially_open')) {
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
39 // hide body initially
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
40 $body.hide();
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
41 $img.toggle();
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
42 }
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
43 });
103
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
44 $('.foldableById').each(function () {
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
45 var $container = $(this);
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
46 var io = $container.hasClass('initially_open');
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
47 var $heads = $container.find('.fold_head');
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
48 $heads.each(function () {
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
49 var $this = $(this);
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
50 var $img = $this.find('img');
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
51 var id = null;
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
52 // find id in class
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
53 var cls = $this.attr('class').split(' ');
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
54 for (var i = 0; i < cls.length; ++i) {
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
55 var c = cls[i];
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
56 if (c.startsWith('foldId_')) {
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
57 id = c;
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
58 break;
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
59 }
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
60 }
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
61 if (id == null) return;
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
62 // get body using id
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
63 var $body = $container.find('.fold_body.'+id);
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
64 $this.on('click', function () {
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
65 $body.slideToggle('fast');
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
66 $img.toggle();
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
67 });
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
68 if (!io) {
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
69 // hide body initially
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
70 $body.hide();
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
71 $img.toggle();
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
72 }
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
73 }).css('cursor', 'pointer');
79a198e7b1b7 foldable table rows.
casties
parents: 88
diff changeset
74 });
88
04a26a5d3d1d .foldable.initially_open implementation.
casties
parents: 66
diff changeset
75 });