Fossil SCM

Attempt to add a separate JS file and source it just prior to </body>

drh 2017-12-04 21:08 UTC trunk
Commit 487aa43f424222bd28e09cb7b8cdce4a1c088ae6ea577cb21ab51f7a4429226c
+33
--- a/src/main.js
+++ b/src/main.js
@@ -0,0 +1,33 @@
1
+/* This script is sourced just prior to the </body> in every Fossil webpage */
2
+var pageDataObj = document.getElementById('page-data');
3
+var links = new Array();
4
+if( pageDataObj ){
5
+ var pageData = JSON.parse(pageDataObj.textContent || pageDataObj.innerText);
6
+ var r;
7
+ for(r in pageData){
8
+ switch(r.op){
9
+ "setAllHrefs": {
10
+ links = r.links;
11
+ if(r.mouseMove){
12
+ document.getElementsByTagName("body")[0].onmousemove=function(){
13
+ setTimeout("setAllHrefs();",r.nDelay);
14
+ }
15
+ }else{
16
+ setTimeout("setAllHrefs();",r.nDelay);
17
+ }
18
+ break;
19
+ }
20
+ "no-op": {
21
+ alert('finished processing page-data');
22
+ break;
23
+ }
24
+ }
25
+ }
26
+}
27
+function setAllHrefs(){
28
+ var x;
29
+ for(x in links){
30
+ var y = document.getElementById(x.id);
31
+ if(y) y.href=x.href
32
+ }
33
+}
--- a/src/main.js
+++ b/src/main.js
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/src/main.js
+++ b/src/main.js
@@ -0,0 +1,33 @@
1 /* This script is sourced just prior to the </body> in every Fossil webpage */
2 var pageDataObj = document.getElementById('page-data');
3 var links = new Array();
4 if( pageDataObj ){
5 var pageData = JSON.parse(pageDataObj.textContent || pageDataObj.innerText);
6 var r;
7 for(r in pageData){
8 switch(r.op){
9 "setAllHrefs": {
10 links = r.links;
11 if(r.mouseMove){
12 document.getElementsByTagName("body")[0].onmousemove=function(){
13 setTimeout("setAllHrefs();",r.nDelay);
14 }
15 }else{
16 setTimeout("setAllHrefs();",r.nDelay);
17 }
18 break;
19 }
20 "no-op": {
21 alert('finished processing page-data');
22 break;
23 }
24 }
25 }
26 }
27 function setAllHrefs(){
28 var x;
29 for(x in links){
30 var y = document.getElementById(x.id);
31 if(y) y.href=x.href
32 }
33 }
--- src/main.mk
+++ src/main.mk
@@ -194,10 +194,11 @@
194194
$(SRCDIR)/../skins/xekri/css.txt \
195195
$(SRCDIR)/../skins/xekri/details.txt \
196196
$(SRCDIR)/../skins/xekri/footer.txt \
197197
$(SRCDIR)/../skins/xekri/header.txt \
198198
$(SRCDIR)/diff.tcl \
199
+ $(SRCDIR)/main.js \
199200
$(SRCDIR)/markdown.md \
200201
$(SRCDIR)/wiki.wiki
201202
202203
TRANS_SRC = \
203204
$(OBJDIR)/add_.c \
204205
--- src/main.mk
+++ src/main.mk
@@ -194,10 +194,11 @@
194 $(SRCDIR)/../skins/xekri/css.txt \
195 $(SRCDIR)/../skins/xekri/details.txt \
196 $(SRCDIR)/../skins/xekri/footer.txt \
197 $(SRCDIR)/../skins/xekri/header.txt \
198 $(SRCDIR)/diff.tcl \
 
199 $(SRCDIR)/markdown.md \
200 $(SRCDIR)/wiki.wiki
201
202 TRANS_SRC = \
203 $(OBJDIR)/add_.c \
204
--- src/main.mk
+++ src/main.mk
@@ -194,10 +194,11 @@
194 $(SRCDIR)/../skins/xekri/css.txt \
195 $(SRCDIR)/../skins/xekri/details.txt \
196 $(SRCDIR)/../skins/xekri/footer.txt \
197 $(SRCDIR)/../skins/xekri/header.txt \
198 $(SRCDIR)/diff.tcl \
199 $(SRCDIR)/main.js \
200 $(SRCDIR)/markdown.md \
201 $(SRCDIR)/wiki.wiki
202
203 TRANS_SRC = \
204 $(OBJDIR)/add_.c \
205
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -160,10 +160,11 @@
160160
#
161161
set extra_files {
162162
diff.tcl
163163
markdown.md
164164
wiki.wiki
165
+ main.js
165166
../skins/*/*.txt
166167
}
167168
168169
# Options used to compile the included SQLite library.
169170
#
170171
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -160,10 +160,11 @@
160 #
161 set extra_files {
162 diff.tcl
163 markdown.md
164 wiki.wiki
 
165 ../skins/*/*.txt
166 }
167
168 # Options used to compile the included SQLite library.
169 #
170
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -160,10 +160,11 @@
160 #
161 set extra_files {
162 diff.tcl
163 markdown.md
164 wiki.wiki
165 main.js
166 ../skins/*/*.txt
167 }
168
169 # Options used to compile the included SQLite library.
170 #
171
+45 -5
--- src/style.c
+++ src/style.c
@@ -83,10 +83,15 @@
8383
/*
8484
** Ad-unit styles.
8585
*/
8686
static unsigned adUnitFlags = 0;
8787
88
+/*
89
+** Page data JSON
90
+*/
91
+static Blob pageDataJson = BLOB_INITIALIZER;
92
+
8893
8994
/*
9095
** List of hyperlinks and forms that need to be resolved by javascript in
9196
** the footer.
9297
*/
@@ -192,10 +197,23 @@
192197
aFormAction[nFormAction++] = zLink;
193198
n = nFormAction;
194199
@ <form id="form%d(n)" method="POST" action='%R/login' %s(zOtherArgs)>
195200
}
196201
}
202
+
203
+/*
204
+** Append page-data JSON
205
+*/
206
+void style_pagedata_appendf(const char *zFormat, ...){
207
+ va_list ap;
208
+ if( blob_size(&pageDataJson)==0 ){
209
+ blob_append(&pageDataJson, "[", 1);
210
+ }
211
+ va_start(ap, zFormat);
212
+ blob_vappendf(&pageDataJson, zFormat, ap);
213
+ va_end(ap);
214
+}
197215
198216
/*
199217
** Generate javascript that will set the href= attribute on all anchors.
200218
*/
201219
void style_resolve_href(void){
@@ -423,15 +441,17 @@
423441
*/
424442
static char zDfltHeader[] =
425443
@ <html>
426444
@ <head>
427445
@ <base href="$baseurl/$current_page" />
446
+@ <meta http-equiv="Content-Security-Policy-xxx" \
447
+@ content="default-src 'self' 'unsafe-inline'" />
428448
@ <title>$<project_name>: $<title></title>
429
-@ <link rel="alternate" type="application/rss+xml" title="RSS Feed"
430
-@ href="$home/timeline.rss" />
431
-@ <link rel="stylesheet" href="$stylesheet_url" type="text/css"
432
-@ media="screen" />
449
+@ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
450
+@ href="$home/timeline.rss" />
451
+@ <link rel="stylesheet" href="$stylesheet_url" type="text/css" \
452
+@ media="screen" />
433453
@ </head>
434454
@ <body>
435455
;
436456
437457
/*
@@ -724,11 +744,18 @@
724744
cgi_append_content("</span>\n", -1);
725745
}
726746
727747
/* Add document end mark if it was not in the footer */
728748
if( sqlite3_strlike("%</body>%", zFooter, 0)!=0 ){
729
- @ </body></html>
749
+ style_pagedata_appendf("{'op':'no-op'}]");
750
+ @ <script type='application/json' id='page-data'>
751
+ @ %s(blob_str(&pageDataJson))
752
+ @ </script>
753
+ @ <script src='%s(g.zBaseURL)/main.js' type='application/javascript'>\
754
+ @ <script>
755
+ @ </body>
756
+ @ </html>
730757
}
731758
}
732759
733760
/*
734761
** Begin a side-box on the right-hand side of a page. The title and
@@ -858,10 +885,23 @@
858885
Th_Render(blob_str(&css));
859886
860887
/* Tell CGI that the content returned by this page is considered cacheable */
861888
g.isConst = 1;
862889
}
890
+
891
+/*
892
+** WEBPAGE: main.js
893
+**
894
+** Return the javascript
895
+*/
896
+void page_main_js(void){
897
+ Blob mainjs;
898
+ cgi_set_content_type("application/javascript");
899
+ blob_init(&mainjs, builtin_text("main.js"), -1);
900
+ cgi_set_content(&mainjs);
901
+}
902
+
863903
864904
/*
865905
** WEBPAGE: test_env
866906
**
867907
** Display CGI-variables and other aspects of the run-time
868908
--- src/style.c
+++ src/style.c
@@ -83,10 +83,15 @@
83 /*
84 ** Ad-unit styles.
85 */
86 static unsigned adUnitFlags = 0;
87
 
 
 
 
 
88
89 /*
90 ** List of hyperlinks and forms that need to be resolved by javascript in
91 ** the footer.
92 */
@@ -192,10 +197,23 @@
192 aFormAction[nFormAction++] = zLink;
193 n = nFormAction;
194 @ <form id="form%d(n)" method="POST" action='%R/login' %s(zOtherArgs)>
195 }
196 }
 
 
 
 
 
 
 
 
 
 
 
 
 
197
198 /*
199 ** Generate javascript that will set the href= attribute on all anchors.
200 */
201 void style_resolve_href(void){
@@ -423,15 +441,17 @@
423 */
424 static char zDfltHeader[] =
425 @ <html>
426 @ <head>
427 @ <base href="$baseurl/$current_page" />
 
 
428 @ <title>$<project_name>: $<title></title>
429 @ <link rel="alternate" type="application/rss+xml" title="RSS Feed"
430 @ href="$home/timeline.rss" />
431 @ <link rel="stylesheet" href="$stylesheet_url" type="text/css"
432 @ media="screen" />
433 @ </head>
434 @ <body>
435 ;
436
437 /*
@@ -724,11 +744,18 @@
724 cgi_append_content("</span>\n", -1);
725 }
726
727 /* Add document end mark if it was not in the footer */
728 if( sqlite3_strlike("%</body>%", zFooter, 0)!=0 ){
729 @ </body></html>
 
 
 
 
 
 
 
730 }
731 }
732
733 /*
734 ** Begin a side-box on the right-hand side of a page. The title and
@@ -858,10 +885,23 @@
858 Th_Render(blob_str(&css));
859
860 /* Tell CGI that the content returned by this page is considered cacheable */
861 g.isConst = 1;
862 }
 
 
 
 
 
 
 
 
 
 
 
 
 
863
864 /*
865 ** WEBPAGE: test_env
866 **
867 ** Display CGI-variables and other aspects of the run-time
868
--- src/style.c
+++ src/style.c
@@ -83,10 +83,15 @@
83 /*
84 ** Ad-unit styles.
85 */
86 static unsigned adUnitFlags = 0;
87
88 /*
89 ** Page data JSON
90 */
91 static Blob pageDataJson = BLOB_INITIALIZER;
92
93
94 /*
95 ** List of hyperlinks and forms that need to be resolved by javascript in
96 ** the footer.
97 */
@@ -192,10 +197,23 @@
197 aFormAction[nFormAction++] = zLink;
198 n = nFormAction;
199 @ <form id="form%d(n)" method="POST" action='%R/login' %s(zOtherArgs)>
200 }
201 }
202
203 /*
204 ** Append page-data JSON
205 */
206 void style_pagedata_appendf(const char *zFormat, ...){
207 va_list ap;
208 if( blob_size(&pageDataJson)==0 ){
209 blob_append(&pageDataJson, "[", 1);
210 }
211 va_start(ap, zFormat);
212 blob_vappendf(&pageDataJson, zFormat, ap);
213 va_end(ap);
214 }
215
216 /*
217 ** Generate javascript that will set the href= attribute on all anchors.
218 */
219 void style_resolve_href(void){
@@ -423,15 +441,17 @@
441 */
442 static char zDfltHeader[] =
443 @ <html>
444 @ <head>
445 @ <base href="$baseurl/$current_page" />
446 @ <meta http-equiv="Content-Security-Policy-xxx" \
447 @ content="default-src 'self' 'unsafe-inline'" />
448 @ <title>$<project_name>: $<title></title>
449 @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
450 @ href="$home/timeline.rss" />
451 @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" \
452 @ media="screen" />
453 @ </head>
454 @ <body>
455 ;
456
457 /*
@@ -724,11 +744,18 @@
744 cgi_append_content("</span>\n", -1);
745 }
746
747 /* Add document end mark if it was not in the footer */
748 if( sqlite3_strlike("%</body>%", zFooter, 0)!=0 ){
749 style_pagedata_appendf("{'op':'no-op'}]");
750 @ <script type='application/json' id='page-data'>
751 @ %s(blob_str(&pageDataJson))
752 @ </script>
753 @ <script src='%s(g.zBaseURL)/main.js' type='application/javascript'>\
754 @ <script>
755 @ </body>
756 @ </html>
757 }
758 }
759
760 /*
761 ** Begin a side-box on the right-hand side of a page. The title and
@@ -858,10 +885,23 @@
885 Th_Render(blob_str(&css));
886
887 /* Tell CGI that the content returned by this page is considered cacheable */
888 g.isConst = 1;
889 }
890
891 /*
892 ** WEBPAGE: main.js
893 **
894 ** Return the javascript
895 */
896 void page_main_js(void){
897 Blob mainjs;
898 cgi_set_content_type("application/javascript");
899 blob_init(&mainjs, builtin_text("main.js"), -1);
900 cgi_set_content(&mainjs);
901 }
902
903
904 /*
905 ** WEBPAGE: test_env
906 **
907 ** Display CGI-variables and other aspects of the run-time
908
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -603,10 +603,11 @@
603603
$(SRCDIR)/../skins/xekri/css.txt \
604604
$(SRCDIR)/../skins/xekri/details.txt \
605605
$(SRCDIR)/../skins/xekri/footer.txt \
606606
$(SRCDIR)/../skins/xekri/header.txt \
607607
$(SRCDIR)/diff.tcl \
608
+ $(SRCDIR)/main.js \
608609
$(SRCDIR)/markdown.md \
609610
$(SRCDIR)/wiki.wiki
610611
611612
TRANS_SRC = \
612613
$(OBJDIR)/add_.c \
613614
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -603,10 +603,11 @@
603 $(SRCDIR)/../skins/xekri/css.txt \
604 $(SRCDIR)/../skins/xekri/details.txt \
605 $(SRCDIR)/../skins/xekri/footer.txt \
606 $(SRCDIR)/../skins/xekri/header.txt \
607 $(SRCDIR)/diff.tcl \
 
608 $(SRCDIR)/markdown.md \
609 $(SRCDIR)/wiki.wiki
610
611 TRANS_SRC = \
612 $(OBJDIR)/add_.c \
613
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -603,10 +603,11 @@
603 $(SRCDIR)/../skins/xekri/css.txt \
604 $(SRCDIR)/../skins/xekri/details.txt \
605 $(SRCDIR)/../skins/xekri/footer.txt \
606 $(SRCDIR)/../skins/xekri/header.txt \
607 $(SRCDIR)/diff.tcl \
608 $(SRCDIR)/main.js \
609 $(SRCDIR)/markdown.md \
610 $(SRCDIR)/wiki.wiki
611
612 TRANS_SRC = \
613 $(OBJDIR)/add_.c \
614
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -529,10 +529,11 @@
529529
$(SRCDIR)\../skins/xekri/css.txt \
530530
$(SRCDIR)\../skins/xekri/details.txt \
531531
$(SRCDIR)\../skins/xekri/footer.txt \
532532
$(SRCDIR)\../skins/xekri/header.txt \
533533
$(SRCDIR)\diff.tcl \
534
+ $(SRCDIR)\main.js \
534535
$(SRCDIR)\markdown.md \
535536
$(SRCDIR)\wiki.wiki
536537
537538
OBJ = $(OX)\add$O \
538539
$(OX)\allrepo$O \
539540
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -529,10 +529,11 @@
529 $(SRCDIR)\../skins/xekri/css.txt \
530 $(SRCDIR)\../skins/xekri/details.txt \
531 $(SRCDIR)\../skins/xekri/footer.txt \
532 $(SRCDIR)\../skins/xekri/header.txt \
533 $(SRCDIR)\diff.tcl \
 
534 $(SRCDIR)\markdown.md \
535 $(SRCDIR)\wiki.wiki
536
537 OBJ = $(OX)\add$O \
538 $(OX)\allrepo$O \
539
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -529,10 +529,11 @@
529 $(SRCDIR)\../skins/xekri/css.txt \
530 $(SRCDIR)\../skins/xekri/details.txt \
531 $(SRCDIR)\../skins/xekri/footer.txt \
532 $(SRCDIR)\../skins/xekri/header.txt \
533 $(SRCDIR)\diff.tcl \
534 $(SRCDIR)\main.js \
535 $(SRCDIR)\markdown.md \
536 $(SRCDIR)\wiki.wiki
537
538 OBJ = $(OX)\add$O \
539 $(OX)\allrepo$O \
540

Keyboard Shortcuts

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