| ︙ | | | ︙ | |
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
*/
static int submenuEnable = 1;
/*
** Flags for various javascript files needed prior to </body>
*/
static int needHrefJs = 0; /* href.js */
static int needSortJs = 0; /* sorttable.js */
static int needGraphJs = 0; /* graph.js */
static int needCopyBtnJs = 0; /* copybtn.js */
static int needAccordionJs = 0; /* accordion.js */
/*
** Extra JS added to the end of the file.
*/
static Blob blobOnLoad = BLOB_INITIALIZER;
/*
|
<
<
<
<
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
*/
static int submenuEnable = 1;
/*
** Flags for various javascript files needed prior to </body>
*/
static int needHrefJs = 0; /* href.js */
/*
** Extra JS added to the end of the file.
*/
static Blob blobOnLoad = BLOB_INITIALIZER;
/*
|
| ︙ | | | ︙ | |
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
|
}else{
zResult = mprintf(
zBtnFmt/*works-like:"%h%s%h%h%d"*/,
zTargetId,zText,zTargetId,zTargetId,cchLength);
}
}
free(zText);
style_copybutton_control();
return zResult;
}
/*
** Return a random nonce that is stored in static space. For a particular
** run, the same nonce is always returned.
*/
|
|
|
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
|
}else{
zResult = mprintf(
zBtnFmt/*works-like:"%h%s%h%h%d"*/,
zTargetId,zText,zTargetId,zTargetId,cchLength);
}
}
free(zText);
builtin_request_js("copybtn.js");
return zResult;
}
/*
** Return a random nonce that is stored in static space. For a particular
** run, the same nonce is always returned.
*/
|
| ︙ | | | ︙ | |
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
|
return 0;
}
/*
** Indicate that the table-sorting javascript is needed.
*/
void style_table_sorter(void){
needSortJs = 1;
}
/*
** Indicate that the accordion javascript is needed.
*/
void style_accordion(void){
needAccordionJs = 1;
}
/*
** Indicate that the timeline graph javascript is needed.
*/
void style_graph_generator(void){
needGraphJs = 1;
}
/*
** Indicate that the copy button javascript is needed.
*/
void style_copybutton_control(void){
needCopyBtnJs = 1;
}
/*
** Generate code to load a single javascript file
*/
void style_load_one_js_file(const char *zFile){
@ <script src='%R/builtin/%s(zFile)?id=%S(fossil_exe_id())'></script>
}
/*
** All extra JS files to load.
*/
static const char *azJsToLoad[4];
static int nJsToLoad = 0;
/*
** Register a new JS file to load at the end of the document.
*/
void style_load_js(const char *zName){
int i;
for(i=0; i<nJsToLoad; i++){
if( fossil_strcmp(zName, azJsToLoad[i])==0 ) return;
}
if( nJsToLoad>=sizeof(azJsToLoad)/sizeof(azJsToLoad[0]) ){
fossil_panic("too many JS files");
}
azJsToLoad[nJsToLoad++] = zName;
}
/*
** Generate code to load all required javascript files.
*/
static void style_load_all_js_files(void){
int i;
if( needHrefJs ){
int nDelay = db_get_int("auto-hyperlink-delay",0);
int bMouseover = db_get_boolean("auto-hyperlink-mouseover",0);
@ <script id='href-data' type='application/json'>\
@ {"delay":%d(nDelay),"mouseover":%d(bMouseover)}</script>
}
@ <script nonce="%h(style_nonce())">
@ function debugMsg(msg){
@ var n = document.getElementById("debugMsg");
@ if(n){n.textContent=msg;}
@ }
if( needHrefJs ){
cgi_append_content(builtin_text("href.js"),-1);
}
if( needSortJs ){
cgi_append_content(builtin_text("sorttable.js"),-1);
}
if( needGraphJs ){
cgi_append_content(builtin_text("graph.js"),-1);
}
if( needCopyBtnJs ){
cgi_append_content(builtin_text("copybtn.js"),-1);
}
if( needAccordionJs ){
cgi_append_content(builtin_text("accordion.js"),-1);
}
for(i=0; i<nJsToLoad; i++){
cgi_append_content(builtin_text(azJsToLoad[i]),-1);
}
if( blob_size(&blobOnLoad)>0 ){
@ window.onload = function(){
cgi_append_content(blob_buffer(&blobOnLoad), blob_size(&blobOnLoad));
cgi_append_content("\n}\n", -1);
}
@ </script>
}
/*
** Extra JS to run after all content is loaded.
*/
void style_js_onload(const char *zFormat, ...){
va_list ap;
va_start(ap, zFormat);
blob_vappendf(&blobOnLoad, zFormat, ap);
va_end(ap);
}
/*
** Draw the footer at the bottom of the page.
*/
void style_footer(void){
const char *zFooter;
|
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
|
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
|
return 0;
}
/*
** Indicate that the table-sorting javascript is needed.
*/
void style_table_sorter(void){
builtin_request_js("sorttable.js");
}
/*
** Generate code to load all required javascript files.
*/
static void style_load_all_js_files(void){
if( needHrefJs ){
int nDelay = db_get_int("auto-hyperlink-delay",0);
int bMouseover = db_get_boolean("auto-hyperlink-mouseover",0);
@ <script id='href-data' type='application/json'>\
@ {"delay":%d(nDelay),"mouseover":%d(bMouseover)}</script>
}
@ <script nonce="%h(style_nonce())">
@ function debugMsg(msg){
@ var n = document.getElementById("debugMsg");
@ if(n){n.textContent=msg;}
@ }
if( needHrefJs ){
@ /* href.js */
cgi_append_content(builtin_text("href.js"),-1);
}
if( blob_size(&blobOnLoad)>0 ){
@ window.onload = function(){
cgi_append_content(blob_buffer(&blobOnLoad), blob_size(&blobOnLoad));
cgi_append_content("\n}\n", -1);
}
@ </script>
builtin_fulfill_js_requests();
}
/*
** Draw the footer at the bottom of the page.
*/
void style_footer(void){
const char *zFooter;
|
| ︙ | | | ︙ | |
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
|
}
}
@ </div>
if( nSubmenuCtrl ){
cgi_query_parameters_to_hidden();
cgi_tag_query_parameter(0);
@ </form>
style_load_one_js_file("menu.js");
}
}
zAd = style_adunit_text(&mAdFlags);
if( (mAdFlags & ADUNIT_RIGHT_OK)!=0 ){
@ <div class="content adunit_right_container">
@ <div class="adunit_right">
|
|
|
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
|
}
}
@ </div>
if( nSubmenuCtrl ){
cgi_query_parameters_to_hidden();
cgi_tag_query_parameter(0);
@ </form>
builtin_request_js("menu.js");
}
}
zAd = style_adunit_text(&mAdFlags);
if( (mAdFlags & ADUNIT_RIGHT_OK)!=0 ){
@ <div class="content adunit_right_container">
@ <div class="adunit_right">
|
| ︙ | | | ︙ | |
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
|
image_url_var("background");
Th_Render(blob_str(&css));
/* Tell CGI that the content returned by this page is considered cacheable */
g.isConst = 1;
}
/*
** Maps a "bundle" name to a callback which emits the text of that
** bundle. For use in consolidating scripts for certain pages into a
** single cacheable request.
*/
typedef struct {
const char * zName; /* Name of the bundle (maps to /builtin/:NAME) */
void (*xEmit)(void); /* Emits amalgamated text output for this
bundle */
} BundleEmitter;
/*
** Map each required bundle here...
*/
static const BundleEmitter BundleEmitters[] = {
/* Keep these sorted for bsearch() */
{"fileedit.js", fileedit_emit_js_bundle},
{"forum.js", forumpost_emit_js_bundle},
{"wikiedit.js", wikiedit_emit_js_bundle}
};
/*
** Comparison function for bsearch() for searching a BundleEmitter
** list for a matching name.
*/
static int cmp_builtin_bundle_name(const void *a, const void *b){
const BundleEmitter * rA = (const BundleEmitter*)a;
const BundleEmitter * rB = (const BundleEmitter*)b;
return fossil_strcmp(rA->zName, rB->zName);
}
/*
** Internal helper for /builtin/FILENAME for dispatching "bundles"
** of amalgamated text (primarily JS) code.
**
** Returns true if it finds a bundle matcing the given name, else
** false. On success it outputs the amalgamated bundle without any
** sort of wrapper, e.g. SCRIPT tag
*/
static int page_builtin_text_bundle(const char * zFilename){
const BundleEmitter * pBH;
BundleEmitter needle = {zFilename, 0};
pBH = (const BundleEmitter *)bsearch(&needle, BundleEmitters,
count(BundleEmitters),
sizeof BundleEmitters[0],
cmp_builtin_bundle_name);
if(pBH!=0){
pBH->xEmit();
}
return pBH!=0;
}
/*
** WEBPAGE: builtin
** URL: builtin/FILENAME
**
** Return the built-in text given by FILENAME. This is used internally
** by many Fossil web pages to load built-in javascript files.
**
** If the id= parameter is present, then Fossil assumes that the
** result is immutable and sets a very large cache retention time (1
** year).
*/
void page_builtin_text(void){
Blob out;
const char *zName = P("name");
const char *zTxt = 0;
const char *zId = P("id");
int nId;
int isBundle = 0;
if( zId && (nId = (int)strlen(zId))>=8 && strncmp(zId,MANIFEST_UUID,nId)==0 ){
g.isConst = 1;
}else{
etag_check(0,0)/*might not return*/;
}
if( zName ){
if( sqlite3_strglob("*.js", zName)==0 ){
cgi_set_content_type("application/javascript");
}else{
cgi_set_content_type("text/plain");
}
if(':'==zName[0]){
isBundle = 1;
zTxt = page_builtin_text_bundle(zName+1) ? "" : NULL;
}else{
zTxt = builtin_text(zName);
}
}
if( zTxt==0 ){
cgi_set_content_type("text/html");
cgi_set_status(404, "Not Found");
@ File "%h(zName)" not found
}else if(isBundle==0){
blob_init(&out, zTxt, -1);
cgi_set_content(&out);
}
}
/*
** All possible capabilities
*/
static const char allCap[] =
"abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKL";
/*
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
|
image_url_var("background");
Th_Render(blob_str(&css));
/* Tell CGI that the content returned by this page is considered cacheable */
g.isConst = 1;
}
/*
** All possible capabilities
*/
static const char allCap[] =
"abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKL";
/*
|
| ︙ | | | ︙ | |
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
|
** It emits 2 parts:
**
** 1) window.fossil core object, some of which depends on C-lelel
** runtime data. That part of the script is always emitted inline. If
** addScripTag is true then it is wrapped in its own SCRIPT tag, else
** it is assumed that the caller already opened a tag.
**
** 2) Emits the static fossil.bootstrap.js. If asInline is true then
** it is emitted inline with the components from (1), else it is
** emitted as a separate SCRIPT tag with
** src=/builtin/fossil.bootstrap.js (so causes another HTTP request).
*/
void style_emit_script_fossil_bootstrap(int asInline){
static int once = 0;
if(0==once++){
/* Set up the generic/app-agnostic parts of window.fossil
** which require C-level state... */
if(asInline==0){
style_emit_script_tag(0,0);
}
CX("(function(){\n"
"if(!window.fossil) window.fossil={};\n"
"window.fossil.version = %!j;\n"
/* fossil.rootPath is the top-most CGI/server path,
** including a trailing slash. */
|
|
<
<
<
|
|
|
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
|
** It emits 2 parts:
**
** 1) window.fossil core object, some of which depends on C-lelel
** runtime data. That part of the script is always emitted inline. If
** addScripTag is true then it is wrapped in its own SCRIPT tag, else
** it is assumed that the caller already opened a tag.
**
** 2) Emits the static fossil.bootstrap.js using builtin_request_js().
*/
void style_emit_script_fossil_bootstrap(int addScriptTag){
static int once = 0;
if(0==once++){
/* Set up the generic/app-agnostic parts of window.fossil
** which require C-level state... */
if(addScriptTag!=0){
style_emit_script_tag(0,0);
}
CX("(function(){\n"
"if(!window.fossil) window.fossil={};\n"
"window.fossil.version = %!j;\n"
/* fossil.rootPath is the top-most CGI/server path,
** including a trailing slash. */
|
| ︙ | | | ︙ | |
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
|
** where the current page "should" store any of its own
** page-specific state, and it is reserved for that purpose.
*/
CX("window.fossil.page = {"
"name:\"%T\""
"};\n", g.zPath);
CX("})();\n");
/* The remaining fossil object bootstrap code is not dependent on
** C-runtime state... */
if(asInline!=0){
CX("%s\n", builtin_text("fossil.bootstrap.js"));
}else{
style_emit_script_tag(1,0);
style_emit_script_builtin(0,1,"fossil.bootstrap.js");
}
}
}
/*
** If passed 0 as its first argument, it emits a script opener tag
** with this request's nonce. If passed non-0 it emits a script
** closing tag. Mnemonic for remembering the order in which to pass 0
|
<
<
|
<
<
<
>
>
>
|
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
|
** where the current page "should" store any of its own
** page-specific state, and it is reserved for that purpose.
*/
CX("window.fossil.page = {"
"name:\"%T\""
"};\n", g.zPath);
CX("})();\n");
if(addScriptTag!=0){
style_emit_script_tag(1,0);
}
/* The remaining window.fossil bootstrap code is not dependent on
** C-runtime state... */
builtin_request_js("fossil.bootstrap.js");
}
}
/*
** If passed 0 as its first argument, it emits a script opener tag
** with this request's nonce. If passed non-0 it emits a script
** closing tag. Mnemonic for remembering the order in which to pass 0
|
| ︙ | | | ︙ | |
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
|
}
}else{
CX("</script>\n");
}
}
/*
** Emits a script tag which uses content from a builtin script file.
**
** If asInline is false, the script is emitted as a SCRIPT tag with a
** src attribute of /builtin/zName and the 2nd parameter is
** ignored. If asInline is true then the contents of the script are
** emitted directly, with a wrapping SCRIPT tag if addScripTag is
** true, else no wrapping script tag..
**
** If it is false, a script tag loading it via
** src=builtin/{{zName}}?cache=XYZ is emitted, where XYZ is a
** build-time-dependent cache-buster value.
*/
void style_emit_script_builtin(int asInline, int addScripTag,
char const * zName){
if(asInline){
if(addScripTag){
style_emit_script_tag(0,0);
}
CX("%s", builtin_text(zName));
if(addScripTag){
style_emit_script_tag(1,0);
}
}else{
char * zFullName = mprintf("builtin/%s",zName);
const char * zHash = fossil_exe_id();
CX("<script src='%R/%T?cache=%.8s'></script>\n",
zFullName, zHash);
fossil_free(zFullName);
}
}
/*
** A convenience wrapper arond style_emit_script_builtin() which
** prepends a ':' to zName and passes (0,0,newName) to that
** function. i.e. it emits a SCRIPT tag with
** src=.../builtin/:${zName}?cache=.... The given name is assumed to
** have been added to the style.c:BundleEmitters map.
*/
void style_emit_script_bundle(char const * zName){
char *zBundle = mprintf(":%s", zName);
style_emit_script_builtin(0, 0, zBundle);
fossil_free(zBundle);
}
/*
** The first time this is called it emits the JS code from the
** built-in file fossil.fossil.js. Subsequent calls are no-ops.
**
** If passed a true first argument, it emits the contents directly
** to the page output, else it emits a script tag with a
** src=builtin/... to load the script.
**
** If asInline is true and addScripTag is true then the contents
** are emitted directly but wrapped in a SCRIPT tag. If asInline
** is false, addScriptTag is ignored.
**
** Note that this code relies on that loaded via
** style_emit_script_fossil_bootstrap() but it does not call that
** routine.
*/
void style_emit_script_fetch(int asInline, int addScripTag){
static int once = 0;
if(0==once++){
style_emit_script_builtin(asInline, addScripTag, "fossil.fetch.js");
}
}
/*
** The first time this is called it emits the JS code from the
** built-in file fossil.dom.js. Subsequent calls are no-ops.
**
** If passed a true first argument, it emits the contents directly
** to the page output, else it emits a script tag with a
** src=builtin/... to load the script.
**
** If asInline is true and addScripTag is true then the contents
** are emitted directly but wrapped in a SCRIPT tag. If asInline
** is false, addScriptTag is ignored.
**
** Note that this code relies on that loaded via
** style_emit_script_fossil_bootstrap(), but it does not call that
** routine.
*/
void style_emit_script_dom(int asInline, int addScripTag){
static int once = 0;
if(0==once++){
style_emit_script_builtin(asInline, addScripTag, "fossil.dom.js");
}
}
/*
** The fossil.tabs.js counterpart of style_emit_script_fetch().
** Also emits fossil.dom.js.
*/
void style_emit_script_tabs(int asInline, int addScripTag){
static int once = 0;
if(0==once++){
style_emit_script_dom(asInline, addScripTag);
style_emit_script_builtin(asInline, addScripTag, "fossil.tabs.js");
}
}
/*
** The fossil.confirmer.js counterpart of style_emit_script_fetch().
*/
void style_emit_script_confirmer(int asInline, int addScripTag){
static int once = 0;
if(0==once++){
style_emit_script_builtin(asInline, 0, "fossil.confirmer.js");
}
}
|
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
|
<
<
<
<
<
<
|
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
|
<
<
<
<
<
<
<
<
|
<
|
|
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
|
<
<
|
<
<
<
<
<
<
<
<
|
<
<
|
<
<
<
<
>
|
<
|
>
>
|
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
|
}
}else{
CX("</script>\n");
}
}
/*
** Convenience wrapper which calls builtin_request_js() for a series
** of builtin scripts named fossil.NAME.js. The first time it is
** called, it also calls style_emit_script_fossil_bootstrap() to
** initialize the window.fossil JS API. The first argument is a
** no-meaning dummy required by the va_start() interface. All
** subsequent arguments must be strings of the NAME part of
** fossil.NAME.js, followed by a NULL argument to terminate the list.
**
** e.g. pass it (0, "fetch", "dom", "tabs", 0) to load those 3
** APIs. Do not forget the trailing 0!
*/
void style_emit_fossil_js_apis( int dummy, ... ) {
static int once = 0;
const char *zArg;
char * zName;
va_list vargs;
if(0==once++){
style_emit_script_fossil_bootstrap(1);
}
va_start(vargs,dummy);
while( (zArg = va_arg (vargs, const char *))!=0 ){
zName = mprintf("fossil.%s.js", zArg);
builtin_request_js(zName);
fossil_free(zName);
}
va_end(vargs);
}
|