Fossil SCM
Inconsequential JS cleanups.
Commit
5dd9ff1c04150728407b5ffae0b023590628f00d1b3fb7ec4aa3262bce68a26f
Parent
e70f2fbc7bcdd25…
2 files changed
+2
-2
+20
-8
+2
-2
| --- src/fossil.bootstrap.js | ||
| +++ src/fossil.bootstrap.js | ||
| @@ -125,20 +125,20 @@ | ||
| 125 | 125 | repoUrl( repoRelativePath [,urlParams] ) |
| 126 | 126 | |
| 127 | 127 | Creates a URL by prepending this.rootPath to the given path |
| 128 | 128 | (which must be relative from the top of the site, without a |
| 129 | 129 | 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 | |
| 131 | 131 | a leading '?'. If it's an object, all of its properties get |
| 132 | 132 | appended to the URL in that form. |
| 133 | 133 | */ |
| 134 | 134 | F.repoUrl = function(path,urlParams){ |
| 135 | 135 | if(!urlParams) return this.rootPath+path; |
| 136 | 136 | const url=[this.rootPath,path]; |
| 137 | 137 | url.push('?'); |
| 138 | 138 | if('string'===typeof urlParams) url.push(urlParams); |
| 139 | - else if('object'===typeof urlParams){ | |
| 139 | + else if(urlParams && 'object'===typeof urlParams){ | |
| 140 | 140 | this.encodeUrlArgs(urlParams, url); |
| 141 | 141 | } |
| 142 | 142 | return url.join(''); |
| 143 | 143 | }; |
| 144 | 144 | |
| 145 | 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('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 |
+20
-8
| --- src/fossil.fetch.js | ||
| +++ src/fossil.fetch.js | ||
| @@ -1,10 +1,13 @@ | ||
| 1 | 1 | "use strict"; |
| 2 | 2 | /** |
| 3 | 3 | 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 | |
| 6 | 9 | similar (but not identical) to the not-quite-ubiquitous |
| 7 | 10 | window.fetch(). |
| 8 | 11 | |
| 9 | 12 | JS usages: |
| 10 | 13 | |
| @@ -97,11 +100,11 @@ | ||
| 97 | 100 | that instance should not be kept around for later use. |
| 98 | 101 | |
| 99 | 102 | Returns this object, noting that the XHR request is asynchronous, |
| 100 | 103 | and still in transit (or has yet to be sent) when that happens. |
| 101 | 104 | */ |
| 102 | -window.fossil.fetch = function f(uri,opt){ | |
| 105 | +fossil.fetch = function f(uri,opt){ | |
| 103 | 106 | const F = fossil; |
| 104 | 107 | if(!f.onload){ |
| 105 | 108 | f.onload = (r)=>console.debug('fossil.fetch() XHR response:',r); |
| 106 | 109 | } |
| 107 | 110 | if(!f.onerror){ |
| @@ -108,11 +111,11 @@ | ||
| 108 | 111 | f.onerror = function(e/*exception*/){ |
| 109 | 112 | console.error("fossil.fetch() XHR error:",e); |
| 110 | 113 | if(e instanceof Error) F.error('Exception:',e); |
| 111 | 114 | else F.error("Unknown error in handling of XHR request."); |
| 112 | 115 | }; |
| 113 | - }/*f.onerror()*/ | |
| 116 | + } | |
| 114 | 117 | if(!f.parseResponseHeaders){ |
| 115 | 118 | f.parseResponseHeaders = function(h){ |
| 116 | 119 | const rc = {}; |
| 117 | 120 | if(!h) return rc; |
| 118 | 121 | const ar = h.trim().split(/[\r\n]+/); |
| @@ -144,11 +147,11 @@ | ||
| 144 | 147 | || payload instanceof Array)){ |
| 145 | 148 | payload = JSON.stringify(payload); |
| 146 | 149 | opt.contentType = 'application/json'; |
| 147 | 150 | } |
| 148 | 151 | } |
| 149 | - const url=[F.repoUrl(uri,opt.urlParams)], | |
| 152 | + const url=[f.urlTransform(uri,opt.urlParams)], | |
| 150 | 153 | x=new XMLHttpRequest(); |
| 151 | 154 | if('json'===opt.responseType){ |
| 152 | 155 | /* 'json' is an extension to the supported XHR.responseType |
| 153 | 156 | list. We use it as a flag to tell us to JSON.parse() |
| 154 | 157 | the response. */ |
| @@ -203,8 +206,17 @@ | ||
| 203 | 206 | if(undefined!==payload) x.send(payload); |
| 204 | 207 | else x.send(); |
| 205 | 208 | return this; |
| 206 | 209 | }; |
| 207 | 210 | |
| 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); | |
| 211 | 223 |
| --- 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 |