Fossil SCM

Add JS for collapsing/expanding directories in tree-view.

joel 2014-01-06 23:42 trunk
Commit b66100d3edd1be3d06c2b7a2a177a5071eb1f036
1 file changed +41
+41
--- src/browse.c
+++ src/browse.c
@@ -588,10 +588,51 @@
588588
}
589589
}
590590
}
591591
@ </ul>
592592
@ </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>
593634
style_footer();
594635
595636
/* We could free memory used by sTree here if we needed to. But
596637
** the process is about to exit, so doing so would not really accomplish
597638
** anything useful. */
598639
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button