mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-10-05 15:41:42 +00:00
Initial commit
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
/*\
|
||||
|
||||
title: $:/core/modules/widgets/action-confirm.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -14,14 +12,8 @@ var ConfirmWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
ConfirmWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
ConfirmWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.computeAttributes();
|
||||
this.execute();
|
||||
@@ -29,18 +21,12 @@ ConfirmWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
ConfirmWidget.prototype.execute = function() {
|
||||
this.message = this.getAttribute("$message",$tw.language.getString("ConfirmAction"));
|
||||
this.prompt = (this.getAttribute("$prompt","yes") == "no" ? false : true);
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
ConfirmWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes["$message"] || changedAttributes["$prompt"]) {
|
||||
@@ -50,9 +36,6 @@ ConfirmWidget.prototype.refresh = function(changedTiddlers) {
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
};
|
||||
|
||||
/*
|
||||
Invoke the action associated with this widget
|
||||
*/
|
||||
ConfirmWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
var invokeActions = true,
|
||||
handled = true,
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/action-createtiddler.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Action widget to create a new tiddler with a unique name and specified fields.
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var CreateTiddlerWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
CreateTiddlerWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
CreateTiddlerWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -31,9 +22,6 @@ CreateTiddlerWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
CreateTiddlerWidget.prototype.execute = function() {
|
||||
this.actionBaseTitle = this.getAttribute("$basetitle");
|
||||
this.hasBase = !!this.actionBaseTitle;
|
||||
@@ -48,9 +36,6 @@ CreateTiddlerWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
CreateTiddlerWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if($tw.utils.count(changedAttributes) > 0) {
|
||||
@@ -60,9 +45,6 @@ CreateTiddlerWidget.prototype.refresh = function(changedTiddlers) {
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
};
|
||||
|
||||
/*
|
||||
Invoke the action associated with this widget
|
||||
*/
|
||||
CreateTiddlerWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
var title = this.wiki.getTiddlerText("$:/language/DefaultNewTiddlerTitle"), // Get the initial new-tiddler title
|
||||
fields = {},
|
||||
@@ -82,7 +64,7 @@ CreateTiddlerWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
} else if (this.hasBase && this.actionOverwrite === "yes") {
|
||||
title = this.actionBaseTitle
|
||||
}
|
||||
// NO $basetitle BUT $template parameter is available
|
||||
|
||||
// the title MUST be unique, otherwise the template would be overwritten
|
||||
if (!this.hasBase && this.useTemplate) {
|
||||
title = this.wiki.generateNewTitle(this.actionTemplate);
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/action-deletefield.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Action widget to delete fields of a tiddler.
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,31 +12,19 @@ var DeleteFieldWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
DeleteFieldWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
DeleteFieldWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.computeAttributes();
|
||||
this.execute();
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
DeleteFieldWidget.prototype.execute = function() {
|
||||
this.actionTiddler = this.getAttribute("$tiddler",this.getVariable("currentTiddler"));
|
||||
this.actionField = this.getAttribute("$field",null);
|
||||
this.actionTimestamp = this.getAttribute("$timestamp","yes") === "yes";
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
DeleteFieldWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes["$tiddler"]) {
|
||||
@@ -49,9 +34,6 @@ DeleteFieldWidget.prototype.refresh = function(changedTiddlers) {
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
};
|
||||
|
||||
/*
|
||||
Invoke the action associated with this widget
|
||||
*/
|
||||
DeleteFieldWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
var self = this,
|
||||
tiddler = this.wiki.getTiddler(self.actionTiddler),
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/action-deletetiddler.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Action widget to delete a tiddler.
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,30 +12,18 @@ var DeleteTiddlerWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
DeleteTiddlerWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
DeleteTiddlerWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.computeAttributes();
|
||||
this.execute();
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
DeleteTiddlerWidget.prototype.execute = function() {
|
||||
this.actionFilter = this.getAttribute("$filter");
|
||||
this.actionTiddler = this.getAttribute("$tiddler");
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
DeleteTiddlerWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes["$filter"] || changedAttributes["$tiddler"]) {
|
||||
@@ -48,9 +33,6 @@ DeleteTiddlerWidget.prototype.refresh = function(changedTiddlers) {
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
};
|
||||
|
||||
/*
|
||||
Invoke the action associated with this widget
|
||||
*/
|
||||
DeleteTiddlerWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
var tiddlers = [];
|
||||
if(this.actionFilter) {
|
||||
|
||||
@@ -2,29 +2,17 @@
|
||||
title: $:/core/modules/widgets/action-listops.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Action widget to apply list operations to any tiddler field (defaults to the 'list' field of the current tiddler)
|
||||
|
||||
\*/
|
||||
"use strict";
|
||||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
var ActionListopsWidget = function(parseTreeNode, options) {
|
||||
this.initialise(parseTreeNode, options);
|
||||
};
|
||||
/**
|
||||
* Inherit from the base widget class
|
||||
*/
|
||||
ActionListopsWidget.prototype = new Widget();
|
||||
/**
|
||||
* Render this widget into the DOM
|
||||
*/
|
||||
ActionListopsWidget.prototype.render = function(parent, nextSibling) {
|
||||
this.computeAttributes();
|
||||
this.execute();
|
||||
};
|
||||
/**
|
||||
* Compute the internal state of the widget
|
||||
*/
|
||||
ActionListopsWidget.prototype.execute = function() {
|
||||
// Get our parameters
|
||||
this.target = this.getAttribute("$tiddler", this.getVariable(
|
||||
@@ -35,9 +23,6 @@ ActionListopsWidget.prototype.execute = function() {
|
||||
this.listIndex = this.getAttribute("$index");
|
||||
this.filtertags = this.getAttribute("$tags");
|
||||
};
|
||||
/**
|
||||
* Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
ActionListopsWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if($tw.utils.count(changedAttributes) > 0) {
|
||||
@@ -46,9 +31,6 @@ ActionListopsWidget.prototype.refresh = function(changedTiddlers) {
|
||||
}
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
};
|
||||
/**
|
||||
* Invoke the action associated with this widget
|
||||
*/
|
||||
ActionListopsWidget.prototype.invokeAction = function(triggeringWidget,
|
||||
event) {
|
||||
//Apply the specified filters to the lists
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
/*\
|
||||
title: $:/core/modules/widgets/action-log.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Action widget to log debug messages
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -16,14 +12,8 @@ var LogWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
LogWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
LogWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.computeAttributes();
|
||||
this.execute();
|
||||
@@ -35,17 +25,11 @@ LogWidget.prototype.execute = function(){
|
||||
this.filter = this.getAttribute("$$filter");
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
LogWidget.prototype.refresh = function(changedTiddlers) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
};
|
||||
|
||||
/*
|
||||
Invoke the action associated with this widget
|
||||
*/
|
||||
LogWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
this.log();
|
||||
return true; // Action was invoked
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/action-navigate.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Action widget to navigate to a tiddler
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,30 +12,18 @@ var NavigateWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
NavigateWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
NavigateWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.computeAttributes();
|
||||
this.execute();
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
NavigateWidget.prototype.execute = function() {
|
||||
this.actionTo = this.getAttribute("$to");
|
||||
this.actionScroll = this.getAttribute("$scroll");
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
NavigateWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes["$to"] || changedAttributes["$scroll"]) {
|
||||
@@ -48,9 +33,6 @@ NavigateWidget.prototype.refresh = function(changedTiddlers) {
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
};
|
||||
|
||||
/*
|
||||
Invoke the action associated with this widget
|
||||
*/
|
||||
NavigateWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
event = event || {};
|
||||
var bounds = triggeringWidget && triggeringWidget.getBoundingClientRect && triggeringWidget.getBoundingClientRect(),
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/action-popup.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Action widget to trigger a popup.
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -17,31 +14,19 @@ var ActionPopupWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
ActionPopupWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
ActionPopupWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.computeAttributes();
|
||||
this.execute();
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
ActionPopupWidget.prototype.execute = function() {
|
||||
this.actionState = this.getAttribute("$state");
|
||||
this.actionCoords = this.getAttribute("$coords");
|
||||
this.floating = this.getAttribute("$floating","no") === "yes";
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
ActionPopupWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes["$state"] || changedAttributes["$coords"]) {
|
||||
@@ -51,9 +36,6 @@ ActionPopupWidget.prototype.refresh = function(changedTiddlers) {
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
};
|
||||
|
||||
/*
|
||||
Invoke the action associated with this widget
|
||||
*/
|
||||
ActionPopupWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
// Trigger the popup
|
||||
var coordinates = Popup.parseCoordinates(this.actionCoords || "");
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/action-sendmessage.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Action widget to send a message
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,22 +12,13 @@ var SendMessageWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
SendMessageWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
SendMessageWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.computeAttributes();
|
||||
this.execute();
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
SendMessageWidget.prototype.execute = function() {
|
||||
this.actionMessage = this.getAttribute("$message");
|
||||
this.actionParam = this.getAttribute("$param");
|
||||
@@ -40,9 +28,6 @@ SendMessageWidget.prototype.execute = function() {
|
||||
this.actionValues = this.getAttribute("$values");
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
SendMessageWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(Object.keys(changedAttributes).length) {
|
||||
@@ -52,9 +37,6 @@ SendMessageWidget.prototype.refresh = function(changedTiddlers) {
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
};
|
||||
|
||||
/*
|
||||
Invoke the action associated with this widget
|
||||
*/
|
||||
SendMessageWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
// Get the string parameter
|
||||
var param = this.actionParam;
|
||||
@@ -68,7 +50,7 @@ SendMessageWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
paramObject[name] = values[index] || "";
|
||||
});
|
||||
}
|
||||
// Add raw parameters
|
||||
|
||||
$tw.utils.each(this.attributes,function(attribute,name) {
|
||||
if(name.charAt(0) !== "$") {
|
||||
paramObject[name] = attribute;
|
||||
@@ -78,7 +60,7 @@ SendMessageWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
if(this.actionName) {
|
||||
paramObject[this.actionName] = this.actionValue;
|
||||
}
|
||||
// Dispatch the message
|
||||
|
||||
var params = {
|
||||
type: this.actionMessage,
|
||||
param: param,
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/action-setfield.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Action widget to set a single field or index on a tiddler.
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,22 +12,13 @@ var SetFieldWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
SetFieldWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
SetFieldWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.computeAttributes();
|
||||
this.execute();
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
SetFieldWidget.prototype.execute = function() {
|
||||
this.actionTiddler = this.getAttribute("$tiddler") || (!this.hasParseTreeNodeAttribute("$tiddler") && this.getVariable("currentTiddler"));
|
||||
this.actionField = this.getAttribute("$field");
|
||||
@@ -39,17 +27,11 @@ SetFieldWidget.prototype.execute = function() {
|
||||
this.actionTimestamp = this.getAttribute("$timestamp","yes") === "yes";
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
SetFieldWidget.prototype.refresh = function(changedTiddlers) {
|
||||
// Nothing to refresh
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
};
|
||||
|
||||
/*
|
||||
Invoke the action associated with this widget
|
||||
*/
|
||||
SetFieldWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
var self = this,
|
||||
options = {};
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/action-setmultiplefields.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Action widget to set multiple fields or indexes on a tiddler
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,22 +12,13 @@ var SetMultipleFieldsWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
SetMultipleFieldsWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
SetMultipleFieldsWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.computeAttributes();
|
||||
this.execute();
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
SetMultipleFieldsWidget.prototype.execute = function() {
|
||||
this.actionTiddler = this.getAttribute("$tiddler",this.getVariable("currentTiddler"));
|
||||
this.actionFields = this.getAttribute("$fields");
|
||||
@@ -39,9 +27,6 @@ SetMultipleFieldsWidget.prototype.execute = function() {
|
||||
this.actionTimestamp = this.getAttribute("$timestamp","yes") === "yes";
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
SetMultipleFieldsWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes["$tiddler"] || changedAttributes["$fields"] || changedAttributes["$indexes"] || changedAttributes["$values"] || changedAttributes["$timestamp"]) {
|
||||
@@ -51,9 +36,6 @@ SetMultipleFieldsWidget.prototype.refresh = function(changedTiddlers) {
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
};
|
||||
|
||||
/*
|
||||
Invoke the action associated with this widget
|
||||
*/
|
||||
SetMultipleFieldsWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
var tiddler = this.wiki.getTiddler(this.actionTiddler),
|
||||
names, values = this.wiki.filterTiddlers(this.actionValues,this);
|
||||
|
||||
@@ -2,15 +2,8 @@
|
||||
title: $:/core/modules/widgets/audio.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Basic Audio widget for displaying audio files.
|
||||
This is a simple implementation that can be overridden by plugins
|
||||
for more advanced functionality.
|
||||
|
||||
\*/
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
@@ -19,25 +12,19 @@ var AudioWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
AudioWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
AudioWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
this.execute();
|
||||
|
||||
|
||||
// Create audio element
|
||||
var audioElement = this.document.createElement("audio");
|
||||
audioElement.setAttribute("controls", this.getAttribute("controls", "controls"));
|
||||
audioElement.setAttribute("style", this.getAttribute("style", "width: 100%; object-fit: contain"));
|
||||
audioElement.className = "tw-audio-element";
|
||||
|
||||
|
||||
// Set source
|
||||
if(this.audioSource) {
|
||||
if (this.audioSource.indexOf("data:") === 0) {
|
||||
@@ -51,21 +38,17 @@ AudioWidget.prototype.render = function(parent,nextSibling) {
|
||||
audioElement.appendChild(sourceElement);
|
||||
}
|
||||
}
|
||||
|
||||
// Insert the audio into the DOM
|
||||
|
||||
parent.insertBefore(audioElement, nextSibling);
|
||||
this.domNodes.push(audioElement);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
AudioWidget.prototype.execute = function() {
|
||||
// Get the audio source and type
|
||||
this.audioSource = this.getAttribute("src");
|
||||
this.audioType = this.getAttribute("type");
|
||||
this.audioControls = this.getAttribute("controls", "controls");
|
||||
|
||||
|
||||
// Try to get from tiddler attribute
|
||||
if(!this.audioSource && this.getAttribute("tiddler")) {
|
||||
var tiddlerTitle = this.getAttribute("tiddler");
|
||||
@@ -80,14 +63,10 @@ AudioWidget.prototype.execute = function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we have a tiddler for saving timestamps
|
||||
|
||||
this.tiddlerTitle = this.getAttribute("tiddler");
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
AudioWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.src || changedAttributes.type || changedAttributes.controls || changedAttributes.tiddler) {
|
||||
@@ -99,5 +78,3 @@ AudioWidget.prototype.refresh = function(changedTiddlers) {
|
||||
};
|
||||
|
||||
exports.audio = AudioWidget;
|
||||
|
||||
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/browse.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Browse widget for browsing for files to import
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var BrowseWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
BrowseWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
BrowseWidget.prototype.render = function(parent,nextSibling) {
|
||||
var self = this;
|
||||
// Remember parent
|
||||
@@ -42,14 +33,14 @@ BrowseWidget.prototype.render = function(parent,nextSibling) {
|
||||
if(this.tabIndex) {
|
||||
domNode.setAttribute("tabindex", this.tabIndex);
|
||||
}
|
||||
// Nw.js supports "nwsaveas" to force a "save as" dialogue that allows a new or existing file to be selected
|
||||
|
||||
if(this.nwsaveas) {
|
||||
domNode.setAttribute("nwsaveas",this.nwsaveas);
|
||||
}
|
||||
if(this.accept) {
|
||||
domNode.setAttribute("accept",this.accept);
|
||||
}
|
||||
// Nw.js supports "webkitdirectory" and "nwdirectory" to allow a directory to be selected
|
||||
|
||||
if(this.webkitdirectory) {
|
||||
domNode.setAttribute("webkitdirectory",this.webkitdirectory);
|
||||
}
|
||||
@@ -59,7 +50,7 @@ BrowseWidget.prototype.render = function(parent,nextSibling) {
|
||||
if(this.isDisabled === "yes") {
|
||||
domNode.setAttribute("disabled", true);
|
||||
}
|
||||
// Add a click event handler
|
||||
|
||||
domNode.addEventListener("change",function (event) {
|
||||
if(self.message) {
|
||||
self.dispatchEvent({type: self.message, param: self.param, files: event.target.files});
|
||||
@@ -84,9 +75,6 @@ BrowseWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(domNode,null);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
BrowseWidget.prototype.execute = function() {
|
||||
this.browseMultiple = this.getAttribute("multiple");
|
||||
this.deserializer = this.getAttribute("deserializer");
|
||||
@@ -101,14 +89,11 @@ BrowseWidget.prototype.execute = function() {
|
||||
this.isDisabled = this.getAttribute("disabled", "no");
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
BrowseWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if($tw.utils.count(changedAttributes) > 0) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/button.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Button widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -19,14 +16,8 @@ var ButtonWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
ButtonWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
ButtonWidget.prototype.render = function(parent,nextSibling) {
|
||||
var self = this,
|
||||
tag = "button",
|
||||
@@ -85,14 +76,14 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
|
||||
if(this.popup || this.popupTitle) {
|
||||
domNode.setAttribute("aria-expanded",isPoppedUp ? "true" : "false");
|
||||
}
|
||||
// Set the tabindex
|
||||
|
||||
if(this.tabIndex) {
|
||||
domNode.setAttribute("tabindex",this.tabIndex);
|
||||
}
|
||||
if(this.isDisabled === "yes") {
|
||||
domNode.setAttribute("disabled",true);
|
||||
}
|
||||
// Add a click event handler
|
||||
|
||||
domNode.addEventListener("click",function (event) {
|
||||
var handled = false;
|
||||
if(self.invokeActions(self,event)) {
|
||||
@@ -133,15 +124,12 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
|
||||
widget: this
|
||||
});
|
||||
}
|
||||
// Insert element
|
||||
|
||||
parent.insertBefore(domNode,nextSibling);
|
||||
this.domNodes.push(domNode);
|
||||
this.renderChildren(domNode,null);
|
||||
};
|
||||
|
||||
/*
|
||||
We don't allow actions to propagate because we trigger actions ourselves
|
||||
*/
|
||||
ButtonWidget.prototype.allowActionPropagation = function() {
|
||||
return false;
|
||||
};
|
||||
@@ -210,9 +198,6 @@ ButtonWidget.prototype.setTiddler = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
ButtonWidget.prototype.execute = function() {
|
||||
// Get attributes
|
||||
this.actions = this.getAttribute("actions");
|
||||
@@ -262,9 +247,6 @@ ButtonWidget.prototype.updateDomNodeClasses = function() {
|
||||
this.domNode.className = domNodeClasses.join(" ");
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
ButtonWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.tooltip || changedAttributes.actions || changedAttributes.to || changedAttributes.message || changedAttributes.param || changedAttributes.set || changedAttributes.setTo || changedAttributes.popup || changedAttributes.hover || changedAttributes.selectedClass || changedAttributes.style || changedAttributes.dragFilter || changedAttributes.dragTiddler || (this.set && changedTiddlers[this.set]) || (this.popup && changedTiddlers[this.popup]) || (this.popupTitle && changedTiddlers[this.popupTitle]) || changedAttributes.popupAbsCoords || changedAttributes.setTitle || changedAttributes.setField || changedAttributes.setIndex || changedAttributes.popupTitle || changedAttributes.disabled || changedAttributes["default"]) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/checkbox.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Checkbox widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var CheckboxWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
CheckboxWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
CheckboxWidget.prototype.render = function(parent,nextSibling) {
|
||||
var isChecked;
|
||||
// Save the parent dom node
|
||||
@@ -96,7 +87,7 @@ CheckboxWidget.prototype.getValue = function() {
|
||||
if(value === this.checkboxUnchecked) {
|
||||
return false;
|
||||
}
|
||||
// Neither value found: were both specified?
|
||||
|
||||
if(this.checkboxChecked && !this.checkboxUnchecked) {
|
||||
return false; // Absence of checked value
|
||||
}
|
||||
@@ -132,7 +123,7 @@ CheckboxWidget.prototype.getValue = function() {
|
||||
if(list.indexOf(this.checkboxUnchecked) !== -1) {
|
||||
return false;
|
||||
}
|
||||
// Neither one present
|
||||
|
||||
if(this.checkboxChecked && !this.checkboxUnchecked) {
|
||||
return false; // Absence of checked value
|
||||
}
|
||||
@@ -147,7 +138,7 @@ CheckboxWidget.prototype.getValue = function() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Neither specified, so empty list is false, non-empty is true
|
||||
|
||||
return !!list.length;
|
||||
}
|
||||
} else {
|
||||
@@ -181,7 +172,7 @@ CheckboxWidget.prototype.handleChangeEvent = function(event) {
|
||||
} else {
|
||||
tagCheck = hasTag !== checked;
|
||||
}
|
||||
// Set the tag if specified
|
||||
|
||||
if(this.checkboxTag && (!tiddler || tagCheck)) {
|
||||
newFields.tags = tiddler ? (tiddler.fields.tags || []).slice(0) : [];
|
||||
var pos = newFields.tags.indexOf(this.checkboxTag);
|
||||
@@ -195,21 +186,21 @@ CheckboxWidget.prototype.handleChangeEvent = function(event) {
|
||||
}
|
||||
hasChanged = true;
|
||||
}
|
||||
// Set the field if specified
|
||||
|
||||
if(this.checkboxField) {
|
||||
if(!tiddler || tiddler.fields[this.checkboxField] !== value) {
|
||||
newFields[this.checkboxField] = value;
|
||||
hasChanged = true;
|
||||
}
|
||||
}
|
||||
// Set the index if specified
|
||||
|
||||
if(this.checkboxIndex) {
|
||||
var indexValue = this.wiki.extractTiddlerDataItem(this.checkboxTitle,this.checkboxIndex);
|
||||
if(!tiddler || indexValue !== value) {
|
||||
hasChanged = true;
|
||||
}
|
||||
}
|
||||
// Set the list field (or index) if specified
|
||||
|
||||
if(this.checkboxListField || this.checkboxListIndex) {
|
||||
var fieldContents, listContents, oldPos, newPos;
|
||||
if(this.checkboxListField) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/codeblock.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Code block node widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var CodeBlockWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
CodeBlockWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
CodeBlockWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -38,16 +29,10 @@ CodeBlockWidget.prototype.render = function(parent,nextSibling) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
CodeBlockWidget.prototype.execute = function() {
|
||||
this.language = this.getAttribute("language");
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
CodeBlockWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.code || changedAttributes.language) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/count.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Count widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var CountWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
CountWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
CountWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -32,9 +23,6 @@ CountWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.domNodes.push(textNode);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
CountWidget.prototype.execute = function() {
|
||||
// Get parameters from our attributes
|
||||
this.filter = this.getAttribute("filter");
|
||||
@@ -46,9 +34,6 @@ CountWidget.prototype.execute = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
CountWidget.prototype.refresh = function(changedTiddlers) {
|
||||
// Re-execute the filter to get the count
|
||||
this.computeAttributes();
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/data.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Widget to dynamically represent one or more tiddlers
|
||||
|
||||
\*/
|
||||
"use strict";
|
||||
|
||||
@@ -15,14 +12,8 @@ var DataWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
DataWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
DataWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -33,16 +24,10 @@ DataWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.domNodes.push(this.domNode);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
DataWidget.prototype.execute = function() {
|
||||
// Nothing to do here
|
||||
};
|
||||
|
||||
/*
|
||||
Read the tiddler value(s) from a data widget as an array of tiddler field objects (not $tw.Tiddler objects)
|
||||
*/
|
||||
DataWidget.prototype.readDataTiddlerValues = function() {
|
||||
var results = [];
|
||||
$tw.utils.each(this.dataPayload,function(tiddler,index) {
|
||||
@@ -51,23 +36,17 @@ DataWidget.prototype.readDataTiddlerValues = function() {
|
||||
return results;
|
||||
};
|
||||
|
||||
/*
|
||||
Read the tiddler value(s) from a data widget as an array of tiddler field objects (not $tw.Tiddler objects)
|
||||
*/
|
||||
DataWidget.prototype.readDataTiddlerValuesAsJson = function() {
|
||||
return JSON.stringify(this.readDataTiddlerValues(),null,4);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute list of tiddlers from a data widget
|
||||
*/
|
||||
DataWidget.prototype.computeDataTiddlerValues = function() {
|
||||
var self = this;
|
||||
// Read any attributes not prefixed with $
|
||||
var item = Object.create(null);
|
||||
$tw.utils.each(this.attributes,function(value,name) {
|
||||
if(name.charAt(0) !== "$") {
|
||||
item[name] = value;
|
||||
item[name] = value;
|
||||
}
|
||||
});
|
||||
// Deal with $tiddler, $filter or $compound-tiddler attributes
|
||||
@@ -110,7 +89,7 @@ DataWidget.prototype.computeDataTiddlerValues = function() {
|
||||
});
|
||||
}
|
||||
}
|
||||
// Return the literal item if none of the special attributes were used
|
||||
|
||||
if(!this.hasAttribute("$tiddler") && !this.hasAttribute("$filter") && !this.hasAttribute("$compound-tiddler") && !this.hasAttribute("$compound-filter")) {
|
||||
if(Object.keys(item).length > 0 && !!item.title) {
|
||||
return [new $tw.Tiddler(item)];
|
||||
@@ -128,9 +107,6 @@ DataWidget.prototype.computeDataTiddlerValues = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Helper to extract tiddlers from text/vnd.tiddlywiki-multiple tiddlers
|
||||
*/
|
||||
DataWidget.prototype.extractCompoundTiddler = function(title) {
|
||||
var tiddler = this.wiki.getTiddler(title);
|
||||
if(tiddler && tiddler.fields.type === "text/vnd.tiddlywiki-multiple") {
|
||||
@@ -154,9 +130,6 @@ DataWidget.prototype.extractCompoundTiddler = function(title) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
DataWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
var newPayload = this.computeDataTiddlerValues();
|
||||
@@ -169,9 +142,6 @@ DataWidget.prototype.refresh = function(changedTiddlers) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Compare two arrays of tiddlers and return true if they are different
|
||||
*/
|
||||
function hasPayloadChanged(a,b) {
|
||||
if(a.length === b.length) {
|
||||
for(var t=0; t<a.length; t++) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/diff-text.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Widget to display a diff between two texts
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -16,9 +13,6 @@ var DiffTextWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
DiffTextWidget.prototype = new Widget();
|
||||
|
||||
DiffTextWidget.prototype.invisibleCharacters = {
|
||||
@@ -27,9 +21,6 @@ DiffTextWidget.prototype.invisibleCharacters = {
|
||||
"\t": "⇥\t"
|
||||
};
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
DiffTextWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -43,7 +34,7 @@ DiffTextWidget.prototype.render = function(parent,nextSibling) {
|
||||
} else {
|
||||
diffs = dmp.diffMain(this.getAttribute("source",""),this.getAttribute("dest",""),{diffEditCost: editCost});
|
||||
}
|
||||
// Apply required cleanup
|
||||
|
||||
switch(this.getAttribute("cleanup","semantic")) {
|
||||
case "none":
|
||||
// No cleanup
|
||||
@@ -55,8 +46,8 @@ DiffTextWidget.prototype.render = function(parent,nextSibling) {
|
||||
dmp.diffCleanupSemantic(diffs);
|
||||
break;
|
||||
}
|
||||
// Create the elements
|
||||
var domContainer = this.document.createElement("div"),
|
||||
|
||||
var domContainer = this.document.createElement("div"),
|
||||
domDiff = this.createDiffDom(diffs);
|
||||
parent.insertBefore(domContainer,nextSibling);
|
||||
// Save our container
|
||||
@@ -74,9 +65,6 @@ DiffTextWidget.prototype.render = function(parent,nextSibling) {
|
||||
domContainer.appendChild(domDiff);
|
||||
};
|
||||
|
||||
/*
|
||||
Create DOM elements representing a list of diffs
|
||||
*/
|
||||
DiffTextWidget.prototype.createDiffDom = function(diffs) {
|
||||
var self = this;
|
||||
// Create the element and assign the attributes
|
||||
@@ -114,9 +102,6 @@ DiffTextWidget.prototype.createDiffDom = function(diffs) {
|
||||
return domPre;
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
DiffTextWidget.prototype.execute = function() {
|
||||
// Make child widgets
|
||||
var parseTreeNodes;
|
||||
@@ -133,9 +118,6 @@ DiffTextWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets(parseTreeNodes);
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
DiffTextWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.source || changedAttributes.dest || changedAttributes.cleanup || changedAttributes.mode || changedAttributes.editcost) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/draggable.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Draggable widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var DraggableWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
DraggableWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
DraggableWidget.prototype.render = function(parent,nextSibling) {
|
||||
var self = this,
|
||||
tag,
|
||||
@@ -39,7 +30,7 @@ DraggableWidget.prototype.render = function(parent,nextSibling) {
|
||||
if($tw.config.htmlUnsafeElements.indexOf(tag) !== -1) {
|
||||
tag = "div";
|
||||
}
|
||||
// Create our element
|
||||
|
||||
domNode = this.document.createElement(tag);
|
||||
// Assign classes
|
||||
if(this.draggableClasses) {
|
||||
@@ -73,9 +64,6 @@ DraggableWidget.prototype.render = function(parent,nextSibling) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
DraggableWidget.prototype.execute = function() {
|
||||
// Pick up our attributes
|
||||
this.draggableTag = this.getAttribute("tag","div");
|
||||
@@ -89,7 +77,6 @@ DraggableWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
|
||||
DraggableWidget.prototype.updateDomNodeClasses = function() {
|
||||
var domNodeClasses = this.domNodes[0].className.split(" "),
|
||||
oldClasses = this.draggableClasses.split(" ");
|
||||
@@ -106,9 +93,6 @@ DraggableWidget.prototype.updateDomNodeClasses = function() {
|
||||
this.domNodes[0].setAttribute("class",domNodeClasses.join(" "))
|
||||
}
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
DraggableWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.tag || changedAttributes.selector || changedAttributes.dragimagetype || changedAttributes.enable || changedAttributes.startactions || changedAttributes.endactions) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/droppable.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Droppable widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var DroppableWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
DroppableWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
DroppableWidget.prototype.render = function(parent,nextSibling) {
|
||||
var self = this,
|
||||
tag = this.parseTreeNode.isBlock ? "div" : "span",
|
||||
@@ -35,7 +26,7 @@ DroppableWidget.prototype.render = function(parent,nextSibling) {
|
||||
if(this.droppableTag && $tw.config.htmlUnsafeElements.indexOf(this.droppableTag) === -1) {
|
||||
tag = this.droppableTag;
|
||||
}
|
||||
// Create element and assign classes
|
||||
|
||||
domNode = this.document.createElement(tag);
|
||||
this.domNode = domNode;
|
||||
this.assignDomNodeClasses();
|
||||
@@ -55,7 +46,7 @@ DroppableWidget.prototype.render = function(parent,nextSibling) {
|
||||
} else {
|
||||
$tw.utils.addClass(this.domNode,this.disabledClass);
|
||||
}
|
||||
// Insert element
|
||||
|
||||
parent.insertBefore(domNode,nextSibling);
|
||||
this.domNodes.push(domNode);
|
||||
this.renderChildren(domNode,null);
|
||||
@@ -67,7 +58,7 @@ DroppableWidget.prototype.enterDrag = function(event) {
|
||||
if(this.currentlyEntered.indexOf(event.target) === -1) {
|
||||
this.currentlyEntered.push(event.target);
|
||||
}
|
||||
// If we're entering for the first time we need to apply highlighting
|
||||
|
||||
$tw.utils.addClass(this.domNodes[0],"tc-dragover");
|
||||
};
|
||||
|
||||
@@ -76,7 +67,7 @@ DroppableWidget.prototype.leaveDrag = function(event) {
|
||||
if(pos !== -1) {
|
||||
this.currentlyEntered.splice(pos,1);
|
||||
}
|
||||
// Remove highlighting if we're leaving externally. The hacky second condition is to resolve a problem with Firefox whereby there is an erroneous dragenter event if the node being dragged is within the dropzone
|
||||
|
||||
if(this.currentlyEntered.length === 0 || (this.currentlyEntered.length === 1 && this.currentlyEntered[0] === $tw.dragInProgress)) {
|
||||
this.currentlyEntered = [];
|
||||
if(this.domNodes[0]) {
|
||||
@@ -129,7 +120,7 @@ DroppableWidget.prototype.handleDropEvent = function(event) {
|
||||
});
|
||||
});
|
||||
}
|
||||
// Send a TitleList to performListActions
|
||||
|
||||
if(this.droppableListActions) {
|
||||
$tw.utils.importDataTransfer(dataTransfer,null,function(fieldsArray) {
|
||||
var titleList = [];
|
||||
@@ -139,7 +130,7 @@ DroppableWidget.prototype.handleDropEvent = function(event) {
|
||||
self.performListActions($tw.utils.stringifyList(titleList),event);
|
||||
});
|
||||
}
|
||||
// Tell the browser that we handled the drop
|
||||
|
||||
event.preventDefault();
|
||||
// Stop the drop ripple up to any parent handlers
|
||||
event.stopPropagation();
|
||||
@@ -160,9 +151,6 @@ DroppableWidget.prototype.performActions = function(title,event) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
DroppableWidget.prototype.execute = function() {
|
||||
this.droppableActions = this.getAttribute("actions");
|
||||
this.droppableListActions = this.getAttribute("listActions");
|
||||
@@ -180,9 +168,6 @@ DroppableWidget.prototype.assignDomNodeClasses = function() {
|
||||
this.domNode.className = classes.join(" ").trim();
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
DroppableWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.tag || changedAttributes.enable || changedAttributes.disabledClass ||
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/dropzone.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Dropzone widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -17,14 +14,8 @@ var DropZoneWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
DropZoneWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
DropZoneWidget.prototype.render = function(parent,nextSibling) {
|
||||
var self = this;
|
||||
// Remember parent
|
||||
@@ -47,7 +38,7 @@ DropZoneWidget.prototype.render = function(parent,nextSibling) {
|
||||
{name: "dragend", handlerObject: this, handlerMethod: "handleDragEndEvent"}
|
||||
]);
|
||||
}
|
||||
// Insert element
|
||||
|
||||
parent.insertBefore(domNode,nextSibling);
|
||||
this.renderChildren(domNode,null);
|
||||
this.domNodes.push(domNode);
|
||||
@@ -185,7 +176,7 @@ DropZoneWidget.prototype.handleDropEvent = function(event) {
|
||||
if(["TEXTAREA","INPUT"].indexOf(event.target.tagName) !== -1) {
|
||||
return false;
|
||||
}
|
||||
// Check for this window being the source of the drag
|
||||
|
||||
if($tw.dragInProgress) {
|
||||
return false;
|
||||
}
|
||||
@@ -202,7 +193,7 @@ DropZoneWidget.prototype.handleDropEvent = function(event) {
|
||||
deserializer: this.dropzoneDeserializer
|
||||
});
|
||||
}
|
||||
// Try to import the various data types we understand
|
||||
|
||||
if(numFiles === 0) {
|
||||
var fallbackTitle = self.wiki.generateNewTitle("Untitled");
|
||||
//Use the deserializer specified if any
|
||||
@@ -222,7 +213,7 @@ DropZoneWidget.prototype.handleDropEvent = function(event) {
|
||||
$tw.utils.importDataTransfer(dataTransfer,fallbackTitle,readFileCallback);
|
||||
}
|
||||
}
|
||||
// Tell the browser that we handled the drop
|
||||
|
||||
event.preventDefault();
|
||||
// Stop the drop ripple up to any parent handlers
|
||||
event.stopPropagation();
|
||||
@@ -286,19 +277,16 @@ DropZoneWidget.prototype.handlePasteEvent = function(event) {
|
||||
// Create tiddlers from string items
|
||||
var tiddlerFields;
|
||||
// It's important to give getAsString a closure with the right type
|
||||
// So it can be added to the import queue
|
||||
|
||||
item.getAsString(getItem(item.type));
|
||||
}
|
||||
}
|
||||
// Tell the browser that we've handled the paste
|
||||
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
DropZoneWidget.prototype.execute = function() {
|
||||
this.dropzoneClass = this.getAttribute("class");
|
||||
this.dropzoneDeserializer = this.getAttribute("deserializer");
|
||||
@@ -312,9 +300,6 @@ DropZoneWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
DropZoneWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if($tw.utils.count(changedAttributes) > 0) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/edit-binary.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Edit-binary widget; placeholder for editing binary tiddlers
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -18,14 +15,8 @@ var EditBinaryWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
EditBinaryWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
EditBinaryWidget.prototype.render = function(parent,nextSibling) {
|
||||
var self = this;
|
||||
// Save the parent dom node
|
||||
@@ -37,9 +28,6 @@ EditBinaryWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
EditBinaryWidget.prototype.execute = function() {
|
||||
// Get our parameters
|
||||
var editTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
|
||||
@@ -75,11 +63,11 @@ EditBinaryWidget.prototype.execute = function() {
|
||||
// Set the link href to internal data URI (no external)
|
||||
if(text) {
|
||||
link.attributes.href = {
|
||||
type: "string",
|
||||
type: "string",
|
||||
value: "data:" + type + ";base64," + text
|
||||
};
|
||||
}
|
||||
// Combine warning message and download link in a div
|
||||
|
||||
var element = {
|
||||
type: "element",
|
||||
tag: "div",
|
||||
@@ -88,13 +76,10 @@ EditBinaryWidget.prototype.execute = function() {
|
||||
},
|
||||
children: [warn, link]
|
||||
}
|
||||
// Construct the child widgets
|
||||
|
||||
this.makeChildWidgets([element]);
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh by refreshing our child widget
|
||||
*/
|
||||
EditBinaryWidget.prototype.refresh = function(changedTiddlers) {
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
};
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/edit-bitmap.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Edit-bitmap widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -25,14 +22,8 @@ var EditBitmapWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
EditBitmapWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
EditBitmapWidget.prototype.render = function(parent,nextSibling) {
|
||||
var self = this;
|
||||
// Initialise the editor operations if they've not been done already
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/edit-shortcut.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Widget to display an editable keyboard shortcut
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var EditShortcutWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
EditShortcutWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
EditShortcutWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -32,7 +23,7 @@ EditShortcutWidget.prototype.render = function(parent,nextSibling) {
|
||||
if(this.shortcutClass) {
|
||||
this.inputNode.className = this.shortcutClass;
|
||||
}
|
||||
// Assign other attributes
|
||||
|
||||
if(this.shortcutStyle) {
|
||||
this.inputNode.setAttribute("style",this.shortcutStyle);
|
||||
}
|
||||
@@ -48,7 +39,7 @@ EditShortcutWidget.prototype.render = function(parent,nextSibling) {
|
||||
if(this.isDisabled === "yes") {
|
||||
this.inputNode.setAttribute("disabled", true);
|
||||
}
|
||||
// Assign the current shortcut
|
||||
|
||||
this.updateInputNode();
|
||||
// Add event handlers
|
||||
$tw.utils.addEventListeners(this.inputNode,[
|
||||
@@ -63,9 +54,6 @@ EditShortcutWidget.prototype.render = function(parent,nextSibling) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
EditShortcutWidget.prototype.execute = function() {
|
||||
this.shortcutTiddler = this.getAttribute("tiddler");
|
||||
this.shortcutField = this.getAttribute("field");
|
||||
@@ -80,9 +68,6 @@ EditShortcutWidget.prototype.execute = function() {
|
||||
this.isDisabled = this.getAttribute("disabled", "no");
|
||||
};
|
||||
|
||||
/*
|
||||
Update the value of the input node
|
||||
*/
|
||||
EditShortcutWidget.prototype.updateInputNode = function() {
|
||||
if(this.shortcutField) {
|
||||
var tiddler = this.wiki.getTiddler(this.shortcutTiddler);
|
||||
@@ -98,9 +83,6 @@ EditShortcutWidget.prototype.updateInputNode = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Handle a dom "keydown" event
|
||||
*/
|
||||
EditShortcutWidget.prototype.handleKeydownEvent = function(event) {
|
||||
// Ignore shift, ctrl, meta, alt
|
||||
if(event.keyCode && $tw.keyboardManager.getModifierKeys().indexOf(event.keyCode) === -1) {
|
||||
@@ -115,7 +97,7 @@ EditShortcutWidget.prototype.handleKeydownEvent = function(event) {
|
||||
if(value.length > 0) {
|
||||
this.wiki.setText(this.shortcutTiddler,this.shortcutField,this.shortcutIndex,value[0]);
|
||||
}
|
||||
// Ignore the keydown if it was already handled
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
@@ -124,9 +106,6 @@ EditShortcutWidget.prototype.handleKeydownEvent = function(event) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
focus the input node
|
||||
*/
|
||||
EditShortcutWidget.prototype.focus = function() {
|
||||
if(this.inputNode.focus && this.inputNode.select) {
|
||||
this.inputNode.focus();
|
||||
@@ -134,9 +113,6 @@ EditShortcutWidget.prototype.focus = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget needed re-rendering
|
||||
*/
|
||||
EditShortcutWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.placeholder || changedAttributes["default"] || changedAttributes["class"] || changedAttributes.style || changedAttributes.tooltip || changedAttributes["aria-label"] || changedAttributes.focus || changedAttributes.disabled) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/edit-text.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Edit-text widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/edit.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Edit widget is a meta-widget chooses the appropriate actual editting widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var EditWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
EditWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
EditWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -33,9 +24,6 @@ EditWidget.prototype.render = function(parent,nextSibling) {
|
||||
// Mappings from content type to editor type are stored in tiddlers with this prefix
|
||||
var EDITOR_MAPPING_PREFIX = "$:/config/EditorTypeMappings/";
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
EditWidget.prototype.execute = function() {
|
||||
// Get our parameters
|
||||
this.editTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/element.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Element widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var ElementWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
ElementWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
ElementWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -31,7 +22,7 @@ ElementWidget.prototype.render = function(parent,nextSibling) {
|
||||
if($tw.config.htmlUnsafeElements.indexOf(this.tag) !== -1) {
|
||||
this.tag = "safe-" + this.tag;
|
||||
}
|
||||
// Restrict tag name to digits, letts and dashes
|
||||
|
||||
this.tag = this.tag.replace(/[^0-9a-zA-Z\-]/mg,"");
|
||||
// Default to a span
|
||||
this.tag = this.tag || "span";
|
||||
@@ -42,7 +33,7 @@ ElementWidget.prototype.render = function(parent,nextSibling) {
|
||||
headingLevel = Math.min(Math.max(headingLevel + 1 + baseLevel,1),6);
|
||||
this.tag = "h" + headingLevel;
|
||||
}
|
||||
// Select the namespace for the tag
|
||||
|
||||
var XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml",
|
||||
tagNamespaces = {
|
||||
svg: "http://www.w3.org/2000/svg",
|
||||
@@ -60,7 +51,7 @@ ElementWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.namespace = this.getVariable("namespace",{defaultValue: XHTML_NAMESPACE});
|
||||
}
|
||||
}
|
||||
// Invoke the th-rendering-element hook
|
||||
|
||||
var parseTreeNodes = $tw.hooks.invokeHook("th-rendering-element",null,this);
|
||||
this.isReplaced = !!parseTreeNodes;
|
||||
if(parseTreeNodes) {
|
||||
@@ -69,7 +60,7 @@ ElementWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(this.parentDomNode,null);
|
||||
return;
|
||||
}
|
||||
// Make the child widgets
|
||||
|
||||
this.makeChildWidgets();
|
||||
// Create the DOM node and render children
|
||||
var domNode = this.document.createElementNS(this.namespace,this.tag);
|
||||
@@ -81,9 +72,6 @@ ElementWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(domNode,null);
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
ElementWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes(),
|
||||
hasChangedAttributes = $tw.utils.count(changedAttributes) > 0;
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/encrypt.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Encrypt widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var EncryptWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
EncryptWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
EncryptWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -32,9 +23,6 @@ EncryptWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.domNodes.push(textNode);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
EncryptWidget.prototype.execute = function() {
|
||||
// Get parameters from our attributes
|
||||
this.filter = this.getAttribute("filter","[!is[system]]");
|
||||
@@ -53,9 +41,6 @@ EncryptWidget.prototype.execute = function() {
|
||||
this.encryptedText = $tw.utils.htmlEncode($tw.crypto.encrypt(JSON.stringify(json)));
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
EncryptWidget.prototype.refresh = function(changedTiddlers) {
|
||||
// We don't need to worry about refreshing because the encrypt widget isn't for interactive use
|
||||
return false;
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/entity.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
HTML entity widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var EntityWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
EntityWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
EntityWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -33,15 +24,9 @@ EntityWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.domNodes.push(textNode);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
EntityWidget.prototype.execute = function() {
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
EntityWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.entity) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/error.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Error widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var ErrorWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
ErrorWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
ErrorWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -35,16 +26,10 @@ ErrorWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.domNodes.push(domNode);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
ErrorWidget.prototype.execute = function() {
|
||||
// Nothing to do for a text node
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
ErrorWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes["$message"]) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/eventcatcher.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Event handler widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var EventWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
EventWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
EventWidget.prototype.render = function(parent,nextSibling) {
|
||||
var self = this;
|
||||
// Remember parent
|
||||
@@ -47,9 +38,6 @@ EventWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(domNode,null);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
EventWidget.prototype.execute = function() {
|
||||
var self = this;
|
||||
// Get attributes that require a refresh on change
|
||||
@@ -65,9 +53,6 @@ EventWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Cache and pre-create all event listeners, called when first needed
|
||||
*/
|
||||
EventWidget.prototype.cacheEventListeners = function() {
|
||||
if(this._eventListeners) {
|
||||
return;
|
||||
@@ -100,7 +85,7 @@ EventWidget.prototype.cacheEventListeners = function() {
|
||||
if(selectedNode) {
|
||||
clearPointerCapture(event);
|
||||
}
|
||||
// Remove dynamic-only listeners
|
||||
|
||||
this.cleanupDynamicListeners();
|
||||
return this.handleEvent(event, type, selectedNode);
|
||||
};
|
||||
@@ -110,7 +95,6 @@ EventWidget.prototype.cacheEventListeners = function() {
|
||||
}
|
||||
}
|
||||
|
||||
// Create any listeners not already defined above
|
||||
this.types.forEach(type => {
|
||||
if(!this._eventListeners[type]) {
|
||||
this._eventListeners[type] = event => {
|
||||
@@ -118,7 +102,7 @@ EventWidget.prototype.cacheEventListeners = function() {
|
||||
if(!selectedNode) {
|
||||
return false;
|
||||
}
|
||||
// Handle pointer capture for pointerdown
|
||||
|
||||
if(type === "pointerdown") {
|
||||
if(this.pointerCaptureMode !== "no") {
|
||||
this.startPointerCapture(event.pointerId, event.target);
|
||||
@@ -136,9 +120,6 @@ EventWidget.prototype.cacheEventListeners = function() {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
Check if an event qualifies and return the matching selected node
|
||||
*/
|
||||
EventWidget.prototype.checkEvent = function(event, type) {
|
||||
const domNode = this.domNode;
|
||||
let node = event.target;
|
||||
@@ -177,9 +158,6 @@ EventWidget.prototype.checkEvent = function(event, type) {
|
||||
return node;
|
||||
};
|
||||
|
||||
/*
|
||||
Handle the event and execute actions
|
||||
*/
|
||||
EventWidget.prototype.handleEvent = function(event, type, selectedNode) {
|
||||
if(!selectedNode) {
|
||||
return false;
|
||||
@@ -214,7 +192,7 @@ EventWidget.prototype.handleEvent = function(event, type, selectedNode) {
|
||||
};
|
||||
|
||||
EventWidget.prototype.startPointerCapture = function(pointerId, captureTarget) {
|
||||
// Start capture only if none active; pointerId can be 0
|
||||
// Start capture only if none active; pointerId can be 0
|
||||
if(!Number.isInteger(this._capturePointerId) && this.domNode && this.domNode.setPointerCapture) {
|
||||
this.domNode.setPointerCapture(pointerId);
|
||||
this._capturePointerId = pointerId;
|
||||
@@ -230,9 +208,6 @@ EventWidget.prototype.stopPointerCapture = function(pointerId) {
|
||||
this._captureTarget = undefined;
|
||||
};
|
||||
|
||||
/*
|
||||
Attach all relevant listeners
|
||||
*/
|
||||
EventWidget.prototype.attachListeners = function() {
|
||||
this.cacheEventListeners();
|
||||
const domNode = this.domNode;
|
||||
@@ -244,9 +219,6 @@ EventWidget.prototype.attachListeners = function() {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
Remove dynamic active listeners
|
||||
*/
|
||||
EventWidget.prototype.cleanupDynamicListeners = function() {
|
||||
const domNode = this.domNode;
|
||||
Object.keys(this._captureActiveListeners || {}).forEach(type => {
|
||||
@@ -255,9 +227,6 @@ EventWidget.prototype.cleanupDynamicListeners = function() {
|
||||
this._captureActiveListeners = Object.create(null);
|
||||
};
|
||||
|
||||
/*
|
||||
Remove all listeners
|
||||
*/
|
||||
EventWidget.prototype.removeAllListeners = function() {
|
||||
if(Number.isInteger(this._capturePointerId)) {
|
||||
this.stopPointerCapture(this._capturePointerId);
|
||||
@@ -270,9 +239,6 @@ EventWidget.prototype.removeAllListeners = function() {
|
||||
this._captureTarget = null;
|
||||
};
|
||||
|
||||
/*
|
||||
Enable or disable listeners
|
||||
*/
|
||||
EventWidget.prototype.toggleListeners = function() {
|
||||
let disabled = this.getAttribute("disabled","no") === "yes";
|
||||
if(disabled) {
|
||||
@@ -282,18 +248,12 @@ EventWidget.prototype.toggleListeners = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Assign DOM node classes
|
||||
*/
|
||||
EventWidget.prototype.assignDomNodeClasses = function() {
|
||||
var classes = this.getAttribute("class","").split(" ");
|
||||
classes.push("tc-eventcatcher");
|
||||
this.domNode.className = classes.join(" ").trim();
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh widget
|
||||
*/
|
||||
EventWidget.prototype.refresh = function(changedTiddlers) {
|
||||
const changedAttributes = this.computeAttributes(),
|
||||
changedKeys = Object.keys(changedAttributes),
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/fieldmangler.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Field mangler widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var FieldManglerWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
FieldManglerWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
FieldManglerWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.addEventListeners([
|
||||
{type: "tm-remove-field", handler: "handleRemoveFieldEvent"},
|
||||
@@ -36,9 +27,6 @@ FieldManglerWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
FieldManglerWidget.prototype.execute = function() {
|
||||
// Get our parameters
|
||||
this.mangleTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
|
||||
@@ -46,9 +34,6 @@ FieldManglerWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
FieldManglerWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.tiddler) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/fields.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Fields widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var FieldsWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
FieldsWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
FieldsWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -32,9 +23,6 @@ FieldsWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.domNodes.push(textNode);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
FieldsWidget.prototype.execute = function() {
|
||||
// Get parameters from our attributes
|
||||
this.tiddlerTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
|
||||
@@ -91,9 +79,6 @@ FieldsWidget.prototype.execute = function() {
|
||||
this.text = text.join("");
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
FieldsWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if( changedAttributes.tiddler || changedAttributes.template || changedAttributes.exclude ||
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/fill.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Sub-widget used by the transclude widget for specifying values for slots within transcluded content. It doesn't do anything by itself because the transclude widget only ever deals with the parse tree nodes, and doesn't instantiate the widget itself
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -16,9 +13,6 @@ var FillWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
FillWidget.prototype = new Widget();
|
||||
|
||||
FillWidget.prototype.execute = function() {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/genesis.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Genesis widget for dynamically creating widgets
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,9 +12,6 @@ var GenesisWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
GenesisWidget.prototype = new Widget();
|
||||
|
||||
GenesisWidget.prototype.computeAttributes = function(options) {
|
||||
@@ -29,9 +23,6 @@ GenesisWidget.prototype.computeAttributes = function(options) {
|
||||
return Widget.prototype.computeAttributes.call(this,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
GenesisWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -39,9 +30,6 @@ GenesisWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
GenesisWidget.prototype.execute = function() {
|
||||
var self = this;
|
||||
// Collect attributes
|
||||
@@ -55,7 +43,7 @@ GenesisWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets(this.parseTreeNode.children);
|
||||
return;
|
||||
}
|
||||
// Construct parse tree
|
||||
|
||||
var isElementWidget = this.genesisType.charAt(0) !== "$",
|
||||
nodeType = isElementWidget ? "element" : this.genesisType.substr(1),
|
||||
nodeTag = isElementWidget ? this.genesisType : undefined;
|
||||
@@ -78,7 +66,7 @@ GenesisWidget.prototype.execute = function() {
|
||||
$tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],varname,self.attributeValues[index] || "");
|
||||
});
|
||||
}
|
||||
// Apply explicit attributes
|
||||
|
||||
$tw.utils.each($tw.utils.getOrderedAttributesFromParseTreeNode(this.parseTreeNode),function(attribute) {
|
||||
var name = attribute.name;
|
||||
if(name.charAt(0) === "$") {
|
||||
@@ -96,9 +84,6 @@ GenesisWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets(parseTreeNodes);
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
GenesisWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes(),
|
||||
filterNames = this.getAttribute("$names",""),
|
||||
|
||||
@@ -2,25 +2,6 @@
|
||||
title: $:/core/modules/widgets/image.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
The image widget displays an image referenced with an external URI or with a local tiddler title.
|
||||
|
||||
```
|
||||
<$image src="TiddlerTitle" width="320" height="400" class="classnames">
|
||||
```
|
||||
|
||||
The image source can be the title of an existing tiddler or the URL of an external image.
|
||||
|
||||
External images always generate an HTML `<img>` tag.
|
||||
|
||||
Tiddlers that have a _canonical_uri field generate an HTML `<img>` tag with the src attribute containing the URI.
|
||||
|
||||
Tiddlers that contain image data generate an HTML `<img>` tag with the src attribute containing a base64 representation of the image.
|
||||
|
||||
Tiddlers that contain wikitext could be rendered to a DIV of the usual size of a tiddler, and then transformed to the size requested.
|
||||
|
||||
The width and height attributes are interpreted as a number of pixels, and do not need to include the "px" suffix.
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -31,20 +12,14 @@ var ImageWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
ImageWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
ImageWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
this.execute();
|
||||
// Create element
|
||||
// Determine what type of image it is
|
||||
|
||||
var tag = "img", src = "", self = this,
|
||||
tiddler = this.wiki.getTiddler(this.imageSource);
|
||||
if(!tiddler) {
|
||||
@@ -91,7 +66,7 @@ ImageWidget.prototype.render = function(parent,nextSibling) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Create the element and assign the attributes
|
||||
|
||||
var domNode = this.document.createElement(tag);
|
||||
domNode.setAttribute("src",src);
|
||||
if(this.imageClass) {
|
||||
@@ -128,7 +103,7 @@ ImageWidget.prototype.render = function(parent,nextSibling) {
|
||||
var variables = $tw.utils.collectDOMVariables(domNode,null,event);
|
||||
variables["img-natural-width"] = domNode.naturalWidth.toString();
|
||||
variables["img-natural-height"] = domNode.naturalHeight.toString();
|
||||
self.invokeActionString(self.loadedActions,self,event,variables);
|
||||
self.invokeActionString(self.loadedActions,self,event,variables);
|
||||
}
|
||||
},false);
|
||||
domNode.addEventListener("error",function() {
|
||||
@@ -140,9 +115,6 @@ ImageWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.domNodes.push(domNode);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
ImageWidget.prototype.execute = function() {
|
||||
// Get our parameters
|
||||
this.imageSource = this.getAttribute("source");
|
||||
@@ -156,9 +128,6 @@ ImageWidget.prototype.execute = function() {
|
||||
this.loadedActions = this.getAttribute("loadActions");
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
ImageWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes(),
|
||||
hasChangedAttributes = $tw.utils.count(changedAttributes) > 0;
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/importvariables.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Import variable definitions from other tiddlers
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var ImportVariablesWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
ImportVariablesWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
ImportVariablesWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -30,9 +21,6 @@ ImportVariablesWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
ImportVariablesWidget.prototype.execute = function(tiddlerList) {
|
||||
var widgetPointer = this;
|
||||
// Got to flush all the accumulated variables
|
||||
@@ -40,7 +28,7 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
|
||||
if(this.parentWidget) {
|
||||
Object.setPrototypeOf(this.variables,this.parentWidget.variables);
|
||||
}
|
||||
// Get our parameters
|
||||
|
||||
this.filter = this.getAttribute("filter");
|
||||
// Compute the filter
|
||||
this.tiddlerList = tiddlerList || this.wiki.filterTiddlers(this.filter,this);
|
||||
@@ -64,15 +52,15 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
|
||||
if(parseTreeNode.type === "set" || parseTreeNode.type === "setvariable") {
|
||||
if(parseTreeNode.isMacroDefinition || parseTreeNode.isProcedureDefinition || parseTreeNode.isWidgetDefinition || parseTreeNode.isFunctionDefinition) {
|
||||
// Macro definitions can be folded into
|
||||
// current widget instead of adding
|
||||
|
||||
// another link to the chain.
|
||||
var widget = widgetPointer.makeChildWidget(node);
|
||||
widget.computeAttributes();
|
||||
widget.execute();
|
||||
// We SHALLOW copy over all variables
|
||||
// in widget. We can't use
|
||||
|
||||
// $tw.utils.assign, because that copies
|
||||
// up the prototype chain, which we
|
||||
|
||||
// don't want.
|
||||
$tw.utils.each(Object.keys(widget.variables), function(key) {
|
||||
widgetPointer.variables[key] = widget.variables[key];
|
||||
@@ -82,7 +70,7 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
|
||||
// No more regenerating children for
|
||||
// this widget. If it needs to refresh,
|
||||
// it'll do so along with the the whole
|
||||
// importvariable tree.
|
||||
|
||||
if(widgetPointer != this) {
|
||||
widgetPointer.makeChildWidgets = function(){};
|
||||
}
|
||||
@@ -91,7 +79,7 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
|
||||
}
|
||||
parseTreeNode = parseTreeNode.children && parseTreeNode.children[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(widgetPointer != this) {
|
||||
@@ -101,9 +89,6 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
ImportVariablesWidget.prototype.refresh = function(changedTiddlers) {
|
||||
// Recompute our attributes and the filter list
|
||||
var changedAttributes = this.computeAttributes(),
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/jsontiddler.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Render a tiddler as JSON text
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var JSONTiddlerWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
JSONTiddlerWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
JSONTiddlerWidget.prototype.render = function(parent,nextSibling) {
|
||||
var self = this;
|
||||
this.parentDomNode = parent;
|
||||
@@ -42,24 +33,18 @@ JSONTiddlerWidget.prototype.render = function(parent,nextSibling) {
|
||||
if(this.attEscapeUnsafeScriptChars) {
|
||||
json = json.replace(/</g,"\\u003C");
|
||||
}
|
||||
// Update the DOM
|
||||
|
||||
var textNode = this.document.createTextNode(json);
|
||||
parent.insertBefore(textNode,nextSibling);
|
||||
this.domNodes.push(textNode);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
JSONTiddlerWidget.prototype.execute = function() {
|
||||
this.attTiddler = this.getAttribute("tiddler");
|
||||
this.attExclude = this.getAttribute("exclude","");
|
||||
this.attEscapeUnsafeScriptChars = this.getAttribute("escapeUnsafeScriptChars","no") === "yes";
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
JSONTiddlerWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if($tw.utils.count(changedAttributes) > 0 || (this.attTiddler && changedTiddlers[this.attTiddler])) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/keyboard.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Keyboard shortcut widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var KeyboardWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
KeyboardWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
KeyboardWidget.prototype.render = function(parent,nextSibling) {
|
||||
var self = this;
|
||||
// Remember parent
|
||||
@@ -34,7 +25,7 @@ KeyboardWidget.prototype.render = function(parent,nextSibling) {
|
||||
if(this.tag && $tw.config.htmlUnsafeElements.indexOf(this.tag) === -1) {
|
||||
tag = this.tag;
|
||||
}
|
||||
// Create element
|
||||
|
||||
var domNode = this.document.createElement(tag);
|
||||
// Assign classes
|
||||
this.domNode = domNode;
|
||||
@@ -82,9 +73,6 @@ KeyboardWidget.prototype.dispatchMessage = function(event) {
|
||||
this.dispatchEvent({type: this.message, param: this.param, tiddlerTitle: this.getVariable("currentTiddler")});
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
KeyboardWidget.prototype.execute = function() {
|
||||
var self = this;
|
||||
// Get attributes
|
||||
@@ -101,9 +89,9 @@ KeyboardWidget.prototype.execute = function() {
|
||||
$tw.utils.each($tw.keyboardManager.lookupNames,function(platformDescriptor) {
|
||||
self.shortcutTiddlers.push("$:/config/" + platformDescriptor + "/" + name);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// Make child widgets
|
||||
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
@@ -113,9 +101,6 @@ KeyboardWidget.prototype.assignDomNodeClasses = function() {
|
||||
this.domNode.className = classes.join(" ").trim();
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
KeyboardWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.message || changedAttributes.param || changedAttributes.key || changedAttributes.tag) {
|
||||
@@ -124,7 +109,7 @@ KeyboardWidget.prototype.refresh = function(changedTiddlers) {
|
||||
} else if(changedAttributes["class"]) {
|
||||
this.assignDomNodeClasses();
|
||||
}
|
||||
// Update the keyInfoArray if one of its shortcut-config-tiddlers has changed
|
||||
|
||||
if(this.shortcutTiddlers && $tw.utils.hopArray(changedTiddlers,this.shortcutTiddlers) && $tw.keyboardManager) {
|
||||
this.keyInfoArray = $tw.keyboardManager.parseKeyDescriptors(this.key);
|
||||
}
|
||||
|
||||
@@ -2,16 +2,6 @@
|
||||
title: $:/core/modules/widgets/let.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
This widget allows defining multiple variables at once, while allowing
|
||||
the later variables to depend upon the earlier ones.
|
||||
|
||||
```
|
||||
<$let currentTiddler="target" value={{!!value}} currentTiddler="different">
|
||||
{{!!value}} will be different from <<value>>
|
||||
</$let>
|
||||
```
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -23,14 +13,8 @@ var LetWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
LetWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
LetWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -40,7 +24,7 @@ LetWidget.prototype.render = function(parent,nextSibling) {
|
||||
|
||||
LetWidget.prototype.computeAttributes = function() {
|
||||
// Before computing attributes, we must make clear that none of the
|
||||
// existing attributes are staged for lookup, even on a refresh
|
||||
|
||||
var changedAttributes = {},
|
||||
self = this;
|
||||
this.currentValueFor = Object.create(null);
|
||||
@@ -48,7 +32,7 @@ LetWidget.prototype.computeAttributes = function() {
|
||||
var value = self.computeAttribute(attribute,{asList: true}),
|
||||
name = attribute.name;
|
||||
// Now that it's prepped, we're allowed to look this variable up
|
||||
// when defining later variables
|
||||
|
||||
if(value !== undefined) {
|
||||
self.currentValueFor[name] = value;
|
||||
}
|
||||
@@ -66,7 +50,7 @@ LetWidget.prototype.computeAttributes = function() {
|
||||
|
||||
LetWidget.prototype.getVariableInfo = function(name,options) {
|
||||
// Special handling: If this variable exists in this very $let, we can
|
||||
// use it, but only if it's been staged.
|
||||
|
||||
if($tw.utils.hop(this.currentValueFor,name)) {
|
||||
var value = this.currentValueFor[name];
|
||||
return {
|
||||
@@ -77,9 +61,6 @@ LetWidget.prototype.getVariableInfo = function(name,options) {
|
||||
return Widget.prototype.getVariableInfo.call(this,name,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
LetWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if($tw.utils.count(changedAttributes) > 0) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/link.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Link widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var LinkWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
LinkWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
LinkWidget.prototype.render = function(parent,nextSibling) {
|
||||
// Save the parent dom node
|
||||
this.parentDomNode = parent;
|
||||
@@ -55,9 +46,6 @@ LinkWidget.prototype.render = function(parent,nextSibling) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
LinkWidget.prototype.renderLink = function(parent,nextSibling) {
|
||||
var self = this;
|
||||
// Sanitise the specified tag
|
||||
@@ -65,7 +53,7 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) {
|
||||
if($tw.config.htmlUnsafeElements.indexOf(tag) !== -1) {
|
||||
tag = "a";
|
||||
}
|
||||
// Create our element
|
||||
|
||||
var namespace = this.getVariable("namespace",{defaultValue: "http://www.w3.org/1999/xhtml"}),
|
||||
domNode = this.document.createElementNS(namespace,tag);
|
||||
// Assign classes
|
||||
@@ -91,7 +79,7 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) {
|
||||
if(classes.length > 0) {
|
||||
domNode.setAttribute("class",classes.join(" "));
|
||||
}
|
||||
// Set an href
|
||||
|
||||
var wikilinkTransformFilter = this.getVariable("tv-filter-export-link"),
|
||||
wikiLinkText;
|
||||
if(wikilinkTransformFilter) {
|
||||
@@ -106,17 +94,17 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) {
|
||||
wikiLinkText = $tw.utils.replaceString(wikiLinkTemplate,"$uri_encoded$",$tw.utils.encodeURIComponentExtended(this.to));
|
||||
wikiLinkText = $tw.utils.replaceString(wikiLinkText,"$uri_doubleencoded$",$tw.utils.encodeURIComponentExtended($tw.utils.encodeURIComponentExtended(this.to)));
|
||||
}
|
||||
// Override with the value of tv-get-export-link if defined
|
||||
|
||||
wikiLinkText = this.getVariable("tv-get-export-link",{params: [{name: "to",value: this.to}],defaultValue: wikiLinkText});
|
||||
if(tag === "a") {
|
||||
var namespaceHref = (namespace === "http://www.w3.org/2000/svg") ? "http://www.w3.org/1999/xlink" : undefined;
|
||||
domNode.setAttributeNS(namespaceHref,"href",wikiLinkText);
|
||||
}
|
||||
// Set the tabindex
|
||||
|
||||
if(this.tabIndex) {
|
||||
domNode.setAttribute("tabindex",this.tabIndex);
|
||||
}
|
||||
// Set the tooltip
|
||||
|
||||
// HACK: Performance issues with re-parsing the tooltip prevent us defaulting the tooltip to "<$transclude field='tooltip'><$transclude field='title'/></$transclude>"
|
||||
var tooltipWikiText = this.tooltip || this.getVariable("tv-wikilink-tooltip");
|
||||
if(tooltipWikiText) {
|
||||
@@ -152,7 +140,7 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) {
|
||||
} else if(this.draggable === "no") {
|
||||
domNode.setAttribute("draggable","false");
|
||||
}
|
||||
// Assign data- attributes
|
||||
|
||||
this.assignAttributes(domNode,{
|
||||
sourcePrefix: "data-",
|
||||
destPrefix: "data-"
|
||||
@@ -193,9 +181,6 @@ LinkWidget.prototype.handleClickEvent = function(event) {
|
||||
return false;
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
LinkWidget.prototype.execute = function() {
|
||||
// Pick up our attributes
|
||||
this.to = this.getAttribute("to",this.getVariable("currentTiddler"));
|
||||
@@ -223,9 +208,6 @@ LinkWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets(templateTree);
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
LinkWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if($tw.utils.count(changedAttributes) > 0 || changedTiddlers[this.to]) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/linkcatcher.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Linkcatcher widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var LinkCatcherWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
LinkCatcherWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
LinkCatcherWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.addEventListeners([
|
||||
{type: "tm-navigate", handler: "handleNavigateEvent"}
|
||||
@@ -33,9 +24,6 @@ LinkCatcherWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
LinkCatcherWidget.prototype.execute = function() {
|
||||
// Get our parameters
|
||||
this.catchTo = this.getAttribute("to");
|
||||
|
||||
@@ -2,27 +2,17 @@
|
||||
title: $:/core/modules/widgets/list.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
List and list item widgets
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
|
||||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
/*
|
||||
The list widget creates list element sub-widgets that reach back into the list widget for their configuration
|
||||
*/
|
||||
|
||||
var ListWidget = function(parseTreeNode,options) {
|
||||
// Main initialisation inherited from widget.js
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
ListWidget.prototype = new Widget();
|
||||
|
||||
ListWidget.prototype.initialise = function(parseTreeNode,options) {
|
||||
@@ -30,16 +20,13 @@ ListWidget.prototype.initialise = function(parseTreeNode,options) {
|
||||
if(parseTreeNode === undefined) {
|
||||
return;
|
||||
}
|
||||
// First call parent constructor to set everything else up
|
||||
|
||||
Widget.prototype.initialise.call(this,parseTreeNode,options);
|
||||
// Now look for <$list-template> and <$list-empty> widgets as immediate child widgets
|
||||
// This is safe to do during initialization because parse trees never change after creation
|
||||
|
||||
this.findExplicitTemplates();
|
||||
}
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
ListWidget.prototype.render = function(parent,nextSibling) {
|
||||
// Initialise the storyviews if they've not been done already
|
||||
if(!this.storyViews) {
|
||||
@@ -177,9 +164,6 @@ ListWidget.prototype.makeJoinTemplate = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Compose the template for a list item
|
||||
*/
|
||||
ListWidget.prototype.makeItemTemplate = function(title,index) {
|
||||
// Check if the tiddler is a draft
|
||||
var tiddler = this.wiki.getTiddler(title),
|
||||
@@ -190,7 +174,7 @@ ListWidget.prototype.makeItemTemplate = function(title,index) {
|
||||
if(isDraft && this.editTemplate) {
|
||||
template = this.editTemplate;
|
||||
}
|
||||
// Compose the transclusion of the template
|
||||
|
||||
if(template) {
|
||||
templateTree = [{type: "transclude", attributes: {tiddler: {type: "string", value: template}}}];
|
||||
} else {
|
||||
@@ -210,7 +194,7 @@ ListWidget.prototype.makeItemTemplate = function(title,index) {
|
||||
]}]}];
|
||||
}
|
||||
}
|
||||
// Return the list item
|
||||
|
||||
var parseTreeNode = {type: "listitem", itemTitle: title, variableName: this.variableName, children: templateTree, join: join};
|
||||
parseTreeNode.isLast = index === this.list.length - 1;
|
||||
if(this.counterName) {
|
||||
@@ -221,9 +205,6 @@ ListWidget.prototype.makeItemTemplate = function(title,index) {
|
||||
return parseTreeNode;
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
ListWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes(),
|
||||
result;
|
||||
@@ -231,7 +212,7 @@ ListWidget.prototype.refresh = function(changedTiddlers) {
|
||||
if(this.storyview && this.storyview.refreshStart) {
|
||||
this.storyview.refreshStart(changedTiddlers,changedAttributes);
|
||||
}
|
||||
// Completely refresh if any of our attributes have changed
|
||||
|
||||
if(changedAttributes.filter || changedAttributes.variable || changedAttributes.counter || changedAttributes.template || changedAttributes.editTemplate || changedAttributes.join || changedAttributes.emptyMessage || changedAttributes.storyview || changedAttributes.history) {
|
||||
this.refreshSelf();
|
||||
result = true;
|
||||
@@ -243,16 +224,13 @@ ListWidget.prototype.refresh = function(changedTiddlers) {
|
||||
this.handleHistoryChanges();
|
||||
}
|
||||
}
|
||||
// Call the storyview
|
||||
|
||||
if(this.storyview && this.storyview.refreshEnd) {
|
||||
this.storyview.refreshEnd(changedTiddlers,changedAttributes);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
/*
|
||||
Handle any changes to the history list
|
||||
*/
|
||||
ListWidget.prototype.handleHistoryChanges = function() {
|
||||
// Get the history data
|
||||
var newHistory = this.wiki.getTiddlerDataCached(this.historyTitle,[]);
|
||||
@@ -261,20 +239,17 @@ ListWidget.prototype.handleHistoryChanges = function() {
|
||||
while(entry < newHistory.length && entry < this.history.length && newHistory[entry].title === this.history[entry].title) {
|
||||
entry++;
|
||||
}
|
||||
// Navigate forwards to each of the new tiddlers
|
||||
|
||||
while(entry < newHistory.length) {
|
||||
if(this.storyview && this.storyview.navigateTo) {
|
||||
this.storyview.navigateTo(newHistory[entry]);
|
||||
}
|
||||
entry++;
|
||||
}
|
||||
// Update the history
|
||||
|
||||
this.history = newHistory;
|
||||
};
|
||||
|
||||
/*
|
||||
Process any changes to the list
|
||||
*/
|
||||
ListWidget.prototype.handleListChanges = function(changedTiddlers) {
|
||||
// Get the new list
|
||||
var prevList = this.list;
|
||||
@@ -301,7 +276,7 @@ ListWidget.prototype.handleListChanges = function(changedTiddlers) {
|
||||
this.removeChildDomNodes();
|
||||
this.children = [];
|
||||
}
|
||||
// If we are providing an counter variable then we must refresh the items, otherwise we can rearrange them
|
||||
|
||||
var hasRefreshed = false,t;
|
||||
if(this.counterName) {
|
||||
var mustRefreshOldLast = false;
|
||||
@@ -379,7 +354,7 @@ ListWidget.prototype.handleListChanges = function(changedTiddlers) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Remove any left over items
|
||||
|
||||
for(t=this.children.length-1; t>=this.list.length; t--) {
|
||||
this.removeListItem(t);
|
||||
hasRefreshed = true;
|
||||
@@ -388,9 +363,6 @@ ListWidget.prototype.handleListChanges = function(changedTiddlers) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Find the list item with a given title, starting from a specified position
|
||||
*/
|
||||
ListWidget.prototype.findListItem = function(startIndex,title) {
|
||||
while(startIndex < this.children.length) {
|
||||
if(this.children[startIndex].parseTreeNode.itemTitle === title) {
|
||||
@@ -401,9 +373,6 @@ ListWidget.prototype.findListItem = function(startIndex,title) {
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/*
|
||||
Insert a new list item at the specified index
|
||||
*/
|
||||
ListWidget.prototype.insertListItem = function(index,title) {
|
||||
// Create, insert and render the new child widgets
|
||||
var widget = this.makeChildWidget(this.makeItemTemplate(title,index));
|
||||
@@ -418,9 +387,6 @@ ListWidget.prototype.insertListItem = function(index,title) {
|
||||
return true;
|
||||
};
|
||||
|
||||
/*
|
||||
Remove the specified list item
|
||||
*/
|
||||
ListWidget.prototype.removeListItem = function(index) {
|
||||
var widget = this.children[index];
|
||||
// Animate the removal if required
|
||||
@@ -429,7 +395,7 @@ ListWidget.prototype.removeListItem = function(index) {
|
||||
} else {
|
||||
widget.removeChildDomNodes();
|
||||
}
|
||||
// Remove the child widget
|
||||
|
||||
this.children.splice(index,1);
|
||||
};
|
||||
|
||||
@@ -439,14 +405,8 @@ var ListItemWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
ListItemWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
ListItemWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -454,9 +414,6 @@ ListItemWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
ListItemWidget.prototype.execute = function() {
|
||||
// Set the current list item title
|
||||
this.setVariable(this.parseTreeNode.variableName,this.parseTreeNode.itemTitle);
|
||||
@@ -465,7 +422,7 @@ ListItemWidget.prototype.execute = function() {
|
||||
this.setVariable(this.parseTreeNode.counterName + "-first",this.parseTreeNode.isFirst ? "yes" : "no");
|
||||
this.setVariable(this.parseTreeNode.counterName + "-last",this.parseTreeNode.isLast ? "yes" : "no");
|
||||
}
|
||||
// Add join if needed
|
||||
|
||||
var children = this.parseTreeNode.children,
|
||||
join = this.parseTreeNode.join;
|
||||
if(join && join.length && !this.parseTreeNode.isLast) {
|
||||
@@ -474,22 +431,16 @@ ListItemWidget.prototype.execute = function() {
|
||||
children.push(joinNode);
|
||||
})
|
||||
}
|
||||
// Construct the child widgets
|
||||
|
||||
this.makeChildWidgets(children);
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
ListItemWidget.prototype.refresh = function(changedTiddlers) {
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
};
|
||||
|
||||
exports.listitem = ListItemWidget;
|
||||
|
||||
/*
|
||||
Make <$list-template> and <$list-empty> widgets that do nothing
|
||||
*/
|
||||
var ListTemplateWidget = function(parseTreeNode,options) {
|
||||
// Main initialisation inherited from widget.js
|
||||
this.initialise(parseTreeNode,options);
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/log.js
|
||||
type: application/javascript
|
||||
module-type: widget-subclass
|
||||
|
||||
Widget to log debug messages
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/macrocall.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Macrocall widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var MacroCallWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
MacroCallWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
MacroCallWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -30,9 +21,6 @@ MacroCallWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
MacroCallWidget.prototype.execute = function() {
|
||||
this.macroName = this.parseTreeNode.name || this.getAttribute("$name"),
|
||||
this.parseType = this.getAttribute("$type","text/vnd.tiddlywiki");
|
||||
@@ -69,9 +57,6 @@ MacroCallWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets(parseTreeNodes);
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
MacroCallWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if($tw.utils.count(changedAttributes) > 0) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/messagecatcher.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Message catcher widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var MessageCatcherWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
MessageCatcherWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
MessageCatcherWidget.prototype.render = function(parent,nextSibling) {
|
||||
var self = this;
|
||||
// Remember parent
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/navigator.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Navigator widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -17,14 +14,8 @@ var NavigatorWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
NavigatorWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
NavigatorWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.addEventListeners([
|
||||
{type: "tm-navigate", handler: "handleNavigateEvent"},
|
||||
@@ -49,9 +40,6 @@ NavigatorWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
NavigatorWidget.prototype.execute = function() {
|
||||
// Get our parameters
|
||||
this.storyTitle = this.getAttribute("story");
|
||||
@@ -67,9 +55,6 @@ NavigatorWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
NavigatorWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.story || changedAttributes.history) {
|
||||
@@ -131,18 +116,10 @@ NavigatorWidget.prototype.addToStory = function(title,fromTitle) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Add a new record to the top of the history stack
|
||||
title: a title string or an array of title strings
|
||||
fromPageRect: page coordinates of the origin of the navigation
|
||||
*/
|
||||
NavigatorWidget.prototype.addToHistory = function(title,fromPageRect) {
|
||||
this.story.addToHistory(title,fromPageRect,this.historyTitle);
|
||||
};
|
||||
|
||||
/*
|
||||
Handle a tm-navigate event
|
||||
*/
|
||||
NavigatorWidget.prototype.handleNavigateEvent = function(event) {
|
||||
event = $tw.hooks.invokeHook("th-navigating",event);
|
||||
if(event.navigateTo) {
|
||||
@@ -201,7 +178,7 @@ NavigatorWidget.prototype.handleEditTiddlerEvent = function(event) {
|
||||
if(isUnmodifiedShadow(title) && !confirmEditShadow(title)) {
|
||||
return false;
|
||||
}
|
||||
// Replace the specified tiddler with a draft in edit mode
|
||||
|
||||
var draftTiddler = this.makeDraftTiddler(title);
|
||||
// Update the story and history if required
|
||||
if(!event.paramObject || event.paramObject.suppressNavigation !== "yes") {
|
||||
@@ -253,7 +230,7 @@ NavigatorWidget.prototype.handleDeleteTiddlerEvent = function(event) {
|
||||
// Invoke the hook function and delete this tiddler
|
||||
if(tiddler) {
|
||||
$tw.hooks.invokeHook("th-deleting-tiddler",tiddler);
|
||||
this.wiki.deleteTiddler(title);
|
||||
this.wiki.deleteTiddler(title);
|
||||
}
|
||||
// Remove the closed tiddler from the story
|
||||
this.removeTitleFromStory(storyList,title);
|
||||
@@ -294,9 +271,6 @@ NavigatorWidget.prototype.makeDraftTiddler = function(targetTitle) {
|
||||
return draftTiddler;
|
||||
};
|
||||
|
||||
/*
|
||||
Generate a title for the draft of a given tiddler
|
||||
*/
|
||||
NavigatorWidget.prototype.generateDraftTitle = function(title) {
|
||||
return this.wiki.generateDraftTitle(title);
|
||||
};
|
||||
@@ -336,7 +310,7 @@ NavigatorWidget.prototype.handleSaveTiddlerEvent = function(event) {
|
||||
if(isRename && shouldRelink && this.wiki.tiddlerExists(draftOf)) {
|
||||
this.wiki.relinkTiddler(draftOf,draftTitle);
|
||||
}
|
||||
// Remove the draft tiddler
|
||||
|
||||
this.wiki.deleteTiddler(title);
|
||||
// Remove the original tiddler if we're renaming it
|
||||
if(isRename) {
|
||||
@@ -449,7 +423,7 @@ NavigatorWidget.prototype.handleNewTiddlerEvent = function(event) {
|
||||
draftTitle = this.generateDraftTitle(title);
|
||||
existingTiddler = this.wiki.getTiddler(title);
|
||||
}
|
||||
// Merge the tags
|
||||
|
||||
var mergedTags = [];
|
||||
if(existingTiddler && existingTiddler.fields.tags) {
|
||||
$tw.utils.pushTop(mergedTags,existingTiddler.fields.tags);
|
||||
@@ -464,7 +438,7 @@ NavigatorWidget.prototype.handleNewTiddlerEvent = function(event) {
|
||||
templateHasTags = true;
|
||||
mergedTags = $tw.utils.pushTop(mergedTags,templateTiddler.fields.tags);
|
||||
}
|
||||
// Save the draft tiddler
|
||||
|
||||
var draftTiddler = new $tw.Tiddler({
|
||||
text: "",
|
||||
"draft.title": title
|
||||
@@ -581,7 +555,7 @@ NavigatorWidget.prototype.handlePerformImportEvent = function(event) {
|
||||
var tiddler = new $tw.Tiddler(tiddlerFields);
|
||||
}
|
||||
// th-importing-tiddler doesn't allow user interaction by default
|
||||
// If you want to use the default UI then use: $:/core/modules/upgraders/ instead
|
||||
|
||||
tiddler = $tw.hooks.invokeHook("th-importing-tiddler",tiddler);
|
||||
// Add the tiddlers to the store
|
||||
self.wiki.addTiddler(tiddler);
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/parameters.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Widget for definition of transclusion parameters
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -17,14 +14,8 @@ var ParametersWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
ParametersWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
ParametersWidget.prototype.render = function(parent,nextSibling) {
|
||||
// Call the constructor
|
||||
Widget.call(this);
|
||||
@@ -34,9 +25,6 @@ ParametersWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
ParametersWidget.prototype.execute = function() {
|
||||
var self = this;
|
||||
this.parametersDepth = Math.max(parseInt(this.getAttribute("$depth","1"),10) || 1,1);
|
||||
@@ -52,7 +40,7 @@ ParametersWidget.prototype.execute = function() {
|
||||
}
|
||||
pointer = pointer.parentWidget;
|
||||
}
|
||||
// Process each parameter
|
||||
|
||||
if(pointer instanceof TranscludeWidget) {
|
||||
// Get the value for each defined parameter
|
||||
$tw.utils.each($tw.utils.getOrderedAttributesFromParseTreeNode(self.parseTreeNode),function(attr,index) {
|
||||
@@ -75,7 +63,7 @@ ParametersWidget.prototype.execute = function() {
|
||||
});
|
||||
} else {
|
||||
// There is no parent transclude. i.e. direct rendering.
|
||||
// We use default values only.
|
||||
|
||||
$tw.utils.each($tw.utils.getOrderedAttributesFromParseTreeNode(self.parseTreeNode),function(attr,index) {
|
||||
var name = attr.name;
|
||||
// If the attribute name starts with $$ then reduce to a single dollar
|
||||
@@ -87,13 +75,10 @@ ParametersWidget.prototype.execute = function() {
|
||||
self.setVariable(name,value);
|
||||
});
|
||||
}
|
||||
// Construct the child widgets
|
||||
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
ParametersWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(Object.keys(changedAttributes).length) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/password.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Password widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var PasswordWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
PasswordWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
PasswordWidget.prototype.render = function(parent,nextSibling) {
|
||||
// Save the parent dom node
|
||||
this.parentDomNode = parent;
|
||||
@@ -51,9 +42,6 @@ PasswordWidget.prototype.handleChangeEvent = function(event) {
|
||||
return $tw.utils.savePassword(this.passwordName,password);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
PasswordWidget.prototype.execute = function() {
|
||||
// Get the parameters from the attributes
|
||||
this.passwordName = this.getAttribute("name","");
|
||||
@@ -61,9 +49,6 @@ PasswordWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
PasswordWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.name) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/qualify.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Qualify text to a variable
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var QualifyWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
QualifyWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
QualifyWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -30,9 +21,6 @@ QualifyWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
QualifyWidget.prototype.execute = function() {
|
||||
// Get our parameters
|
||||
this.qualifyName = this.getAttribute("name");
|
||||
@@ -41,13 +29,10 @@ QualifyWidget.prototype.execute = function() {
|
||||
if(this.qualifyName) {
|
||||
this.setVariable(this.qualifyName,this.qualifyTitle + "-" + this.getStateQualifier());
|
||||
}
|
||||
// Construct the child widgets
|
||||
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
QualifyWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.name || changedAttributes.title) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/radio.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Set a field or index at a given tiddler via radio buttons
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -14,14 +11,8 @@ var RadioWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
RadioWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
RadioWidget.prototype.render = function(parent,nextSibling) {
|
||||
// Save the parent dom node
|
||||
this.parentDomNode = parent;
|
||||
@@ -93,15 +84,12 @@ RadioWidget.prototype.handleChangeEvent = function(event) {
|
||||
if(this.inputDomNode.checked) {
|
||||
this.setValue();
|
||||
}
|
||||
// Trigger actions
|
||||
|
||||
if(this.radioActions) {
|
||||
this.invokeActionString(this.radioActions,this,event,{"actionValue": this.radioValue});
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
RadioWidget.prototype.execute = function() {
|
||||
// Get the parameters from the attributes
|
||||
this.radioTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
|
||||
@@ -117,9 +105,6 @@ RadioWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
RadioWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(($tw.utils.count(changedAttributes) > 0)) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/range.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Range widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var RangeWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
RangeWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
RangeWidget.prototype.render = function(parent,nextSibling) {
|
||||
// Save the parent dom node
|
||||
this.parentDomNode = parent;
|
||||
@@ -88,21 +79,19 @@ RangeWidget.prototype.getActionVariables = function(options) {
|
||||
options = options || {};
|
||||
var hasChanged = (this.startValue !== this.inputDomNode.value) ? "yes" : "no";
|
||||
// Trigger actions. Use variables = {key:value, key:value ...}
|
||||
// the "value" is needed.
|
||||
|
||||
return $tw.utils.extend({"actionValue": this.inputDomNode.value, "actionValueHasChanged": hasChanged}, options);
|
||||
}
|
||||
|
||||
// actionsStart
|
||||
RangeWidget.prototype.handleMouseDownEvent = function(event) {
|
||||
this.handleEvent(event);
|
||||
// Trigger actions
|
||||
if(this.actionsMouseDown) {
|
||||
var variables = this.getActionVariables() // TODO this line will go into the function call below.
|
||||
var variables = this.getActionVariables()
|
||||
this.invokeActionString(this.actionsMouseDown,this,event,variables);
|
||||
}
|
||||
}
|
||||
|
||||
// actionsStop
|
||||
RangeWidget.prototype.handleMouseUpEvent = function(event) {
|
||||
this.handleEvent(event);
|
||||
// Trigger actions
|
||||
@@ -121,7 +110,7 @@ RangeWidget.prototype.handleInputEvent = function(event) {
|
||||
// Trigger actions
|
||||
if(this.actionsInput) {
|
||||
// "tiddler" parameter may be missing. See .execute() below
|
||||
var variables = this.getActionVariables({"actionValueHasChanged": "yes"}) // TODO this line will go into the function call below.
|
||||
var variables = this.getActionVariables({"actionValueHasChanged": "yes"})
|
||||
this.invokeActionString(this.actionsInput,this,event,variables);
|
||||
}
|
||||
};
|
||||
@@ -136,9 +125,6 @@ RangeWidget.prototype.handleEvent = function(event) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
RangeWidget.prototype.execute = function() {
|
||||
// Get the parameters from the attributes
|
||||
this.tiddlerTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
|
||||
@@ -152,7 +138,7 @@ RangeWidget.prototype.execute = function() {
|
||||
this.isDisabled = this.getAttribute("disabled","no");
|
||||
this.tabIndex = this.getAttribute("tabindex");
|
||||
// Actions since 5.1.23
|
||||
// Next 2 only fire once!
|
||||
|
||||
this.actionsMouseDown = this.getAttribute("actionsStart","");
|
||||
this.actionsMouseUp = this.getAttribute("actionsStop","");
|
||||
// Input fires very often!
|
||||
@@ -161,9 +147,6 @@ RangeWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
RangeWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if($tw.utils.count(changedAttributes) > 0) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/raw.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Raw widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var RawWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
RawWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
RawWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.execute();
|
||||
@@ -32,15 +23,9 @@ RawWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.domNodes.push(div);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
RawWidget.prototype.execute = function() {
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
RawWidget.prototype.refresh = function(changedTiddlers) {
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/reveal.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Reveal widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -17,14 +14,8 @@ var RevealWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
RevealWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
RevealWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/scrollable.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Scrollable widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -17,9 +14,6 @@ var ScrollableWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
ScrollableWidget.prototype = new Widget();
|
||||
|
||||
ScrollableWidget.prototype.cancelScroll = function() {
|
||||
@@ -29,9 +23,6 @@ ScrollableWidget.prototype.cancelScroll = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Handle a scroll event
|
||||
*/
|
||||
ScrollableWidget.prototype.handleScrollEvent = function(event) {
|
||||
// Pass the scroll event through if our offsetsize is larger than our scrollsize
|
||||
if(this.outerDomNode.scrollWidth <= this.outerDomNode.offsetWidth && this.outerDomNode.scrollHeight <= this.outerDomNode.offsetHeight && this.fallthrough === "yes") {
|
||||
@@ -49,9 +40,6 @@ ScrollableWidget.prototype.handleScrollEvent = function(event) {
|
||||
return false; // Handled event
|
||||
};
|
||||
|
||||
/*
|
||||
Scroll an element into view
|
||||
*/
|
||||
ScrollableWidget.prototype.scrollIntoView = function(element,callback,options) {
|
||||
var duration = $tw.utils.hop(options,"animationDuration") ? parseInt(options.animationDuration) : $tw.utils.getAnimationDuration(),
|
||||
srcWindow = element ? element.ownerDocument.defaultView : window;
|
||||
@@ -219,9 +207,6 @@ ScrollableWidget.prototype.updateScrollPositionFromBoundTiddler = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
ScrollableWidget.prototype.execute = function() {
|
||||
// Get attributes
|
||||
this.scrollableBind = this.getAttribute("bind");
|
||||
@@ -231,16 +216,13 @@ ScrollableWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
ScrollableWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes["class"]) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
}
|
||||
// If the bound tiddler has changed, update the eventListener and update scroll position
|
||||
|
||||
if(changedAttributes["bind"]) {
|
||||
if(this.currentListener) {
|
||||
this.outerDomNode.removeEventListener("scroll", this.currentListener, false);
|
||||
@@ -249,7 +231,7 @@ ScrollableWidget.prototype.refresh = function(changedTiddlers) {
|
||||
this.currentListener = this.listenerFunction.bind(this);
|
||||
this.outerDomNode.addEventListener("scroll", this.currentListener);
|
||||
}
|
||||
// Refresh children
|
||||
|
||||
var result = this.refreshChildren(changedTiddlers);
|
||||
// If the bound tiddler has changed, update scroll position
|
||||
if(changedAttributes["bind"] || changedTiddlers[this.getAttribute("bind")]) {
|
||||
|
||||
@@ -2,19 +2,6 @@
|
||||
title: $:/core/modules/widgets/select.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Select widget:
|
||||
|
||||
```
|
||||
<$select tiddler="MyTiddler" field="text">
|
||||
<$list filter="[tag[chapter]]">
|
||||
<option value=<<currentTiddler>>>
|
||||
<$view field="description"/>
|
||||
</option>
|
||||
</$list>
|
||||
</$select>
|
||||
```
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -25,14 +12,8 @@ var SelectWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
SelectWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
SelectWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -42,7 +23,7 @@ SelectWidget.prototype.render = function(parent,nextSibling) {
|
||||
if(this.selectClass) {
|
||||
domNode.className = this.selectClass;
|
||||
}
|
||||
// Assign data- attributes
|
||||
|
||||
this.assignAttributes(domNode,{
|
||||
sourcePrefix: "data-",
|
||||
destPrefix: "data-"
|
||||
@@ -74,9 +55,6 @@ SelectWidget.prototype.render = function(parent,nextSibling) {
|
||||
]);
|
||||
};
|
||||
|
||||
/*
|
||||
Handle a change event
|
||||
*/
|
||||
SelectWidget.prototype.handleChangeEvent = function(event) {
|
||||
// Get the new value and assign it to the tiddler
|
||||
if(this.selectMultiple == false) {
|
||||
@@ -92,9 +70,6 @@ SelectWidget.prototype.handleChangeEvent = function(event) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
If necessary, set the value of the select element to the current value
|
||||
*/
|
||||
SelectWidget.prototype.setSelectValue = function() {
|
||||
var value = this.selectDefault;
|
||||
// Get the value
|
||||
@@ -117,7 +92,7 @@ SelectWidget.prototype.setSelectValue = function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Assign it to the select element if it's different than the current value
|
||||
|
||||
if(this.selectMultiple) {
|
||||
value = value === undefined ? "" : value;
|
||||
var select = this.getSelectDomNode();
|
||||
@@ -142,15 +117,12 @@ SelectWidget.prototype.setSelectValue = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Get the DOM node of the select element
|
||||
*/
|
||||
SelectWidget.prototype.getSelectDomNode = function() {
|
||||
return this.domNodes[0];
|
||||
};
|
||||
|
||||
// Return an array of the selected opion values
|
||||
// select is an HTML select element
|
||||
|
||||
SelectWidget.prototype.getSelectValues = function() {
|
||||
var select, result, options, opt;
|
||||
select = this.getSelectDomNode();
|
||||
@@ -165,9 +137,6 @@ SelectWidget.prototype.getSelectValues = function() {
|
||||
return result;
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
SelectWidget.prototype.execute = function() {
|
||||
// Get our parameters
|
||||
this.selectActions = this.getAttribute("actions");
|
||||
@@ -186,9 +155,6 @@ SelectWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
SelectWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
// If we're using a different tiddler/field/index then completely refresh ourselves
|
||||
@@ -198,7 +164,7 @@ SelectWidget.prototype.refresh = function(changedTiddlers) {
|
||||
} else {
|
||||
if(changedAttributes.class) {
|
||||
this.selectClass = this.getAttribute("class");
|
||||
this.getSelectDomNode().setAttribute("class",this.selectClass);
|
||||
this.getSelectDomNode().setAttribute("class",this.selectClass);
|
||||
}
|
||||
this.assignAttributes(this.getSelectDomNode(),{
|
||||
changedAttributes: changedAttributes,
|
||||
@@ -209,7 +175,7 @@ SelectWidget.prototype.refresh = function(changedTiddlers) {
|
||||
// If the target tiddler value has changed, just update setting and refresh the children
|
||||
if(changedTiddlers[this.selectTitle] || childrenRefreshed) {
|
||||
this.setSelectValue();
|
||||
}
|
||||
}
|
||||
return childrenRefreshed;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/setmultiplevariables.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Widget to set multiple variables at once from a list of names and a list of values
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var SetMultipleVariablesWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
SetMultipleVariablesWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
SetMultipleVariablesWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -30,9 +21,6 @@ SetMultipleVariablesWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
SetMultipleVariablesWidget.prototype.execute = function() {
|
||||
// Setup our variables
|
||||
this.setVariables();
|
||||
@@ -40,7 +28,6 @@ SetMultipleVariablesWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
|
||||
SetMultipleVariablesWidget.prototype.setVariables = function() {
|
||||
// Set the variables
|
||||
var self = this,
|
||||
@@ -57,9 +44,6 @@ SetMultipleVariablesWidget.prototype.setVariables = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
SetMultipleVariablesWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var filterNames = this.getAttribute("$names",""),
|
||||
filterValues = this.getAttribute("$values",""),
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/set.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Set variable widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var SetWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
SetWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
SetWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -30,9 +21,6 @@ SetWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
SetWidget.prototype.execute = function() {
|
||||
// Get our parameters
|
||||
this.setName = this.getAttribute("name","currentTiddler");
|
||||
@@ -56,13 +44,10 @@ SetWidget.prototype.execute = function() {
|
||||
} else {
|
||||
this.setVariable(this.setName,this.getValue());
|
||||
}
|
||||
// Construct the child widgets
|
||||
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Get the value to be assigned
|
||||
*/
|
||||
SetWidget.prototype.getValue = function() {
|
||||
var value = this.setValue;
|
||||
if(this.setTiddler) {
|
||||
@@ -103,9 +88,6 @@ SetWidget.prototype.getValue = function() {
|
||||
return value || "";
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
SetWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.name || changedAttributes.filter || changedAttributes.select || changedAttributes.tiddler || (this.setTiddler && changedTiddlers[this.setTiddler]) || changedAttributes.field || changedAttributes.index || changedAttributes.value || changedAttributes.emptyValue ||
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/slot.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Widget for definition of slots within transcluded content. The values provided by the translusion are passed to the slot.
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -17,14 +14,8 @@ var SlotWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
SlotWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
SlotWidget.prototype.render = function(parent,nextSibling) {
|
||||
// Call the constructor
|
||||
Widget.call(this);
|
||||
@@ -34,9 +25,6 @@ SlotWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
SlotWidget.prototype.execute = function() {
|
||||
var self = this;
|
||||
this.slotName = this.getAttribute("$name");
|
||||
@@ -58,13 +46,10 @@ SlotWidget.prototype.execute = function() {
|
||||
// Get the parse tree nodes comprising the slot contents
|
||||
parseTreeNodes = pointer.getTransclusionSlotFill(this.slotName,this.parseTreeNode.children);
|
||||
}
|
||||
// Construct the child widgets
|
||||
|
||||
this.makeChildWidgets(parseTreeNodes);
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
SlotWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes["$name"] || changedAttributes["$depth"]) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/testcase.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Widget to display a test case
|
||||
|
||||
\*/
|
||||
"use strict";
|
||||
|
||||
@@ -14,14 +11,8 @@ var TestCaseWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
TestCaseWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
TestCaseWidget.prototype.render = function(parent,nextSibling) {
|
||||
var self = this;
|
||||
this.parentDomNode = parent;
|
||||
@@ -79,7 +70,7 @@ TestCaseWidget.prototype.render = function(parent,nextSibling) {
|
||||
if(this.testcaseTestOutput && this.testcaseWiki.tiddlerExists(this.testcaseTestOutput) && this.testcaseTestExpectedResult && this.testcaseWiki.tiddlerExists(this.testcaseTestExpectedResult)) {
|
||||
shouldRunTests = true;
|
||||
}
|
||||
// Render the test rendering if required
|
||||
|
||||
if(shouldRunTests) {
|
||||
var testcaseOutputContainer = $tw.fakeDocument.createElement("div");
|
||||
var testcaseOutputWidget = this.testcaseWiki.makeTranscludeWidget(this.testcaseTestOutput,{
|
||||
@@ -92,14 +83,14 @@ TestCaseWidget.prototype.render = function(parent,nextSibling) {
|
||||
});
|
||||
testcaseOutputWidget.render(testcaseOutputContainer);
|
||||
}
|
||||
// Clear changes queue
|
||||
|
||||
this.testcaseWiki.clearTiddlerEventQueue();
|
||||
// Run the actions if provided
|
||||
if(this.testcaseWiki.tiddlerExists(this.testcaseTestActions)) {
|
||||
testcaseOutputWidget.invokeActionString(this.testcaseWiki.getTiddlerText(this.testcaseTestActions));
|
||||
testcaseOutputWidget.refresh(this.testcaseWiki.changedTiddlers,testcaseOutputContainer);
|
||||
}
|
||||
// Set up the test result variables
|
||||
|
||||
var testResult = "",
|
||||
outputHTML = "",
|
||||
expectedHTML = "";
|
||||
@@ -116,11 +107,11 @@ TestCaseWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.setVariable("testResult",testResult);
|
||||
this.setVariable("currentTiddler",this.testcaseTestOutput);
|
||||
}
|
||||
// Don't display anything if testHideIfPass is "yes" and the tests have passed
|
||||
|
||||
if(this.testcaseHideIfPass === "yes" && testResult !== "fail") {
|
||||
return;
|
||||
}
|
||||
// Render the page root template of the subwiki
|
||||
|
||||
var rootWidget = this.testcaseWiki.makeTranscludeWidget(this.testcaseTemplate,{
|
||||
document: this.document,
|
||||
parseAsInline: false,
|
||||
@@ -133,9 +124,6 @@ TestCaseWidget.prototype.render = function(parent,nextSibling) {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
TestCaseWidget.prototype.execute = function() {
|
||||
this.testcaseTemplate = this.getAttribute("template","$:/core/ui/testcases/DefaultTemplate");
|
||||
this.testcaseTestOutput = this.getAttribute("testOutput");
|
||||
@@ -145,9 +133,6 @@ TestCaseWidget.prototype.execute = function() {
|
||||
this.testcaseClass = this.getAttribute("class","");
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
TestCaseWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if($tw.utils.count(changedAttributes) > 0) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/text.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Text node widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var TextNodeWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
TextNodeWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
TextNodeWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -34,16 +25,10 @@ TextNodeWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.domNodes.push(textNode);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
TextNodeWidget.prototype.execute = function() {
|
||||
// Nothing to do for a text node
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
TextNodeWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.text) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/tiddler.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Tiddler widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var TiddlerWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
TiddlerWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
TiddlerWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -30,9 +21,6 @@ TiddlerWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
TiddlerWidget.prototype.execute = function() {
|
||||
this.tiddlerState = this.computeTiddlerState();
|
||||
this.setVariable("currentTiddler",this.tiddlerState.currentTiddler);
|
||||
@@ -44,9 +32,6 @@ TiddlerWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the tiddler state flags
|
||||
*/
|
||||
TiddlerWidget.prototype.computeTiddlerState = function() {
|
||||
// Get our parameters
|
||||
this.tiddlerTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
|
||||
@@ -63,9 +48,6 @@ TiddlerWidget.prototype.computeTiddlerState = function() {
|
||||
return state;
|
||||
};
|
||||
|
||||
/*
|
||||
Create a string of CSS classes derived from the tags of the current tiddler
|
||||
*/
|
||||
TiddlerWidget.prototype.getTagClasses = function() {
|
||||
var tiddler = this.wiki.getTiddler(this.tiddlerTitle);
|
||||
if(tiddler) {
|
||||
@@ -79,9 +61,6 @@ TiddlerWidget.prototype.getTagClasses = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
TiddlerWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes(),
|
||||
newTiddlerState = this.computeTiddlerState();
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/transclude.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Transclude widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var TranscludeWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
TranscludeWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
TranscludeWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes({asList: true});
|
||||
@@ -32,24 +23,24 @@ TranscludeWidget.prototype.render = function(parent,nextSibling) {
|
||||
} catch(error) {
|
||||
if(error instanceof $tw.utils.TranscludeRecursionError) {
|
||||
// We were infinite looping.
|
||||
// We need to try and abort as much of the loop as we
|
||||
|
||||
// can, so we will keep "throwing" upward until we find
|
||||
// a transclusion that has a different signature.
|
||||
|
||||
// Hopefully that will land us just outside where the
|
||||
// loop began. That's where we want to issue an error.
|
||||
|
||||
// Rendering widgets beneath this point may result in a
|
||||
// freezing browser if they explode exponentially.
|
||||
|
||||
var transcludeSignature = this.getVariable("transclusion");
|
||||
if(this.getAncestorCount() > $tw.utils.TranscludeRecursionError.MAX_WIDGET_TREE_DEPTH - 50) {
|
||||
// For the first fifty transcludes we climb up,
|
||||
// we simply collect signatures.
|
||||
// We're assuming those first 50 will likely
|
||||
|
||||
// include all transcludes involved in the loop.
|
||||
error.signatures[transcludeSignature] = true;
|
||||
} else if(!error.signatures[transcludeSignature]) {
|
||||
// Now that we're past the first 50, look for
|
||||
// the first signature that wasn't in that loop.
|
||||
// That's where we print the error and resume
|
||||
|
||||
// rendering.
|
||||
this.removeChildDomNodes();
|
||||
this.children = [this.makeChildWidget({type: "error", attributes: {
|
||||
@@ -63,9 +54,6 @@ TranscludeWidget.prototype.render = function(parent,nextSibling) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
TranscludeWidget.prototype.execute = function() {
|
||||
// Get our attributes, string parameters, and slot values into properties of the widget object
|
||||
this.collectAttributes();
|
||||
@@ -114,13 +102,10 @@ TranscludeWidget.prototype.execute = function() {
|
||||
var recursionMarker = this.makeRecursionMarker();
|
||||
this.setVariable("transclusion",recursionMarker);
|
||||
}
|
||||
// Construct the child widgets
|
||||
|
||||
this.makeChildWidgets(parseTreeNodes);
|
||||
};
|
||||
|
||||
/*
|
||||
Collect the attributes we need, in the process determining whether we're being used in legacy mode
|
||||
*/
|
||||
TranscludeWidget.prototype.collectAttributes = function() {
|
||||
var self = this;
|
||||
// Detect legacy mode
|
||||
@@ -152,9 +137,6 @@ TranscludeWidget.prototype.collectAttributes = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Collect string parameters
|
||||
*/
|
||||
TranscludeWidget.prototype.collectStringParameters = function() {
|
||||
var self = this;
|
||||
this.stringParametersByName = Object.create(null);
|
||||
@@ -179,9 +161,6 @@ TranscludeWidget.prototype.collectStringParameters = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Collect slot value parameters
|
||||
*/
|
||||
TranscludeWidget.prototype.collectSlotFillParameters = function() {
|
||||
var self = this;
|
||||
this.slotFillParseTrees = Object.create(null);
|
||||
@@ -210,9 +189,6 @@ TranscludeWidget.prototype.collectSlotFillParameters = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Get transcluded details as an object {text:,type:}
|
||||
*/
|
||||
TranscludeWidget.prototype.getTransclusionTarget = function() {
|
||||
var self = this;
|
||||
var text;
|
||||
@@ -247,9 +223,6 @@ TranscludeWidget.prototype.getTransclusionTarget = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Get transcluded parse tree nodes as an object {text:,type:,parseTreeNodes:,parseAsInline:}
|
||||
*/
|
||||
TranscludeWidget.prototype.parseTransclusionTarget = function(parseAsInline) {
|
||||
var self = this;
|
||||
var parser;
|
||||
@@ -360,7 +333,7 @@ TranscludeWidget.prototype.parseTransclusionTarget = function(parseAsInline) {
|
||||
defaultType: this.transcludeType
|
||||
});
|
||||
}
|
||||
// Return the parse tree
|
||||
|
||||
return {
|
||||
parser: parser,
|
||||
parseTreeNodes: parser ? parser.tree : (this.slotFillParseTrees["ts-missing"] || []),
|
||||
@@ -370,9 +343,6 @@ TranscludeWidget.prototype.parseTransclusionTarget = function(parseAsInline) {
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
Fetch all the string parameters as an ordered array of {name:, value:} where the name is optional
|
||||
*/
|
||||
TranscludeWidget.prototype.getOrderedTransclusionParameters = function() {
|
||||
var result = [];
|
||||
// Collect the parameters
|
||||
@@ -384,7 +354,7 @@ TranscludeWidget.prototype.getOrderedTransclusionParameters = function() {
|
||||
}
|
||||
result.push(param);
|
||||
}
|
||||
// Sort numerical parameter names first
|
||||
|
||||
result.sort(function(a,b) {
|
||||
var aIsNumeric = !isNaN(a.name),
|
||||
bIsNumeric = !isNaN(b.name);
|
||||
@@ -407,9 +377,6 @@ TranscludeWidget.prototype.getOrderedTransclusionParameters = function() {
|
||||
return result;
|
||||
};
|
||||
|
||||
/*
|
||||
Fetch the value of a parameter
|
||||
*/
|
||||
TranscludeWidget.prototype.getTransclusionParameter = function(name,index,defaultValue) {
|
||||
if(name in this.stringParametersByName) {
|
||||
if(this.multiValuedParametersByName[name]) {
|
||||
@@ -428,9 +395,6 @@ TranscludeWidget.prototype.getTransclusionParameter = function(name,index,defaul
|
||||
return defaultValue;
|
||||
};
|
||||
|
||||
/*
|
||||
Get one of the special parameters to be provided by the parameters widget
|
||||
*/
|
||||
TranscludeWidget.prototype.getTransclusionMetaParameters = function() {
|
||||
var self = this;
|
||||
return {
|
||||
@@ -449,9 +413,6 @@ TranscludeWidget.prototype.getTransclusionMetaParameters = function() {
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
Fetch the value of a slot
|
||||
*/
|
||||
TranscludeWidget.prototype.getTransclusionSlotFill = function(name,defaultParseTreeNodes) {
|
||||
if(name && this.slotFillParseTrees[name] && this.slotFillParseTrees[name].length > 0) {
|
||||
return this.slotFillParseTrees[name];
|
||||
@@ -460,16 +421,10 @@ TranscludeWidget.prototype.getTransclusionSlotFill = function(name,defaultParseT
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Return whether this transclusion should be visible to the slot widget
|
||||
*/
|
||||
TranscludeWidget.prototype.hasVisibleSlots = function() {
|
||||
return this.getAttribute("$fillignore","no") === "no";
|
||||
}
|
||||
|
||||
/*
|
||||
Compose a string comprising the title, field and/or index to identify this transclusion for recursion detection
|
||||
*/
|
||||
TranscludeWidget.prototype.makeRecursionMarker = function() {
|
||||
var output = [];
|
||||
output.push("{");
|
||||
@@ -502,9 +457,6 @@ TranscludeWidget.prototype.functionNeedsRefresh = function() {
|
||||
return oldResult !== newResult;
|
||||
}
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
TranscludeWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(($tw.utils.count(changedAttributes) > 0) || (this.transcludeVariableIsFunction && this.functionNeedsRefresh()) || (!this.transcludeVariable && changedTiddlers[this.transcludeTitle] && this.parserNeedsRefresh())) {
|
||||
|
||||
@@ -2,16 +2,6 @@
|
||||
title: $:/core/modules/widgets/vars.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
This widget allows multiple variables to be set in one go:
|
||||
|
||||
```
|
||||
\define helloworld() Hello world!
|
||||
<$vars greeting="Hi" me={{!!title}} sentence=<<helloworld>>>
|
||||
<<greeting>>! I am <<me>> and I say: <<sentence>>
|
||||
</$vars>
|
||||
```
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -23,14 +13,8 @@ var VarsWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
VarsWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
VarsWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -38,9 +22,6 @@ VarsWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
VarsWidget.prototype.execute = function() {
|
||||
// Parse variables
|
||||
var self = this;
|
||||
@@ -53,9 +34,6 @@ VarsWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
VarsWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if($tw.utils.count(changedAttributes) > 0) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/view.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
View widget
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var ViewWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
ViewWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
ViewWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -37,9 +28,6 @@ ViewWidget.prototype.render = function(parent,nextSibling) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
ViewWidget.prototype.execute = function() {
|
||||
// Get parameters from our attributes
|
||||
this.viewTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
|
||||
@@ -89,14 +77,6 @@ ViewWidget.prototype.execute = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
The various formatter functions are baked into this widget for the moment. Eventually they will be replaced by macro functions
|
||||
*/
|
||||
|
||||
/*
|
||||
Retrieve the value of the widget. Options are:
|
||||
asString: Optionally return the value as a string
|
||||
*/
|
||||
ViewWidget.prototype.getValue = function(options) {
|
||||
options = options || {};
|
||||
var value = options.asString ? "" : undefined;
|
||||
@@ -207,9 +187,6 @@ ViewWidget.prototype.getValueAsJsEncoded = function() {
|
||||
return $tw.utils.stringify(this.getValueAsText());
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
ViewWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.template || changedAttributes.format || changedTiddlers[this.viewTitle]) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/void.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Void widget that corresponds to pragma and comment AST nodes, etc. It does not render itself but renders all its children.
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,9 +12,6 @@ var VoidNodeWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
VoidNodeWidget.prototype = new Widget();
|
||||
|
||||
exports.void = VoidNodeWidget;
|
||||
|
||||
+19
-165
@@ -2,29 +2,14 @@
|
||||
title: $:/core/modules/widgets/widget.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Widget base class
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Create a widget object for a parse tree node
|
||||
parseTreeNode: reference to the parse tree node to be rendered
|
||||
options: see below
|
||||
Options include:
|
||||
wiki: mandatory reference to wiki associated with this render tree
|
||||
parentWidget: optional reference to a parent renderer node for the context chain
|
||||
document: optional document object to use instead of global document
|
||||
*/
|
||||
var Widget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Initialise widget properties. These steps are pulled out of the constructor so that we can reuse them in subclasses
|
||||
*/
|
||||
Widget.prototype.initialise = function(parseTreeNode,options) {
|
||||
// Bail if parseTreeNode is undefined, meaning that the widget constructor was called without any arguments so that it can be subclassed
|
||||
if(parseTreeNode === undefined) {
|
||||
@@ -61,33 +46,16 @@ Widget.prototype.initialise = function(parseTreeNode,options) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
Widget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.execute();
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
Widget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Set the value of a context variable
|
||||
name: name of the variable
|
||||
value: value of the variable, can be a string or an array
|
||||
params: array of {name:, default:} for each parameter
|
||||
isMacroDefinition: true if the variable is set via a \define macro pragma (and hence should have variable substitution performed)
|
||||
options includes:
|
||||
isProcedureDefinition: true if the variable is set via a \procedure pragma (and hence should not have variable substitution performed)
|
||||
isFunctionDefinition: true if the variable is set via a \function pragma (and hence should not have variable substitution performed)
|
||||
isWidgetDefinition: true if the variable is set via a \widget pragma (and hence should not have variable substitution performed)
|
||||
*/
|
||||
Widget.prototype.setVariable = function(name,value,params,isMacroDefinition,options) {
|
||||
options = options || {};
|
||||
var valueIsArray = $tw.utils.isArray(value);
|
||||
@@ -103,24 +71,6 @@ Widget.prototype.setVariable = function(name,value,params,isMacroDefinition,opti
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
Get the prevailing value of a context variable
|
||||
name: name of variable
|
||||
options: see below
|
||||
Options include
|
||||
|
||||
params: array of {name:, value:} for each parameter
|
||||
defaultValue: default value if the variable is not defined
|
||||
source: optional source iterator for evaluating function invocations
|
||||
allowSelfAssigned: if true, includes the current widget in the context chain instead of just the parent
|
||||
|
||||
Returns an object with the following fields:
|
||||
|
||||
params: array of {name:,value:,multiValue:} of parameters to be applied (name is optional)
|
||||
text: text of variable, with parameters properly substituted
|
||||
resultList: result of variable evaluation as an array
|
||||
srcVariable: reference to the object defining the variable
|
||||
*/
|
||||
Widget.prototype.getVariableInfo = function(name,options) {
|
||||
options = options || {};
|
||||
var self = this,
|
||||
@@ -131,7 +81,7 @@ Widget.prototype.getVariableInfo = function(name,options) {
|
||||
} else {
|
||||
variable = this.parentWidget && this.parentWidget.variables[name];
|
||||
}
|
||||
// Check for the variable defined in the parent widget (or an ancestor in the prototype chain)
|
||||
|
||||
if(variable) {
|
||||
var originalValue = variable.value,
|
||||
value = originalValue,
|
||||
@@ -182,7 +132,7 @@ Widget.prototype.getVariableInfo = function(name,options) {
|
||||
isCacheable: originalValue === value
|
||||
};
|
||||
}
|
||||
// If the variable doesn't exist in the parent widget then look for a macro module
|
||||
|
||||
var text = this.evaluateMacroModule(name,actualParams);
|
||||
if(text === undefined) {
|
||||
text = options.defaultValue;
|
||||
@@ -193,18 +143,10 @@ Widget.prototype.getVariableInfo = function(name,options) {
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
Simplified version of getVariableInfo() that just returns the text
|
||||
*/
|
||||
Widget.prototype.getVariable = function(name,options) {
|
||||
return this.getVariableInfo(name,options).text;
|
||||
};
|
||||
|
||||
/*
|
||||
Maps actual parameters onto formal parameters, returning an array of {name:,value:} objects
|
||||
formalParams - Array of {name:,default:} (default value is optional)
|
||||
actualParams - Array of string values or {name:,value:,multiValue} (name and multiValue is optional)
|
||||
*/
|
||||
Widget.prototype.resolveVariableParameters = function(formalParams,actualParams) {
|
||||
formalParams = formalParams || [];
|
||||
actualParams = actualParams || [];
|
||||
@@ -237,7 +179,7 @@ Widget.prototype.resolveVariableParameters = function(formalParams,actualParams)
|
||||
paramValue = paramInfo["default"] || "";
|
||||
paramMultiValue = [paramValue];
|
||||
}
|
||||
// Store the parameter name and value
|
||||
|
||||
results.push({name: paramInfo.name, value: paramValue, multiValue: paramMultiValue});
|
||||
}
|
||||
return results;
|
||||
@@ -289,9 +231,6 @@ Widget.prototype.evaluateMacroModule = function(name,actualParams,defaultValue)
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Check whether a given context variable value exists in the parent chain
|
||||
*/
|
||||
Widget.prototype.hasVariable = function(name,value) {
|
||||
var node = this;
|
||||
while(node) {
|
||||
@@ -303,9 +242,6 @@ Widget.prototype.hasVariable = function(name,value) {
|
||||
return false;
|
||||
};
|
||||
|
||||
/*
|
||||
Construct a qualifying string based on a hash of concatenating the values of a given variable in the parent chain
|
||||
*/
|
||||
Widget.prototype.getStateQualifier = function(name) {
|
||||
this.qualifiers = this.qualifiers || Object.create(null);
|
||||
name = name || "transclusion";
|
||||
@@ -326,9 +262,6 @@ Widget.prototype.getStateQualifier = function(name) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Make a fake widget with specified variables, suitable for variable lookup in filters. Each variable can be a string or an array of strings
|
||||
*/
|
||||
Widget.prototype.makeFakeWidgetWithVariables = function(vars = {}) {
|
||||
const self = this;
|
||||
|
||||
@@ -345,7 +278,6 @@ Widget.prototype.makeFakeWidgetWithVariables = function(vars = {}) {
|
||||
return self.getVariableInfo(name, opts);
|
||||
},
|
||||
|
||||
|
||||
getVariable(name,opts) {
|
||||
return this.getVariableInfo(name, opts).text;
|
||||
},
|
||||
@@ -356,7 +288,7 @@ Widget.prototype.makeFakeWidgetWithVariables = function(vars = {}) {
|
||||
|
||||
get variables() {
|
||||
// Merge parent vars via prototype-like delegation
|
||||
return Object.create(self.variables || {},
|
||||
return Object.create(self.variables || {},
|
||||
Object.keys(vars).reduce((acc, key) => {
|
||||
acc[key] = { value: vars[key], enumerable: true, configurable: true };
|
||||
return acc;
|
||||
@@ -368,12 +300,6 @@ Widget.prototype.makeFakeWidgetWithVariables = function(vars = {}) {
|
||||
return fakeWidget;
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the current values of the attributes of the widget. Returns a hashmap of the names of the attributes that have changed.
|
||||
Options include:
|
||||
filterFn: only include attributes where filterFn(name) returns true
|
||||
asList: boolean if true returns results as an array instead of a single value
|
||||
*/
|
||||
Widget.prototype.computeAttributes = function(options) {
|
||||
options = options || {};
|
||||
var changedAttributes = {},
|
||||
@@ -405,10 +331,6 @@ Widget.prototype.computeAttributes = function(options) {
|
||||
return changedAttributes;
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the value of a single attribute. Options include:
|
||||
asList: boolean if true returns results as an array instead of a single value
|
||||
*/
|
||||
Widget.prototype.computeAttribute = function(attribute,options) {
|
||||
options = options || {};
|
||||
var self = this,
|
||||
@@ -462,23 +384,14 @@ Widget.prototype.computeAttribute = function(attribute,options) {
|
||||
return value;
|
||||
};
|
||||
|
||||
/*
|
||||
Check for the presence of an evaluated attribute on the widget. Note that attributes set to a missing variable (ie attr=<<missing>>) will be treated as missing
|
||||
*/
|
||||
Widget.prototype.hasAttribute = function(name) {
|
||||
return $tw.utils.hop(this.attributes,name);
|
||||
};
|
||||
|
||||
/*
|
||||
Check for the presence of a raw attribute on the widget parse tree node. Note that attributes set to a missing variable (ie attr=<<missing>>) will NOT be treated as missing
|
||||
*/
|
||||
Widget.prototype.hasParseTreeNodeAttribute = function(name) {
|
||||
return $tw.utils.hop(this.parseTreeNode.attributes,name);
|
||||
};
|
||||
|
||||
/*
|
||||
Get the value of an attribute
|
||||
*/
|
||||
Widget.prototype.getAttribute = function(name,defaultText) {
|
||||
if($tw.utils.hop(this.attributes,name)) {
|
||||
return this.attributes[name];
|
||||
@@ -487,14 +400,6 @@ Widget.prototype.getAttribute = function(name,defaultText) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Assign the common attributes of the widget to a domNode
|
||||
options include:
|
||||
sourcePrefix: prefix of attributes that are to be directly assigned (defaults to the empty string meaning all attributes)
|
||||
destPrefix: prefix to be applied to attribute names that are to be directly assigned (defaults to the emtpy string which means no prefix is added)
|
||||
changedAttributes: hashmap by attribute name of attributes to process (if missing, process all attributes)
|
||||
excludeEventAttributes: ignores attributes whose name would begin with "on"
|
||||
*/
|
||||
Widget.prototype.assignAttributes = function(domNode,options) {
|
||||
options = options || {};
|
||||
var self = this,
|
||||
@@ -508,18 +413,18 @@ Widget.prototype.assignAttributes = function(domNode,options) {
|
||||
domNode.style.setProperty(name,value);
|
||||
return;
|
||||
}
|
||||
// Process any style attributes before considering sourcePrefix and destPrefix
|
||||
|
||||
if(name.substr(0,6) === "style." && name.length > 6) {
|
||||
domNode.style[$tw.utils.unHyphenateCss(name.substr(6))] = value;
|
||||
return;
|
||||
}
|
||||
// Check if the sourcePrefix is a match
|
||||
|
||||
if(name.substr(0,sourcePrefix.length) === sourcePrefix) {
|
||||
name = destPrefix + name.substr(sourcePrefix.length);
|
||||
} else {
|
||||
value = undefined;
|
||||
}
|
||||
// Check for excluded attribute names
|
||||
|
||||
if(options.excludeEventAttributes && name.substr(0,2).toLowerCase() === EVENT_ATTRIBUTE_PREFIX) {
|
||||
value = undefined;
|
||||
}
|
||||
@@ -530,7 +435,7 @@ Widget.prototype.assignAttributes = function(domNode,options) {
|
||||
namespace = "http://www.w3.org/1999/xlink";
|
||||
name = name.substr(6);
|
||||
}
|
||||
// Setting certain attributes can cause a DOM error (eg xmlns on the svg element)
|
||||
|
||||
try {
|
||||
domNode.setAttributeNS(namespace,name,value);
|
||||
} catch(e) {
|
||||
@@ -548,13 +453,10 @@ Widget.prototype.assignAttributes = function(domNode,options) {
|
||||
} else {
|
||||
$tw.utils.each(changedAttributes,function(value,name) {
|
||||
assignAttribute(name,self.getAttribute(name));
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Get the number of ancestor widgets for this widget
|
||||
*/
|
||||
Widget.prototype.getAncestorCount = function() {
|
||||
if(this.ancestorCount === undefined) {
|
||||
if(this.parentWidget) {
|
||||
@@ -566,9 +468,6 @@ Widget.prototype.getAncestorCount = function() {
|
||||
return this.ancestorCount;
|
||||
};
|
||||
|
||||
/*
|
||||
Make child widgets correspondng to specified parseTreeNodes
|
||||
*/
|
||||
Widget.prototype.makeChildWidgets = function(parseTreeNodes,options) {
|
||||
options = options || {};
|
||||
this.children = [];
|
||||
@@ -596,11 +495,6 @@ Widget.prototype.makeChildWidgets = function(parseTreeNodes,options) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Construct the widget object for a parse tree node
|
||||
options include:
|
||||
variables: optional hashmap of variables to wrap around the widget
|
||||
*/
|
||||
Widget.prototype.makeChildWidget = function(parseTreeNode,options) {
|
||||
var self = this;
|
||||
options = options || {};
|
||||
@@ -611,7 +505,7 @@ Widget.prototype.makeChildWidget = function(parseTreeNode,options) {
|
||||
// Widget is overrideable if its name contains a period, or if it is an existing JS widget and we're not in safe mode
|
||||
return parseTreeNode.type.indexOf(".") !== -1 || (!!self.widgetClasses[parseTreeNode.type] && !$tw.safeMode);
|
||||
};
|
||||
if(!parseTreeNode.isNotRemappable && isOverrideable()) {
|
||||
if(!parseTreeNode.isNotRemappable && isOverrideable()) {
|
||||
var variableInfo = this.getVariableInfo(variableDefinitionName,{allowSelfAssigned: true});
|
||||
if(variableInfo && variableInfo.srcVariable && variableInfo.srcVariable.value && variableInfo.srcVariable.isWidgetDefinition) {
|
||||
var newParseTreeNode = {
|
||||
@@ -629,13 +523,13 @@ Widget.prototype.makeChildWidget = function(parseTreeNode,options) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Get the widget class for this node type
|
||||
|
||||
var WidgetClass = this.widgetClasses[parseTreeNode.type];
|
||||
if(!WidgetClass) {
|
||||
WidgetClass = this.widgetClasses.text;
|
||||
parseTreeNode = {type: "text", text: "Undefined widget '" + parseTreeNode.type + "'"};
|
||||
}
|
||||
// Create set variable widgets for each variable
|
||||
|
||||
$tw.utils.each(options.variables,function(value,name) {
|
||||
var setVariableWidget = {
|
||||
type: "set",
|
||||
@@ -656,9 +550,6 @@ Widget.prototype.makeChildWidget = function(parseTreeNode,options) {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
Get the next sibling of this widget
|
||||
*/
|
||||
Widget.prototype.nextSibling = function() {
|
||||
if(this.parentWidget) {
|
||||
var index = this.parentWidget.children.indexOf(this);
|
||||
@@ -669,9 +560,6 @@ Widget.prototype.nextSibling = function() {
|
||||
return null;
|
||||
};
|
||||
|
||||
/*
|
||||
Get the previous sibling of this widget
|
||||
*/
|
||||
Widget.prototype.previousSibling = function() {
|
||||
if(this.parentWidget) {
|
||||
var index = this.parentWidget.children.indexOf(this);
|
||||
@@ -682,9 +570,6 @@ Widget.prototype.previousSibling = function() {
|
||||
return null;
|
||||
};
|
||||
|
||||
/*
|
||||
Render the children of this widget into the DOM
|
||||
*/
|
||||
Widget.prototype.renderChildren = function(parent,nextSibling) {
|
||||
var children = this.children;
|
||||
for(var i = 0; i < children.length; i++) {
|
||||
@@ -692,9 +577,6 @@ Widget.prototype.renderChildren = function(parent,nextSibling) {
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
Add a list of event listeners from an array [{type:,handler:},...]
|
||||
*/
|
||||
Widget.prototype.addEventListeners = function(listeners) {
|
||||
var self = this;
|
||||
$tw.utils.each(listeners,function(listenerInfo) {
|
||||
@@ -702,11 +584,6 @@ Widget.prototype.addEventListeners = function(listeners) {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
Add an event listener.
|
||||
|
||||
Listener could return a boolean indicating whether to further propagation or not, default to `false`.
|
||||
*/
|
||||
Widget.prototype.addEventListener = function(type,handler) {
|
||||
this.eventListeners[type] = this.eventListeners[type] || [];
|
||||
if(this.eventListeners[type].indexOf(handler) === -1) {
|
||||
@@ -714,9 +591,6 @@ Widget.prototype.addEventListener = function(type,handler) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Remove an event listener
|
||||
*/
|
||||
Widget.prototype.removeEventListener = function(type,handler) {
|
||||
if(!this.eventListeners[type]) return;
|
||||
var index = this.eventListeners[type].indexOf(handler);
|
||||
@@ -725,11 +599,6 @@ Widget.prototype.removeEventListener = function(type,handler) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Dispatch an event to a widget.
|
||||
|
||||
If the widget doesn't handle the event then it is also dispatched to the parent widget
|
||||
*/
|
||||
Widget.prototype.dispatchEvent = function(event) {
|
||||
event.widget = event.widget || this;
|
||||
var listeners = this.eventListeners[event.type];
|
||||
@@ -753,32 +622,23 @@ Widget.prototype.dispatchEvent = function(event) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Dispatch the event to the parent widget
|
||||
|
||||
if(this.parentWidget) {
|
||||
return this.parentWidget.dispatchEvent(event);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
Widget.prototype.refresh = function(changedTiddlers) {
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
};
|
||||
|
||||
/*
|
||||
Rebuild a previously rendered widget
|
||||
*/
|
||||
Widget.prototype.refreshSelf = function() {
|
||||
var nextSibling = this.findNextSiblingDomNode();
|
||||
this.removeChildDomNodes();
|
||||
this.render(this.parentDomNode,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Refresh all the children of a widget
|
||||
*/
|
||||
Widget.prototype.refreshChildren = function(changedTiddlers) {
|
||||
var children = this.children,
|
||||
refreshed = false;
|
||||
@@ -788,9 +648,6 @@ Widget.prototype.refreshChildren = function(changedTiddlers) {
|
||||
return refreshed;
|
||||
};
|
||||
|
||||
/*
|
||||
Find the next sibling in the DOM to this widget. This is done by scanning the widget tree through all next siblings and their descendents that share the same parent DOM node
|
||||
*/
|
||||
Widget.prototype.findNextSiblingDomNode = function(startIndex) {
|
||||
// Refer to this widget by its index within its parents children
|
||||
var parent = this.parentWidget,
|
||||
@@ -798,14 +655,14 @@ Widget.prototype.findNextSiblingDomNode = function(startIndex) {
|
||||
if(index === -1) {
|
||||
throw "node not found in parents children";
|
||||
}
|
||||
// Look for a DOM node in the later siblings
|
||||
|
||||
while(++index < parent.children.length) {
|
||||
var domNode = parent.children[index].findFirstDomNode();
|
||||
if(domNode) {
|
||||
return domNode;
|
||||
}
|
||||
}
|
||||
// Go back and look for later siblings of our parent if it has the same parent dom node
|
||||
|
||||
var grandParent = parent.parentWidget;
|
||||
if(grandParent && parent.parentDomNode === this.parentDomNode) {
|
||||
index = grandParent.children.indexOf(parent);
|
||||
@@ -816,9 +673,6 @@ Widget.prototype.findNextSiblingDomNode = function(startIndex) {
|
||||
return null;
|
||||
};
|
||||
|
||||
/*
|
||||
Find the first DOM node generated by a widget or its children
|
||||
*/
|
||||
Widget.prototype.findFirstDomNode = function() {
|
||||
// Return the first dom node of this widget, if we've got one
|
||||
if(this.domNodes.length > 0) {
|
||||
@@ -867,20 +721,20 @@ Widget.prototype.destroy = function(options) {
|
||||
// Destroy children first
|
||||
this.destroyChildren({removeDOMNodes: removeChildDOMNodes});
|
||||
this.children = [];
|
||||
|
||||
|
||||
// Call custom cleanup method if implemented
|
||||
if(typeof this.onDestroy === "function") {
|
||||
this.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
// Remove our DOM nodes if needed
|
||||
if(removeDOMNodes) {
|
||||
this.removeLocalDomNodes();
|
||||
this.removeLocalDomNodes();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Remove any DOM nodes created by this widget
|
||||
Remove any DOM nodes created by this widget
|
||||
*/
|
||||
Widget.prototype.removeLocalDomNodes = function() {
|
||||
for(const domNode of this.domNodes) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
title: $:/core/modules/widgets/wikify.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Widget to wikify text into a variable
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
@@ -15,14 +12,8 @@ var WikifyWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
WikifyWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
WikifyWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
@@ -30,9 +21,6 @@ WikifyWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
WikifyWidget.prototype.execute = function() {
|
||||
// Get our parameters
|
||||
this.wikifyName = this.getAttribute("name");
|
||||
@@ -44,7 +32,7 @@ WikifyWidget.prototype.execute = function() {
|
||||
this.wikifyParser = this.wiki.parseText(this.wikifyType,this.wikifyText,{
|
||||
parseAsInline: this.wikifyMode === "inline"
|
||||
});
|
||||
// Create the widget tree
|
||||
// Create the widget tree
|
||||
this.wikifyWidgetNode = this.wiki.makeWidget(this.wikifyParser,{
|
||||
document: $tw.fakeDocument,
|
||||
parentWidget: this
|
||||
@@ -59,9 +47,6 @@ WikifyWidget.prototype.execute = function() {
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Return the result string
|
||||
*/
|
||||
WikifyWidget.prototype.getResult = function() {
|
||||
var result;
|
||||
switch(this.wikifyOutput) {
|
||||
@@ -84,9 +69,6 @@ WikifyWidget.prototype.getResult = function() {
|
||||
return result;
|
||||
};
|
||||
|
||||
/*
|
||||
Return a string of the widget tree
|
||||
*/
|
||||
WikifyWidget.prototype.getWidgetTree = function() {
|
||||
var copyNode = function(widgetNode,resultNode) {
|
||||
var type = widgetNode.parseTreeNode.type;
|
||||
@@ -119,9 +101,6 @@ WikifyWidget.prototype.getWidgetTree = function() {
|
||||
return results;
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
WikifyWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
// Refresh ourselves entirely if any of our attributes have changed
|
||||
@@ -144,7 +123,7 @@ WikifyWidget.prototype.refresh = function(changedTiddlers) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Just refresh the children
|
||||
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user