Cum am făcut sidebar-ul cu elementele ”collapsed”?
Așa (șutit de la Peter):
<SCRIPT type=”text/javascript”> 1:
2: function CollapsiblePanel(elem) {
3: if (!elem) {
4: return null;
5: }
6:
7: // Close ‘this’.
8: var self = this;
9:
10: this.toggle = function() {
11: if (self.sibling.style.display == „none”) {
12: self.elem.innerHTML = self.collapseHTML + self.title;
13: self.sibling.style.display = „block”;
14: } else {
15: self.elem.innerHTML = self.expandHTML + self.title;
16: self.sibling.style.display = „none”;
17: }
18: }
19:
20: this.elem = elem;
21: this.title = elem.innerHTML;
22: this.expandHTML = ‘<img src=”INSERT URL TO EXPAND IMAGE HERE” width=”9″ height=”9″> ’;
23: this.collapseHTML = ‘<img src=”INSERT URL TO COLLAPSE IMAGE HERE” width=”9″ height=”9″> ’;
24: this.elem.style.cursor = „pointer”;
25:
26: this.sibling = elem.nextSibling;
27: if (this.sibling.nodeType == 3) {
28: // Get second sibling if text node is next.
29: this.sibling = this.sibling.nextSibling;
30: }
31:
32: elem.onclick = this.toggle;
33: this.toggle();
34: }
35:
36: window.onload = function() {
37: // Enumerate headers after document is loaded.
38: var i, h3s = document.body.getElementsByTagName(„h3”);
39: for (i = 0; i < h3s.length; i++) {
40: var elem = h3s.item(i);
41: //Modify this OR statement with the names of the sidebar lists you want to make collapsible
42: if (elem.innerHTML == „Archives” || elem.innerHTML == „Tags”) {
43: new CollapsiblePanel(elem);
44: }
45: if (elem.innerHTML == „Recent Posts”) {
46: elem.innerHTML = „Latest Bits + Bytes”;
47: }
48: }
49: }
</SCRIPT>
Filed under: Blogging