Skip to content

Commit 93d2709

Browse files
committed
fix bugs in quagPartsToURLHash, fix server.go bugs, fix favicon
1 parent 4653871 commit 93d2709

File tree

3 files changed

+28
-37
lines changed

3 files changed

+28
-37
lines changed

favicon.ico

-13.7 KB
Binary file not shown.

server.go

-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ func serveFiles(w http.ResponseWriter, r *http.Request) {
1919
if filePath == "" {
2020
// On empty path display home/index (`test.html`)
2121
filePath = "index.html"
22-
} else if filePath == "test_run.js" || filePath == "test.js" || filePath == "example.js" || filePath == "urlform.js" || filePath == "fragment_text_demonstration.html" {
23-
// Do nothing, serve filepath unmodified.
24-
} else {
25-
filePath = "../" + filePath
2622
}
2723

2824
log.Printf("Serving: %s", filePath)

urlform.js

+28-33
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
'use strict';
22

3-
/**
4-
* Making file/module accessible through the global 'window' under the
5-
* namespace 'URLForm'.
6-
* Taken from
7-
* https://github.com/paulmillr/noble-secp256k1/releases/tag/1.6.3
8-
* and
9-
* https://stackoverflow.com/a/63751410/15147681
10-
*/
11-
(function (global, factory) {
3+
4+
// URLFormJS is used for sticky forms and sharable URL links. See README.
5+
6+
7+
// UMD export pattern. See //TODO LINk
8+
(function(global, factory) {
129
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
1310
typeof define === 'function' && define.amd ? define(['exports'], factory) :
1411
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.URLForm = {}));
15-
})(this, (function (exports) {
12+
})(this, (function(exports) {
1613
exports.Init = Init;
1714
exports.PopulateFromValues = PopulateFromValues;
1815
exports.PopulateFromURI = PopulateFromURI;
@@ -685,9 +682,8 @@ function shareURI(formOptions) {
685682
}
686683
}
687684

688-
// Inherit default query location if empty, not set, or not a recognized
689-
// 'QueryLocation'.
690-
if ((fp.queryLocation === "" || isEmpty(fp.queryLocation) || (fp.queryLocation !== "fragment" || fp.queryLocation !== "query"))) {
685+
// Inherit default query location if not a recognized 'QueryLocation'.
686+
if (fp.queryLocation !== "fragment" && fp.queryLocation !== "query") {
691687
fp.queryLocation = formOptions.defaultQueryLocation;
692688
}
693689

@@ -715,8 +711,11 @@ function shareURI(formOptions) {
715711
url.searchParams.set(extra, extras.query[extra]);
716712
}
717713
}
714+
715+
console.log(q);
718716
// Rebuild fragment query in case new form fields were set.
719717
url.hash = quagPartsToURLHash(q, extras);
718+
console.log(url.href);
720719

721720
// URI Link
722721
let shareUrl = document.querySelector(formOptions.shareURL);
@@ -780,50 +779,46 @@ function getExtraParameters(formOptions) {
780779
*
781780
* @param {QuagParts} qp QuagParts
782781
* @param {ExtraParameters} extras ExtraParameters.
783-
* @param {FormOptions} formOptions
782+
* @param {FormOptions} formOptions
784783
* @returns {String} Fragment query string (#?...).
785784
*/
786785
function quagPartsToURLHash(qp, extras, formOptions) {
787-
if (isEmpty(qp.fragmentParts)) {
786+
if (isEmpty(qp.fragmentPairs)) {
788787
return "";
789788
}
790789
let fqs = "#";
791-
if (!isEmpty(qp.fragmentParts.before)) {
792-
fqs += qp.fragmentParts.before;
793-
}
790+
// Append anything that was in *fragment* before, but not in, *fragment query*.
791+
fqs += qp.fragmentParts.before;
792+
793+
// Build the fragment query
794794
fqs += "?";
795795
var last = Object.keys(qp.fragmentPairs).length - 1;
796796
var i = 0;
797-
var suffix = "&";
798-
if (last === 0) {
799-
suffix = "";
800-
}
797+
801798
for (let key in qp.fragmentPairs) {
802-
if (i === (last)) {
803-
suffix = "";
804-
}
805799
i++;
806800
if (extras.fragKeys.includes(key)) {
807801
continue;
808802
}
809-
fqs += key + "=" + qp.fragmentPairs[key] + suffix;
803+
fqs += key + "=" + qp.fragmentPairs[key]
804+
if (i !== 0) {
805+
fqs += "&"; // Add separator on everything except the last.
806+
}
810807
}
811808

812809
// Set extras back in query params, if given and 'cleanURL' is false in 'formOptions'.
813810
if (!isEmpty(extras.frag) && !formOptions.cleanURL) {
814-
i = 0;
815-
suffix = "&";
816811
last = extras.fragKeys.length - 1;
817812
for (let extra in extras.frag) {
818-
if (i === (last)) {
819-
suffix = "";
820-
}
821813
i++;
822-
fqs += extra + "=" + extras.frag[extra] + suffix;
814+
fqs += extra + "=" + extras.frag[extra]
815+
if (i !== 0) {
816+
fqs += "&";
817+
}
823818
}
824819
}
825820

826-
// Append text-fragment.
821+
// Append anything that was in *fragment* after, but not in, *fragment query*.
827822
fqs += qp.fragmentParts.after;
828823
return fqs;
829824
}

0 commit comments

Comments
 (0)