Fossil SCM

Use history API instead of sessionStorage.

joel 2014-01-15 00:15 tree-view-enhancements
Commit 434e4538bc95f423804c4e6af1bfeb8a40644b07
1 file changed +17 -12
+17 -12
--- src/browse.c
+++ src/browse.c
@@ -643,11 +643,14 @@
643643
@
644644
@ function toggleDir(a, useInitValue){
645645
@ var ul = a.nextSibling;
646646
@ while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling;
647647
@ if( !ul ) return false; /* This is a file link, not a directory */
648
- @ if( !useInitValue ) expandMap[a.id] = !isExpanded(ul);
648
+ @ if( !useInitValue ){
649
+ @ expandMap[a.id] = !isExpanded(ul);
650
+ @ history.replaceState(expandMap, '');
651
+ @ }
649652
@ ul.style.display = expandMap[a.id] ? 'block' : 'none';
650653
@ return true;
651654
@ }
652655
@
653656
@ function toggleAll(tree, useInitValue){
@@ -659,20 +662,32 @@
659662
@ expand = false; /* Any already visible - make them all hidden */
660663
@ break;
661664
@ }
662665
@ }
663666
@ expandMap = {'*': expand};
667
+ @ history.replaceState(expandMap, '');
664668
@ }
665669
@ var display = expandMap['*'] ? 'block' : 'none';
666670
@ for( var i=0; lists[i]; i++ ){
667671
@ lists[i].style.display = display;
668672
@ }
669673
@ }
670674
@
671
- @ var expandMap = {};
675
+ @ function checkState(){
676
+ @ expandMap = history.state || {};
677
+ @ if( expandMap['*'] ) toggleAll(outer_ul, true);
678
+ @ for( var id in expandMap ){
679
+ @ if( id!=='*' ) toggleDir(gebi(id), true);
680
+ @ }
681
+ @ }
682
+ @
683
+ @ /* No-op shim for IE9 */
684
+ @ if( !history.replaceState ) history.replaceState = function(){};
672685
@ var outer_ul = document.querySelector('.filetree > ul');
673686
@ var subdir = outer_ul.querySelector('.subdir');
687
+ @ var expandMap = {};
688
+ @ checkState();
674689
@ outer_ul.onclick = function(e){
675690
@ var a = e.target;
676691
@ if( a.nodeName!='A' ) return true;
677692
@ if( a.parentNode==subdir ){
678693
@ toggleAll(outer_ul);
@@ -679,20 +694,10 @@
679694
@ return false;
680695
@ }
681696
@ if( !subdir.contains(a) ) return true;
682697
@ return !toggleDir(a);
683698
@ }
684
- @ addEventListener('pagehide', function(){
685
- @ sessionStorage.setItem('tree-expandMap', JSON.stringify(expandMap));
686
- @ });
687
- @ addEventListener('pageshow', function(){
688
- @ expandMap = JSON.parse(sessionStorage.getItem('tree-expandMap')) || {};
689
- @ if( expandMap['*'] ) toggleAll(outer_ul, true);
690
- @ for( var id in expandMap ){
691
- @ if( id!=='*' ) toggleDir(gebi(id), true);
692
- @ }
693
- @ });
694699
@ }())</script>
695700
style_footer();
696701
697702
/* We could free memory used by sTree here if we needed to. But
698703
** the process is about to exit, so doing so would not really accomplish
699704
--- src/browse.c
+++ src/browse.c
@@ -643,11 +643,14 @@
643 @
644 @ function toggleDir(a, useInitValue){
645 @ var ul = a.nextSibling;
646 @ while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling;
647 @ if( !ul ) return false; /* This is a file link, not a directory */
648 @ if( !useInitValue ) expandMap[a.id] = !isExpanded(ul);
 
 
 
649 @ ul.style.display = expandMap[a.id] ? 'block' : 'none';
650 @ return true;
651 @ }
652 @
653 @ function toggleAll(tree, useInitValue){
@@ -659,20 +662,32 @@
659 @ expand = false; /* Any already visible - make them all hidden */
660 @ break;
661 @ }
662 @ }
663 @ expandMap = {'*': expand};
 
664 @ }
665 @ var display = expandMap['*'] ? 'block' : 'none';
666 @ for( var i=0; lists[i]; i++ ){
667 @ lists[i].style.display = display;
668 @ }
669 @ }
670 @
671 @ var expandMap = {};
 
 
 
 
 
 
 
 
 
672 @ var outer_ul = document.querySelector('.filetree > ul');
673 @ var subdir = outer_ul.querySelector('.subdir');
 
 
674 @ outer_ul.onclick = function(e){
675 @ var a = e.target;
676 @ if( a.nodeName!='A' ) return true;
677 @ if( a.parentNode==subdir ){
678 @ toggleAll(outer_ul);
@@ -679,20 +694,10 @@
679 @ return false;
680 @ }
681 @ if( !subdir.contains(a) ) return true;
682 @ return !toggleDir(a);
683 @ }
684 @ addEventListener('pagehide', function(){
685 @ sessionStorage.setItem('tree-expandMap', JSON.stringify(expandMap));
686 @ });
687 @ addEventListener('pageshow', function(){
688 @ expandMap = JSON.parse(sessionStorage.getItem('tree-expandMap')) || {};
689 @ if( expandMap['*'] ) toggleAll(outer_ul, true);
690 @ for( var id in expandMap ){
691 @ if( id!=='*' ) toggleDir(gebi(id), true);
692 @ }
693 @ });
694 @ }())</script>
695 style_footer();
696
697 /* We could free memory used by sTree here if we needed to. But
698 ** the process is about to exit, so doing so would not really accomplish
699
--- src/browse.c
+++ src/browse.c
@@ -643,11 +643,14 @@
643 @
644 @ function toggleDir(a, useInitValue){
645 @ var ul = a.nextSibling;
646 @ while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling;
647 @ if( !ul ) return false; /* This is a file link, not a directory */
648 @ if( !useInitValue ){
649 @ expandMap[a.id] = !isExpanded(ul);
650 @ history.replaceState(expandMap, '');
651 @ }
652 @ ul.style.display = expandMap[a.id] ? 'block' : 'none';
653 @ return true;
654 @ }
655 @
656 @ function toggleAll(tree, useInitValue){
@@ -659,20 +662,32 @@
662 @ expand = false; /* Any already visible - make them all hidden */
663 @ break;
664 @ }
665 @ }
666 @ expandMap = {'*': expand};
667 @ history.replaceState(expandMap, '');
668 @ }
669 @ var display = expandMap['*'] ? 'block' : 'none';
670 @ for( var i=0; lists[i]; i++ ){
671 @ lists[i].style.display = display;
672 @ }
673 @ }
674 @
675 @ function checkState(){
676 @ expandMap = history.state || {};
677 @ if( expandMap['*'] ) toggleAll(outer_ul, true);
678 @ for( var id in expandMap ){
679 @ if( id!=='*' ) toggleDir(gebi(id), true);
680 @ }
681 @ }
682 @
683 @ /* No-op shim for IE9 */
684 @ if( !history.replaceState ) history.replaceState = function(){};
685 @ var outer_ul = document.querySelector('.filetree > ul');
686 @ var subdir = outer_ul.querySelector('.subdir');
687 @ var expandMap = {};
688 @ checkState();
689 @ outer_ul.onclick = function(e){
690 @ var a = e.target;
691 @ if( a.nodeName!='A' ) return true;
692 @ if( a.parentNode==subdir ){
693 @ toggleAll(outer_ul);
@@ -679,20 +694,10 @@
694 @ return false;
695 @ }
696 @ if( !subdir.contains(a) ) return true;
697 @ return !toggleDir(a);
698 @ }
 
 
 
 
 
 
 
 
 
 
699 @ }())</script>
700 style_footer();
701
702 /* We could free memory used by sTree here if we needed to. But
703 ** the process is about to exit, so doing so would not really accomplish
704

Keyboard Shortcuts

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