| | @@ -83,10 +83,15 @@ |
| 83 | 83 | /* |
| 84 | 84 | ** Ad-unit styles. |
| 85 | 85 | */ |
| 86 | 86 | static unsigned adUnitFlags = 0; |
| 87 | 87 | |
| 88 | +/* |
| 89 | +** True if the "href.js" javascript file is required. |
| 90 | +*/ |
| 91 | +static int needHrefJs = 0; |
| 92 | + |
| 88 | 93 | |
| 89 | 94 | /* |
| 90 | 95 | ** Generate and return a anchor tag like this: |
| 91 | 96 | ** |
| 92 | 97 | ** <a href="URL"> |
| | @@ -138,10 +143,11 @@ |
| 138 | 143 | if( g.perm.Hyperlink && !g.javascriptHyperlink ){ |
| 139 | 144 | char *zHUrl = mprintf("<a %s href=\"%h\">", zExtra, zUrl); |
| 140 | 145 | fossil_free(zUrl); |
| 141 | 146 | return zHUrl; |
| 142 | 147 | } |
| 148 | + needHrefJs = 1; |
| 143 | 149 | return mprintf("<a %s data-href='%z' href='%R/honeypot'>", |
| 144 | 150 | zExtra, zUrl); |
| 145 | 151 | } |
| 146 | 152 | char *chref(const char *zExtra, const char *zFormat, ...){ |
| 147 | 153 | char *zUrl; |
| | @@ -152,10 +158,11 @@ |
| 152 | 158 | if( g.perm.Hyperlink && !g.javascriptHyperlink ){ |
| 153 | 159 | char *zHUrl = mprintf("<a %s href=\"%h\">", zExtra, zUrl); |
| 154 | 160 | fossil_free(zUrl); |
| 155 | 161 | return zHUrl; |
| 156 | 162 | } |
| 163 | + needHrefJs = 1; |
| 157 | 164 | return mprintf("<a class='%s' data-href='%z' href='%R/honeypot'>", |
| 158 | 165 | zExtra, zUrl); |
| 159 | 166 | } |
| 160 | 167 | char *href(const char *zFormat, ...){ |
| 161 | 168 | char *zUrl; |
| | @@ -166,10 +173,11 @@ |
| 166 | 173 | if( g.perm.Hyperlink && !g.javascriptHyperlink ){ |
| 167 | 174 | char *zHUrl = mprintf("<a href=\"%h\">", zUrl); |
| 168 | 175 | fossil_free(zUrl); |
| 169 | 176 | return zHUrl; |
| 170 | 177 | } |
| 178 | + needHrefJs = 1; |
| 171 | 179 | return mprintf("<a data-href='%s' href='%R/honeypot'>", |
| 172 | 180 | zUrl); |
| 173 | 181 | } |
| 174 | 182 | |
| 175 | 183 | /* |
| | @@ -184,10 +192,11 @@ |
| 184 | 192 | zLink = vmprintf(zAction, ap); |
| 185 | 193 | va_end(ap); |
| 186 | 194 | if( g.perm.Hyperlink && !g.javascriptHyperlink ){ |
| 187 | 195 | @ <form method="POST" action="%z(zLink)" %s(zOtherArgs)> |
| 188 | 196 | }else{ |
| 197 | + needHrefJs = 1; |
| 189 | 198 | @ <form method="POST" data-action='%s(zLink)' action='%R/login' \ |
| 190 | 199 | @ %s(zOtherArgs)> |
| 191 | 200 | } |
| 192 | 201 | } |
| 193 | 202 | |
| | @@ -503,10 +512,33 @@ |
| 503 | 512 | }else if( !fossil_all_whitespace(zAd = db_get("adunit",0)) ){ |
| 504 | 513 | return zAd; |
| 505 | 514 | } |
| 506 | 515 | return 0; |
| 507 | 516 | } |
| 517 | + |
| 518 | +/* |
| 519 | +** Generate code to load a single javascript file |
| 520 | +*/ |
| 521 | +static void style_load_one_js_file(const char *zFile){ |
| 522 | + @ <script src='%R/builtin/%s(zFile)/%S(MANIFEST_UUID)'></script> |
| 523 | +} |
| 524 | + |
| 525 | +/* |
| 526 | +** Generate code to load all required javascript files. |
| 527 | +*/ |
| 528 | +static void style_load_all_js_files(void){ |
| 529 | + if( needHrefJs ){ |
| 530 | + int nDelay = db_get_int("auto-hyperlink-delay",0); |
| 531 | + int bMouseover; |
| 532 | + /* Load up the page data */ |
| 533 | + bMouseover = (!g.isHuman || db_get_boolean("auto-hyperlink-ishuman",0)) |
| 534 | + && db_get_boolean("auto-hyperlink-mouseover",0); |
| 535 | + @ <script id='href-data' type='application/json'>\ |
| 536 | + @ {"delay":%d(nDelay),"mouseover":%d(bMouseover)}</script> |
| 537 | + style_load_one_js_file("href.js"); |
| 538 | + } |
| 539 | +} |
| 508 | 540 | |
| 509 | 541 | /* |
| 510 | 542 | ** Draw the footer at the bottom of the page. |
| 511 | 543 | */ |
| 512 | 544 | void style_footer(void){ |
| | @@ -662,32 +694,15 @@ |
| 662 | 694 | */ |
| 663 | 695 | @ <div class="endContent"></div> |
| 664 | 696 | } |
| 665 | 697 | @ </div> |
| 666 | 698 | |
| 667 | | - /* Load up the page data */ |
| 668 | | - @ <script id='page-data' type='application/json'> |
| 669 | | - if( !g.javascriptHyperlink ){ |
| 670 | | - @ {"antibot":{"enable":0}, |
| 671 | | - }else{ |
| 672 | | - int nDelay = db_get_int("auto-hyperlink-delay",0); |
| 673 | | - int bMouseover; |
| 674 | | - bMouseover = (!g.isHuman || db_get_boolean("auto-hyperlink-ishuman",0)) |
| 675 | | - && db_get_boolean("auto-hyperlink-mouseover",0); |
| 676 | | - @ {"antibot": |
| 677 | | - @ {"enable":1, |
| 678 | | - @ "delay":%d(nDelay), |
| 679 | | - @ "mouseover":%d(bMouseover)}, |
| 680 | | - } |
| 681 | | - @ "noop":0} |
| 682 | | - @ </script> |
| 683 | 699 | |
| 684 | 700 | |
| 685 | 701 | zFooter = skin_get("footer"); |
| 686 | 702 | if( sqlite3_strlike("%</body>%", zFooter, 0)==0 ){ |
| 687 | | - @ <script src='%s(g.zBaseURL)/main.js/%S(MANIFEST_UUID)' \ |
| 688 | | - @ type='application/javascript'></script> |
| 703 | + style_load_all_js_files(); |
| 689 | 704 | } |
| 690 | 705 | if( g.thTrace ) Th_Trace("BEGIN_FOOTER<br />\n", -1); |
| 691 | 706 | Th_Render(zFooter); |
| 692 | 707 | if( g.thTrace ) Th_Trace("END_FOOTER<br />\n", -1); |
| 693 | 708 | |
| | @@ -698,12 +713,11 @@ |
| 698 | 713 | cgi_append_content("</span>\n", -1); |
| 699 | 714 | } |
| 700 | 715 | |
| 701 | 716 | /* Add document end mark if it was not in the footer */ |
| 702 | 717 | if( sqlite3_strlike("%</body>%", zFooter, 0)!=0 ){ |
| 703 | | - @ <script src='%s(g.zBaseURL)/main.js/%S(MANIFEST_UUID)' \ |
| 704 | | - @ type='application/javascript'></script> |
| 718 | + style_load_all_js_files(); |
| 705 | 719 | @ </body> |
| 706 | 720 | @ </html> |
| 707 | 721 | } |
| 708 | 722 | } |
| 709 | 723 | |
| | @@ -837,19 +851,47 @@ |
| 837 | 851 | /* Tell CGI that the content returned by this page is considered cacheable */ |
| 838 | 852 | g.isConst = 1; |
| 839 | 853 | } |
| 840 | 854 | |
| 841 | 855 | /* |
| 842 | | -** WEBPAGE: main.js |
| 856 | +** WEBPAGE: builtin |
| 857 | +** URL: builtin/FILENAME/VERSION |
| 858 | +** |
| 859 | +** Return the built-in text given by FILENAME. This is used internally |
| 860 | +** by many Fossil web pages to load built-in javascript files. |
| 843 | 861 | ** |
| 844 | | -** Return the javascript |
| 862 | +** The VERSION string at the end is ignored. Fossil web pages will |
| 863 | +** typically put the current Fossil check-in hash as VERSION, to cause |
| 864 | +** javascript files to be reloaded rather than sourcing a stale javascript |
| 865 | +** file from cache. |
| 845 | 866 | */ |
| 846 | | -void page_main_js(void){ |
| 847 | | - Blob mainjs; |
| 848 | | - cgi_set_content_type("application/javascript"); |
| 849 | | - blob_init(&mainjs, builtin_text("main.js"), -1); |
| 850 | | - cgi_set_content(&mainjs); |
| 867 | +void page_builtin_text(void){ |
| 868 | + Blob out; |
| 869 | + const char *zName = P("name"); |
| 870 | + const char *zTxt = 0; |
| 871 | + if( zName ){ |
| 872 | + int i; |
| 873 | + for(i=0; zName[i]; i++){ |
| 874 | + if( zName[i]=='/' ){ |
| 875 | + zName = mprintf("%.*s", i, zName); |
| 876 | + break; |
| 877 | + } |
| 878 | + } |
| 879 | + zTxt = builtin_text(zName); |
| 880 | + } |
| 881 | + if( zTxt==0 ){ |
| 882 | + cgi_set_status(404, "Not Found"); |
| 883 | + @ File \"%h(zName)\" not found |
| 884 | + return; |
| 885 | + } |
| 886 | + if( sqlite3_strglob("*.js", zName)==0 ){ |
| 887 | + cgi_set_content_type("application/javascript"); |
| 888 | + }else{ |
| 889 | + cgi_set_content_type("text/plain"); |
| 890 | + } |
| 891 | + blob_init(&out, zTxt, -1); |
| 892 | + cgi_set_content(&out); |
| 851 | 893 | g.isConst = 1; |
| 852 | 894 | } |
| 853 | 895 | |
| 854 | 896 | |
| 855 | 897 | /* |
| 856 | 898 | |