Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Added optional fossil.fetch() beforesend/aftersend callbacks to allow us to... /efilepage now disables all input elements while AJAX requests are in-flight and updates the page with a 'wait' cursor. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | fileedit-ajaxify |
Files: | files | file ages | folders |
SHA3-256: |
7e197260fd1a797fee9ce4f5a863948f |
User & Date: | stephan 2020-05-18 05:19:19.238 |
Context
2020-05-18
| ||
06:05 | Internal commentary on the validity of the global UI enable/disable approach to XHR handling. ... (check-in: 7a95a0f1 user: stephan tags: fileedit-ajaxify) | |
05:19 | Added optional fossil.fetch() beforesend/aftersend callbacks to allow us to... /efilepage now disables all input elements while AJAX requests are in-flight and updates the page with a 'wait' cursor. ... (check-in: 7e197260 user: stephan tags: fileedit-ajaxify) | |
03:41 | Replaced style.css?page=xxx with style.css/page, like the [style-css-revamp] branch does. ... (check-in: bc407074 user: stephan tags: fileedit-ajaxify) | |
Changes
Changes to src/fossil.fetch.js.
︙ | ︙ | |||
20 21 22 23 24 25 26 | of these properties: - onload: callback(responseData) (default = output response to the console). In the context of the callback, the options object is "this", noting that this call may have amended the options object with state other than what the caller provided. | | | > > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | of these properties: - onload: callback(responseData) (default = output response to the console). In the context of the callback, the options object is "this", noting that this call may have amended the options object with state other than what the caller provided. - onerror: callback(XHR onload event | exception) (default = event or exception to the console). Triggered if the request generates any response other than HTTP 200. In the context of the callback, the options object is "this". - method: 'POST' | 'GET' (default = 'GET'). CASE SENSITIVE! - 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 payload is set then the method is automatically set to 'POST'. By default XHR2 |
︙ | ︙ | |||
62 63 64 65 66 67 68 | value of that single header. If it's an array, it's treated as a list of headers to return, and the 2nd argument is a map of those header values. When a map is passed on, all of its keys are lower-cased. When a given header is requested and that header is set multiple times, their values are (per the XHR docs) concatenated together with ", " between them. | > > > > > > > > > | | > | | | > | | | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | value of that single header. If it's an array, it's treated as a list of headers to return, and the 2nd argument is a map of those header values. When a map is passed on, all of its keys are lower-cased. When a given header is requested and that header is set multiple times, their values are (per the XHR docs) concatenated together with ", " between them. - beforesend/aftersend: optional callbacks which are called without arguments immediately before the request is submitted and immediately after it is received, regardless of success or error. In the context of the callback, the options object is the "this". These can be used to, e.g., keep track of in-flight requests and update the UI accordingly, e.g. disabling/enabling DOM elements. Any exceptions triggered by beforesend/aftersend are caught and silently ignored. When an options object does not provide onload/onerror/beforesend/aftersend handlers of its own, this function falls to defaults which are member properties of this function with the same name, e.g. fossil.fetch.onload(). The default onload/onerror implementations route the data through the dev console and (for onerror()) through fossil.error(). The default beforesend/aftersend are no-ops. Individual pages may overwrite those members to provide default implementations suitable for the page's use, e.g. keeping track of how many in-flight Returns this object, noting that the XHR request is asynchronous, and still in transit (or has yet to be sent) when that happens. */ window.fossil.fetch = function f(uri,opt){ const F = fossil; if(!f.onload){ |
︙ | ︙ | |||
119 120 121 122 123 124 125 126 127 128 129 130 131 132 | }; } if('/'===uri[0]) uri = uri.substr(1); if(!opt) opt = {}; else if('function'===typeof opt) opt={onload:opt}; if(!opt.onload) opt.onload = f.onload; if(!opt.onerror) opt.onerror = f.onerror; let payload = opt.payload, jsonResponse = false; if(undefined!==payload){ opt.method = 'POST'; if(!(payload instanceof FormData) && !(payload instanceof Document) && !(payload instanceof Blob) && !(payload instanceof File) | > > | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | }; } if('/'===uri[0]) uri = uri.substr(1); if(!opt) opt = {}; else if('function'===typeof opt) opt={onload:opt}; if(!opt.onload) opt.onload = f.onload; if(!opt.onerror) opt.onerror = f.onerror; if(!opt.beforesend) opt.beforesend = f.beforesend; if(!opt.aftersend) opt.aftersend = f.aftersend; let payload = opt.payload, jsonResponse = false; if(undefined!==payload){ opt.method = 'POST'; if(!(payload instanceof FormData) && !(payload instanceof Document) && !(payload instanceof Blob) && !(payload instanceof File) |
︙ | ︙ | |||
149 150 151 152 153 154 155 156 157 158 159 160 161 162 | the response. */ jsonResponse = true; x.responseType = 'text'; }else{ x.responseType = opt.responseType||'text'; } x.onload = function(e){ if(200!==this.status){ opt.onerror(e); return; } const orh = opt.responseHeaders; let head; if(true===orh){ | > | 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | the response. */ jsonResponse = true; x.responseType = 'text'; }else{ x.responseType = opt.responseType||'text'; } x.onload = function(e){ try{opt.aftersend()}catch(e){/*ignore*/} if(200!==this.status){ opt.onerror(e); return; } const orh = opt.responseHeaders; let head; if(true===orh){ |
︙ | ︙ | |||
174 175 176 177 178 179 180 181 182 183 184 | ? JSON.parse(this.response) : this.response]; if(head) args.push(head); opt.onload.apply(opt, args); }catch(e){ opt.onerror(e); } }; if(undefined!==payload) x.send(payload); else x.send(); return this; }; | > > > > | 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | ? JSON.parse(this.response) : this.response]; if(head) args.push(head); opt.onload.apply(opt, args); }catch(e){ opt.onerror(e); } }; try{opt.beforesend()}catch(e){/*ignore*/} if(undefined!==payload) x.send(payload); else x.send(); return this; }; window.fossil.fetch.beforesend = function(){}; window.fossil.fetch.aftersend = function(){}; |
Changes to src/fossil.page.fileedit.js.
︙ | ︙ | |||
459 460 461 462 463 464 465 | F.storage.storageImplName()), "):", sel, btnClear); D.attr(wrapper, "title", [ 'Locally-edited files. Timestamps are the last local edit time.', 'Only the',P.config.defaultMaxStashSize,'most recent checkin/file', 'combinations are retained.', | | | 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | F.storage.storageImplName()), "):", sel, btnClear); D.attr(wrapper, "title", [ 'Locally-edited files. Timestamps are the last local edit time.', 'Only the',P.config.defaultMaxStashSize,'most recent checkin/file', 'combinations are retained.', 'Committing or reloading a file removes it from this list.' ].join(' ')); D.option(D.disable(sel), "(empty)"); F.page.addEventListener('fileedit-stash-updated',(e)=>this.updateList(e.detail)); F.page.addEventListener('fileedit-file-loaded',(e)=>this.updateList($stash, e.detail)); sel.addEventListener('change',function(e){ const opt = this.selectedOptions[0]; if(opt && opt._finfo) P.loadFile(opt._finfo); |
︙ | ︙ | |||
556 557 558 559 560 561 562 563 564 565 566 567 568 569 | forceEvent = true; } if(forceEvent){ // Force UI update s.dispatchEvent(new Event('change',{target:s})); } }; F.onPageLoad(function() { P.base = {tag: E('base')}; P.base.originalHref = P.base.tag.href; P.tabs = new fossil.TabManager('#fileedit-tabs'); P.e = { /* various DOM elements we work with... */ taEditor: E('#fileedit-content-editor'), | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 | forceEvent = true; } if(forceEvent){ // Force UI update s.dispatchEvent(new Event('change',{target:s})); } }; /** Keep track of how many in-flight AJAX requests there are so we can disable input elements while any are pending. For simplicity's sake we simply disable ALL OF IT while any AJAX is pending, rather than disabling operation-specific UI elements, which would be a huge maintenance hassle.. */ const ajaxState = { count: 0 /* in-flight F.fetch() requests */, toDisable: undefined /* elements to disable during ajax activity */ }; F.fetch.beforesend = function f(){ if(!ajaxState.toDisable){ ajaxState.toDisable = document.querySelectorAll( 'button, input, select, textarea' ); } if(1===++ajaxState.count){ D.addClass(document.body, 'waiting'); D.disable(ajaxState.toDisable); } }; F.fetch.aftersend = function(){ if(0===--ajaxState.count){ D.removeClass(document.body, 'waiting'); D.enable(ajaxState.toDisable); } }; F.onPageLoad(function() { P.base = {tag: E('base')}; P.base.originalHref = P.base.tag.href; P.tabs = new fossil.TabManager('#fileedit-tabs'); P.e = { /* various DOM elements we work with... */ taEditor: E('#fileedit-content-editor'), |
︙ | ︙ |
Changes to src/style.fileedit.css.
1 2 3 4 5 6 7 8 | /** Styles specific to /fileedit... */ body.fileedit .error { padding: 0.25em; } body.fileedit .warning { padding: 0.25em; } body.fileedit textarea { | > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 | /** Styles specific to /fileedit... */ body.fileedit.waiting * { /* Triggered during AJAX requests. */ cursor: wait; } body.fileedit .error { padding: 0.25em; } body.fileedit .warning { padding: 0.25em; } body.fileedit textarea { |
︙ | ︙ |