LP#1424815: 'Read more' accordion in record view
[evergreen-equinox.git] / Open-ILS / web / js / ui / default / opac / accordion.js
1 function toggleAccordion(elm, alternate_elm) {
2     var truncatedSpan;
3     var ellipse;
4     
5     if (!alternate_elm) {
6         var children = getSiblings(elm);
7         for (i = 0; i < children.length; i++) {
8             if (children[i].className == "truncated") {
9                 truncatedSpan = children[i];
10             } else if (children[i].className == "truncEllipse") {
11                 ellipse = children[i];
12             }
13         }
14     } else {
15         truncatedSpan = iterateChildren(alternate_elm, 'truncated');
16         ellipse = iterateChildren(alternate_elm, 'truncEllipse');
17     }
18
19     if (truncatedSpan.style.display == "none") {
20         truncatedSpan.style.display = "inline";
21         elm.innerHTML = eg_opac_i18n.EG_READ_LESS;
22         ellipse.style.display = "none";
23     } else {
24         truncatedSpan.style.display = "none";
25         elm.innerHTML = eg_opac_i18n.EG_READ_MORE;
26         ellipse.style.display = "inline";
27     }
28 }
29
30 function getSiblings(elm) {
31     return Array.prototype.filter.call(elm.parentNode.children, function (sibling) {
32                 return sibling !== elm;
33         });
34 }
35
36 function iterateChildren(elm, classname) {
37     var child_to_return;
38     if (elm.className == classname) return elm;
39     for (i = 0; i < elm.children.length; i++) {
40         if (elm.children[i].className == classname) {
41             return elm.children[i];
42         } else {
43             child_to_return = iterateChildren(elm.children[i], classname);
44         }
45     }
46     if (child_to_return) return child_to_return;
47 }