Fossil SCM

Better NULL-protection against browsers which don't have "history" API

jan.nijtmans 2014-01-16 10:54 trunk
Commit 02b607a07a5ed13f92d06d5d8425ffb036f71635
1 file changed +7 -5
+7 -5
--- src/browse.c
+++ src/browse.c
@@ -644,11 +644,13 @@
644644
@ }
645645
@
646646
@ function toggleDir(ul, useInitValue){
647647
@ if( !useInitValue ){
648648
@ expandMap[ul.id] = !isExpanded(ul);
649
- @ history.replaceState(expandMap, '');
649
+ @ if( history && history.replaceState ){
650
+ @ history.replaceState(expandMap, '');
651
+ @ }
650652
@ }
651653
@ ul.style.display = expandMap[ul.id] ? 'block' : 'none';
652654
@ }
653655
@
654656
@ function toggleAll(tree, useInitValue){
@@ -660,28 +662,28 @@
660662
@ expand = false; /* Any already visible - make them all hidden */
661663
@ break;
662664
@ }
663665
@ }
664666
@ expandMap = {'*': expand};
665
- @ history.replaceState(expandMap, '');
667
+ @ if( history && history.replaceState ){
668
+ @ history.replaceState(expandMap, '');
669
+ @ }
666670
@ }
667671
@ var display = expandMap['*'] ? 'block' : 'none';
668672
@ for( var i=0; lists[i]; i++ ){
669673
@ lists[i].style.display = display;
670674
@ }
671675
@ }
672676
@
673677
@ function checkState(){
674
- @ expandMap = history.state || {};
678
+ @ expandMap = (history && history.state) || {};
675679
@ if( expandMap['*'] ) toggleAll(outer_ul, true);
676680
@ for( var id in expandMap ){
677681
@ if( id!=='*' ) toggleDir(gebi(id), true);
678682
@ }
679683
@ }
680684
@
681
- @ /* No-op shim for IE9 */
682
- @ if( !history.replaceState ) history.replaceState = function(){};
683685
@ var outer_ul = document.querySelector('.filetree > ul');
684686
@ var subdir = outer_ul.querySelector('.subdir');
685687
@ var expandMap = {};
686688
@ checkState();
687689
@ outer_ul.onclick = function(e){
688690
--- src/browse.c
+++ src/browse.c
@@ -644,11 +644,13 @@
644 @ }
645 @
646 @ function toggleDir(ul, useInitValue){
647 @ if( !useInitValue ){
648 @ expandMap[ul.id] = !isExpanded(ul);
649 @ history.replaceState(expandMap, '');
 
 
650 @ }
651 @ ul.style.display = expandMap[ul.id] ? 'block' : 'none';
652 @ }
653 @
654 @ function toggleAll(tree, useInitValue){
@@ -660,28 +662,28 @@
660 @ expand = false; /* Any already visible - make them all hidden */
661 @ break;
662 @ }
663 @ }
664 @ expandMap = {'*': expand};
665 @ history.replaceState(expandMap, '');
 
 
666 @ }
667 @ var display = expandMap['*'] ? 'block' : 'none';
668 @ for( var i=0; lists[i]; i++ ){
669 @ lists[i].style.display = display;
670 @ }
671 @ }
672 @
673 @ function checkState(){
674 @ expandMap = history.state || {};
675 @ if( expandMap['*'] ) toggleAll(outer_ul, true);
676 @ for( var id in expandMap ){
677 @ if( id!=='*' ) toggleDir(gebi(id), true);
678 @ }
679 @ }
680 @
681 @ /* No-op shim for IE9 */
682 @ if( !history.replaceState ) history.replaceState = function(){};
683 @ var outer_ul = document.querySelector('.filetree > ul');
684 @ var subdir = outer_ul.querySelector('.subdir');
685 @ var expandMap = {};
686 @ checkState();
687 @ outer_ul.onclick = function(e){
688
--- src/browse.c
+++ src/browse.c
@@ -644,11 +644,13 @@
644 @ }
645 @
646 @ function toggleDir(ul, useInitValue){
647 @ if( !useInitValue ){
648 @ expandMap[ul.id] = !isExpanded(ul);
649 @ if( history && history.replaceState ){
650 @ history.replaceState(expandMap, '');
651 @ }
652 @ }
653 @ ul.style.display = expandMap[ul.id] ? 'block' : 'none';
654 @ }
655 @
656 @ function toggleAll(tree, useInitValue){
@@ -660,28 +662,28 @@
662 @ expand = false; /* Any already visible - make them all hidden */
663 @ break;
664 @ }
665 @ }
666 @ expandMap = {'*': expand};
667 @ if( history && history.replaceState ){
668 @ history.replaceState(expandMap, '');
669 @ }
670 @ }
671 @ var display = expandMap['*'] ? 'block' : 'none';
672 @ for( var i=0; lists[i]; i++ ){
673 @ lists[i].style.display = display;
674 @ }
675 @ }
676 @
677 @ function checkState(){
678 @ expandMap = (history && history.state) || {};
679 @ if( expandMap['*'] ) toggleAll(outer_ul, true);
680 @ for( var id in expandMap ){
681 @ if( id!=='*' ) toggleDir(gebi(id), true);
682 @ }
683 @ }
684 @
 
 
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

Keyboard Shortcuts

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