mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-16 17:29:43 +00:00
04e91245cb
Now there is now longer a dummy DOM element corresponding to the macro itself. Instead, macros must create a single element child. This allows us to more easily fit Bootstrap's requirements for HTML layout (eg, that problem with links in navbars not being recognised). The refactoring isn't complete, there are still a few bugs to chase down
87 lines
2.0 KiB
JavaScript
87 lines
2.0 KiB
JavaScript
/*\
|
|
title: $:/core/modules/macros/list.js
|
|
type: application/javascript
|
|
module-type: macro
|
|
|
|
List macro
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
var handlers = {
|
|
all: function(wiki) {
|
|
return wiki.getTiddlers("title","excludeLists");
|
|
},
|
|
missing: function(wiki) {
|
|
return wiki.getMissingTitles();
|
|
},
|
|
orphans: function(wiki) {
|
|
return wiki.getOrphanTitles();
|
|
},
|
|
shadowed: function(wiki) {
|
|
return wiki.getShadowTitles();
|
|
},
|
|
touched: function(wiki) {
|
|
// Server syncing isn't implemented yet
|
|
return [];
|
|
},
|
|
filter: function(wiki) {
|
|
// Filters aren't implemented yet
|
|
return [];
|
|
}
|
|
};
|
|
|
|
exports.info = {
|
|
name: "list",
|
|
dependentAll: true, // Tiddlers containing <<list>> macro are dependent on every tiddler
|
|
params: {
|
|
type: {byName: "default", type: "text"},
|
|
template: {byName: true, type: "tiddler"},
|
|
emptyMessage: {byName: true, type: "text"}
|
|
}
|
|
};
|
|
|
|
|
|
exports.executeMacro = function() {
|
|
var templateType = "text/x-tiddlywiki",
|
|
templateText = "<<view title link>>",
|
|
template = this.params.template ? this.wiki.getTiddler(this.params.template) : null,
|
|
children = [],
|
|
t,
|
|
parents = this.parents,
|
|
attributes = {};
|
|
if(template) {
|
|
parents = parents.slice(0);
|
|
parents.push(template.title);
|
|
templateType = template.type;
|
|
templateText = template.text;
|
|
}
|
|
var handler = handlers[this.params.type];
|
|
handler = handler || handlers.all;
|
|
var tiddlers = handler(this.wiki);
|
|
if(this.classes) {
|
|
$tw.utils.pushTop(attributes["class"],this.classes);
|
|
}
|
|
if(tiddlers.length === 0) {
|
|
return $tw.Tree.Text(this.params.emptyMessage || "");
|
|
} else {
|
|
var templateTree = this.wiki.parseText(templateType,templateText).tree;
|
|
for(t=0; t<tiddlers.length; t++) {
|
|
var cloneTemplate = [];
|
|
for(var c=0; c<templateTree.length; c++) {
|
|
cloneTemplate.push(templateTree[c].clone());
|
|
}
|
|
var listNode = $tw.Tree.Element("li",null,cloneTemplate);
|
|
listNode.execute(parents,tiddlers[t]);
|
|
children.push(listNode);
|
|
}
|
|
return $tw.Tree.Element("ul",attributes,children);
|
|
}
|
|
};
|
|
|
|
})();
|