Fossil SCM

Move all the in-line javascript from the file tree browser into a separate "tree.js" script.

drh 2017-12-06 02:02 trunk
Commit 2f5c2f658c257fd521aff2596afb341e4c9485aab784bf63364c6c8932a45a7e
+1 -70
--- src/browse.c
+++ src/browse.c
@@ -843,80 +843,11 @@
843843
}
844844
}
845845
}
846846
@ </ul>
847847
@ </ul></div>
848
- @ <script>(function(){
849
- @ function isExpanded(ul){
850
- @ return ul.className=='';
851
- @ }
852
- @
853
- @ function toggleDir(ul, useInitValue){
854
- @ if( !useInitValue ){
855
- @ expandMap[ul.id] = !isExpanded(ul);
856
- @ history.replaceState(expandMap, '');
857
- @ }
858
- @ ul.className = expandMap[ul.id] ? '' : 'collapsed';
859
- @ }
860
- @
861
- @ function toggleAll(tree, useInitValue){
862
- @ var lists = tree.querySelectorAll('.subdir > ul > li ul');
863
- @ if( !useInitValue ){
864
- @ var expand = true; /* Default action: make all sublists visible */
865
- @ for( var i=0; lists[i]; i++ ){
866
- @ if( isExpanded(lists[i]) ){
867
- @ expand = false; /* Any already visible - make them all hidden */
868
- @ break;
869
- @ }
870
- @ }
871
- @ expandMap = {'*': expand};
872
- @ history.replaceState(expandMap, '');
873
- @ }
874
- @ var className = expandMap['*'] ? '' : 'collapsed';
875
- @ for( var i=0; lists[i]; i++ ){
876
- @ lists[i].className = className;
877
- @ }
878
- @ }
879
- @
880
- @ function checkState(){
881
- @ expandMap = history.state || {};
882
- @ if( '*' in expandMap ) toggleAll(outer_ul, true);
883
- @ for( var id in expandMap ){
884
- @ if( id!=='*' ) toggleDir(gebi(id), true);
885
- @ }
886
- @ }
887
- @
888
- @ function belowSubdir(node){
889
- @ do{
890
- @ node = node.parentNode;
891
- @ if( node==subdir ) return true;
892
- @ } while( node && node!=outer_ul );
893
- @ return false;
894
- @ }
895
- @
896
- @ var history = window.history || {};
897
- @ if( !history.replaceState ) history.replaceState = function(){};
898
- @ var outer_ul = document.querySelector('.filetree > ul');
899
- @ var subdir = outer_ul.querySelector('.subdir');
900
- @ var expandMap = {};
901
- @ checkState();
902
- @ outer_ul.onclick = function(e){
903
- @ e = e || window.event;
904
- @ var a = e.target || e.srcElement;
905
- @ if( a.nodeName!='A' ) return true;
906
- @ if( a.parentNode.parentNode==subdir ){
907
- @ toggleAll(outer_ul);
908
- @ return false;
909
- @ }
910
- @ if( !belowSubdir(a) ) return true;
911
- @ var ul = a.parentNode.nextSibling;
912
- @ while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling;
913
- @ if( !ul ) return true; /* This is a file link, not a directory */
914
- @ toggleDir(ul);
915
- @ return false;
916
- @ }
917
- @ }())</script>
848
+ style_load_one_js_file("tree.js");
918849
style_footer();
919850
920851
/* We could free memory used by sTree here if we needed to. But
921852
** the process is about to exit, so doing so would not really accomplish
922853
** anything useful. */
923854
--- src/browse.c
+++ src/browse.c
@@ -843,80 +843,11 @@
843 }
844 }
845 }
846 @ </ul>
847 @ </ul></div>
848 @ <script>(function(){
849 @ function isExpanded(ul){
850 @ return ul.className=='';
851 @ }
852 @
853 @ function toggleDir(ul, useInitValue){
854 @ if( !useInitValue ){
855 @ expandMap[ul.id] = !isExpanded(ul);
856 @ history.replaceState(expandMap, '');
857 @ }
858 @ ul.className = expandMap[ul.id] ? '' : 'collapsed';
859 @ }
860 @
861 @ function toggleAll(tree, useInitValue){
862 @ var lists = tree.querySelectorAll('.subdir > ul > li ul');
863 @ if( !useInitValue ){
864 @ var expand = true; /* Default action: make all sublists visible */
865 @ for( var i=0; lists[i]; i++ ){
866 @ if( isExpanded(lists[i]) ){
867 @ expand = false; /* Any already visible - make them all hidden */
868 @ break;
869 @ }
870 @ }
871 @ expandMap = {'*': expand};
872 @ history.replaceState(expandMap, '');
873 @ }
874 @ var className = expandMap['*'] ? '' : 'collapsed';
875 @ for( var i=0; lists[i]; i++ ){
876 @ lists[i].className = className;
877 @ }
878 @ }
879 @
880 @ function checkState(){
881 @ expandMap = history.state || {};
882 @ if( '*' in expandMap ) toggleAll(outer_ul, true);
883 @ for( var id in expandMap ){
884 @ if( id!=='*' ) toggleDir(gebi(id), true);
885 @ }
886 @ }
887 @
888 @ function belowSubdir(node){
889 @ do{
890 @ node = node.parentNode;
891 @ if( node==subdir ) return true;
892 @ } while( node && node!=outer_ul );
893 @ return false;
894 @ }
895 @
896 @ var history = window.history || {};
897 @ if( !history.replaceState ) history.replaceState = function(){};
898 @ var outer_ul = document.querySelector('.filetree > ul');
899 @ var subdir = outer_ul.querySelector('.subdir');
900 @ var expandMap = {};
901 @ checkState();
902 @ outer_ul.onclick = function(e){
903 @ e = e || window.event;
904 @ var a = e.target || e.srcElement;
905 @ if( a.nodeName!='A' ) return true;
906 @ if( a.parentNode.parentNode==subdir ){
907 @ toggleAll(outer_ul);
908 @ return false;
909 @ }
910 @ if( !belowSubdir(a) ) return true;
911 @ var ul = a.parentNode.nextSibling;
912 @ while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling;
913 @ if( !ul ) return true; /* This is a file link, not a directory */
914 @ toggleDir(ul);
915 @ return false;
916 @ }
917 @ }())</script>
918 style_footer();
919
920 /* We could free memory used by sTree here if we needed to. But
921 ** the process is about to exit, so doing so would not really accomplish
922 ** anything useful. */
923
--- src/browse.c
+++ src/browse.c
@@ -843,80 +843,11 @@
843 }
844 }
845 }
846 @ </ul>
847 @ </ul></div>
848 style_load_one_js_file("tree.js");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
849 style_footer();
850
851 /* We could free memory used by sTree here if we needed to. But
852 ** the process is about to exit, so doing so would not really accomplish
853 ** anything useful. */
854
--- src/main.mk
+++ src/main.mk
@@ -199,10 +199,11 @@
199199
$(SRCDIR)/graph.js \
200200
$(SRCDIR)/href.js \
201201
$(SRCDIR)/markdown.md \
202202
$(SRCDIR)/menu.js \
203203
$(SRCDIR)/sbsdiff.js \
204
+ $(SRCDIR)/tree.js \
204205
$(SRCDIR)/wiki.wiki
205206
206207
TRANS_SRC = \
207208
$(OBJDIR)/add_.c \
208209
$(OBJDIR)/allrepo_.c \
209210
210211
ADDED src/tree.js
--- src/main.mk
+++ src/main.mk
@@ -199,10 +199,11 @@
199 $(SRCDIR)/graph.js \
200 $(SRCDIR)/href.js \
201 $(SRCDIR)/markdown.md \
202 $(SRCDIR)/menu.js \
203 $(SRCDIR)/sbsdiff.js \
 
204 $(SRCDIR)/wiki.wiki
205
206 TRANS_SRC = \
207 $(OBJDIR)/add_.c \
208 $(OBJDIR)/allrepo_.c \
209
210 DDED src/tree.js
--- src/main.mk
+++ src/main.mk
@@ -199,10 +199,11 @@
199 $(SRCDIR)/graph.js \
200 $(SRCDIR)/href.js \
201 $(SRCDIR)/markdown.md \
202 $(SRCDIR)/menu.js \
203 $(SRCDIR)/sbsdiff.js \
204 $(SRCDIR)/tree.js \
205 $(SRCDIR)/wiki.wiki
206
207 TRANS_SRC = \
208 $(OBJDIR)/add_.c \
209 $(OBJDIR)/allrepo_.c \
210
211 DDED src/tree.js
+71
--- a/src/tree.js
+++ b/src/tree.js
@@ -0,0 +1,71 @@
1
+/* Javascript to implement the file hierarchy tree.
2
+*/
3
+(function(){
4
+function isExpanded(ul){
5
+ return ul.className=='';
6
+}
7
+
8
+function toggleDir(ul, useInitValue){
9
+ if( !useInitValue ){
10
+ expandMap[ul.id] = !isExpanded(ul);
11
+ history.replaceState(expandMap, '');
12
+ }
13
+ ul.className = expandMap[ul.id] ? '' : 'collapsed';
14
+}
15
+
16
+function toggleAll(tree, useInitValue){
17
+ var lists = tree.querySelectorAll('.subdir > ul > li ul');
18
+ if( !useInitValue ){
19
+ var expand = true; /* Default action: make all sublists visible */
20
+ for( var i=0; lists[i]; i++ ){
21
+ if( isExpanded(lists[i]) ){
22
+ expand = false; /* Any already visible - make them all hidden */
23
+ break;
24
+ }
25
+ }
26
+ expandMap = {'*': expand};
27
+ history.replaceState(expandMap, '');
28
+ }
29
+ var className = expandMap['*'] ? '' : 'collapsed';
30
+ for( var i=0; lists[i]; i++ ){
31
+ lists[i].className = className;
32
+ }
33
+}
34
+
35
+function checkState(){
36
+ expandMap = history.state || {};
37
+ if( '*' in expandMap ) toggleAll(outer_ul, true);
38
+ for( var id in expandMap ){
39
+ gebi(id)andMap ) to}
40
+}
41
+
42
+function belowSubdir(node){
43
+ do{
44
+ node = node.parentNode;
45
+ if( node==subdir ) return true;
46
+ } while( node && node!=outer_ul );
47
+ return false;
48
+}
49
+
50
+var history = window.history || {};
51
+if( !history.replaceState ) history.replaceState = function(){};
52
+var outer_ul = document.querySelector('.filetree > ul');
53
+var subdir = outer_ul.querySelector('.subdir');
54
+var expandMap = {};
55
+checkState();
56
+outer_ul.onclick = function(e){
57
+ e = e || window.event;
58
+ var a = e.target || e.srcElement;
59
+ if( a.nodeName!='A' ) return true;
60
+ if( a.parentNode.parentNode==subdir ){
61
+ toggleAll(outer_ul);
62
+ return false;
63
+ }
64
+ if( !belowSubdir(a) ) return true;
65
+ var ul = a.parentNode.nextSibling;
66
+ while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling;
67
+ if( !ul ) return true; /* This is a file link, not a directory */
68
+ toggleDir(ul);
69
+ return false;
70
+}
71
+}())
--- a/src/tree.js
+++ b/src/tree.js
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/src/tree.js
+++ b/src/tree.js
@@ -0,0 +1,71 @@
1 /* Javascript to implement the file hierarchy tree.
2 */
3 (function(){
4 function isExpanded(ul){
5 return ul.className=='';
6 }
7
8 function toggleDir(ul, useInitValue){
9 if( !useInitValue ){
10 expandMap[ul.id] = !isExpanded(ul);
11 history.replaceState(expandMap, '');
12 }
13 ul.className = expandMap[ul.id] ? '' : 'collapsed';
14 }
15
16 function toggleAll(tree, useInitValue){
17 var lists = tree.querySelectorAll('.subdir > ul > li ul');
18 if( !useInitValue ){
19 var expand = true; /* Default action: make all sublists visible */
20 for( var i=0; lists[i]; i++ ){
21 if( isExpanded(lists[i]) ){
22 expand = false; /* Any already visible - make them all hidden */
23 break;
24 }
25 }
26 expandMap = {'*': expand};
27 history.replaceState(expandMap, '');
28 }
29 var className = expandMap['*'] ? '' : 'collapsed';
30 for( var i=0; lists[i]; i++ ){
31 lists[i].className = className;
32 }
33 }
34
35 function checkState(){
36 expandMap = history.state || {};
37 if( '*' in expandMap ) toggleAll(outer_ul, true);
38 for( var id in expandMap ){
39 gebi(id)andMap ) to}
40 }
41
42 function belowSubdir(node){
43 do{
44 node = node.parentNode;
45 if( node==subdir ) return true;
46 } while( node && node!=outer_ul );
47 return false;
48 }
49
50 var history = window.history || {};
51 if( !history.replaceState ) history.replaceState = function(){};
52 var outer_ul = document.querySelector('.filetree > ul');
53 var subdir = outer_ul.querySelector('.subdir');
54 var expandMap = {};
55 checkState();
56 outer_ul.onclick = function(e){
57 e = e || window.event;
58 var a = e.target || e.srcElement;
59 if( a.nodeName!='A' ) return true;
60 if( a.parentNode.parentNode==subdir ){
61 toggleAll(outer_ul);
62 return false;
63 }
64 if( !belowSubdir(a) ) return true;
65 var ul = a.parentNode.nextSibling;
66 while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling;
67 if( !ul ) return true; /* This is a file link, not a directory */
68 toggleDir(ul);
69 return false;
70 }
71 }())
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -608,10 +608,11 @@
608608
$(SRCDIR)/graph.js \
609609
$(SRCDIR)/href.js \
610610
$(SRCDIR)/markdown.md \
611611
$(SRCDIR)/menu.js \
612612
$(SRCDIR)/sbsdiff.js \
613
+ $(SRCDIR)/tree.js \
613614
$(SRCDIR)/wiki.wiki
614615
615616
TRANS_SRC = \
616617
$(OBJDIR)/add_.c \
617618
$(OBJDIR)/allrepo_.c \
618619
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -608,10 +608,11 @@
608 $(SRCDIR)/graph.js \
609 $(SRCDIR)/href.js \
610 $(SRCDIR)/markdown.md \
611 $(SRCDIR)/menu.js \
612 $(SRCDIR)/sbsdiff.js \
 
613 $(SRCDIR)/wiki.wiki
614
615 TRANS_SRC = \
616 $(OBJDIR)/add_.c \
617 $(OBJDIR)/allrepo_.c \
618
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -608,10 +608,11 @@
608 $(SRCDIR)/graph.js \
609 $(SRCDIR)/href.js \
610 $(SRCDIR)/markdown.md \
611 $(SRCDIR)/menu.js \
612 $(SRCDIR)/sbsdiff.js \
613 $(SRCDIR)/tree.js \
614 $(SRCDIR)/wiki.wiki
615
616 TRANS_SRC = \
617 $(OBJDIR)/add_.c \
618 $(OBJDIR)/allrepo_.c \
619
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -534,10 +534,11 @@
534534
$(SRCDIR)\graph.js \
535535
$(SRCDIR)\href.js \
536536
$(SRCDIR)\markdown.md \
537537
$(SRCDIR)\menu.js \
538538
$(SRCDIR)\sbsdiff.js \
539
+ $(SRCDIR)\tree.js \
539540
$(SRCDIR)\wiki.wiki
540541
541542
OBJ = $(OX)\add$O \
542543
$(OX)\allrepo$O \
543544
$(OX)\attach$O \
544545
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -534,10 +534,11 @@
534 $(SRCDIR)\graph.js \
535 $(SRCDIR)\href.js \
536 $(SRCDIR)\markdown.md \
537 $(SRCDIR)\menu.js \
538 $(SRCDIR)\sbsdiff.js \
 
539 $(SRCDIR)\wiki.wiki
540
541 OBJ = $(OX)\add$O \
542 $(OX)\allrepo$O \
543 $(OX)\attach$O \
544
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -534,10 +534,11 @@
534 $(SRCDIR)\graph.js \
535 $(SRCDIR)\href.js \
536 $(SRCDIR)\markdown.md \
537 $(SRCDIR)\menu.js \
538 $(SRCDIR)\sbsdiff.js \
539 $(SRCDIR)\tree.js \
540 $(SRCDIR)\wiki.wiki
541
542 OBJ = $(OX)\add$O \
543 $(OX)\allrepo$O \
544 $(OX)\attach$O \
545

Keyboard Shortcuts

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