mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-01-26 21:03:42 +00:00
Compare commits
12 Commits
element-ma
...
saqimtiaz-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5797855aa1 | ||
|
|
d3fded71c2 | ||
|
|
293dbca5a1 | ||
|
|
d07fe25cdb | ||
|
|
4d1645d16d | ||
|
|
b58c14b906 | ||
|
|
ad5d3c3cde | ||
|
|
f0d8852121 | ||
|
|
48c6694d30 | ||
|
|
a993cea80c | ||
|
|
a40ce29451 | ||
|
|
75647eb623 |
@@ -42,6 +42,8 @@ function Server(options) {
|
||||
}
|
||||
// Setup the default required plugins
|
||||
this.requiredPlugins = this.get("required-plugins").split(',');
|
||||
// Initialise CORS
|
||||
this.corsEnable = this.get("cors-enable") === "yes";
|
||||
// Initialise CSRF
|
||||
this.csrfDisable = this.get("csrf-disable") === "yes";
|
||||
// Initialize Gzip compression
|
||||
@@ -261,6 +263,13 @@ Server.prototype.requestHandler = function(request,response,options) {
|
||||
state.urlInfo = url.parse(request.url);
|
||||
state.queryParameters = querystring.parse(state.urlInfo.query);
|
||||
state.pathPrefix = options.pathPrefix || this.get("path-prefix") || "";
|
||||
// Enable CORS
|
||||
if(this.corsEnable) {
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
response.setHeader("Access-Control-Allow-Headers", "*");
|
||||
response.setHeader("Access-Control-Allow-Methods", "*");
|
||||
response.setHeader("Access-Control-Expose-Headers", "*");
|
||||
}
|
||||
state.sendResponse = sendResponse.bind(self,request,response);
|
||||
// Get the principals authorized to access this resource
|
||||
state.authorizationType = options.authorizationType || this.methodMappings[request.method] || "readers";
|
||||
@@ -285,6 +294,12 @@ Server.prototype.requestHandler = function(request,response,options) {
|
||||
response.end();
|
||||
return;
|
||||
}
|
||||
// Reply to OPTIONS
|
||||
if(this.corsEnable && request.method === "OPTIONS") {
|
||||
response.writeHead(204);
|
||||
response.end();
|
||||
return;
|
||||
}
|
||||
// Find the route that matches this path
|
||||
var route = self.findMatchingRoute(request,state);
|
||||
// Optionally output debug info
|
||||
|
||||
@@ -37,6 +37,7 @@ Object.defineProperty(TW_Node.prototype, 'TEXT_NODE', {
|
||||
var TW_TextNode = function(text) {
|
||||
bumpSequenceNumber(this);
|
||||
this.textContent = text + "";
|
||||
this.children = [];
|
||||
};
|
||||
|
||||
Object.setPrototypeOf(TW_TextNode.prototype,TW_Node.prototype);
|
||||
|
||||
@@ -25,6 +25,7 @@ Render this widget into the DOM
|
||||
*/
|
||||
ElementWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
// Neuter blacklisted elements
|
||||
this.tag = this.parseTreeNode.tag;
|
||||
if($tw.config.htmlUnsafeElements.indexOf(this.tag) !== -1) {
|
||||
@@ -41,8 +42,6 @@ ElementWidget.prototype.render = function(parent,nextSibling) {
|
||||
headingLevel = Math.min(Math.max(headingLevel + 1 + baseLevel,1),6);
|
||||
this.tag = "h" + headingLevel;
|
||||
}
|
||||
// Compute the attributes, mapping the element tag if needed
|
||||
this.computeAttributes();
|
||||
// Select the namespace for the tag
|
||||
var XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml",
|
||||
tagNamespaces = {
|
||||
@@ -100,25 +99,4 @@ ElementWidget.prototype.refresh = function(changedTiddlers) {
|
||||
return this.refreshChildren(changedTiddlers) || hasChangedAttributes;
|
||||
};
|
||||
|
||||
/*
|
||||
Override the base computeAttributes method
|
||||
*/
|
||||
ElementWidget.prototype.computeAttributes = function() {
|
||||
// Call the base class to compute the initial values of the attributes
|
||||
var changedAttributes = Widget.prototype.computeAttributes.call(this);
|
||||
// Check for element mapping
|
||||
var mappedTag = this.getVariable("tv-map-" + this.tag),
|
||||
mappedClass = this.getVariable("tv-map-" + this.tag + "-class");
|
||||
if(mappedTag) {
|
||||
this.tag = mappedTag.trim();
|
||||
// Add an attribute to indicate the original tag
|
||||
this.attributes["data-element-mapping-from"] = this.parseTreeNode.tag;
|
||||
// Check for a mapped class
|
||||
if(mappedClass) {
|
||||
this.attributes["class"] = mappedClass.trim() + (this.attributes["class"] ? " " + this.attributes["class"] : "");
|
||||
}
|
||||
}
|
||||
return changedAttributes;
|
||||
};
|
||||
|
||||
exports.element = ElementWidget;
|
||||
|
||||
@@ -121,9 +121,18 @@ SelectWidget.prototype.setSelectValue = function() {
|
||||
if (this.selectMultiple) {
|
||||
value = value === undefined ? "" : value;
|
||||
var select = this.getSelectDomNode();
|
||||
var values = Array.isArray(value) ? value : $tw.utils.parseStringArray(value);
|
||||
var child,
|
||||
values = Array.isArray(value) ? value : $tw.utils.parseStringArray(value);
|
||||
for(var i=0; i < select.children.length; i++){
|
||||
select.children[i].selected = values.indexOf(select.children[i].value) !== -1
|
||||
child=select.children[i];
|
||||
if(child.children.length === 0){
|
||||
child.selected = values.indexOf(child.value) !== -1;
|
||||
} else {
|
||||
// grouped options
|
||||
for(var y=0; y < child.children.length; y++){
|
||||
child.children[y].selected = values.indexOf(child.children[y].value) !== -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var domNode = this.getSelectDomNode();
|
||||
|
||||
@@ -160,7 +160,7 @@ Widget.prototype.getVariableInfo = function(name,options) {
|
||||
});
|
||||
// Parameters are an array of {name:, value:, multivalue:} pairs (name and multivalue are optional)
|
||||
$tw.utils.each(params,function(param) {
|
||||
if(param.multiValue) {
|
||||
if(param.multiValue && param.multiValue.length) {
|
||||
variables[param.name] = param.multiValue;
|
||||
} else {
|
||||
variables[param.name] = param.value || "";
|
||||
@@ -233,8 +233,10 @@ Widget.prototype.resolveVariableParameters = function(formalParams,actualParams)
|
||||
paramMultiValue = typeof param === "string" ? [param] : (param.multiValue || [paramValue]);
|
||||
}
|
||||
// If we've still not got a value, use the default, if any
|
||||
paramValue = paramValue || paramInfo["default"] || "";
|
||||
paramMultiValue = paramMultiValue || [paramValue];
|
||||
if(!paramValue) {
|
||||
paramValue = paramInfo["default"] || "";
|
||||
paramMultiValue = [paramValue];
|
||||
}
|
||||
// Store the parameter name and value
|
||||
results.push({name: paramInfo.name, value: paramValue, multiValue: paramMultiValue});
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
title: ElementMapping/Basic
|
||||
description: Mapping one element to another
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
|
||||
<!-- Map <p> to <div>, adding the class my-class -->
|
||||
\define tv-map-p() div
|
||||
|
||||
This is a paragraph
|
||||
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<div data-element-mapping-from="p">This is a paragraph</div>
|
||||
@@ -1,19 +0,0 @@
|
||||
title: ElementMapping/BasicWithClass
|
||||
description: Mapping one element to another with an added class
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
|
||||
<!-- Map <p> to <div>, adding the class my-class -->
|
||||
\define tv-map-p() div
|
||||
\define tv-map-p-class() my-class
|
||||
|
||||
This is a paragraph
|
||||
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<div class="my-class" data-element-mapping-from="p">This is a paragraph</div>
|
||||
@@ -0,0 +1,16 @@
|
||||
title: Functions/FunctionDefaultValues
|
||||
description: Use defaults for missing parameters in functions in filters
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
\function .test(prefix:Default) [[ Content]addprefix<prefix>]
|
||||
|
||||
<$text text={{{ [.test[Special]] }}}/>,<$text text={{{ [.test[]] }}}/>
|
||||
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>Special Content,Default Content</p>
|
||||
10
editions/tw5.com/tiddlers/releasenotes/5.4.0/#8093.tid
Normal file
10
editions/tw5.com/tiddlers/releasenotes/5.4.0/#8093.tid
Normal file
@@ -0,0 +1,10 @@
|
||||
title: $:/changenotes/5.4.0/#8093
|
||||
description: Fixes SelectWidget does not work with multiple options organised into group - issue #8092
|
||||
release: 5.4.0
|
||||
tags: $:/tags/ChangeNote
|
||||
change-type: bugfix
|
||||
change-category: widget
|
||||
github-links: https://github.com/TiddlyWiki/TiddlyWiki5/issues/8093 https://github.com/TiddlyWiki/TiddlyWiki5/pull/9616
|
||||
github-contributors: buggyj saqimtiaz
|
||||
|
||||
Fixed SelectWidget does not work with multiple options organised into group.
|
||||
@@ -4,8 +4,8 @@ release: 5.4.0
|
||||
tags: $:/tags/ChangeNote
|
||||
change-type: enhancement
|
||||
change-category: hackability
|
||||
github-links: https://github.com/TiddlyWiki/TiddlyWiki5/pull/8972
|
||||
github-contributors: Jermolene
|
||||
github-links: https://github.com/TiddlyWiki/TiddlyWiki5/pull/8972 https://github.com/TiddlyWiki/TiddlyWiki5/pull/9614
|
||||
github-contributors: Jermolene saqimtiaz
|
||||
|
||||
This PR introduces a new filter run prefix `:let` that assigns the result of the filter run to a variable that is made available for the remaining filter runs of the filter expression. It solves the problem that previously it was impossible to compute values for filter operator parameters; parameters could only be a literal string, text reference or variable reference.
|
||||
|
||||
|
||||
10
editions/tw5.com/tiddlers/releasenotes/5.4.0/#9277.tid
Normal file
10
editions/tw5.com/tiddlers/releasenotes/5.4.0/#9277.tid
Normal file
@@ -0,0 +1,10 @@
|
||||
title: $:/changenotes/5.4.0/#9277
|
||||
description: Added an option to enable CORS
|
||||
release: 5.4.0
|
||||
tags: $:/tags/ChangeNote
|
||||
change-type: feature
|
||||
change-category: developer
|
||||
github-links: https://github.com/TiddlyWiki/TiddlyWiki5/pull/9277
|
||||
github-contributors: kixam
|
||||
|
||||
Added an option to the TiddlyWiki5 server to enable CORS (ie. don't check `same-origin`). It is meant for advanced users, do not use it unless you understand the full consequences.
|
||||
Reference in New Issue
Block a user