Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Begin integrating the builtin_request_js() interface. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | refactor-js-handling |
| Files: | files | file ages | folders |
| SHA3-256: |
13caa6e61e0a13c93ea47edc9ce33b3b |
| User & Date: | drh 2020-07-31 20:02:37.478 |
Context
|
2020-07-31
| ||
| 20:16 | Fix lines for separate JS modes. check-in: 314bb1579e user: drh tags: refactor-js-handling | |
| 20:02 | Begin integrating the builtin_request_js() interface. check-in: 13caa6e61e user: drh tags: refactor-js-handling | |
| 16:58 | Add routines for standardized loading of javascript resources. check-in: 01d96c6b45 user: drh tags: refactor-js-handling | |
Changes
Changes to src/browse.c.
| ︙ | ︙ | |||
909 910 911 912 913 914 915 |
while( nClose-- > 0 ){
@ </ul>
}
}
}
@ </ul>
@ </ul></div>
| | | 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 |
while( nClose-- > 0 ){
@ </ul>
}
}
}
@ </ul>
@ </ul></div>
builtin_request_js("tree.js");
style_footer();
/* We could free memory used by sTree here if we needed to. But
** the process is about to exit, so doing so would not really accomplish
** anything useful. */
}
|
| ︙ | ︙ |
Changes to src/builtin.c.
| ︙ | ︙ | |||
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
/* Variables controlling the JS cache.
*/
static struct {
int aReq[30]; /* Indexes of all requested built-in JS files */
int nReq; /* Number of slots in aReq[] currently used */
int nSent; /* Number of slots in aReq[] fulfilled */
} builtin;
/*
** The caller wants the Javascript file named by zFilename to be
** included in the generated page. Add the file to the queue of
** requested javascript resources, if it is not there already.
**
** The current implementation queues the file to be included in the
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
/* Variables controlling the JS cache.
*/
static struct {
int aReq[30]; /* Indexes of all requested built-in JS files */
int nReq; /* Number of slots in aReq[] currently used */
int nSent; /* Number of slots in aReq[] fulfilled */
int eDelivery; /* Delivery mechanism */
} builtin;
#if INTERFACE
/* Various delivery mechanisms. The 0 option is the default.
*/
#define JS_INLINE_BATCH 0 /* inline, batched together */
#define JS_INLINE_IMM 1 /* inline, as soon as requested */
#define JS_SEP_BATCH 2 /* Separate resources, batched */
#define JS_SEP_IMM 3 /* Separate resources, as requested */
#define JS_BUNDLED 4 /* Single separate resource */
#endif /* INTERFACE */
/*
** The argument is a request to change the javascript delivery mode.
** The argument is a string which is a command-line option or CGI
** parameter. Try to match it against one of the delivery options
** and set things up accordingly. Throw an error if no match unless
** bSilent is true.
*/
void builtin_set_js_delivery_mode(const char *zMode, int bSilent){
if( zMode==0 ) return;
if( strcmp(zMode, "inline")==0 ){
builtin.eDelivery = JS_INLINE_BATCH;
}else
if( strcmp(zMode, "inline-imm")==0 ){
builtin.eDelivery = JS_INLINE_IMM;
}else
if( strcmp(zMode, "sep")==0 ){
builtin.eDelivery = JS_SEP_BATCH;
}else
if( strcmp(zMode, "sep-imm")==0 ){
builtin.eDelivery = JS_SEP_IMM;
}else
if( strcmp(zMode, "bundled")==0 ){
builtin.eDelivery = JS_BUNDLED;
}else if( !bSilent ){
fossil_fatal("unknown javascript delivery mode \"%s\" - should be"
" one of: inline inline-immediate separate"
" separate-immediate bundled", zMode);
}
}
/*
** The caller wants the Javascript file named by zFilename to be
** included in the generated page. Add the file to the queue of
** requested javascript resources, if it is not there already.
**
** The current implementation queues the file to be included in the
|
| ︙ | ︙ | |||
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
for(j=0; j<builtin.nReq; j++){
if( builtin.aReq[j]==i ) return; /* Already queued or sent */
}
if( builtin.nReq>=count(builtin.aReq) ){
fossil_panic("too many javascript files requested");
}
builtin.aReq[builtin.nReq++] = i;
}
/*
** Fulfill all pending requests for javascript files.
**
** The current implementation delivers all javascript in-line. However,
** the caller should not depend on this. Future changes to this routine
** might choose to deliver javascript as separate resources.
*/
void builtin_fulfill_js_requests(void){
| > > > > > | > > > | | | > | | | | > | > > > > > > > | > > > > > > > > > > > > > > | 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
for(j=0; j<builtin.nReq; j++){
if( builtin.aReq[j]==i ) return; /* Already queued or sent */
}
if( builtin.nReq>=count(builtin.aReq) ){
fossil_panic("too many javascript files requested");
}
builtin.aReq[builtin.nReq++] = i;
if( builtin.eDelivery==JS_INLINE_IMM
|| builtin.eDelivery==JS_SEP_IMM
){
builtin_fulfill_js_requests();
}
}
/*
** Fulfill all pending requests for javascript files.
**
** The current implementation delivers all javascript in-line. However,
** the caller should not depend on this. Future changes to this routine
** might choose to deliver javascript as separate resources.
*/
void builtin_fulfill_js_requests(void){
if( builtin.nSent>=builtin.nReq ) return; /* nothing to do */
switch( builtin.eDelivery ){
case JS_INLINE_BATCH:
case JS_INLINE_IMM: {
CX("<script nonce='%h'>\n",style_nonce());
do{
int i = builtin.aReq[builtin.nSent++];
CX("/* %s */\n", aBuiltinFiles[i].zName);
cgi_append_content((const char*)aBuiltinFiles[i].pData,
aBuiltinFiles[i].nByte);
}while( builtin.nSent<builtin.nReq );
CX("</script>\n");
break;
}
case JS_SEP_BATCH:
case JS_SEP_IMM: {
/* Each JS file as a separate resource */
while( builtin.nSent<builtin.nReq ){
int i = builtin.aReq[builtin.nSent++];
CX("<script src='/builtin?name=%t&id=%.8s'></script>\n",
aBuiltinFiles[i].zName, fossil_exe_id());
}
break;
}
case JS_BUNDLED: {
Blob aList;
blob_init(&aList,0,0);
while( builtin.nSent<builtin.nReq ){
blob_appendf(&aList, ",%d", builtin.aReq[builtin.nSent++]+1);
}
CX("<script src='/builtin?m=%s&id=%.8s'></script>\n",
blob_str(&aList)+1, fossil_exe_id());
blob_reset(&aList);
}
}
}
|
Changes to src/forum.c.
| ︙ | ︙ | |||
757 758 759 760 761 762 763 |
** closes the document's <BODY> and <HTML> tags). Calls after the first
** are a no-op.
*/
static void forum_emit_page_js(){
static int once = 0;
if(0==once){
once = 1;
| | | 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 |
** closes the document's <BODY> and <HTML> tags). Calls after the first
** are a no-op.
*/
static void forum_emit_page_js(){
static int once = 0;
if(0==once){
once = 1;
builtin_request_js("forum.js");
style_emit_script_fossil_bootstrap(0);
style_emit_script_dom(0);
style_emit_script_builtin(0, "fossil.page.forumpost.js");
}
}
/*
|
| ︙ | ︙ |
Changes to src/info.c.
| ︙ | ︙ | |||
439 440 441 442 443 444 445 |
}
/*
** Generate javascript to enhance HTML diffs.
*/
void append_diff_javascript(int sideBySide){
if( !sideBySide ) return;
| | | 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
}
/*
** Generate javascript to enhance HTML diffs.
*/
void append_diff_javascript(int sideBySide){
if( !sideBySide ) return;
builtin_request_js("sbsdiff.js");
}
/*
** Construct an appropriate diffFlag for text_diff() based on query
** parameters and the to boolean arguments.
*/
u64 construct_diff_flags(int diffType){
|
| ︙ | ︙ | |||
2087 2088 2089 2090 2091 2092 2093 |
else cgi_append_content("\n", 1);
z += i;
if( z[0]=='\n' ) z++;
}
if( n<iEnd ) cgi_printf("</div>");
@ </pre>
if( db_int(0, "SELECT EXISTS(SELECT 1 FROM lnos)") ){
| | | 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 |
else cgi_append_content("\n", 1);
z += i;
if( z[0]=='\n' ) z++;
}
if( n<iEnd ) cgi_printf("</div>");
@ </pre>
if( db_int(0, "SELECT EXISTS(SELECT 1 FROM lnos)") ){
builtin_request_js("scroll.js");
}
}
/*
** WEBPAGE: artifact
** WEBPAGE: file
|
| ︙ | ︙ | |||
3111 3112 3113 3114 3115 3116 3117 |
@ <input type="submit" name="preview" value="Preview" />
if( P("preview") ){
@ <input type="submit" name="apply" value="Apply Changes" />
}
@ </td></tr>
@ </table>
@ </div></form>
| | | 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 |
@ <input type="submit" name="preview" value="Preview" />
if( P("preview") ){
@ <input type="submit" name="apply" value="Apply Changes" />
}
@ </td></tr>
@ </table>
@ </div></form>
builtin_request_js("ci_edit.js");
style_footer();
}
/*
** Prepare an ammended commit comment. Let the user modify it using the
** editor specified in the global_config table or either
** the VISUAL or EDITOR environment variable.
|
| ︙ | ︙ |
Changes to src/login.c.
| ︙ | ︙ | |||
750 751 752 753 754 755 756 |
@ <div class="captcha"><table class="captcha"><tr><td>\
@ <pre class="captcha">
@ %h(zCaptcha)
@ </pre></td></tr></table>
if( bAutoCaptcha ) {
@ <input type="button" value="Fill out captcha" id='autofillButton' \
@ data-af='%s(zDecoded)' />
| | | 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 |
@ <div class="captcha"><table class="captcha"><tr><td>\
@ <pre class="captcha">
@ %h(zCaptcha)
@ </pre></td></tr></table>
if( bAutoCaptcha ) {
@ <input type="button" value="Fill out captcha" id='autofillButton' \
@ data-af='%s(zDecoded)' />
builtin_request_js("login.js");
}
@ </div>
free(zCaptcha);
}
@ </form>
}
if( login_is_individual() ){
|
| ︙ | ︙ |
Changes to src/main.c.
| ︙ | ︙ | |||
2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 | ** --create Create a new REPOSITORY if it does not already exist ** --extroot DIR Document root for the /ext extension mechanism ** --files GLOBLIST Comma-separated list of glob patterns for static files ** --localauth enable automatic login for requests from localhost ** --localhost listen on 127.0.0.1 only (always true for "ui") ** --https Indicates that the input is coming through a reverse ** proxy that has already translated HTTPS into HTTP. ** --max-latency N Do not let any single HTTP request run for more than N ** seconds (only works on unix) ** --nocompress Do not compress HTTP replies ** --nojail Drop root privileges but do not enter the chroot jail ** --nossl signal that no SSL connections are available (Always ** set by default for the "ui" command) ** --notfound URL Redirect | > > > > > > > > > | 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 | ** --create Create a new REPOSITORY if it does not already exist ** --extroot DIR Document root for the /ext extension mechanism ** --files GLOBLIST Comma-separated list of glob patterns for static files ** --localauth enable automatic login for requests from localhost ** --localhost listen on 127.0.0.1 only (always true for "ui") ** --https Indicates that the input is coming through a reverse ** proxy that has already translated HTTPS into HTTP. ** --jsmode MODE Determine how javascript is delivered with pages. ** Mode can be one of: ** inline JS inline at the end of the file ** inline-imm JS inline at point of need ** sep Separate HTTP requests for JS ** sep-imm Separate HTTP requests each issued ** at the need ** bundled One single separate HTTP for all ** JS resources ** --max-latency N Do not let any single HTTP request run for more than N ** seconds (only works on unix) ** --nocompress Do not compress HTTP replies ** --nojail Drop root privileges but do not enter the chroot jail ** --nossl signal that no SSL connections are available (Always ** set by default for the "ui" command) ** --notfound URL Redirect |
| ︙ | ︙ | |||
2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 |
zStopperFile = find_option("stopper", 0, 1);
#endif
if( g.zErrlog==0 ){
g.zErrlog = "-";
}
g.zExtRoot = find_option("extroot",0,1);
zFileGlob = find_option("files-urlenc",0,1);
if( zFileGlob ){
char *z = mprintf("%s", zFileGlob);
dehttpize(z);
zFileGlob = z;
}else{
zFileGlob = find_option("files",0,1);
| > | 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 |
zStopperFile = find_option("stopper", 0, 1);
#endif
if( g.zErrlog==0 ){
g.zErrlog = "-";
}
g.zExtRoot = find_option("extroot",0,1);
builtin_set_js_delivery_mode(find_option("jsmode",0,1),0);
zFileGlob = find_option("files-urlenc",0,1);
if( zFileGlob ){
char *z = mprintf("%s", zFileGlob);
dehttpize(z);
zFileGlob = z;
}else{
zFileGlob = find_option("files",0,1);
|
| ︙ | ︙ |
Changes to src/mkbuiltin.c.
| ︙ | ︙ | |||
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
while( j>0 && (z[j-1]==' ' || z[j-1]=='\t') ){ j--; }
for(k=i+2; k<n && z[k]!='\n'; k++){}
i = k-1;
continue;
}
}
if( c=='\n' ){
while( j>0 && isspace(z[j-1]) ) j--;
z[j++] = '\n';
while( i+1<n && isspace(z[i+1]) ) i++;
continue;
}
z[j++] = c;
}
| > | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
while( j>0 && (z[j-1]==' ' || z[j-1]=='\t') ){ j--; }
for(k=i+2; k<n && z[k]!='\n'; k++){}
i = k-1;
continue;
}
}
if( c=='\n' ){
if( j==0 ) continue;
while( j>0 && isspace(z[j-1]) ) j--;
z[j++] = '\n';
while( i+1<n && isspace(z[i+1]) ) i++;
continue;
}
z[j++] = c;
}
|
| ︙ | ︙ |
Changes to src/setupuser.c.
| ︙ | ︙ | |||
700 701 702 703 704 705 706 |
}
@ <input type="submit" name="can" value="Cancel"></td>
@ </tr>
}
@ </table>
@ </div></form>
@ </div>
| | | 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 |
}
@ <input type="submit" name="can" value="Cancel"></td>
@ </tr>
}
@ </table>
@ </div></form>
@ </div>
builtin_request_js("useredit.js");
@ <hr>
@ <h1>Notes On Privileges And Capabilities:</h1>
@ <ul>
if( higherUser ){
@ <li><p class="missingPriv">
@ User %h(zLogin) has Setup privileges and you only have Admin privileges
@ so you are not permitted to make changes to %h(zLogin).
|
| ︙ | ︙ |
Changes to src/skins.c.
| ︙ | ︙ | |||
1099 1100 1101 1102 1103 1104 1105 |
if( !g.perm.Admin ){
@ <p>Administrators can optionally save or restore legacy skins, and/or
@ undo a prior publish.
}else{
@ <p>Visit the <a href='%R/setup_skin_admin'>Skin Admin</a> page
@ for cleanup and recovery actions.
}
| | | 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 |
if( !g.perm.Admin ){
@ <p>Administrators can optionally save or restore legacy skins, and/or
@ undo a prior publish.
}else{
@ <p>Visit the <a href='%R/setup_skin_admin'>Skin Admin</a> page
@ for cleanup and recovery actions.
}
builtin_request_js("skin.js");
style_footer();
}
|
Changes to src/style.c.
| ︙ | ︙ | |||
86 87 88 89 90 91 92 | */ static int submenuEnable = 1; /* ** Flags for various javascript files needed prior to </body> */ static int needHrefJs = 0; /* href.js */ | < < < < | 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 |
}else{
zResult = mprintf(
zBtnFmt/*works-like:"%h%s%h%h%d"*/,
zTargetId,zText,zTargetId,zTargetId,cchLength);
}
}
free(zText);
| | | 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 |
return 0;
}
/*
** Indicate that the table-sorting javascript is needed.
*/
void style_table_sorter(void){
| < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < | < < < < < < < < < < < < > | 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();
}
/*
** Extra JS to run after all content is loaded.
*/
void style_js_onload(const char *zFormat, ...){
va_list ap;
|
| ︙ | ︙ | |||
914 915 916 917 918 919 920 |
}
}
@ </div>
if( nSubmenuCtrl ){
cgi_query_parameters_to_hidden();
cgi_tag_query_parameter(0);
@ </form>
| | | 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 |
}
}
@ </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">
|
| ︙ | ︙ |
Changes to src/timeline.c.
| ︙ | ︙ | |||
1081 1082 1083 1084 1085 1086 1087 |
}
if( k ) cgi_printf("],");
cgi_printf("\"br\":\"%j\",", pRow->zBranch ? pRow->zBranch : "");
cgi_printf("\"h\":\"%!S\"}%s",
pRow->zUuid, pRow->pNext ? ",\n" : "]\n");
}
@ }</script>
| | | | 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 |
}
if( k ) cgi_printf("],");
cgi_printf("\"br\":\"%j\",", pRow->zBranch ? pRow->zBranch : "");
cgi_printf("\"h\":\"%!S\"}%s",
pRow->zUuid, pRow->pNext ? ",\n" : "]\n");
}
@ }</script>
builtin_request_js("graph.js");
builtin_request_js("copybtn.js"); /* Required by graph.js */
graph_free(pGraph);
}
}
/*
** Create a temporary table suitable for storing timeline data.
*/
|
| ︙ | ︙ | |||
1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 |
nEntry = 10;
}
}
}else{
z = "50";
nEntry = 50;
}
secondaryRid = name_to_typed_rid(P("sel2"),"ci");
selectedRid = name_to_typed_rid(P("sel1"),"ci");
cgi_replace_query_parameter("n",z);
cookie_write_parameter("n","n",0);
tmFlags |= timeline_ss_submenu();
cookie_link_parameter("advm","advm","0");
advancedMenu = atoi(PD("advm","0"));
| > > > > | 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 |
nEntry = 10;
}
}
}else{
z = "50";
nEntry = 50;
}
/* Undocumented query parameter to set JS mode */
builtin_set_js_delivery_mode(P("jsmode"),1);
secondaryRid = name_to_typed_rid(P("sel2"),"ci");
selectedRid = name_to_typed_rid(P("sel1"),"ci");
cgi_replace_query_parameter("n",z);
cookie_write_parameter("n","n",0);
tmFlags |= timeline_ss_submenu();
cookie_link_parameter("advm","advm","0");
advancedMenu = atoi(PD("advm","0"));
|
| ︙ | ︙ |
Changes to src/wiki.c.
| ︙ | ︙ | |||
1842 1843 1844 1845 1846 1847 1848 |
wiki_convert(pBody, 0, WIKI_BUTTONS);
@ </div></div>
blob_reset(&tail);
blob_reset(&title);
blob_reset(&wiki);
}
manifest_destroy(pWiki);
| | | 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 |
wiki_convert(pBody, 0, WIKI_BUTTONS);
@ </div></div>
blob_reset(&tail);
blob_reset(&title);
blob_reset(&wiki);
}
manifest_destroy(pWiki);
builtin_request_js("accordion.js");
return 1;
}
|