Fossil

Diff
Login

Differences From Artifact [457c2faee7]:

To Artifact [63766f0f30]:


1418
1419
1420
1421
1422
1423
1424
1425
1426


1427
1428













1429
1430
1431
1432
1433


































































** window.fossil if it's not already defined, and may set some
** properties on it.
*/
void style_emit_script_tag(int phase){
  static int once = 0;
  if(0==phase){
    CX("<script nonce='%s'>", style_nonce());
      if(0==once){
        once = 1;


        CX("\nif(!window.fossil) window.fossil={};\n");
        CX("window.fossil.version = %Q;\n", get_version());













      }
  }else{
    CX("</script>\n");
  }
}









































































|
|
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
** window.fossil if it's not already defined, and may set some
** properties on it.
*/
void style_emit_script_tag(int phase){
  static int once = 0;
  if(0==phase){
    CX("<script nonce='%s'>", style_nonce());
    if(0==once){
      once = 1;
      /* Set up the generic/app-agnostic parts of window.fossil */
      CX("(function(){\n");
      CX("\nif(!window.fossil) window.fossil={};\n");
      CX("window.fossil.version = '%j';\n", get_version());
      /* fossil.rootPath is the top-most CGI/server path,
         including a trailing slash. */
      CX("window.fossil.rootPath = '%j'+'/';\n", g.zTop);
      /*
      ** fossil.page holds info about the current page. This is
      ** also where the current page "should" store any of its
      ** own page-specific state.
      */
      CX("window.fossil.page = {"
         "page:'%T'"
         "};\n", g.zPath);
      CX("%s\n", builtin_text("fossil.bootstrap.js"));
      CX("})();\n");
    }
  }else{
    CX("</script>\n");
  }
}


/*
** The *FIRST* time this is called, it emits a JS script block,
** including tags, which defines window.fossil.fetch(), which works
** similarly (not identically) to the not-quite-ubiquitous global
** fetch(). It calls style_emit_script_tag(), which may inject
** other JS bootstrapping bits.
**
** JS usages:
**
** fossilFetch( URI, onLoadCallback );
**
** fossilFetch( URI, optionsObject );
**
** Noting that URI must be relative to the top of the repository and
** should not start with a slash (if it does, it is stripped). It gets
** the equivalent of "%R/" prepended to it.
**
** The optionsObject may be an onload callback or an object with any
** of these properties:
**
** - onload: callback(responseData) (default = output response to
**   the console).
**
** - onerror: callback(XHR onload event | exception)
**   (default = output event or exception to the console).
**
** - method: 'POST' | 'GET' (default = 'GET')
**
** - payload: anything acceptable by XHR2.send(ARG) (DOMString,
**   Document, FormData, Blob, File, ArrayBuffer), or a plain object
**   or array, either of which gets JSON.stringify()'d. If set then
**   the method is automatically set to 'POST'. If an object/array is
**   converted to JSON, the content-type is set to 'application/json'.
**   By default XHR2 will set the content type based on the payload
**   type.
**
** - contentType: Optional request content type when POSTing. Ignored
**   if the method is not 'POST'.
**
** - responseType: optional string. One of ("text", "arraybuffer",
**   "blob", or "document") (as specified by XHR2). Default = "text".
**   As an extension, it supports "json", which tells it that the
**   response is expected to be text and that it should be
**   JSON.parse()d before passing it on to the onload() callback. In
**   this case, if the payload property is an object/array.
**
** - urlParams: string|object. If a string, it is assumed to be a
**   URI-encoded list of params in the form "key1=val1&key2=val2...",
**   with NO leading '?'.  If it is an object, all of its properties
**   get converted to that form. Either way, the parameters get
**   appended to the URL.
**
** Returns this object, noting that the XHR request is still in
** transit (or has yet to be sent) when that happens.
*/
void style_emit_script_fetch(){
  static int once = 0;
  if(0==once){
    once = 1;
    style_emit_script_tag(0);
    CX("%s", builtin_text("fossil.fetch.js"));
    style_emit_script_tag(1);
  }
}