diff --git a/core/modules/new_widgets/list.js b/core/modules/new_widgets/list.js index 7b58af661..522c1f104 100755 --- a/core/modules/new_widgets/list.js +++ b/core/modules/new_widgets/list.js @@ -44,6 +44,7 @@ ListWidget.prototype.execute = function() { // Get our attributes this.template = this.getAttribute("template"); this.editTemplate = this.getAttribute("editTemplate"); + this.variableName = this.getAttribute("variable","currentTiddler"); // Compose the list elements this.list = this.getTiddlerList(); var members = [], @@ -88,27 +89,20 @@ ListWidget.prototype.makeItemTemplate = function(title) { template = this.editTemplate; } // Compose the transclusion of the template - if(this.hasAttribute("hackTemplate")) { - templateTree = [{type: "transclude", attributes: {tiddler: {type: "string", value: title}}}]; + if(template) { + templateTree = [{type: "transclude", attributes: {tiddler: {type: "string", value: template}}}]; } else { - if(template) { - templateTree = [{type: "transclude", attributes: {tiddler: {type: "string", value: template}}}]; + if(this.parseTreeNode.children && this.parseTreeNode.children.length > 0) { + templateTree = this.parseTreeNode.children; } else { - if(this.parseTreeNode.children && this.parseTreeNode.children.length > 0) { - templateTree = this.parseTreeNode.children; - } else { - // Default template is a link to the title - templateTree = [{type: "element", tag: this.parseTreeNode.isBlock ? "div" : "span", children: [{type: "link", attributes: {to: {type: "string", value: title}}, children: [ - {type: "text", text: title} - ]}]}]; - } - } - if(!this.hasAttribute("hackCurrentTiddler")) { - templateTree = [{type: "tiddler", attributes: {tiddler: {type: "string", value: title}}, children: templateTree}] + // Default template is a link to the title + templateTree = [{type: "element", tag: this.parseTreeNode.isBlock ? "div" : "span", children: [{type: "link", attributes: {to: {type: "string", value: title}}, children: [ + {type: "text", text: title} + ]}]}]; } } // Return the list item - return {type: "listitem", itemTitle: title, children: templateTree}; + return {type: "listitem", itemTitle: title, variableName: this.variableName, children: templateTree}; }; /* @@ -242,7 +236,7 @@ Compute the internal state of the widget */ ListItemWidget.prototype.execute = function() { // Set the current list item title - this.setVariable("listItem",this.parseTreeNode.itemTitle); + this.setVariable(this.parseTreeNode.variableName,this.parseTreeNode.itemTitle); // Construct the child widgets this.makeChildWidgets(); }; diff --git a/core/ui/TiddlerFields.tid b/core/ui/TiddlerFields.tid index 2f5689dc4..897615dd0 100644 --- a/core/ui/TiddlerFields.tid +++ b/core/ui/TiddlerFields.tid @@ -1,5 +1,5 @@ title: $:/core/ui/TiddlerFields -
TiddlerFourTiddlerOneTiddlerThreeTiddlerTwo
"); + expect(wrapper.innerHTML).toBe("(TiddlerFour)(TiddlerOne)(TiddlerThree)(TiddlerTwo)
"); }); it("should deal with the list widget and empty lists", function() { diff --git a/editions/tw5.com/tiddlers/widgets/ListWidget.tid b/editions/tw5.com/tiddlers/widgets/ListWidget.tid index 75e731d43..e2cd9528a 100644 --- a/editions/tw5.com/tiddlers/widgets/ListWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ListWidget.tid @@ -24,16 +24,13 @@ The content of the `<$list>` widget is an optional template to use for rendering |filter |The TiddlerFilter to display | |template |The title of a template tiddler for rendering each tiddler in the list | |editTemplate |An alternative template to use for DraftTiddlers in edit mode | +|variable |The [[widget variable|WidgetVariables]] name to be assigned the title of each tiddler in the list. Defaults to ''currentTiddler'' | |emptyMessage |Message to be displayed when the list is empty | |listview |Optional name of module responsible for animating/processing the list | |history |The title of the tiddler containing the navigation history | -|hackTemplate |If this attribute is present then the list items are directly transcluded without altering the current tiddler or using a template | -|hackCurrentTiddler |If this attribute is present then the template is directly transcluded without altering the current tiddler | //`listview` and `history` are temporarily unimplemented // -//`hackTemplate` and `hackCurrentTiddler` are temporary hacks that will be removed// - !! Handling edit mode The `<$list>` widget can optionally render draft tiddlers through a different template tiddler than ordinary tiddlers -- see DraftMechanism for a discussion of how this capability is used.