From a1ca53fa9bab218719b582bd553a578a477666c9 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Tue, 6 Jan 2015 14:31:20 +0100 Subject: [PATCH 1/2] implements list iterator variables, see #1328 provides <>, <> and <> --- core/modules/widgets/list.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/core/modules/widgets/list.js b/core/modules/widgets/list.js index 0138e0837..60f4af856 100755 --- a/core/modules/widgets/list.js +++ b/core/modules/widgets/list.js @@ -60,16 +60,18 @@ ListWidget.prototype.execute = function() { this.variableName = this.getAttribute("variable","currentTiddler"); this.storyViewName = this.getAttribute("storyview"); this.historyTitle = this.getAttribute("history"); + this.iterator = this.getAttribute("iterator","iterator"); // Compose the list elements this.list = this.getTiddlerList(); var members = [], - self = this; + self = this, + count = self.list.length; // Check for an empty list - if(this.list.length === 0) { + if(0 === count) { members = this.getEmptyMessage(); } else { $tw.utils.each(this.list,function(title,index) { - members.push(self.makeItemTemplate(title)); + members.push(self.makeItemTemplate(title, index, count, self.iterator)); }); } // Construct the child widgets @@ -96,7 +98,7 @@ ListWidget.prototype.getEmptyMessage = function() { /* Compose the template for a list item */ -ListWidget.prototype.makeItemTemplate = function(title) { +ListWidget.prototype.makeItemTemplate = function(title, index, count, iterator) { // Check if the tiddler is a draft var tiddler = this.wiki.getTiddler(title), isDraft = tiddler && tiddler.hasField("draft.of"), @@ -119,7 +121,15 @@ ListWidget.prototype.makeItemTemplate = function(title) { } } // Return the list item - return {type: "listitem", itemTitle: title, variableName: this.variableName, children: templateTree}; + return { + type: "listitem", + itemTitle: title, + variableName: this.variableName, + children: templateTree, + index: index, + count: count, + iterator: iterator + }; }; /* @@ -291,8 +301,13 @@ ListItemWidget.prototype.render = function(parent,nextSibling) { Compute the internal state of the widget */ ListItemWidget.prototype.execute = function() { + var item = this.parseTreeNode; // Set the current list item title - this.setVariable(this.parseTreeNode.variableName,this.parseTreeNode.itemTitle); + this.setVariable(item.variableName,item.itemTitle); + this.setVariable(item.iterator,(item.index + 1).toString()); + this.setVariable(item.iterator + "-even",item.index % 2 == 1 ? 'true' : ''); + this.setVariable(item.iterator + "-last",item.index + 1 == item.count ? 'true' : ''); + // Construct the child widgets this.makeChildWidgets(); }; From 0dd3ad5e3823c565b6ba7223a866a9d06407db64 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Tue, 6 Jan 2015 14:40:48 +0100 Subject: [PATCH 2/2] =?UTF-8?q?updated=20false=20states=20=E2=80=94=20look?= =?UTF-8?q?s=20more=20conclusive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/modules/widgets/list.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/modules/widgets/list.js b/core/modules/widgets/list.js index 60f4af856..f18e5fc2f 100755 --- a/core/modules/widgets/list.js +++ b/core/modules/widgets/list.js @@ -305,8 +305,8 @@ ListItemWidget.prototype.execute = function() { // Set the current list item title this.setVariable(item.variableName,item.itemTitle); this.setVariable(item.iterator,(item.index + 1).toString()); - this.setVariable(item.iterator + "-even",item.index % 2 == 1 ? 'true' : ''); - this.setVariable(item.iterator + "-last",item.index + 1 == item.count ? 'true' : ''); + this.setVariable(item.iterator + "-even",item.index % 2 == 1 ? 'true' : 'false'); + this.setVariable(item.iterator + "-last",item.index + 1 == item.count ? 'true' : 'false'); // Construct the child widgets this.makeChildWidgets();