mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-12-08 17:58:05 +00:00
Add a Zotero demo for the new http mechanism
An initial experiment for handling paginated APIs. This isn't perfect; it isn't possible to interrupt things, for example.
This commit is contained in:
39
core/modules/filters/url-ops.js
Normal file
39
core/modules/filters/url-ops.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/*\
|
||||
title: $:/core/modules/filters/url-ops.js
|
||||
type: application/javascript
|
||||
module-type: filteroperator
|
||||
|
||||
Filter operators for URL operations
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports["setquerystring"] = function(source,operator,options) {
|
||||
var URL = $tw.browser ? window.URL : require("url").URL,
|
||||
URLSearchParams = $tw.browser ? window.URLSearchParams : require("url").URLSearchParams,
|
||||
name = operator.operands.length >= 1 ? operator.operands[0] : null,
|
||||
value = operator.operands.length >= 2 ? operator.operands[1] : "",
|
||||
results = [];
|
||||
source(function(tiddler,title) {
|
||||
var url;
|
||||
try {
|
||||
url = new URL(title);
|
||||
} catch(e) {
|
||||
}
|
||||
if(url) {
|
||||
var params = new URLSearchParams(url.search);
|
||||
if(name) {
|
||||
params.set(name,value);
|
||||
}
|
||||
url.search = params.toString();
|
||||
results.push(url.toString());
|
||||
}
|
||||
});
|
||||
return results;
|
||||
};
|
||||
|
||||
})();
|
||||
@@ -66,9 +66,9 @@ HttpClient.prototype.handleHttpRequest = function(event) {
|
||||
callback: function(err,data,xhr) {
|
||||
var headers = {};
|
||||
$tw.utils.each(xhr.getAllResponseHeaders().split("\r\n"),function(line) {
|
||||
var parts = line.split(":");
|
||||
if(parts.length === 2) {
|
||||
headers[parts[0].toLowerCase()] = parts[1].trim();
|
||||
var pos = line.indexOf(":");
|
||||
if(pos !== -1) {
|
||||
headers[line.substr(0,pos)] = line.substr(pos + 1).trim();
|
||||
}
|
||||
});
|
||||
setBinding(bindStatus,xhr.status === 200 ? "complete" : "error");
|
||||
|
||||
Reference in New Issue
Block a user