Fossil SCM
Use history API instead of sessionStorage.
Commit
434e4538bc95f423804c4e6af1bfeb8a40644b07
Parent
3bdbc0408f559e7…
1 file changed
+17
-12
+17
-12
| --- src/browse.c | ||
| +++ src/browse.c | ||
| @@ -643,11 +643,14 @@ | ||
| 643 | 643 | @ |
| 644 | 644 | @ function toggleDir(a, useInitValue){ |
| 645 | 645 | @ var ul = a.nextSibling; |
| 646 | 646 | @ while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling; |
| 647 | 647 | @ 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 | + @ } | |
| 649 | 652 | @ ul.style.display = expandMap[a.id] ? 'block' : 'none'; |
| 650 | 653 | @ return true; |
| 651 | 654 | @ } |
| 652 | 655 | @ |
| 653 | 656 | @ function toggleAll(tree, useInitValue){ |
| @@ -659,20 +662,32 @@ | ||
| 659 | 662 | @ expand = false; /* Any already visible - make them all hidden */ |
| 660 | 663 | @ break; |
| 661 | 664 | @ } |
| 662 | 665 | @ } |
| 663 | 666 | @ expandMap = {'*': expand}; |
| 667 | + @ history.replaceState(expandMap, ''); | |
| 664 | 668 | @ } |
| 665 | 669 | @ var display = expandMap['*'] ? 'block' : 'none'; |
| 666 | 670 | @ for( var i=0; lists[i]; i++ ){ |
| 667 | 671 | @ lists[i].style.display = display; |
| 668 | 672 | @ } |
| 669 | 673 | @ } |
| 670 | 674 | @ |
| 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(){}; | |
| 672 | 685 | @ var outer_ul = document.querySelector('.filetree > ul'); |
| 673 | 686 | @ var subdir = outer_ul.querySelector('.subdir'); |
| 687 | + @ var expandMap = {}; | |
| 688 | + @ checkState(); | |
| 674 | 689 | @ outer_ul.onclick = function(e){ |
| 675 | 690 | @ var a = e.target; |
| 676 | 691 | @ if( a.nodeName!='A' ) return true; |
| 677 | 692 | @ if( a.parentNode==subdir ){ |
| 678 | 693 | @ toggleAll(outer_ul); |
| @@ -679,20 +694,10 @@ | ||
| 679 | 694 | @ return false; |
| 680 | 695 | @ } |
| 681 | 696 | @ if( !subdir.contains(a) ) return true; |
| 682 | 697 | @ return !toggleDir(a); |
| 683 | 698 | @ } |
| 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 | 699 | @ }())</script> |
| 695 | 700 | style_footer(); |
| 696 | 701 | |
| 697 | 702 | /* We could free memory used by sTree here if we needed to. But |
| 698 | 703 | ** the process is about to exit, so doing so would not really accomplish |
| 699 | 704 |
| --- 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 |