Fossil SCM
Add JS for collapsing/expanding directories in tree-view.
Commit
b66100d3edd1be3d06c2b7a2a177a5071eb1f036
Parent
4ee58093dd9e19c…
1 file changed
+41
+41
| --- src/browse.c | ||
| +++ src/browse.c | ||
| @@ -588,10 +588,51 @@ | ||
| 588 | 588 | } |
| 589 | 589 | } |
| 590 | 590 | } |
| 591 | 591 | @ </ul> |
| 592 | 592 | @ </ul></div> |
| 593 | + @ <script>(function(){ | |
| 594 | + @ function style(elem, prop){ | |
| 595 | + @ return window.getComputedStyle(elem).getPropertyValue(prop); | |
| 596 | + @ } | |
| 597 | + @ | |
| 598 | + @ function toggleAll(tree){ | |
| 599 | + @ var lists = tree.querySelectorAll('.subdir > ul > li ul'); | |
| 600 | + @ var display = 'block'; | |
| 601 | + @ for( var i=0; lists[i]; i++ ){ | |
| 602 | + @ if( style(lists[i], 'display')!='none'){ | |
| 603 | + @ display = 'none'; | |
| 604 | + @ break; | |
| 605 | + @ } | |
| 606 | + @ } | |
| 607 | + @ for( var i=0; lists[i]; i++ ){ | |
| 608 | + @ lists[i].style.display = display; | |
| 609 | + @ } | |
| 610 | + @ } | |
| 611 | + @ | |
| 612 | + @ function initTree(tree){ | |
| 613 | + @ tree.onclick = function( e ){ | |
| 614 | + @ var a = e.target; | |
| 615 | + @ if( a.nodeName!='A' ) return; | |
| 616 | + @ if( a.parentNode.className.indexOf('subdir')>=0 ){ | |
| 617 | + @ toggleAll(tree); | |
| 618 | + @ return false; | |
| 619 | + @ } | |
| 620 | + @ if( style(a.parentNode, 'display')=='inline' ) return; | |
| 621 | + @ var ul = a.nextSibling; | |
| 622 | + @ while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling; | |
| 623 | + @ ul.style.display = style(ul, 'display')=='none' ? 'block' : 'none'; | |
| 624 | + @ return false; | |
| 625 | + @ } | |
| 626 | + @ var subdirLink = tree.querySelectorAll('.subdir > a')[0]; | |
| 627 | + @ subdirLink.style.cursor = 'pointer'; | |
| 628 | + @ toggleAll(tree); | |
| 629 | + @ } | |
| 630 | + @ | |
| 631 | + @ var trees = document.querySelectorAll('.filetree > ul'); | |
| 632 | + @ for( var i=0; trees[i]; i++ ) initTree(trees[i]); | |
| 633 | + @ }())</script> | |
| 593 | 634 | style_footer(); |
| 594 | 635 | |
| 595 | 636 | /* We could free memory used by sTree here if we needed to. But |
| 596 | 637 | ** the process is about to exit, so doing so would not really accomplish |
| 597 | 638 | ** anything useful. */ |
| 598 | 639 |
| --- src/browse.c | |
| +++ src/browse.c | |
| @@ -588,10 +588,51 @@ | |
| 588 | } |
| 589 | } |
| 590 | } |
| 591 | @ </ul> |
| 592 | @ </ul></div> |
| 593 | style_footer(); |
| 594 | |
| 595 | /* We could free memory used by sTree here if we needed to. But |
| 596 | ** the process is about to exit, so doing so would not really accomplish |
| 597 | ** anything useful. */ |
| 598 |
| --- src/browse.c | |
| +++ src/browse.c | |
| @@ -588,10 +588,51 @@ | |
| 588 | } |
| 589 | } |
| 590 | } |
| 591 | @ </ul> |
| 592 | @ </ul></div> |
| 593 | @ <script>(function(){ |
| 594 | @ function style(elem, prop){ |
| 595 | @ return window.getComputedStyle(elem).getPropertyValue(prop); |
| 596 | @ } |
| 597 | @ |
| 598 | @ function toggleAll(tree){ |
| 599 | @ var lists = tree.querySelectorAll('.subdir > ul > li ul'); |
| 600 | @ var display = 'block'; |
| 601 | @ for( var i=0; lists[i]; i++ ){ |
| 602 | @ if( style(lists[i], 'display')!='none'){ |
| 603 | @ display = 'none'; |
| 604 | @ break; |
| 605 | @ } |
| 606 | @ } |
| 607 | @ for( var i=0; lists[i]; i++ ){ |
| 608 | @ lists[i].style.display = display; |
| 609 | @ } |
| 610 | @ } |
| 611 | @ |
| 612 | @ function initTree(tree){ |
| 613 | @ tree.onclick = function( e ){ |
| 614 | @ var a = e.target; |
| 615 | @ if( a.nodeName!='A' ) return; |
| 616 | @ if( a.parentNode.className.indexOf('subdir')>=0 ){ |
| 617 | @ toggleAll(tree); |
| 618 | @ return false; |
| 619 | @ } |
| 620 | @ if( style(a.parentNode, 'display')=='inline' ) return; |
| 621 | @ var ul = a.nextSibling; |
| 622 | @ while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling; |
| 623 | @ ul.style.display = style(ul, 'display')=='none' ? 'block' : 'none'; |
| 624 | @ return false; |
| 625 | @ } |
| 626 | @ var subdirLink = tree.querySelectorAll('.subdir > a')[0]; |
| 627 | @ subdirLink.style.cursor = 'pointer'; |
| 628 | @ toggleAll(tree); |
| 629 | @ } |
| 630 | @ |
| 631 | @ var trees = document.querySelectorAll('.filetree > ul'); |
| 632 | @ for( var i=0; trees[i]; i++ ) initTree(trees[i]); |
| 633 | @ }())</script> |
| 634 | style_footer(); |
| 635 | |
| 636 | /* We could free memory used by sTree here if we needed to. But |
| 637 | ** the process is about to exit, so doing so would not really accomplish |
| 638 | ** anything useful. */ |
| 639 |