Fossil

Diff
Login

Diff

Differences From Artifact [73071985e6]:

To Artifact [6c4386f8fe]:


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
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+


-
-
-
-
-
+
+
+
+
+
+





-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-






+
+
+
+
+
+
+
+
+
-
+
+

-
-
-
-
-
+
+
+
+
+
+
+







  CX("</select>\n");
  if(zLabel && *zLabel){
    CX("</span>\n");
  }
  va_end(vargs);
}

/*
** The first time this is called, it emits code to install and
** bootstrap the window.fossil object, using the built-in file
** fossil.bootstrap.js (not to be confused with bootstrap.js). It does
** NOT wrap that in a script tag because it's called from
** style_emit_script_tag().
**
** Subsequent calls are no-ops.
*/
static void style_emit_script_fossil_bootstrap(){
  static int once = 0;
  if(0==once++){
    /* Set up the generic/app-agnostic parts of window.fossil */
    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. */
       "window.fossil.rootPath = \"%j\"+'/';\n",
       get_version(), 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);
    /* The remaining code is not dependent on C-runtime state... */
    CX("%s\n", builtin_text("fossil.bootstrap.js"));
    CX("})();\n");

  }
}

/*
** If passed 0, it emits a script opener tag with this request's
** nonce. If passed non-0 it emits a script closing tag. The very
** first time it is called, it emits some bootstrapping JS code
** immediately after the script opener. Specifically, it defines
** window.fossil if it's not already defined, and may set some
** properties on it.
** nonce. If passed non-0 it emits a script closing tag.
**
** The very first time it is called, it emits some bootstrapping JS
** code immediately after the script opener. Specifically, it defines
** window.fossil if it's not already defined, and sets up its most
** basic functionality.
*/
void style_emit_script_tag(int phase){
  static int once = 0;
  if(0==phase){
    CX("<script nonce='%s'>", style_nonce());
    if(0==once){
    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"));
      style_emit_script_fossil_bootstrap();
      CX("})();\n");
    }
  }else{
    CX("</script>\n");
  }
}

/*
** Emits the text of builtin_text(zName), which is assumed to be
** JavaScript code, and wrapps that in a pair of calls to
** style_emit_script_tag().
*/
void style_emit_script_builtin(char const * zName){
    style_emit_script_tag(0);
    CX("%s", builtin_text(zName));
    style_emit_script_tag(1);

}

/*
** 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.
** The first time this is called, it emits a JS script block,
** including tags, using the contents of the built-in file
** fossil.fetch.js, which defines window.fossil.fetch(), an HTTP
** request/response mini-framework similar (but not identical) to the
** not-quite-ubiquitous window.fetch(). It calls
** style_emit_script_tag(), which may inject other JS bootstrapping
** bits. Subsequent calls are no-ops.
**
** JS usages:
**
** fossil.fetch( URI [, onLoadCallback] );
**
** fossil.fetch( URI [, optionsObject = {}] );
**
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
1515
1516

1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535


























1536
1537
1518
1519
1520
1521
1522
1523
1524





1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537

1538

1539
1540
1541
1542
1543

1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558





1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586







-
-
-
-
-
+
+
+
+
+








-
+
-





-
+














-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


** - onerror: callback(XHR onload event | exception)
**   (default = 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.
**   or array, either of which gets JSON.stringify()'d. If payload is
**   set then the method is automatically set to 'POST'. If an
**   object/array is converted to JSON, the contentType option is
**   automatically 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
**   JSON.parse()d before passing it on to the onload() callback.
**   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.
**   appended to the URL before submitting the request.
**
** When an options object does not provide onload() or onerror()
** handlers of its own, this function falls back to
** fossil.fetch.onload() and fossil.fetch.onerror() as defaults. The
** default implementations route the data through the dev console and
** (for onerror()) through fossil.error(). Individual pages may
** overwrite those members to provide default implementations suitable
** for the page's use.
**
** Returns this object, noting that the XHR request is asynchronous,
** and 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);
  if(0==once++){
    style_emit_script_builtin("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.
*/
void style_emit_script_dom(){
  static int once = 0;
  if(0==once++){
    style_emit_script_builtin("fossil.dom.js");
  }
}

/*
** The first time this is called, it calls style_emit_script_dom() and
** emits the JS code from the built-in file fossil.tabs.js.
** Subsequent calls are no-ops.
*/
void style_emit_script_tabs(){
  static int once = 0;
  if(0==once++){
    style_emit_script_dom();
    style_emit_script_builtin("fossil.tabs.js");
  }
}