Fossil SCM

Inconsequential JS cleanups.

stephan 2020-08-12 11:42 trunk
Commit 5dd9ff1c04150728407b5ffae0b023590628f00d1b3fb7ec4aa3262bce68a26f
--- src/fossil.bootstrap.js
+++ src/fossil.bootstrap.js
@@ -125,20 +125,20 @@
125125
repoUrl( repoRelativePath [,urlParams] )
126126
127127
Creates a URL by prepending this.rootPath to the given path
128128
(which must be relative from the top of the site, without a
129129
leading slash). If urlParams is a string, it must be
130
- paramters encoded in the form "key=val&key2=val2...", WITHOUT
130
+ paramters encoded in the form "key=val&key2=val2..." WITHOUT
131131
a leading '?'. If it's an object, all of its properties get
132132
appended to the URL in that form.
133133
*/
134134
F.repoUrl = function(path,urlParams){
135135
if(!urlParams) return this.rootPath+path;
136136
const url=[this.rootPath,path];
137137
url.push('?');
138138
if('string'===typeof urlParams) url.push(urlParams);
139
- else if('object'===typeof urlParams){
139
+ else if(urlParams && 'object'===typeof urlParams){
140140
this.encodeUrlArgs(urlParams, url);
141141
}
142142
return url.join('');
143143
};
144144
145145
--- src/fossil.bootstrap.js
+++ src/fossil.bootstrap.js
@@ -125,20 +125,20 @@
125 repoUrl( repoRelativePath [,urlParams] )
126
127 Creates a URL by prepending this.rootPath to the given path
128 (which must be relative from the top of the site, without a
129 leading slash). If urlParams is a string, it must be
130 paramters encoded in the form "key=val&key2=val2...", WITHOUT
131 a leading '?'. If it's an object, all of its properties get
132 appended to the URL in that form.
133 */
134 F.repoUrl = function(path,urlParams){
135 if(!urlParams) return this.rootPath+path;
136 const url=[this.rootPath,path];
137 url.push('?');
138 if('string'===typeof urlParams) url.push(urlParams);
139 else if('object'===typeof urlParams){
140 this.encodeUrlArgs(urlParams, url);
141 }
142 return url.join('');
143 };
144
145
--- src/fossil.bootstrap.js
+++ src/fossil.bootstrap.js
@@ -125,20 +125,20 @@
125 repoUrl( repoRelativePath [,urlParams] )
126
127 Creates a URL by prepending this.rootPath to the given path
128 (which must be relative from the top of the site, without a
129 leading slash). If urlParams is a string, it must be
130 paramters encoded in the form "key=val&key2=val2..." WITHOUT
131 a leading '?'. If it's an object, all of its properties get
132 appended to the URL in that form.
133 */
134 F.repoUrl = function(path,urlParams){
135 if(!urlParams) return this.rootPath+path;
136 const url=[this.rootPath,path];
137 url.push('?');
138 if('string'===typeof urlParams) url.push(urlParams);
139 else if(urlParams && 'object'===typeof urlParams){
140 this.encodeUrlArgs(urlParams, url);
141 }
142 return url.join('');
143 };
144
145
--- src/fossil.fetch.js
+++ src/fossil.fetch.js
@@ -1,10 +1,13 @@
11
"use strict";
22
/**
33
Requires that window.fossil has already been set up.
4
-
5
- window.fossil.fetch() is an HTTP request/response mini-framework
4
+*/
5
+(function(namespace){
6
+const fossil = namespace;
7
+ /**
8
+ fetch() is an HTTP request/response mini-framework
69
similar (but not identical) to the not-quite-ubiquitous
710
window.fetch().
811
912
JS usages:
1013
@@ -97,11 +100,11 @@
97100
that instance should not be kept around for later use.
98101
99102
Returns this object, noting that the XHR request is asynchronous,
100103
and still in transit (or has yet to be sent) when that happens.
101104
*/
102
-window.fossil.fetch = function f(uri,opt){
105
+fossil.fetch = function f(uri,opt){
103106
const F = fossil;
104107
if(!f.onload){
105108
f.onload = (r)=>console.debug('fossil.fetch() XHR response:',r);
106109
}
107110
if(!f.onerror){
@@ -108,11 +111,11 @@
108111
f.onerror = function(e/*exception*/){
109112
console.error("fossil.fetch() XHR error:",e);
110113
if(e instanceof Error) F.error('Exception:',e);
111114
else F.error("Unknown error in handling of XHR request.");
112115
};
113
- }/*f.onerror()*/
116
+ }
114117
if(!f.parseResponseHeaders){
115118
f.parseResponseHeaders = function(h){
116119
const rc = {};
117120
if(!h) return rc;
118121
const ar = h.trim().split(/[\r\n]+/);
@@ -144,11 +147,11 @@
144147
|| payload instanceof Array)){
145148
payload = JSON.stringify(payload);
146149
opt.contentType = 'application/json';
147150
}
148151
}
149
- const url=[F.repoUrl(uri,opt.urlParams)],
152
+ const url=[f.urlTransform(uri,opt.urlParams)],
150153
x=new XMLHttpRequest();
151154
if('json'===opt.responseType){
152155
/* 'json' is an extension to the supported XHR.responseType
153156
list. We use it as a flag to tell us to JSON.parse()
154157
the response. */
@@ -203,8 +206,17 @@
203206
if(undefined!==payload) x.send(payload);
204207
else x.send();
205208
return this;
206209
};
207210
208
-window.fossil.fetch.beforesend = function(){};
209
-window.fossil.fetch.aftersend = function(){};
210
-window.fossil.fetch.timeout = 15000/* Default timeout, in ms. */;
211
+/**
212
+ urlTransform() must refer to a function which accepts a relative path
213
+ to the same site as fetch() is served from and an optional set of
214
+ URL parameters to pass with it (in the form a of a string
215
+ ("a=b&c=d...") or an object of key/value pairs (which it converts
216
+ to such a string), and returns the resulting URL or URI as a string.
217
+*/
218
+fossil.fetch.urlTransform = (u,p)=>fossil.repoUrl(u,p);
219
+fossil.fetch.beforesend = function(){};
220
+fossil.fetch.aftersend = function(){};
221
+fossil.fetch.timeout = 15000/* Default timeout, in ms. */;
222
+})(window.fossil);
211223
--- src/fossil.fetch.js
+++ src/fossil.fetch.js
@@ -1,10 +1,13 @@
1 "use strict";
2 /**
3 Requires that window.fossil has already been set up.
4
5 window.fossil.fetch() is an HTTP request/response mini-framework
 
 
 
6 similar (but not identical) to the not-quite-ubiquitous
7 window.fetch().
8
9 JS usages:
10
@@ -97,11 +100,11 @@
97 that instance should not be kept around for later use.
98
99 Returns this object, noting that the XHR request is asynchronous,
100 and still in transit (or has yet to be sent) when that happens.
101 */
102 window.fossil.fetch = function f(uri,opt){
103 const F = fossil;
104 if(!f.onload){
105 f.onload = (r)=>console.debug('fossil.fetch() XHR response:',r);
106 }
107 if(!f.onerror){
@@ -108,11 +111,11 @@
108 f.onerror = function(e/*exception*/){
109 console.error("fossil.fetch() XHR error:",e);
110 if(e instanceof Error) F.error('Exception:',e);
111 else F.error("Unknown error in handling of XHR request.");
112 };
113 }/*f.onerror()*/
114 if(!f.parseResponseHeaders){
115 f.parseResponseHeaders = function(h){
116 const rc = {};
117 if(!h) return rc;
118 const ar = h.trim().split(/[\r\n]+/);
@@ -144,11 +147,11 @@
144 || payload instanceof Array)){
145 payload = JSON.stringify(payload);
146 opt.contentType = 'application/json';
147 }
148 }
149 const url=[F.repoUrl(uri,opt.urlParams)],
150 x=new XMLHttpRequest();
151 if('json'===opt.responseType){
152 /* 'json' is an extension to the supported XHR.responseType
153 list. We use it as a flag to tell us to JSON.parse()
154 the response. */
@@ -203,8 +206,17 @@
203 if(undefined!==payload) x.send(payload);
204 else x.send();
205 return this;
206 };
207
208 window.fossil.fetch.beforesend = function(){};
209 window.fossil.fetch.aftersend = function(){};
210 window.fossil.fetch.timeout = 15000/* Default timeout, in ms. */;
 
 
 
 
 
 
 
 
 
211
--- src/fossil.fetch.js
+++ src/fossil.fetch.js
@@ -1,10 +1,13 @@
1 "use strict";
2 /**
3 Requires that window.fossil has already been set up.
4 */
5 (function(namespace){
6 const fossil = namespace;
7 /**
8 fetch() is an HTTP request/response mini-framework
9 similar (but not identical) to the not-quite-ubiquitous
10 window.fetch().
11
12 JS usages:
13
@@ -97,11 +100,11 @@
100 that instance should not be kept around for later use.
101
102 Returns this object, noting that the XHR request is asynchronous,
103 and still in transit (or has yet to be sent) when that happens.
104 */
105 fossil.fetch = function f(uri,opt){
106 const F = fossil;
107 if(!f.onload){
108 f.onload = (r)=>console.debug('fossil.fetch() XHR response:',r);
109 }
110 if(!f.onerror){
@@ -108,11 +111,11 @@
111 f.onerror = function(e/*exception*/){
112 console.error("fossil.fetch() XHR error:",e);
113 if(e instanceof Error) F.error('Exception:',e);
114 else F.error("Unknown error in handling of XHR request.");
115 };
116 }
117 if(!f.parseResponseHeaders){
118 f.parseResponseHeaders = function(h){
119 const rc = {};
120 if(!h) return rc;
121 const ar = h.trim().split(/[\r\n]+/);
@@ -144,11 +147,11 @@
147 || payload instanceof Array)){
148 payload = JSON.stringify(payload);
149 opt.contentType = 'application/json';
150 }
151 }
152 const url=[f.urlTransform(uri,opt.urlParams)],
153 x=new XMLHttpRequest();
154 if('json'===opt.responseType){
155 /* 'json' is an extension to the supported XHR.responseType
156 list. We use it as a flag to tell us to JSON.parse()
157 the response. */
@@ -203,8 +206,17 @@
206 if(undefined!==payload) x.send(payload);
207 else x.send();
208 return this;
209 };
210
211 /**
212 urlTransform() must refer to a function which accepts a relative path
213 to the same site as fetch() is served from and an optional set of
214 URL parameters to pass with it (in the form a of a string
215 ("a=b&c=d...") or an object of key/value pairs (which it converts
216 to such a string), and returns the resulting URL or URI as a string.
217 */
218 fossil.fetch.urlTransform = (u,p)=>fossil.repoUrl(u,p);
219 fossil.fetch.beforesend = function(){};
220 fossil.fetch.aftersend = function(){};
221 fossil.fetch.timeout = 15000/* Default timeout, in ms. */;
222 })(window.fossil);
223

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button