mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-07 22:33:50 +00:00
Refactored widgets not to use a base class
This commit is contained in:
parent
f8340bc4dc
commit
d96e0073ac
@ -22,7 +22,7 @@ var WidgetRenderer = function(renderTree,renderContext,parseTreeNode) {
|
|||||||
this.parseTreeNode = parseTreeNode;
|
this.parseTreeNode = parseTreeNode;
|
||||||
// Widget classes
|
// Widget classes
|
||||||
if(!this.widgetClasses) {
|
if(!this.widgetClasses) {
|
||||||
WidgetRenderer.prototype.widgetClasses = $tw.modules.createClassesFromModules("widget",null,$tw.WidgetBase);
|
WidgetRenderer.prototype.widgetClasses = $tw.modules.applyMethods("widget");
|
||||||
}
|
}
|
||||||
// Compute our attributes
|
// Compute our attributes
|
||||||
this.attributes = {};
|
this.attributes = {};
|
||||||
@ -30,8 +30,7 @@ var WidgetRenderer = function(renderTree,renderContext,parseTreeNode) {
|
|||||||
// Create the widget object
|
// Create the widget object
|
||||||
var WidgetClass = this.widgetClasses[this.parseTreeNode.tag];
|
var WidgetClass = this.widgetClasses[this.parseTreeNode.tag];
|
||||||
if(WidgetClass) {
|
if(WidgetClass) {
|
||||||
this.widget = new WidgetClass();
|
this.widget = new WidgetClass(this);
|
||||||
this.widget.init(this);
|
|
||||||
} else {
|
} else {
|
||||||
// Error if we couldn't find the widget
|
// Error if we couldn't find the widget
|
||||||
this.children = this.renderTree.createRenderers(this.renderContext,[
|
this.children = this.renderTree.createRenderers(this.renderContext,[
|
||||||
@ -74,26 +73,46 @@ WidgetRenderer.prototype.getAttribute = function(name,defaultValue) {
|
|||||||
|
|
||||||
WidgetRenderer.prototype.render = function(type) {
|
WidgetRenderer.prototype.render = function(type) {
|
||||||
// Render the widget if we've got one
|
// Render the widget if we've got one
|
||||||
if(this.widget && this.widget.render) {
|
if(this.widget) {
|
||||||
return this.widget.render(type);
|
if(this.widget.render) {
|
||||||
|
return this.widget.render(type);
|
||||||
|
} else if(this.widget.children) {
|
||||||
|
var output = [];
|
||||||
|
$tw.utils.each(this.widget.children,function(node) {
|
||||||
|
if(node.render) {
|
||||||
|
output.push(node.render(type));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return output.join("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
WidgetRenderer.prototype.renderInDom = function() {
|
WidgetRenderer.prototype.renderInDom = function() {
|
||||||
|
var self = this;
|
||||||
// Create the wrapper element
|
// Create the wrapper element
|
||||||
this.domNode = document.createElement(this.parseTreeNode.isBlock ? "div" : "span");
|
this.domNode = document.createElement(this.parseTreeNode.isBlock ? "div" : "span");
|
||||||
this.domNode.setAttribute("data-widget-type",this.parseTreeNode.tag);
|
this.domNode.setAttribute("data-widget-type",this.parseTreeNode.tag);
|
||||||
this.domNode.setAttribute("data-widget-attr",JSON.stringify(this.attributes));
|
this.domNode.setAttribute("data-widget-attr",JSON.stringify(this.attributes));
|
||||||
// Render the widget if we've got one
|
// Render the widget if we've got one
|
||||||
if(this.widget) {
|
if(this.widget) {
|
||||||
this.widget.renderInDom(this.domNode);
|
if(this.widget.renderInDom) {
|
||||||
|
this.widget.renderInDom(this.domNode);
|
||||||
|
} else if(this.widget.children) {
|
||||||
|
// Render any child nodes
|
||||||
|
$tw.utils.each(this.widget.children,function(node) {
|
||||||
|
if(node.renderInDom) {
|
||||||
|
self.domNode.appendChild(node.renderInDom());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
// Attach any event handlers
|
// Attach any event handlers
|
||||||
if(this.widget.getEventListeners) {
|
if(this.widget.getEventListeners) {
|
||||||
$tw.utils.addEventListeners(this.domNode,this.widget.getEventListeners());
|
$tw.utils.addEventListeners(this.domNode,this.widget.getEventListeners());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Call the postRenderInDom hook if the widget has one
|
// Call the postRenderInDom hook if the widget has one
|
||||||
if(this.widget.postRenderInDom) {
|
if(this.widget && this.widget.postRenderInDom) {
|
||||||
this.widget.postRenderInDom();
|
this.widget.postRenderInDom();
|
||||||
}
|
}
|
||||||
// Return the dom node
|
// Return the dom node
|
||||||
|
@ -12,16 +12,14 @@ Implements the button widget.
|
|||||||
/*global $tw: false */
|
/*global $tw: false */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports.name = "button";
|
var ButtonWidget = function(renderer) {
|
||||||
|
|
||||||
exports.init = function(renderer) {
|
|
||||||
// Save state
|
// Save state
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
// Generate child nodes
|
// Generate child nodes
|
||||||
this.generateChildNodes();
|
this.generateChildNodes();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generateChildNodes = function() {
|
ButtonWidget.prototype.generateChildNodes = function() {
|
||||||
// Get the parameters from the attributes
|
// Get the parameters from the attributes
|
||||||
this.message = this.renderer.getAttribute("message");
|
this.message = this.renderer.getAttribute("message");
|
||||||
this.param = this.renderer.getAttribute("param");
|
this.param = this.renderer.getAttribute("param");
|
||||||
@ -52,14 +50,14 @@ exports.generateChildNodes = function() {
|
|||||||
}]);
|
}]);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.dispatchMessage = function(event) {
|
ButtonWidget.prototype.dispatchMessage = function(event) {
|
||||||
$tw.utils.dispatchCustomEvent(event.target,this.message,{
|
$tw.utils.dispatchCustomEvent(event.target,this.message,{
|
||||||
param: this.param,
|
param: this.param,
|
||||||
tiddlerTitle: this.renderer.getContextTiddlerTitle()
|
tiddlerTitle: this.renderer.getContextTiddlerTitle()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.triggerPopup = function(event) {
|
ButtonWidget.prototype.triggerPopup = function(event) {
|
||||||
var title = this.popup;
|
var title = this.popup;
|
||||||
if(this.qualifyTiddlerTitles) {
|
if(this.qualifyTiddlerTitles) {
|
||||||
title = title + "-" + this.renderer.getContextScopeId();
|
title = title + "-" + this.renderer.getContextScopeId();
|
||||||
@ -71,12 +69,12 @@ exports.triggerPopup = function(event) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.setTiddler = function() {
|
ButtonWidget.prototype.setTiddler = function() {
|
||||||
var tiddler = this.renderer.renderTree.wiki.getTiddler(this.set);
|
var tiddler = this.renderer.renderTree.wiki.getTiddler(this.set);
|
||||||
this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(tiddler,{title: this.set, text: this.setTo}));
|
this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(tiddler,{title: this.set, text: this.setTo}));
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.handleClickEvent = function(event) {
|
ButtonWidget.prototype.handleClickEvent = function(event) {
|
||||||
if(this.message) {
|
if(this.message) {
|
||||||
this.dispatchMessage(event);
|
this.dispatchMessage(event);
|
||||||
}
|
}
|
||||||
@ -90,7 +88,7 @@ exports.handleClickEvent = function(event) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.handleMouseOverOrOutEvent = function(event) {
|
ButtonWidget.prototype.handleMouseOverOrOutEvent = function(event) {
|
||||||
if(this.popup) {
|
if(this.popup) {
|
||||||
this.triggerPopup(event);
|
this.triggerPopup(event);
|
||||||
}
|
}
|
||||||
@ -98,7 +96,7 @@ exports.handleMouseOverOrOutEvent = function(event) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.refreshInDom = function(changedAttributes,changedTiddlers) {
|
ButtonWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) {
|
||||||
// Check if any of our attributes have changed, or if a tiddler we're interested in has changed
|
// Check if any of our attributes have changed, or if a tiddler we're interested in has changed
|
||||||
if(changedAttributes.message || changedAttributes.param || changedAttributes.set || changedAttributes.setTo || changedAttributes.popup || changedAttributes.hover || changedAttributes.qualifyTiddlerTitles || changedAttributes["class"] || (this.set && changedTiddlers[this.set]) || (this.popup && changedTiddlers[this.popup])) {
|
if(changedAttributes.message || changedAttributes.param || changedAttributes.set || changedAttributes.setTo || changedAttributes.popup || changedAttributes.hover || changedAttributes.qualifyTiddlerTitles || changedAttributes["class"] || (this.set && changedTiddlers[this.set]) || (this.popup && changedTiddlers[this.popup])) {
|
||||||
// Remove old child nodes
|
// Remove old child nodes
|
||||||
@ -121,4 +119,6 @@ exports.refreshInDom = function(changedAttributes,changedTiddlers) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.button = ButtonWidget;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -12,16 +12,14 @@ The view widget displays the fields of a tiddler through a text substitution tem
|
|||||||
/*global $tw: false */
|
/*global $tw: false */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports.name = "fields";
|
var FieldsWidget = function(renderer) {
|
||||||
|
|
||||||
exports.init = function(renderer) {
|
|
||||||
// Save state
|
// Save state
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
// Generate child nodes
|
// Generate child nodes
|
||||||
this.generateChildNodes();
|
this.generateChildNodes();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generateChildNodes = function() {
|
FieldsWidget.prototype.generateChildNodes = function() {
|
||||||
// Get parameters from our attributes
|
// Get parameters from our attributes
|
||||||
this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.getContextTiddlerTitle());
|
this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.getContextTiddlerTitle());
|
||||||
this.template = this.renderer.getAttribute("template");
|
this.template = this.renderer.getAttribute("template");
|
||||||
@ -75,4 +73,6 @@ exports.generateChildNodes = function() {
|
|||||||
this.children = this.renderer.renderTree.createRenderers(this.renderer.renderContext,[node]);
|
this.children = this.renderer.renderTree.createRenderers(this.renderer.renderContext,[node]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.fields = FieldsWidget;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -12,21 +12,19 @@ Implements the link widget.
|
|||||||
/*global $tw: false */
|
/*global $tw: false */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports.name = "link";
|
|
||||||
|
|
||||||
var isLinkExternal = function(to) {
|
var isLinkExternal = function(to) {
|
||||||
var externalRegExp = /(?:file|http|https|mailto|ftp|irc|news|data):[^\s'"]+(?:\/|\b)/i;
|
var externalRegExp = /(?:file|http|https|mailto|ftp|irc|news|data):[^\s'"]+(?:\/|\b)/i;
|
||||||
return externalRegExp.test(to);
|
return externalRegExp.test(to);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.init = function(renderer) {
|
var LinkWidget = function(renderer) {
|
||||||
// Save state
|
// Save state
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
// Generate child nodes
|
// Generate child nodes
|
||||||
this.generateChildNodes();
|
this.generateChildNodes();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generateChildNodes = function() {
|
LinkWidget.prototype.generateChildNodes = function() {
|
||||||
// Get the parameters from the attributes
|
// Get the parameters from the attributes
|
||||||
this.to = this.renderer.getAttribute("to");
|
this.to = this.renderer.getAttribute("to");
|
||||||
this.hover = this.renderer.getAttribute("hover");
|
this.hover = this.renderer.getAttribute("hover");
|
||||||
@ -65,7 +63,7 @@ exports.generateChildNodes = function() {
|
|||||||
}]);
|
}]);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.handleClickEvent = function(event) {
|
LinkWidget.prototype.handleClickEvent = function(event) {
|
||||||
if(isLinkExternal(this.to)) {
|
if(isLinkExternal(this.to)) {
|
||||||
event.target.setAttribute("target","_blank");
|
event.target.setAttribute("target","_blank");
|
||||||
return true;
|
return true;
|
||||||
@ -80,7 +78,7 @@ exports.handleClickEvent = function(event) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.handleMouseOverOrOutEvent = function(event) {
|
LinkWidget.prototype.handleMouseOverOrOutEvent = function(event) {
|
||||||
if(this.hover) {
|
if(this.hover) {
|
||||||
$tw.popup.triggerPopup({
|
$tw.popup.triggerPopup({
|
||||||
textRef: this.hover,
|
textRef: this.hover,
|
||||||
@ -94,7 +92,7 @@ exports.handleMouseOverOrOutEvent = function(event) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.refreshInDom = function(changedAttributes,changedTiddlers) {
|
LinkWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) {
|
||||||
// Set the class for missing tiddlers
|
// Set the class for missing tiddlers
|
||||||
if(this.targetTitle && changedTiddlers[this.targetTitle]) {
|
if(this.targetTitle && changedTiddlers[this.targetTitle]) {
|
||||||
$tw.utils.toggleClass(this.children[0].domNode,"tw-tiddler-missing",!this.renderer.renderTree.wiki.tiddlerExists(this.targetTitle));
|
$tw.utils.toggleClass(this.children[0].domNode,"tw-tiddler-missing",!this.renderer.renderTree.wiki.tiddlerExists(this.targetTitle));
|
||||||
@ -121,4 +119,6 @@ exports.refreshInDom = function(changedAttributes,changedTiddlers) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.link = LinkWidget;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -12,7 +12,12 @@ The list widget
|
|||||||
/*global $tw: false */
|
/*global $tw: false */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports.name = "list";
|
var ListWidget = function(renderer) {
|
||||||
|
// Save state
|
||||||
|
this.renderer = renderer;
|
||||||
|
// Generate child nodes
|
||||||
|
this.generateChildNodes();
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
These types are shorthands for particular filters
|
These types are shorthands for particular filters
|
||||||
@ -25,14 +30,7 @@ var typeMappings = {
|
|||||||
shadows: "[is[shadow]sort[title]]"
|
shadows: "[is[shadow]sort[title]]"
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.init = function(renderer) {
|
ListWidget.prototype.generateChildNodes = function() {
|
||||||
// Save state
|
|
||||||
this.renderer = renderer;
|
|
||||||
// Generate child nodes
|
|
||||||
this.generateChildNodes();
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.generateChildNodes = function() {
|
|
||||||
// Get our attributes
|
// Get our attributes
|
||||||
this.itemClass = this.renderer.getAttribute("itemClass");
|
this.itemClass = this.renderer.getAttribute("itemClass");
|
||||||
this.template = this.renderer.getAttribute("template");
|
this.template = this.renderer.getAttribute("template");
|
||||||
@ -63,7 +61,7 @@ exports.generateChildNodes = function() {
|
|||||||
}]);
|
}]);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getTiddlerList = function() {
|
ListWidget.prototype.getTiddlerList = function() {
|
||||||
var filter;
|
var filter;
|
||||||
if(this.renderer.hasAttribute("type")) {
|
if(this.renderer.hasAttribute("type")) {
|
||||||
filter = typeMappings[this.renderer.getAttribute("type")];
|
filter = typeMappings[this.renderer.getAttribute("type")];
|
||||||
@ -79,7 +77,7 @@ exports.getTiddlerList = function() {
|
|||||||
/*
|
/*
|
||||||
Create and execute the nodes representing the empty message
|
Create and execute the nodes representing the empty message
|
||||||
*/
|
*/
|
||||||
exports.getEmptyMessage = function() {
|
ListWidget.prototype.getEmptyMessage = function() {
|
||||||
return {
|
return {
|
||||||
type: "element",
|
type: "element",
|
||||||
tag: "span",
|
tag: "span",
|
||||||
@ -90,7 +88,7 @@ exports.getEmptyMessage = function() {
|
|||||||
/*
|
/*
|
||||||
Create a list element representing a given tiddler
|
Create a list element representing a given tiddler
|
||||||
*/
|
*/
|
||||||
exports.createListElement = function(title) {
|
ListWidget.prototype.createListElement = function(title) {
|
||||||
// Define an event handler that adds navigation information to the event
|
// Define an event handler that adds navigation information to the event
|
||||||
var handleEvent = function(event) {
|
var handleEvent = function(event) {
|
||||||
event.navigateFromTitle = title;
|
event.navigateFromTitle = title;
|
||||||
@ -122,7 +120,7 @@ exports.createListElement = function(title) {
|
|||||||
/*
|
/*
|
||||||
Create the tiddler macro needed to represent a given tiddler
|
Create the tiddler macro needed to represent a given tiddler
|
||||||
*/
|
*/
|
||||||
exports.createListElementMacro = function(title) {
|
ListWidget.prototype.createListElementMacro = function(title) {
|
||||||
// Check if the tiddler is a draft
|
// Check if the tiddler is a draft
|
||||||
var tiddler = this.renderer.renderTree.wiki.getTiddler(title),
|
var tiddler = this.renderer.renderTree.wiki.getTiddler(title),
|
||||||
isDraft = tiddler ? tiddler.hasField("draft.of") : false;
|
isDraft = tiddler ? tiddler.hasField("draft.of") : false;
|
||||||
@ -164,7 +162,7 @@ exports.createListElementMacro = function(title) {
|
|||||||
/*
|
/*
|
||||||
Remove a list element from the list, along with the attendant DOM nodes
|
Remove a list element from the list, along with the attendant DOM nodes
|
||||||
*/
|
*/
|
||||||
exports.removeListElement = function(index) {
|
ListWidget.prototype.removeListElement = function(index) {
|
||||||
// Get the list element
|
// Get the list element
|
||||||
var listElement = this.children[0].children[index];
|
var listElement = this.children[0].children[index];
|
||||||
// Remove the DOM node
|
// Remove the DOM node
|
||||||
@ -178,7 +176,7 @@ Return the index of the list element that corresponds to a particular title
|
|||||||
startIndex: index to start search (use zero to search from the top)
|
startIndex: index to start search (use zero to search from the top)
|
||||||
title: tiddler title to seach for
|
title: tiddler title to seach for
|
||||||
*/
|
*/
|
||||||
exports.findListElementByTitle = function(startIndex,title) {
|
ListWidget.prototype.findListElementByTitle = function(startIndex,title) {
|
||||||
while(startIndex < this.children[0].children.length) {
|
while(startIndex < this.children[0].children.length) {
|
||||||
if(this.children[0].children[startIndex].children[0].attributes.target === title) {
|
if(this.children[0].children[startIndex].children[0].attributes.target === title) {
|
||||||
return startIndex;
|
return startIndex;
|
||||||
@ -188,7 +186,7 @@ exports.findListElementByTitle = function(startIndex,title) {
|
|||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.refreshInDom = function(changedAttributes,changedTiddlers) {
|
ListWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) {
|
||||||
// Reexecute the widget if any of our attributes have changed
|
// Reexecute the widget if any of our attributes have changed
|
||||||
if(changedAttributes.itemClass || changedAttributes.template || changedAttributes.editTemplate || changedAttributes.emptyMessage || changedAttributes.type || changedAttributes.filter || changedAttributes.template) {
|
if(changedAttributes.itemClass || changedAttributes.template || changedAttributes.editTemplate || changedAttributes.emptyMessage || changedAttributes.type || changedAttributes.filter || changedAttributes.template) {
|
||||||
// Remove old child nodes
|
// Remove old child nodes
|
||||||
@ -207,7 +205,7 @@ exports.refreshInDom = function(changedAttributes,changedTiddlers) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.handleListChanges = function(changedTiddlers) {
|
ListWidget.prototype.handleListChanges = function(changedTiddlers) {
|
||||||
var t,
|
var t,
|
||||||
prevListLength = this.list.length,
|
prevListLength = this.list.length,
|
||||||
frame = this.children[0];
|
frame = this.children[0];
|
||||||
@ -267,4 +265,6 @@ exports.handleListChanges = function(changedTiddlers) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.list = ListWidget;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -12,16 +12,14 @@ Implements the navigator widget.
|
|||||||
/*global $tw: false */
|
/*global $tw: false */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports.name = "navigator";
|
var NavigatorWidget = function(renderer) {
|
||||||
|
|
||||||
exports.init = function(renderer) {
|
|
||||||
// Save state
|
// Save state
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
// Generate child nodes
|
// Generate child nodes
|
||||||
this.generateChildNodes();
|
this.generateChildNodes();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generateChildNodes = function() {
|
NavigatorWidget.prototype.generateChildNodes = function() {
|
||||||
// Get our parameters
|
// Get our parameters
|
||||||
this.storyTitle = this.renderer.getAttribute("story");
|
this.storyTitle = this.renderer.getAttribute("story");
|
||||||
this.historyTitle = this.renderer.getAttribute("history");
|
this.historyTitle = this.renderer.getAttribute("history");
|
||||||
@ -29,7 +27,7 @@ exports.generateChildNodes = function() {
|
|||||||
this.children = this.renderer.renderTree.createRenderers(this.renderer.renderContext,this.renderer.parseTreeNode.children);
|
this.children = this.renderer.renderTree.createRenderers(this.renderer.renderContext,this.renderer.parseTreeNode.children);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getEventListeners = function() {
|
NavigatorWidget.prototype.getEventListeners = function() {
|
||||||
return [
|
return [
|
||||||
{name: "tw-navigate", handlerObject: this, handlerMethod: "handleNavigateEvent"},
|
{name: "tw-navigate", handlerObject: this, handlerMethod: "handleNavigateEvent"},
|
||||||
{name: "tw-EditTiddler", handlerObject: this, handlerMethod: "handleEditTiddlerEvent"},
|
{name: "tw-EditTiddler", handlerObject: this, handlerMethod: "handleEditTiddlerEvent"},
|
||||||
@ -39,7 +37,7 @@ exports.getEventListeners = function() {
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.refreshInDom = function(changedAttributes,changedTiddlers) {
|
NavigatorWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) {
|
||||||
// We don't need to refresh ourselves, so just refresh any child nodes
|
// We don't need to refresh ourselves, so just refresh any child nodes
|
||||||
$tw.utils.each(this.children,function(node) {
|
$tw.utils.each(this.children,function(node) {
|
||||||
if(node.refreshInDom) {
|
if(node.refreshInDom) {
|
||||||
@ -48,7 +46,7 @@ exports.refreshInDom = function(changedAttributes,changedTiddlers) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getStoryList = function() {
|
NavigatorWidget.prototype.getStoryList = function() {
|
||||||
var text = this.renderer.renderTree.wiki.getTextReference(this.storyTitle,"");
|
var text = this.renderer.renderTree.wiki.getTextReference(this.storyTitle,"");
|
||||||
if(text && text.length > 0) {
|
if(text && text.length > 0) {
|
||||||
this.storyList = text.split("\n");
|
this.storyList = text.split("\n");
|
||||||
@ -57,14 +55,14 @@ exports.getStoryList = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.saveStoryList = function() {
|
NavigatorWidget.prototype.saveStoryList = function() {
|
||||||
var storyTiddler = this.renderer.renderTree.wiki.getTiddler(this.storyTitle);
|
var storyTiddler = this.renderer.renderTree.wiki.getTiddler(this.storyTitle);
|
||||||
this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler({
|
this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler({
|
||||||
title: this.storyTitle
|
title: this.storyTitle
|
||||||
},storyTiddler,{text: this.storyList.join("\n")}));
|
},storyTiddler,{text: this.storyList.join("\n")}));
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.findTitleInStory = function(title,defaultIndex) {
|
NavigatorWidget.prototype.findTitleInStory = function(title,defaultIndex) {
|
||||||
for(var t=0; t<this.storyList.length; t++) {
|
for(var t=0; t<this.storyList.length; t++) {
|
||||||
if(this.storyList[t] === title) {
|
if(this.storyList[t] === title) {
|
||||||
return t;
|
return t;
|
||||||
@ -74,7 +72,7 @@ exports.findTitleInStory = function(title,defaultIndex) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Navigate to a specified tiddler
|
// Navigate to a specified tiddler
|
||||||
exports.handleNavigateEvent = function(event) {
|
NavigatorWidget.prototype.handleNavigateEvent = function(event) {
|
||||||
if(this.storyTitle) {
|
if(this.storyTitle) {
|
||||||
// Update the story tiddler if specified
|
// Update the story tiddler if specified
|
||||||
this.getStoryList();
|
this.getStoryList();
|
||||||
@ -101,7 +99,7 @@ exports.handleNavigateEvent = function(event) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Close a specified tiddler
|
// Close a specified tiddler
|
||||||
exports.handleCloseTiddlerEvent = function(event) {
|
NavigatorWidget.prototype.handleCloseTiddlerEvent = function(event) {
|
||||||
this.getStoryList();
|
this.getStoryList();
|
||||||
// Look for tiddlers with this title to close
|
// Look for tiddlers with this title to close
|
||||||
var slot = this.findTitleInStory(event.tiddlerTitle,-1);
|
var slot = this.findTitleInStory(event.tiddlerTitle,-1);
|
||||||
@ -114,7 +112,7 @@ exports.handleCloseTiddlerEvent = function(event) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Place a tiddler in edit mode
|
// Place a tiddler in edit mode
|
||||||
exports.handleEditTiddlerEvent = function(event) {
|
NavigatorWidget.prototype.handleEditTiddlerEvent = function(event) {
|
||||||
this.getStoryList();
|
this.getStoryList();
|
||||||
// Replace the specified tiddler with a draft in edit mode
|
// Replace the specified tiddler with a draft in edit mode
|
||||||
for(var t=0; t<this.storyList.length; t++) {
|
for(var t=0; t<this.storyList.length; t++) {
|
||||||
@ -143,7 +141,7 @@ exports.handleEditTiddlerEvent = function(event) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Take a tiddler out of edit mode, saving the changes
|
// Take a tiddler out of edit mode, saving the changes
|
||||||
exports.handleSaveTiddlerEvent = function(event) {
|
NavigatorWidget.prototype.handleSaveTiddlerEvent = function(event) {
|
||||||
this.getStoryList();
|
this.getStoryList();
|
||||||
var storyTiddlerModified = false;
|
var storyTiddlerModified = false;
|
||||||
for(var t=0; t<this.storyList.length; t++) {
|
for(var t=0; t<this.storyList.length; t++) {
|
||||||
@ -180,7 +178,7 @@ exports.handleSaveTiddlerEvent = function(event) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Create a new draft tiddler
|
// Create a new draft tiddler
|
||||||
exports.handleNewTiddlerEvent = function(event) {
|
NavigatorWidget.prototype.handleNewTiddlerEvent = function(event) {
|
||||||
// Get the story details
|
// Get the story details
|
||||||
this.getStoryList();
|
this.getStoryList();
|
||||||
// Create the new tiddler
|
// Create the new tiddler
|
||||||
@ -218,4 +216,6 @@ exports.handleNewTiddlerEvent = function(event) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.navigator = NavigatorWidget;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -12,16 +12,14 @@ Implements the reveal widget.
|
|||||||
/*global $tw: false */
|
/*global $tw: false */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports.name = "reveal";
|
var RevealWidget = function(renderer) {
|
||||||
|
|
||||||
exports.init = function(renderer) {
|
|
||||||
// Save state
|
// Save state
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
// Generate child nodes
|
// Generate child nodes
|
||||||
this.generateChildNodes();
|
this.generateChildNodes();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generateChildNodes = function() {
|
RevealWidget.prototype.generateChildNodes = function() {
|
||||||
// Get the parameters from the attributes
|
// Get the parameters from the attributes
|
||||||
this.state = this.renderer.getAttribute("state");
|
this.state = this.renderer.getAttribute("state");
|
||||||
this.type = this.renderer.getAttribute("type");
|
this.type = this.renderer.getAttribute("type");
|
||||||
@ -61,7 +59,7 @@ exports.generateChildNodes = function() {
|
|||||||
/*
|
/*
|
||||||
Read the state tiddler
|
Read the state tiddler
|
||||||
*/
|
*/
|
||||||
exports.readState = function() {
|
RevealWidget.prototype.readState = function() {
|
||||||
// Start with the default value for being open or closed
|
// Start with the default value for being open or closed
|
||||||
if(this["default"]) {
|
if(this["default"]) {
|
||||||
this.isOpen = this["default"] === "open";
|
this.isOpen = this["default"] === "open";
|
||||||
@ -84,11 +82,11 @@ exports.readState = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.readMatchState = function(state) {
|
RevealWidget.prototype.readMatchState = function(state) {
|
||||||
this.isOpen = state === this.text;
|
this.isOpen = state === this.text;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.readPopupState = function(state) {
|
RevealWidget.prototype.readPopupState = function(state) {
|
||||||
var popupLocationRegExp = /^\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/,
|
var popupLocationRegExp = /^\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/,
|
||||||
match = popupLocationRegExp.exec(state);
|
match = popupLocationRegExp.exec(state);
|
||||||
// Check if the state matches the location regexp
|
// Check if the state matches the location regexp
|
||||||
@ -108,7 +106,7 @@ exports.readPopupState = function(state) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.handleClickEvent = function(event) {
|
RevealWidget.prototype.handleClickEvent = function(event) {
|
||||||
if(event.type === "click" && this.type === "popup") {
|
if(event.type === "click" && this.type === "popup") {
|
||||||
// Cancel the popup if we get a click on it
|
// Cancel the popup if we get a click on it
|
||||||
if(this.stateTitle) {
|
if(this.stateTitle) {
|
||||||
@ -120,7 +118,7 @@ exports.handleClickEvent = function(event) {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.refreshInDom = function(changedAttributes,changedTiddlers) {
|
RevealWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) {
|
||||||
// Check if any of our attributes have changed, or if a tiddler we're interested in has changed
|
// Check if any of our attributes have changed, or if a tiddler we're interested in has changed
|
||||||
if(changedAttributes.state || changedAttributes.type || changedAttributes.text || changedAttributes.position || changedAttributes["default"] || changedAttributes.qualifyTiddlerTitles || changedAttributes["class"]) {
|
if(changedAttributes.state || changedAttributes.type || changedAttributes.text || changedAttributes.position || changedAttributes["default"] || changedAttributes.qualifyTiddlerTitles || changedAttributes["class"]) {
|
||||||
// Remove old child nodes
|
// Remove old child nodes
|
||||||
@ -161,7 +159,7 @@ exports.refreshInDom = function(changedAttributes,changedTiddlers) {
|
|||||||
this.postRenderInDom();
|
this.postRenderInDom();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.postRenderInDom = function() {
|
RevealWidget.prototype.postRenderInDom = function() {
|
||||||
switch(this.type) {
|
switch(this.type) {
|
||||||
case "popup":
|
case "popup":
|
||||||
if(this.isOpen) {
|
if(this.isOpen) {
|
||||||
@ -198,4 +196,6 @@ exports.postRenderInDom = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.reveal = RevealWidget;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -46,16 +46,14 @@ of the tiddler `Foo`.
|
|||||||
/*global $tw: false */
|
/*global $tw: false */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports.name = "transclude";
|
var TranscludeWidget = function(renderer) {
|
||||||
|
|
||||||
exports.init = function(renderer) {
|
|
||||||
// Save state
|
// Save state
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
// Generate child nodes
|
// Generate child nodes
|
||||||
this.generateChildNodes();
|
this.generateChildNodes();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generateChildNodes = function() {
|
TranscludeWidget.prototype.generateChildNodes = function() {
|
||||||
var tr, templateParseTree, templateTiddler;
|
var tr, templateParseTree, templateTiddler;
|
||||||
// Get the render target details
|
// Get the render target details
|
||||||
this.targetTitle = this.renderer.getAttribute("target",this.renderer.getContextTiddlerTitle());
|
this.targetTitle = this.renderer.getAttribute("target",this.renderer.getContextTiddlerTitle());
|
||||||
@ -109,7 +107,7 @@ exports.generateChildNodes = function() {
|
|||||||
this.children = this.renderer.renderTree.createRenderers(newRenderContext,[node]);
|
this.children = this.renderer.renderTree.createRenderers(newRenderContext,[node]);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.refreshInDom = function(changedAttributes,changedTiddlers) {
|
TranscludeWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) {
|
||||||
// Set the class for missing tiddlers
|
// Set the class for missing tiddlers
|
||||||
if(this.targetTitle && changedTiddlers[this.targetTitle]) {
|
if(this.targetTitle && changedTiddlers[this.targetTitle]) {
|
||||||
$tw.utils.toggleClass(this.children[0].domNode,"tw-tiddler-missing",!this.renderer.renderTree.wiki.tiddlerExists(this.targetTitle));
|
$tw.utils.toggleClass(this.children[0].domNode,"tw-tiddler-missing",!this.renderer.renderTree.wiki.tiddlerExists(this.targetTitle));
|
||||||
@ -136,4 +134,6 @@ exports.refreshInDom = function(changedAttributes,changedTiddlers) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.transclude = TranscludeWidget;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -12,8 +12,6 @@ The view widget displays a tiddler field.
|
|||||||
/*global $tw: false */
|
/*global $tw: false */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports.name = "view";
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Define the "text" viewer here so that it is always available
|
Define the "text" viewer here so that it is always available
|
||||||
*/
|
*/
|
||||||
@ -42,7 +40,7 @@ TextViewer.prototype.render = function() {
|
|||||||
// We'll cache the available field viewers here
|
// We'll cache the available field viewers here
|
||||||
var fieldViewers = undefined;
|
var fieldViewers = undefined;
|
||||||
|
|
||||||
exports.init = function(renderer) {
|
var ViewWidget = function(renderer) {
|
||||||
// Save state
|
// Save state
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
// Initialise the field viewers if they've not been done already
|
// Initialise the field viewers if they've not been done already
|
||||||
@ -54,7 +52,7 @@ exports.init = function(renderer) {
|
|||||||
this.generateChildNodes();
|
this.generateChildNodes();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generateChildNodes = function() {
|
ViewWidget.prototype.generateChildNodes = function() {
|
||||||
// Get parameters from our attributes
|
// Get parameters from our attributes
|
||||||
this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.getContextTiddlerTitle());
|
this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.getContextTiddlerTitle());
|
||||||
this.fieldName = this.renderer.getAttribute("field","text");
|
this.fieldName = this.renderer.getAttribute("field","text");
|
||||||
@ -93,7 +91,7 @@ exports.generateChildNodes = function() {
|
|||||||
this.children = this.viewer.render();
|
this.children = this.viewer.render();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.refreshInDom = function(changedAttributes,changedTiddlers) {
|
ViewWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) {
|
||||||
// Check if any of our attributes have changed, or if a tiddler we're interested in has changed
|
// Check if any of our attributes have changed, or if a tiddler we're interested in has changed
|
||||||
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.format || (this.tiddlerTitle && changedTiddlers[this.tiddlerTitle])) {
|
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.format || (this.tiddlerTitle && changedTiddlers[this.tiddlerTitle])) {
|
||||||
// Remove old child nodes
|
// Remove old child nodes
|
||||||
@ -116,4 +114,6 @@ exports.refreshInDom = function(changedAttributes,changedTiddlers) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.view = ViewWidget;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
title: $:/templates/PageTemplate
|
title: $:/templates/PageTemplate
|
||||||
|
|
||||||
|
<$nosuchwidget />
|
||||||
|
|
||||||
<!-- The navigator catches navigation events and updates the story and history tiddlers -->
|
<!-- The navigator catches navigation events and updates the story and history tiddlers -->
|
||||||
<$navigator story="$:/StoryList" history="$:/HistoryList">
|
<$navigator story="$:/StoryList" history="$:/HistoryList">
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user